Tag Info

Hot answers tagged

6

I guess you have: the_content(); wp_link_pages(); in your theme file. So you can instead try the following (PHP 5.4+): /** * Append the wp_link_pages to the content. */ ! is_admin() && add_filter( 'the_content', function( $content ) { if( in_the_loop() ) { $args = [ 'echo' => false ]; // <-- Adjust the arguments ...


5

Both approaches are not mutually exclusive. As @gmazzap said, don’t create a callback hell. But you can provide an initial hook, so other developers don’t have to rely on the rather slow function_exists() checks. Example In your plugin, provide a hook that other developers can use to call your classes and functions safely. add_action( 'wp_loaded', [new ...


4

The best way to solve this is to simplify your code. Right now, ScriptQueuer::QueueCss() is just a static method, and it is getting its data too late. You could use an immutable object instead and then just register one of its methods as callback. Example: class Enqueuer { private $stylesheets; public function __construct( ArrayObject ...


4

Surely this approach has some benefits, but has also some issues. It's not really easy to use If the target of your plugin are WordPress developers, they will be very familiar with plugin API, but end users are not. For a non-developer, something like: $data = give_me_the_data(); It's easier to understand, remember and type than: $data = ...


3

Make the hook name specific to what it does, not where it is called. Do not pass multiple parameters, because that is not easy to extend. Pass a parameter object instead. Example Create the parameter object with an interface for dependency injection: interface Validation_Parameters { public function id(); public function errors(); // not a ...


2

The thing with class methods is that unless they're static, they belong to an object. And in your case your object is: new WC_Admin_Taxonomies_new(); Which means PHP will create the object and keep it in memory. But unfortunately, since you're not assigning this object to a variable, you have no way of referencing it later in your code. Off the top of my ...


1

The publish_{post-type} action is triggered only when the post change from any post status (not published) to published; for example, if the post is already published and you edit it, the publish_{post-type} action is not triggered. I think you need to hook your function to save_post_{post_type} action, which is triggered every time a post is saved, not ...


1

I believe you are looking for activated_plugin and deactivated_plugin, see the wordpress documentation:


1

This is not possible, since the output of your gtp_users_table_content function for the manage_users_custom_column action hook is printed within predefined <td></td> elements. However, you can put a simple div with a class around your output: // Add users table lead purchase column content add_action( 'manage_users_custom_column', ...


1

You need to insert your term after the init hook (i.e. when the taxonomy is registered): function create_tax() { $args = array(...); register_taxonomy('custom_tax', array('post'), $args); // Now we're safe $result = wp_insert_term('Test Term', 'custom_tax', array('parent'=>0) ); }



Only top voted, non community-wiki answers of a minimum length are eligible