xmlrpc_enabled filter not called

To remove the HTML link: remove_action( ‘wp_head’, ‘rsd_link’ ); To stop all requests to xmlrpc.php for RSD per XML-RPC: if ( defined( ‘XMLRPC_REQUEST’ ) && XMLRPC_REQUEST ) ) exit; This is plugin territory. Never use this code in a theme.

Filter media library items by size

So far, the only workable solution I’ve come up with is to run a new query within the ajax_query_attachments_args filter. It’s definitely not ideal but works as expected in the absence of a more efficient alternative: function restrict_media_library_by_width($query) { $include = array(); $exclude = array(); $temp_query = new WP_Query($query); if($temp_query->have_posts()) { while($temp_query->have_posts()) { $temp_query->the_post(); $meta … Read more

How to auto-translate custom user roles?

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, $domain ) { $plugin_domain = ‘plugin-text-domain’; $roles = array( ‘Someone’, … Read more

How to add icons to post listing (edit.php) in admin

We can style the table with CSS and dashicons. Example: For our video category, we can use for example: .edit-php .wp-list-table tr.category-video td.post-title strong:before { content: “\f126”; color: #ccc; display: inline-block; width: 20px; height: 20px; margin: 0 4px; font-size: 20px; line-height: 20px; font-family: “dashicons”; font-weight: normal; vertical-align: top; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } where we … Read more

What do add_filters() and apply_filter() do?

What are you attempting to filter? I’ll assume you’re trying to add a filter to a filter hook called posts_before. In which case, you need to add your filter to this hook, via add_filter(): function mytheme_filter_posts_before( $where=””, $date) { $where .= ” AND post_date < ‘” . $date . “‘”; return $where; } // Add … Read more

Modify WordPress Rest Api Request/Response

I think I found answer to your question, it is: rest_{$this->post_type}_query filter hook. With this hook you are able to directly edit internal WP_Query parameter. For example, if you’d like to internally sort Posts by post_title by default, then you’d have to write something like this: function order_rest_post_by_post_title($args, $request) { $args[‘orderby’] = ‘post_title’; $args[‘order’] = … Read more

Check if a filter or function has been already been called

You can use a static variable to achieve this: add_filter( ‘the_content’, ‘asdf_the_content’, 99, 1 ); function asdf_the_content( $content ) { static $has_run = false; if ( $has_run ) { return $content; } $has_run = true; // check if the_content has already been // filtered by some other function $content = ucwords( $content ); return $content; … Read more

Filter hook before create order WooCommerce

Stumbled on this looking for the same thing which I’ve now figured out (Woocommerce 3.x)… add_filter( ‘woocommerce_checkout_create_order’, ‘mbm_alter_shipping’, 10, 1 ); function mbm_alter_shipping ($order) { if ($something == $condition) { $address = array( ‘first_name’ => ‘Martin’, ‘last_name’ => ‘Stevens’, ‘company’ => ‘MBM Studio’, ’email’ => ‘[email protected]’, ‘phone’ => ‘777-777-777-777’, ‘address_1′ => ’99 Arcadia Avenue’, ‘address_2’ … Read more