Shortcode Inside Class Not Working

if you use any hooks, filters or shortcodes with class methods, you have three options. either declare it in the context of an instance, in which case, you can refer to the instance of the class. class myClass { function __construct() { add_shortcode(‘my_shortcode_name’, [ $this, ‘shortcode’ ]); } function shortcode() { //your code here //properties … Read more

Override WP Class Private Function

As @jacob suggest, you can add subscriber role into that array using add_filter . add below code in active theme’s functions.php file. add_filter( ‘wf_user_permission_roles’, ‘wf_user_permission_roles_callback’ ) ; function wf_user_permission_roles_callback( $roles ) { $roles[] = ‘subscriber’; return $roles; }

problem with implementing widget via the_content()

Its extremely difficult to remove a filter that’s added as part of an object. You have get the reference to the original object and pass that as part of the function to remove. Luckily the filter was added at an unusual priority, so you will probably be safe removing all filters at priority 100: remove_all_filters( … Read more

Conditional tags inside a class

Your real problem is the god class. You put rendering, sanitation, validation, saving and fetching data, and registration into one class. Separate your tasks to make it it OOP, and let the main class be a very simple front controller that handles the initial registration only. Here is a rough start, illustrating how I would … Read more

Extend a class of a plugin

Woocommerce support sent me the solution of my problem: function unregister_parent_hook() { if ( function_exists( ‘wc_dve’ ) ) { $instance = wc_dve(); remove_action( ‘woocommerce_after_order_notes’, array( $instance, ‘exemption_field’ ) ); } }

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