Get list of shortcodes from content

Here’s one way: You can look at has_shortcode() and find the parsing there: preg_match_all( “https://wordpress.stackexchange.com/” . get_shortcode_regex() . “https://wordpress.stackexchange.com/”, $content, $matches, PREG_SET_ORDER ); using the get_shortcode_regex() function for the regex pattern. For non empty matches, you can then loop through them and collect the full shortcode matches with: $shortcodes = []; foreach( $matches as $shortcode … Read more

Bare minimum to include in PHP file to use WP functions? [duplicate]

You want to include wp-load.php or wp-blog-header.php not wp-settings.php or wp-config.php directly. If you look at the code in wp-load.php you will see why. wp-load.php looks for wp-config.php in several different places, including one level above the rest of the install. If you include wp-config.php directly the script will fail if wp-config.php has been moved. … Read more

Custom widget using get_categories select menu dropdown

Ok I found a solution thanks to this: Using wp_dropdown_categories in widget options Here is the code I used instead: function form( $instance ) { /* Default Widget Settings */ $defaults = array( ‘title’ => ‘Highlight Category’ ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!– Widget Title –> <p> <label for=”<?php echo $this->get_field_id( … Read more

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 );

Using a loop to display terms associated with a post

This answer was a joint effort with tnorthcutt so I made it community wiki. There are several interesting functions available: the_taxonomies(), which calls get_the_taxonomies(), which in turn calls get_object_taxonomies() and wp_get_object_terms(). the_taxonomies() is a documented template tag and is a light wrapper around a call to get_the_taxonomies(), which is undocumented. get_object_taxonomies() returns a list of … Read more