The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
0answers
24 views

calling a function from a class in your template

ok, so I have created a plugin in Wordpress. I want to be able to use some values I have created in a function within my template but I just don't seem to be able to get it to work. I have created my ...
1
vote
1answer
22 views

Getting user roles in plugin files

I have a plugin in which I need to use the get_editable_roles() function but I keep getting a fatal error saying that the function does not exist. In my main plugin file I have this code: function ...
4
votes
1answer
136 views

How Can I Add a Filter to Class Instance Only?

I have a custom class which I use for several cases extending it, for example class A { public function show_things() { print_r( apply_filter( 'yet_another_filter', array( 'coffee', ...
3
votes
2answers
169 views

How to name files of namespaced classes?

WP Core Handbook > PHP Coding Standards > Naming Conventions suggests the following for naming files with classes: Class file names should be based on the class name with class- prepended and ...
0
votes
0answers
27 views

Dynamically creating classes for Widget API

So let's say I want to make new Classes for the Widgets API using some variables that the user can configure. The only way I have figured it out is to use the eval() function. This is due to how ...
1
vote
0answers
26 views

Loading Comments From a Class?

I am not using the function comments_template(). Instead I am trying to load the comments from a Class. There is no comments.php file on the root. Comment Class namespace Core\Views; class ...
0
votes
0answers
70 views

Autoloading a PHP class – working outside, but not inside WordPress plugin

I am thinking about using autoloading in a plugin. Outside of WordPress (as a test) it works as expected, but inside the plugin there are some problems. The directory structure I used for testing: ...
0
votes
2answers
100 views

Object method calling for global $wpdb in header.php

I am developing a Wordpress plugin in an object oriented way, and I would like to read data from the wordpress database using the global $wpdb variable. The global $wpdb variable is called from ...
0
votes
0answers
41 views

Property value of null when value is assigned inside a method hooked to the wp action hook

In my_method() below, I'm assigning an array of post IDs to the property $this->post_ids which is to be used later on in my query args - see process(). If I hook my_method() to the init action ...
0
votes
2answers
68 views

wp_ajax handler with multiple class instances

Eight months ago I asked nearly the same question over there. But the Problem is still not solved so far. But I have an additional ideaa why it is failing. In the meantime my code advanced. I have ...
-1
votes
1answer
51 views

OOP - from plugin add new object and call static method in another file

I am trying to create an object from the plugins main file by first requiring a class file in a sub-directory, then creating a new->object, and then calling a method from within the required class ...
2
votes
1answer
68 views

Creating a menu page in a Object Oriented developed plugin

I am trying for the first time to build a plugin for Wordpress following OOP way. I am having some problems while trying to create a submenu page using add_users_page() function. Here is a simple ...
0
votes
0answers
137 views

How make modular WP plugin based on OOP?

For example I have "my-plugin" plugin created using class: class My_Plugin { public function __construct() { } /** * Other code where I creating plugins admin pagec etc. */ } ...
0
votes
1answer
43 views

OOP and WordPress shortcode

I tried to add a shortcode this way class MyPlugin { function __construct() { $this->make_shortcode(); } function ShowMsg($cls, $lst4) { $data = ...
1
vote
1answer
70 views

Plugin activation hook in an abstract class

I would like to create a common abstract class to use for every WordPress plugin that I develop. As a part of the class' initiation process, I would like to fire the activation hook which calls an ...
0
votes
1answer
29 views

A question about add_action()

I was following this ( http://codex.wordpress.org/Plugin_API ) tut on codex. The part where a class is created and is called in add_action. No argument was passed to emailer::send ? Why? It was ...
1
vote
1answer
196 views

How to structure a plugin into multiple files using classes?

I am writing my first simple plugin from scratch so I'm looking for a bit of advice on structuring the classes within the plugin. I encapsulated some basic functions in a class in the main plugin file ...
1
vote
1answer
110 views

How do I extend one plugin I'm writing with another I'm writing using classes?

I have a set of plugins that do different things. I'm wanting to write a plugin with a class I can extend in each of my custom plugins to meet a common goal. In my "socket" plugin I have something ...
1
vote
2answers
134 views

Conditional tags inside a class

I have a couple of functions that I now combined in a class. The reason for that was that all these functions go towards one goal, and it is more appropriate way to use the globals between these ...
0
votes
0answers
10 views

Custom class file

I have created a class for custom post-type, taxonomy and meta boxes. I made a method called form-elements and within that I have included HTML form elements. I need to share this method with other ...
-1
votes
1answer
243 views

How To Remove The Filter That Adds JetPack Related Content To Dom [closed]

I am trying to remove the filter in JetPack's Related Posts module that adds the element to the DOM that the module's JavaScript populates with the related posts. Once I remove it, I can achieve my ...
0
votes
1answer
280 views

Wp_update_post: Infinite loop even with remove_action solution, OOP

I have a quite complex PHP class, reponsible for creating and printing meta_boxes, generating and saving meta fields, ... Each meta_box (object of class) has its own save function, that updates meta ...
2
votes
1answer
106 views

Single Responsibility Principle and WP Classes

Still working my way through OOP and Solid principles. I’m having a hard time getting around having to have many new SomeClass(); calls, or adding them to an action hook ( add_action( 'init', array( ...
1
vote
3answers
345 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
0answers
59 views

OOP - add_action

I'm making a simple theme framework for personal use and I'm try to set up various options in a class. Basically, I want to use add_action within my class but the function doesn't seem to be firing ...
0
votes
0answers
89 views

Ajax Request not coming back to class

I'm struggling with an ajax request. It's executed but not returning back to my class. My PHP: ... public function __construct() { add_action( 'admin_print_styles', ...
0
votes
1answer
43 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 ...
2
votes
1answer
242 views

Using a front controller in a Wordpress plugin, any suggestions?

My idea was to use a front controller in our plugin. has anyone done that already? The responsibilities of the controller should be initiate router class; provide access to objects registry, which ...
0
votes
3answers
215 views

How to make method from plugin available in theme?

Let's say this was in my plugin: class pluginslug_foo { public function bar() { //stuff } } and I wanted to make the method bar available for use outside of the plugin, for ...
0
votes
3answers
124 views

Registering and using actions which return results in a Plugin class

I have a plugin class which contains a function spektrix_list_events() class SpektrixPlugin { public function __construct(){ add_action( 'init', array ( $this, 'init' )); } ...
0
votes
1answer
209 views

Wp ajax not working from “current_screen” admin hook

I have a class that is doing some backend work ( enqueening css and js files creating metaboxes, registering ajax hooks etc...) Everything works fine when I just include the files. The problem is ...
6
votes
1answer
470 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
1answer
928 views

How to include one class/instance without using global variables

I would like to add http://mobiledetect.net/ class to my template. Which is the best approach to dynamically use this class in every part(s) of my template? For the moment I just loaded the class in ...
1
vote
2answers
1k 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 ...
1
vote
1answer
791 views

Wrapper class: How to get rid of call_user_func_array() warning?

I have several installations of wordpress and now im trying to create my own small framework so I can create and maintain my themes more efficiently. What I would like to do is to have a wrapper for ...
0
votes
1answer
619 views

Wordpress class, using add_action to call member function does not work

I'm learning to create a WP plugin as a class. However, it seems the add_action doesn't work when calling my function; it works when using $this->init(). Example: class test { public $age = ...
0
votes
1answer
130 views

Using Geo Data Store Plugin Code

I'm trying to simply use the Geo Data Store Plugin Code functions from within my theme files and have never done this. I've tested the $sc_gds to see if isset, yet not getting anything when looping ...
0
votes
1answer
115 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
53 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 ...
2
votes
3answers
3k views

Using Ajax with a Class file

At the moment I have an ajax that works (I get a success [200] response), but having an issue with the action hooks on the response. The JSON object is not coming back, instead I'm getting a 0. I ...
0
votes
3answers
112 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 ...
0
votes
1answer
130 views

Dynamically creating multiple widgets from Mustache templates

I built a bunch of basic Mustache templates for a project, and now I'm wanting to effectively make them available to WordPress as widgets. //This uses Composer to manage dependencies (Mustache). ...
0
votes
1answer
152 views

add_action does not work when instance multiple tab-containers via template-file

I wrote my first class in functions.php which I want to use to create multiple tabs with a simple call all over my template files. When I create a new instance directly in functions.php everything is ...
1
vote
1answer
59 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
404 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
186 views

Why can wordpress not find the actions I add in my constructor?

I have a theme which has a page to display a keyword taxonomy called taxonomy-keyword.php. From this page I instantiate a sort of ViewModel called KeywordPage. It looks like this: namespace ...
0
votes
3answers
181 views

Need oop for wordpress theme? [duplicate]

I know how to program in PHP, but I don't know OOPS(Object Oriented Programming). Is it better to make themes in OOPS(Object Oriented Programming) or with normal coding? Is it better for performances, ...
0
votes
1answer
443 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 ...
-1
votes
2answers
96 views

Hooks are not executing

Based on my understanding of hooks, you create a hook, by doing do_action('hook_name'); then add something to said hook and call the method where you want it to do the hook, so: public function ...
1
vote
1answer
94 views

Create hooks based on an array of hook names?

I have this idea where I would create a class that would take in a set of hook names then create them, for me to use when ever, and where ever. Currently the way to create a hook is we do something ...