Filter translations (gettext strings) on specific admin pages

According with the codex, get_current_screen() has to be used later than admin_init hook. After a few tests, it seems that the safiest way is to use current_screen action hook instead of get_current_screen(): add_action(‘current_screen’, ‘current_screen_callback’); function current_screen_callback($screen) { if( is_object($screen) && $screen->post_type == ‘mycpt’ ) { add_filter( ‘gettext’, ‘theme_change_comments_label’, 99, 3 ); } } function theme_change_comments_label( … Read more

What does (10, 2) mean when used with add_filter

Have a look at the codex page for add_filter. The 10 is the $priority parameter (10 is default) which defines when your function will run in regards to the other functions which are attached to the nav_menu_css_class filter. 2 is the $accepted_args parameter which tells wordpress how many parameters the function you want to add … Read more

Where to hook into post content?

You can use the_content with an high prioriety (lower number). add_filter( ‘the_content’, function( $content ) { return ‘Hello World ‘.$content; }, 0); You can even use negative priority: add_filter( ‘the_content’, function( $content ) { return ‘Hello World ‘.$content; }, -10); Note that this will apply everytime ‘the_content’ is used, no matter the post type, or … Read more

Remove Editor From Homepage

There are a couple of issues with your approach By using the admin_init hook you won’t have any reference to the post object. This means you won’t be able to get the post ID or use anything like get_the_ID because the post won’t actually be loaded. You can see that in the order here https://codex.wordpress.org/Plugin_API/Action_Reference … Read more

How to pass/get data to/from the WooCommerce data-product_variations object?

jQuery(document).on(‘found_variation.wc-variation-form’, ‘form.variations_form’, function(event, variation_data) { //this is called when a valid productis found }); jQuery(document).on(‘change.wc-variation-form’, ‘form.variations_form’, function(event) { //this function is called when the user clicks or changes the dropdown }); The PHP function you are looking for is apply_filters( ‘woocommerce_available_variation’, array( ‘attributes’ => $variation->get_variation_attributes(), ‘availability_html’ => wc_get_stock_html( $variation ), ‘backorders_allowed’ => $variation->backorders_allowed(), ‘dimensions’ => … Read more

Is it possible to filter comments in a post so a user can only see the comments they have written?

Assuming your comment authors are intended to be registered users, the easiest way is probably to use a pre_get_comments action hook to modify the WP_Comment_Query object‘s user_id query var such that the query only returns comments from the current user: function wpse262203_restrict_comment_views( $comments_query ) { // Don’t interfere with comment results in the dashboard if( … Read more

Insert new element to array with add_filter

Filters work by calling each of the hooked callback functions (in priority order). The value to be filtered is passed to the first callback funtion. The returned value of that callback function is then passed to the second callback, and the returned value from that is passed onto third and so on, until all hooked … Read more

Earliest hook to reliably get $post/$posts

For all admin pages and front end pages except individual post edit screens (wp-admin/post.php), ‘wp’ is the most reliable hook for getting the global values. http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/class-wp.php.source.html#l486 You can see there that it fires immediately after WP::main() fires WP::register_globals(). The problem with using things like post_results and get_posts is that it will run every time you … Read more

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