Recently, I was trying to do a user query on a WordPress site, but found that the query wasn’t able to fetch the users I wanted it to. This was because when an AJAX request or a WP-Cron job is being executed, there is no currently logged in user, so any parts of a user […]
The function below can be used to get a list of all WordPress pages that contain a shortcode. View the code on Gist. You can use it like this: get_pages_with_shortcode( ‘gravityform’ ), replacing gravityform with the shortcode you’re interested in searching for. The array it returns look like this, with the post IDs as the […]
The functions below can be used to get a list of all Gravity Forms whose fields have a specific CSS class: View the code on Gist. Calling the first function looks like get_gravity_forms_with_css_class( ‘list-users2’ ) and the results it returns look like this: The keys of the array include the form ID and title. Each […]
If you have an indexed array of objects, and you want to remove duplicates by comparing a specific property in each object, a function like the remove_duplicate_models() one below can be used. View the code on Gist. The result is: View the code on Gist.
WordPress’ get_super_admins() function can be used to get the logins for all the users on the current site. Its return value is in array that looks like: [ ‘maryann123’, ‘johnsmith456’, ‘annie-mcarthur’ ]. If you want WP_User objects for each of those users though, you can use get_users() function and pass in get_super_admins() as the ‘login__in‘ argument, like this: View […]
I’ve been doing some work lately with the Beaver Builder page builder for WordPress. For one feature, I needed to get a list of all the Beaver Builder modules that exist on a page. I couldn’t find any native functionality in the plugin to get that data though, so I built the class below to […]
I was recently working on a headless WordPress project. It has a React frontend that uses the WP REST API to communicate with the WP backend. I had some pages that I needed to only be accessible to logged-in users, and was looking for a way to lock down access to those Pages. By default, […]
If you want to check if a remote image file exists on a WordPress site but don’t necessarily want to fetch or download that file, this lightweight helper function can be used for that purpose: View the code on Gist. It can be used like this: View the code on Gist.
The function below can be used for getting the WP_Term object for the term that’s currently being edited on the term.php page in the WordPress admin. Just make sure that when you call this, the global $taxnow variable has been set. Using WP’s admin_init hook, or anything that fires after that point will work. View the code […]
WordPress doesn’t store a last modified date for navigation menus, so I created the set of functions below for keeping track of when menus were last updated. Whenever a menu is created or updated, a timestamp will be saved for it. You can then get the date modified timestamp for any menu using wds_get_menu_modified_timestamp( $menu_id ). […]
I built the following class that downloads a remote image, moves it into the /uploads/ directory of your site, adds it to WordPress as a new attachment and returns to you the attachment ID. Example usage is shown further down the page. View the code on Gist. Example Usage Below are two examples of how […]
To transfer WordPress.org plugin ownership to someone else: Update the plugin’s readme.txt file, changing the Author, Author URI and Contributors in the plugin header and commit those changes to the SVN repository. Log in to wordpress.org and navigate to your plugin’s page. Click the “Advanced View” link in the right sidebar. From here, add and […]