How to bulk delete all users with no posts?

If you have a large number of users to delete, you might consder using the wp user delete wp-cli command to avoid script timeouts. Here’s an example of a SQL query to delete all users without posts of any type and status. You can therefore try this untested one-liner: wp user delete $(wp db query … Read more

How to wrap oEmbed-embedded video in DIV tags inside the_content?

The embed_oembed_html filter runs before an oEmbed resource’s HTML is outputted, so you could hook into this and wrap the output in a div as below. I can’t think of a simple way of wrapping the other content. add_filter(’embed_oembed_html’, ‘my_embed_oembed_html’, 99, 4); function my_embed_oembed_html($html, $url, $attr, $post_id) { return ‘<div id=”video”>’ . $html . ‘</div>’; … Read more

Removing Image and Caption Dimension Attributes

it might not be the exact answer you’re after but i think i just found a pretty good workaround. Iv’e taken the following code from the twenty-eleven theme CSS (who’s neatly responsive imho): /* Images */ .entry-content img, .comment-content img, .widget img { max-width: 97.5%; /* Fluid images for posts, comments, and widgets */ } … Read more

How to get shortcode’s input values inside a filter?

Using a global variable will work. Here’s a demonstration: function wpse_shortcode_function( $atts ){ // User provided values are stored in $atts. // Default values are passed to shortcode_atts() below. // Merged values are stored in the $a array. $a = shortcode_atts( [ ‘id’ => false, ], $atts ); // Set global variable $value using value … Read more

Sanitize and data validation with apply_filters() function

There’s some confusion here, because not all of these are validation, there are 2 others that are necessary to understand what’s appropriate: validation sanitisation escaping Sanitisation Sanitisation makes things clean and well formed This cleans up the data, e.g. trimming trailing spaces, removing letters in a number field, making an all lowercase field all lowercase, … Read more

Query WP REST API v2 by multiple meta keys

Adding a custom endpoint is pretty straightforward. I also modified the url to look more like http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 function wp_json_namespace_v2__init() { // create json-api endpoint add_action(‘rest_api_init’, function () { // http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 register_rest_route(‘namespace/v2’, ‘/posts’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘wp_json_namespace_v2__posts’, ‘permission_callback’ => function (WP_REST_Request $request) { return true; } )); }); // handle the request … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)