1
vote
3answers
125 views

Trying to get logged-in user data inside php class

I am trying to get the current logged-in user data and use this in the parent class(I need it in several functions). In the example below I can get the userID in the first function but it will give ...
0
votes
1answer
38 views

How do add_action and WP_Query

I am new to WP, semi-new to PHP and new to OOP. 1) How can the WP function add_action receive another function as its argument? I know this by itself is not possible. I deliberately broke some code ...
6
votes
1answer
346 views

How to create a flexible abstraction for WP_Query?

My question is about php but it involves wordpress as i am creating a plugin. The case is that i have 5 questions, each question have 6 choices and one choice to choose from each. Now the person would ...
1
vote
2answers
308 views

How to use classes declared in another plugin?

I'm developing a Wordpress Woocommerce plugin. On my local environment it works fine but I have problems when adding the plugin to a replica of the prod environment. I am new to wordpress and not very ...
0
votes
1answer
91 views

learning OOP with wordpress plugin

I used to develop in functional design so far and I am now learning OOP. I stumbled upon following problem. Sometimes in OOP a function needs to send and argument as an array. Example. I want to ...
0
votes
2answers
31 views

private functions in plugins

I've developed two plugins in which one function is the same (same name, same functionality). When trying to activate both plugins Wordpress throws an error because it doesn't let me defining the ...
0
votes
3answers
69 views

plugin class inheritance. cannot change variable

I guess I have a problem understanding inheritance. I have 4 classes like so; class FOO extends WP_Widget { protected $pluginOptions; function __construct() { $this->pluginOptions ...
1
vote
1answer
46 views

accessing parent variables in child construct without executing action in parent

I am quite probably going about this the wrong way, but I cant figure out how to rectify this.... would be great if someone could point me in the right direction. happy to provide more details if ...
0
votes
2answers
249 views

register child class in another plugin

I think this should be relatively easy, but somehow I cannot figure out how to do this. essentially there's a preexisting plugin that does this: add_action('widgets_init', create_function('', ...
0
votes
1answer
244 views

Plugin won't activate, fatal error (widget class not found)

I've been putting together a simple WordPress plugin that employs a sidebar widget and shortcode. One user has reported the following error when trying to activate the plugin on their local WP ...
0
votes
1answer
262 views

Check if a class exists within a method

I'm new to OOP and I'm writing my first plugin. I want to check if the Facebook plugin has already been activated. If so, I want to skip some code: class MyClass { ... function fb_js_sdk_setup() ...
0
votes
1answer
193 views

OOP Plugin: Where should I place the action hooks in the class?

Where in my admin class should I place the action hooks for adding css, scripts and the add menu page? In the __construct? Or should they be placed in a method?
3
votes
3answers
293 views

scheduled event not getting executed

class checkPost{ function __construct() { if ( !wp_next_scheduled('my_task_hook') ) { wp_schedule_event( time(), 'hourly', 'my_task_hook' ); // hourly, daily and twicedaily } ...
16
votes
5answers
1k views

Should all plugins be encapsulated in a Class?

When developing a plugin should the functions be grouped together into a Class to avoid namespace conflicts? Does using classes create performance overheads for PHP? If there is a performance hit, ...
6
votes
1answer
722 views

Registering Class methods as hook callbacks

I'm not sure if I have done this correctly. As I understand it: if I have a class foo and a static method bar I can register that as the callback by passing the array array("foo","bar") as the ...