Articles of oop

Calling custom plugin class methods from a template

Is it possible to call instance methods of a class from a template file that is loaded by that class? If I try to invoke $this from the template, I get Fatal error: Using $this when not in object context and invoking everything statically defeats the purpose of classes. In other words, is it possible […]

OOP plugin not working

I’m developing a custom plugin OOP based. The plugin shows up in the plugins page and it can be activated without displaying any kind of errors. But none of the functions inside seems to be working. The weird thing is that everything works like it’s supposed to if I remove the class method markup. Here’s […]

Plugin: Hooking up classes that have their own hooks

Was wondering if there is a “best” approach to hooking up classes that has their own hooks, still making sure that those hooks haven’t run before the class got a chance to declare it’s own said hooks. I’m getting lost in the hook hierarchy in the context of an OOP plugin, and I’d rather not […]

PHP Helper Class to create shortcodes

I created a helper class to extend other classes for shortcodes. When I try to use $this in the add_shortcode() function I’m getting this error: Using $this when not in object context How can I solve this? Code below: Parent Class //shortcode-helper.php abstract class ShortcodeHelper { private $post_name_id; private $short_code_name; /** * ShortcodeHelper constructor. * […]

WordPress Object Oriented plugin development

Hello I am creating a plugin using WordPress, because the scale of this plugin is pretty big I am attempting to use OOP to implement what I need. The way I am using it is that in the main plugin file I am including all the classes, then when plugins_loaded action is fired I make […]

How to access OOP plugin function inside themes or other plugin

first of all I’m really sorry if the title of the question doesn’t explain everything. Anyways here’s what I was looking for. I’m creating a WordPress plugin with OOP concept. So, I’ve codes like this class somePlugin { //constructor goes here public function is_it_safe() { if( true ) { return true; } else { return […]

update_option does not work in this scenario – how do I fix?

I am attempting to use update_option to add or update an option. I have created a test below which creates a settings page and when loaded it runs my awd_do_sync function, but the option does not get added or updated – why is this happening and what is the fix? class MyClass { public function […]

profile_update hook doesn't works inside a class

When I try to use profile_update hook inside a class the callback function is not called. public function __construct() { add_action(‘profile_update’, array( $this, ‘user_profile_update’, 10, 2) ); } function user_profile_update( $user_id, $old_user_data ) { die(var_dump($old_user_data)); } Outside the class the callback function works correctly.

Obtaining values from objects

This code works fine and returns two StdClass Objects for each of my two posts: $children = get_pages($args); foreach ($children as $cake=>$element) { $args = array( ‘post_id’ => $ID ); $Comments = get_comments( $args ); }; This is great. I get each comment’s properties but I am only interested in the comment date. My desired […]

Need oop for wordpress theme?

This question already has an answer here: Using OOP in themes 6 answers