How to get a list of all users registered before a given date?

Method #1: The pre_user_query hook: There are not many filters available, but you can try the pre_user_query hook: // Add filter: add_action( ‘pre_user_query’, ‘wpse_filter_by_reg_date’ ); // Query: $query = new WP_User_Query( $args ); // Remove filter: remove_action( ‘pre_user_query’, ‘wpse_filter_by_reg_date’ ); where the filter callback is: /** * Filter WP_User_Query by user_registered date * * @see … Read more

How Do I Add User Custom Field to REST API Response?

I got it. Turns out the tutorial I was looking at was old and I was using the wrong WP function. I was using register_api_field but the correct one to use is register_rest_field. It goes like this… function facebook_add_user_data() { register_rest_field( ‘user’, ‘facebook’, array( ‘get_callback’ => ‘rest_get_user_field’, ‘update_callback’ => null, ‘schema’ => null, ) ); … Read more

get_template_part not working with ajax

get_template_part() includes the PHP file, which will break $resp. You need to use output buffering to capture the output into a variable: ob_start(); get_template_part( ‘templates/update’, ‘profile’ ); $data = ob_get_clean(); $resp = array( ‘success’ => true, ‘data’ => $data );

How to add default images into theme customizer image control?

Our journey starts here with the WP_Customize_Background_Image_Control class, which is a WP_Customize_Image_Control. I’d imagine offering these built-in backgrounds in a new tab alongside the existing Upload New and Uploaded tabs. There are at least two ways of achieving the following: either creating your own modified class based off of the WP_Customize_Background_Image_Control class, or altering its … Read more

if post id matches these id’s then do this

This looks almost correct. Let’s have a look at is_single(): Works for any post type, except attachments and pages… So if the given ID isn’t that of a page or attachment post type then you can use the function as so: if( is_single( 2578 ) ) { /* … */ } else { /* … … Read more

Hooking new functions to actions + passing parameters

For this example lets say we have the following do_action(‘bt_custom_action’, get_the_ID(), get_the_title(), get_the_content()); The arguments that will be passed to add_action would be in this order the post id the post title the post content By default if we hook into our do_action without any arguments, like this add_action(‘bt_custom_action’, ‘bt_callback_func’); Our call back function “gets” … Read more

where to include a php file

Variables have a certain scope. The PHP Manual explains that in detail. So when you set a variable you should know in which scope those are set. This depends on where you set them and how that file gets included. As Rarst already suggested, the function.php file is an ideal place as it gets included … Read more