How to add filter with 2 args?

function my_locate_template( $path, $template ){ $path = MY_INCLUDES_DIR . ‘/document/’. $template; return $path; } add_filter( ‘documents_template’,’my_locate_template’, 10, 2 ); add_filter takes 4 variables. The first and second are required. 1. name of the filter, 2. name of the function. The third is the priority (when does the function gets fired). And the fourth is the … Read more

Changing JPEG compression depending on image size

A very special filter The jpeg_quality filter is a really special one: It gets used in three different cases and you’ve to use the second argument to determine, if you want to use the filter or not. Don’t let it do everything The main problem for such a special filter is, that it may fire … Read more

WordPress 3.9 – Trouble Editing TinyMCE 4.0

The strings was new, not more for your requirements. This is the new content of the hook. array ( ‘selector’ => ‘#content’, ‘resize’ => ‘vertical’, ‘menubar’ => false, ‘wpautop’ => true, ‘indent’ => false, ‘toolbar1’ => ‘template,|,bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,wp_fullscreen,wp_adv’, ‘toolbar2’ => ‘formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help’, ‘toolbar3’ => ”, ‘toolbar4’ => ”, ‘tabfocus_elements’ => ‘insert-media-button,save-post’, ‘body_class’ => ‘content post-type-post post-status-draft post-format-standard’, … Read more

How many filter/action hooks are healthy?

As long as hooks don’t have anything hooked to them they are no-ops, that is do nearly nothing and have no considerable effect on runtime. It gets quite different when things are hooked and there are a lot of calls. Since you talk about customizing strings the good example would be gettext hook in core. … Read more

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