Changing Gutenberg / WP block editor width only on pages, not posts or other taxonomies

Because the WordPress hook add_theme_support( ‘editor-styles’ ); adds the css in the style-editor.css and appends the class .editor-styles-wrapper before my .wp-block, the usage of the body classes for page vs. post styles fails. Instead I use the answer from here, from David Walsh, to add the styles independently to the wp admin area: // Update … Read more

Making a class available via actions filters

Build some kind of a registry where other plugins can register new tabs. Let’s say your plugin’s admin page handler is called Main_Controller: class Main_Controller { protected $tabs; public function __construct() { $this->tabs = new Tab_List; do_action( ‘register_tabs’, $this->tabs ); } public function create_tabs() { $all_tabs = $this->tabs->get_tabs(); if ( empty ( $all_tabs ) ) … Read more

Which hook is fired when inserting media into a post

The add_attachment action is fired when the wp_insert_attachment() function is called to add an item to the media library. Images are added to posts after going into the media library first. Even when adding via the post editor, items are added to the library with wp_insert_attachment() then to the post. add_action( ‘add_attachment’, function( $post_ID ) … Read more

How to get list of all hooks of current theme / plugin?

As of 2016-09-25, there is no ideal solution. The WP-Parser does the job, but you need to set up a special WP site to run it. WooCommerce’s Hook-docs is something much simpler, and can be easily tweaked. I just wrote a long comment on the topic here: https://github.com/ApiGen/ApiGen/issues/307#issuecomment-249349187

Apply a filter only once

There is no native WordPress hook called add_filter_once(). This is an custom solution which will help you to run your hook only once. For example if inside a loop or whatever situation you are facing. However, The basic idea is to check when you need to stop using your hook and simply remove_hook from WordPress … Read more

Change email from and display name with a filter action

A couple possibilities. Use the settings API to add a form field somewhere in your admin area where the user can enter the email they want to use. Retrieve it in your hooked function with get_option. This would be the way to go if you’re going to use the same from email everywhere. <?php add_filter(‘wp_mail_from’, … Read more

how to remove filter from wordpress shortcode output

Filters on the_content are not applied on a “per shortcode” basis. Post content is passed to the first filter, and then the altered post content is passed to the second filter, and then the content altered by the first two filters is passed to the third, and so on. You can’t remove a the_content filter, … Read more

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