Tag Info

New answers tagged

0

The translate_user_role function is just a wrapper for translate_with_gettext_context, defining the context 'User role'. In this last function, there is the filter hook gettext_with_context, which provides the context as well as the currently used domain. So we could do this: function wpdev_141551_translate_user_roles( $translations, $text, $context, ...


3

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' => ...


3

wp_terms_checklist early trigger a filter 'wp_terms_checklist_args' so you can use that filter to add your filter and auto-remove it haver 1st run. This should be enough, however, once hooks are global variables, to be sure is better use some stronger check, a static variable inside a function is a simple and nice trick: function switch_terms_filter( $_set ...


0

I found that it required removing 4 filters/actions to undo WPML's home_url modification. Since I didn't know what else this might break, I ended up changing my site's logo to use site_url() which in my case was the same, but not changed by WPML. function disable_things(){ remove_filter( 'page_link', array( $this, 'permalink_filter' ), 1, 2 ); ...


0

What about taking a different approach? Keep the filter and in WPML -> Languages, chose "Use directory for default language". There you can specify a static file or create a "Root page". This page won't be connected to any language. It won't even show the language switcher (unless you use a custom template and play with the code).


0

I had this exact same issue, but it's a problem with the Jobroller theme (seeing as the custom post type is job_listing, I'm guessing you're using Jobroller as well). The Jobroller theme adds the custom columns to the job_listing custom post type using the function jr_edit_jobs_columns in the file jobroller/includes/admin/admin-post-types.php: function ...


1

add_filter('some_base_handle'.sanitize_title($string), ...) What he's doing here is a variable filter handle, and while "sanitize_title" might not be exactly the correct function to use here, it really depends on what the possible values of $string are and what the source of that $string is. Variable filter names can be handy if you have a lot of different ...


4

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I ...


2

These fields are created in Walker_Nav_Menu_Edit::start_el(). To change or to remove them, create a custom walker (example for another walker) that extends Walker_Nav_Menu_Edit and uses other or less fields. Then filter wp_edit_nav_menu_walker and return the class name of your walker. Pseudo-code: class Walker_Nav_Menu_Edit_Simple extends ...


1

Maybe you use the hook deleted_post and create a rewrite. The hook runs just after a post or page is deleted. Action function arguments is post- or page-ID.


1

Per the Codex: relation (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. So you are on the right track, but your tax_query is wrong. relation is part of the outer tax_query array and not part of the top level query ...


1

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


0

If you want to make the output filterable, you simply need to define a custom filter, and pass the output through it. Your function outputs (echoes) this value: <h1>test</h1> If you want it to be filterable, you need to put that output in a PHP string. Instead of this: ?> <h1>test</h1> <?php Do something like this: ...


0

Note as of wordpress 3.8.2 the type of the plugin item passed to this function has changed and it is now an object. /** * @package Plugin_Filter * @version 2.0 */ /* Plugin Name: Plugin Filter Plugin URI: http://www.brideonline.com.au/ Description: Removes certain plugins from being updated. Author: Ben Wise Version: 2.0 Author URI: ...


1

Even if is not very flexible filter you can use the gettex hook. Only be aware that this filter runs for every string being translated, so can affect performarce if over-used. To narrow the performance impact you can add it only of admin footer, and remove it just after had use it: add_action('admin_footer', function() { add_filter( 'gettext', ...


0

Firstly, you will need your code to store the exclude value somewhere. Since you don't want to use a global ( rightly so ), you have few remaining options: a class the class you already have a closure standard APIs Option 1 a new object/class Here we create an object, that holds the category you're excluding, and some logic to exclude it. class ...


0

First of all 'posts_where' filter (just like all other 'posts_*' filters) is not very reliable, because you assume that where clause is the standard one, but if other plugin use same filter before or after the your, result is not the expected, in best case, and in worst case you get only errors for bad sql query. After that, why use a filter when you can ...


0

I see two approaches to this, depending on rest of your architecture. Make filter part method of widget class, instead of function. Assign data to its object property internally and method will have clean access to it, without polluting global namespace. Make custom query variable. Pass your data to the WP_Query constructor and have filter function check ...


0

The function that parses the shortcode, do_shortcode is added as a filter on the_content by default, at priority 11. You can remove it using remove_filter: remove_filter( 'the_content', 'do_shortcode', 11 ); Call this right before you're actually using the_content, and add it afterwards (in the unlikely case that it's needed after that): remove_filter( ...


0

Ok so I worked out what I had to do. @Rarst gave me some guidance which helped massively and I think his idea (in the comments of his question) would work but I haven't actually tested it. Anyway, I fixed it by adding a $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; variable in, and, having changed $content = $post->post_content; to ...


1

For posts is set up by loop (see setup_postdata()) it is split into parts and array of those parts is assigned to global $pages variable. Even if it's not paginated this is still where data goes. Then that variable is actually where get_the_content() looks for post content to process and output, not actual post object. In your function you are overriding ...


0

You need to set the number of arguments your filter accepts: add_filter( 'the_title', 'alternatives_title', 10 /* Priority */, 2 /* Arguments */ ); And you only need to use the_title (there is no get_the_title filter).


2

I copied your code to a file in my home directory on my Ubuntu box, removed the weird character that @s_ha_dum noticed, and ran it. It worked as I'd expect. Code: <?php function get_the_post_imgs($oldPostContent) { $newPostContent = $oldPostContent; $newPostContent = preg_replace_callback( "/<img.*src=[\"']([^\"']*)[\"'].*>/i", ...


2

Your code doesn't really do any "user logged in" check, and you aren't using a couple of the globals you import. function restrict_access_to_unlogged_users($template) { if (!is_user_logged_in()) { $template = get_stylesheet_directory() . '/need-login.php'; } return $template; } add_filter( 'page_template', 'restrict_access_to_unlogged_users', 20 ...


2

What Adam Brown's site says is that the hook no longer appears in 3.8. I greped a 3.9 and found: bash-4.2# grep -Rni 'content_save_pre' * wp-includes/kses.php:1327: * The wp_filter_post_kses() function is added to the 'content_save_pre', wp-includes/kses.php:1344: add_filter('content_save_pre', 'wp_filter_post_kses'); wp-includes/kses.php:1370: ...


3

'the_posts' is an action fired everytime WP_Query get posts, for main query and for other secondary queries, so when you do something like: $foo = new WP_Query($args); in a widget or elsewhere (shortcode, related posts...) 'the_posts' is triggered again. However there is only one main query, so you can use a conditional and do what you do only if the ...


0

I think what you might be looking for is combination of a plugin like https://wordpress.org/plugins/query-multiple-taxonomies/ and hooking into pre_get_posts if you are looping a list of posts. That plugin is in use on http://theboatworksnews.com/ so you can play with the projects section/filters and see if that matches what you're looking for.


0

Looks like it is a privilege thing: Adding those tags as an admin works, while with other users having less privileges (editor, etc) does not.


1

What if you add your filter, with the priority 11, so it goes after? That's ugly, but might work in your case. add_filter( 'manage_edit-comments_columns', function( $default ) { unset( $default['smr_comment_rate'] ); return $default; }, 11, 1 );


3

Use a use statement: add_filter( 'single_template', function ( $template ) use ( $name ) { Or just pass all templates at once, and create just one function: add_filter( 'single_template', function ( $file ) use ( $templates ) { global $post; if ( in_array ( $post->post_type, $templates ) ) return __DIR__ . ...


1

Remove your filter and add orderby'=>'post__in'. That sort order in not automatic when you supply IDs. $wp_query = new WP_Query( array( 'post__in' => $arrayPostsIds, 'ignore_sticky_posts' => true, 'date_query' => $date_query , 'orderby' => 'post__in', ) );


2

You are using wrong number of arguments in add_filter, you specified to get 2 arguments and you are looking for third one: Update your add_filter code to this: add_filter( 'manage_post_tag_custom_column' , 'my_custom_column' , 10 , 3 ); The 3 in the end tells the filter to provide all the three arguments to your function.



Top 50 recent answers are included