Tag Info

New answers tagged

0

The reason is that you can register native PHP functions as callbacks. Passing more parameters to them then they expect will raise a warning. Imagine a filter that can pass 6 parameters and trim() as callback. PHP would now raise an error: Warning: Wrong parameter count for trim() in … Some custom callbacks might also change their behavior depending ...


0

I've found some examples of using regular expressions to add some classes to the HTML. This works for me: add_filter('image_send_to_editor', 'add_class_to_image', 10, 8); with the following function: function add_class_to_image($html, $id, $caption, $title, $align, $url, $size, $alt='') { $classes_to_add = 'media-img'; if (preg_match('/<a.? ...


3

The difference would be negligible. The the_content filter is fired regardless of whether you use it or not because WordPress uses it for other things. So the only thing that would be performance related would be the complexity of your filter function. But since you'd probably be doing the same level of complexity in a template or in the filter function, ...


2

A page template might be more efficient. If you decide to use the filter, you should return the value: function str_load_table($content) { if(is_page('my-table')) { $my_content = 'pretend this is a table'; $content .= $my_content } return $content; }


0

The answer is to specify all the args on the add_filter() call, and then you can have both the array of posts and the query sent to the callback. add_filter( 'posts_results', 'do_stuff', 10, 2 );


0

Here's what I ended up doing: <?php add_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); function wp_trim_excerpt( $text ) { remove_filter( 'the_content', 'my_content_filter' ); $text = apply_filters( 'the_content', $text ); add_filter( 'the_content', 'my_content_filter' ); return $text; } add_filter( 'the_content', ...


0

WordPress only holds the hooks information in global $wp_filter so you can check if a hook is registered with some specified function or not. you can also use function has_filter. But I guess you can not check that, it has been called or not on some specific execution point. But you can do this with PHP using global variable. Check this code add_filter( ...


0

Sorry folks - for those curious, I had already solved this later on in my functions.php file and forgot to turn this filter off (silly). Here's the better solution if anyone cares to comment or improve. Basically, I'm filtering out content based on user role (I have a custom user role as well) so that posts aren't shown to users who aren't allowed to see ...


0

I see a few things missing in your snippet/code. Each field (your location ones) need to include priority: 'priority' => 19, You defined 'type' as 'location' but did not define that field type. The repeated files in resume manager where you based this code on defines template files for education, experience etc. To define your own filter on ...


1

Almost exactly the same to brasofilo, my code below also accounts for different taxonomies and removes the checkbox for parent categories at the top level, only if they have children. This allows for other top level categories that are childless to still be selectable. I put this simple code my theme's functions.php file: class Category_Checklist { ...


0

I'm not sure how your current "hidden" checkbox code is working (there's an undefined $archive variable, in_category might not fire correctly in the context, and I doubt your post type is actually your_post_type). Just to make sure we get everything working, here is a complete solution for adding a checkbox to the edit post screen, where you can toggle it's ...


1

As @bonger said, let your filters accept a second argument, which will be the instance of WP_Query that's executing the filter, and check it is indeed the main query for an event: function single_posts_fields( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_singular( 'event' ) ) { // Do your stuff } } ...


1

Try this. First check if the original string length is less than or equal to passed in length, and if so, we ignore the $after parameter : function the_titlesmall($before = '', $after = '', $echo = true, $length = false) { $title = get_the_title(); if( strlen($title) <= $length ) $after = ''; if ( $length && is_numeric($length) ...


2

Because the credit data is saved in the attachment's post meta, not the main post: $credit = get_post_meta( $post->ID /* Wrong ID! */, 'credit', true ); Instead you need to catch the ID of the inserted image: function attach_image_credit( $images ) { $return = $images[0]; // Get the image ID from the unique class added by insert to editor: ...


0

If you want to add a class before each widget you should use the dynamic_sidebar_params filter. Another post explains this well. Here's the gist of it. function uft_add_nocontent_class($params) { $params[0]['before_widget'] = '<aside id="%1$s" class="widget %2$s nocontent">'; return $params; } add_filter('dynamic_sidebar_params', ...


0

in my opinion this is a valid scenario, its a solid way to offer your plugin as an interface to other plugins but still each plugin can be active or inactive and wp will not crash (in comparison to calling a method directly which may not exist because a plugin was not activated i solved it by passing an object, like so: // define action with param for ...


0

It looks like you're calling preparePDF( $wp_query ) inside your callback, but $wp_query isn't defined and the global $wp_query shouldn't be accessible there without global $wp_query. Try instead preparePDF( $query ) and use wp_reset_postsdata() to restore the global $post object. Another important thing is that you must run your preparePDF() function ...


0

if you create your own hook, here is example. // lets say we have three parameters [ https://codex.wordpress.org/Function_Reference/add_filter ] add_filter( 'filter_name', 'my_func', 10, 3 ); my_func( $first, $second, $third ) { // code } then implement hook: // [ https://codex.wordpress.org/Function_Reference/apply_filters ] echo apply_filters( ...


-2

Instead of having it be an "after" variable, add the ... where you are cutting the substring. Check the length of the string first, and if it's greater than 50, add ... when you cut the substring, in that line.


0

You should probably be doing this when it's being displayed, not when the sidebar is registered. For example, sidebar.php or whatever variant your theme is using for the sidebar in question. You're probably attempting to change it before it's been set.


0

If you used people and location as custom taxonomies, you'd be able to build them into a new WP Query instead. In fact, depending on how you're storing your custom fields, you might be able to do it through WP Query without going down the custom taxonomy route. Then, you don't need to post request anything - the query handles everything.


1

The filter wp_title won't pass $id to your function. Drop the parameter and instead retrieve it with get_queried_object_id(): function dw_listing_title( $title ) { if ( is_singular() && $id = get_queried_object_id() ) { // Modify $title as required } return $title; }


0

answer ^^ add_action( 'load-edit.php', function() { global $typenow; // Not our post type, bail out if( 'community' !== $typenow ) return; // Administrator users don't need this, bail out if( current_user_can('add_users') ) return; // Only the Mine tab fills this conditions, redirect if( !isset( $_GET['post_status'] ) && !isset( ...


0

We can different types of fields for 'Resume Manager' & save it. We can achieve this via filter, as follows, //code to add custom field for Resume Manager on front end add_filter( 'submit_resume_form_fields', 'wdm_customize_resume_fields' ); function wdm_customize_resume_fields($fields) { $fields['resume_fields']['candidate_address'] = array( ...


0

I wouldn't recommend disabling ssl verification - that leaves your system vulnerable to potential man in the middle attacks as explained in this SO post. Also, your use of sslv3 is most likely causing this issue now SPECIFICALLY because Authorize.net identified it as vulnerable to the POODLE compromise. Since that happened, many vendors removed the older ...


3

You have a syntax-ish error, or a spelling one. There is a space after "taxonomy" in your tax_query array. If that were the sum of it I'd have just posted a comment, but additionally that $query->tax_query->queries[] = $workspace_taxonomy_query; line is pointless. Nothing changes with or without it. Don't try to hack the array like that. Just use ...


0

I don't see where your posts are pulling from, just the category list, but you are most likely missing the post_count variable where you have your query args to retrieve the posts. post_count=-1 will return all, but it defaults to 10 (or whatever is set in your settings) if you do not specifically say otherwise.


1

Here's a slightly modified version of your code snippet: add_action( 'login_head', [ 'WPSE_Admin', 'plugin_setup' ] ); class WPSE_Admin { public static function plugin_setup() { add_filter( 'login_headerurl', [ 'WPSE_Admin', 'the_logo_url' ] ); } public function the_logo_url() { return get_bloginfo('url'); } } The ...


0

I think you are encountering a bug in _wp_translate_postdata() that makes it check edit_others_posts without providing any context for map_meta_cap and other filters to use in situations like yours (where you want a user to be able to edit specific posts that aren't theirs): https://core.trac.wordpress.org/ticket/30452#comment:5 It specifically has the ...


0

I believe the 'strange' character is one that exists outside of the standard character set. Some browsers and text editors will display this as a small square or rectangle, some may display a small dot, some may not display it at all. It could have crept in through a copy and paste, but that's just a guess. If commenting the tag out and adding a fresh one ...


0

I managed to fix this issue by commenting out the first body tag and placing a second body tag below like this: <!-- <body> --> <body <?php body_class( $class ); ?>> Now the site is working correctly. However the strange character is still appearing in the first body tag. Hope this helps someone.


0

Unsure of WP version compatibility, but taken from the Soil plugin module clean-up.php for Roots. Use in your theme's functions.php or similar. function clean_script_tag($input) { $input = str_replace("type='text/javascript' ", '', $input); return str_replace("'", '"', $input); } add_filter('script_loader_tag', 'clean_script_tag');


0

A prettier solution would be to disable the capability of creating a custom_post_type: Simply pass the the parameter 'create_posts' => false, in the capabilities array when calling register_post_type. $args = array( 'label' => __( 'Custom Post Type', 'text_domain' ), 'description' => __( 'Custom Post Type', ...


0

The comment form is generated from another domain via the iframe. While I was accessing the iframe using jQuery content() it returned me Permission denied to access. It means the Jetpack is Cross Site Scripting protected and you cannot edit the placeholder.


0

At the end of your function return the output as described in the documentation. return ob_get_clean(); Add the [myshorcode] shortcode to a text widget. By default, widgets are not rendered in text widgets so make sure you add this snippet to your plugin: add_filter('widget_text', 'do_shortcode');


2

Better solution if you want to disable this: use a plugin. Same code as from Christine's comments: https://wordpress.org/plugins/disable-emojis/ Same code that also fixes the smilies to be the older ones: https://wordpress.org/plugins/classic-smilies/ Source: Me, since I wrote that code in the first place. ...


15

We will hook into init and remove actions as followed: function disable_wp_emojicons() { // all actions related to emojis remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( ...


0

Thanks for raising this issue, it interests me as well. After searching everywhere for an acceptable solution, this is how I approach the problem on my site, at least for now: comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => '25' ))) If you change '25' to, say, '1000', this will give you pretty much 'infinite replies', ...



Top 50 recent answers are included