How do you render_callback for register_block_type to a method in another class?

Option 1 is the solution, here’s a smaller example: $obj = new Obj(); …. register_block_type( ‘my-plugin/my-block’, [ ‘editor_script’ => ‘editor-script-handle’, ‘render_callback’ => [ $obj, ‘block_save_function’ ] ] ); In that code [ $obj, ‘block_save_function’ ] is equivalent to $obj->block_save_function(…. The important thing to note, is that render_callback‘s value is a PHP callable type. You need … Read more

Current user in plugin returns NULL

Wait for the action plugins_loaded before you create the class instance. The pluggable functions are loaded at this time. From wp-settings.php: /** * Fires once activated plugins have loaded. * * Pluggable functions are also available at this point in the loading order. * * @since 1.5.0 */ do_action( ‘plugins_loaded’ ); I would even wait … Read more

When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?

You’re doing it correct @its_me. The latter, get_term_by() would be the best way, In my opinion , as I believe get_category_by_path uses get_term_by, just prepopulating the taxonomy to be category. Edit: As I mentioned in my comment, get_category_by_path is much less efficient, since it gets multiple terms,. and then compares the hierarchical path. get_term_by is … Read more

How to do conditional publishing?

That’s because the hook “transition_post_status” is called: After the post has been published or updated in the database After the status has been updated in the database. Based on your problem statement, I believe the hook you want is “pre_post_update”, as stated in relevant WordPress source code: /** * Fires immediately before an existing post … Read more

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