Static vs Dynamic methods in WordPress

This question is about the famous debate on using Dynamic methods over static methods in classes. According to my research the widely acknowledged idea is to limit the use of static methods as much as we can. If you need to store something it’d need to be a static member variable, which is problematic. Just … Read more

Extend Woocommerce Widget Class – WC_Widget_Product_Categories

When calling parent::__construct() from WC_Widget_Product_Departments the constructor of WC_Widget_Product_Categories immediately overwrites the class properties (especially the widget_id), see here at GitHub. So you have to extend WC_Widget to create a new widget and then you can copy anything what you need in your widget from WC_Widget_Product_Categories to WC_Widget_Product_Departments.

Remove an action by extending class and replacing it

Problem lies in this line: remove_action(‘woocommerce_before_my_account’, array( $this, ‘my_packages’)); This won’t remove action registered by parent class, because $this is a different object in this case, so you won’t remove any action at all. So how to remove such action? Since you can’t access the same $this value in your class, you’ll have to iterate … Read more

Why is my custom post type not being activated on plug-in activation?

That’s not how register_activation_hook works. register_activation_hook is called only once, when the plugin is activated. CPT’s however need to be registered on every single request, not just when the plugin is activated. This is because WP doesn’t store a list of CPT’s in the database, it’s generated at runtime by PHP code. So instead, register … Read more

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