Extending the WP_Widget_Text class

Think about it, why would WordPress do anything just because you have defined additional class? It’s not magic (neither magical magic or code driven magic). The text widget doesn’t appear simply because class exists. When WordPress loads it runs wp_widgets_init(), which executes register_widget(‘WP_Widget_Text’). So technically you cannot tell it to use different class. What you … Read more

Using $post->post_name in body id causing error: Trying to get property of non-object

A better method for what you are trying to achieve This answer is not about the php error you are getting. You need these classes for styling your website right? Put the following code in your functions.php // A better body class function condensed_body_class($classes) { global $post; // add a class for the name of … Read more

Load classes using spl_autoload_register

Right, to answer my own stupidity. spl_autoload_register is called when you instantiate a class. Moving new water(); from file water.php to file test.php solves the problem. The test.php should then look like this: <?php /* Plugin Name: test Plugin URI: test Description: Version: 1.0 Author: test Author URI: test */ class test_main { public function … Read more

database interactions using OOP

This is potentially a fairly involved question, so I may not be totally rigorous in my answer, but this should give you a good start when creating and deleting tables.. Include the following lines in your plugin _construct() function of class_my_plugin.php: if (is_admin()){ //manage the the database tables when registering or deactivating register_activation_hook($loc, array($this, ‘your_plugin_installation’)); … Read more

Use object in template part

As of WordPress 5.5 you can pass variables to template parts by passing them in an array to the third argument of get_template_part(): foreach ($categories as $category) { get_template_part( ‘temp-parts/loop/blcnr_loop’, null, [ ‘category’ => $category ] ); } These variables will populate an $args variable accessible from the the template: echo $args[‘category’]->name;