The tag has no usage guidance.

learn more… | top users | synonyms (1)

0
votes
1answer
21 views

Issues separating my Plugin pages into different files

As my last (first) plugin got a bit hard to manage with 6 admin pages in 1 file, I decided to split them up for this one, but I am getting nothing but issues doing so. In my plugins functions file (...
0
votes
0answers
16 views

Use the methods of a class coded in a plugin

I have a plugin which creates a page in the admin options part (backend). It is based on a single class which creates a unique object when initializing the extension. Various methods in this class ...
3
votes
2answers
2k 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
0answers
18 views

Object Oriented plugin, add action and variables

I'm developing a plugin using the WordPress Plugin Boilerplate and am after hitting a wall. I need to hook into when a custom post type is published (as in the user hits publish) and when its ...
1
vote
1answer
9 views

trouble calling an import class from an action in a plugin before wp_cron executes

I’m using the wp_crontrol plugin to call an action added in my functions.php file which then calls a function in my plugin file. WP gets to my function but can’t call the class, I get this error: PHP ...
2
votes
0answers
28 views

__NAMESPACE__ with register_activation_hook

Im teaching myself namespaces and OOP in wordpress at the moment so bare with me. In the base of my plugin I'm loading activation and deactivation hooks. Currently the deactivation hook works but ...
1
vote
3answers
4k 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
45 views

Using OOP inside a Plugin - Is it allowed?

I have pre-written Objects that do such things like file checking the MIME type, then a main upload object but neither of which use the Database. So I am just curious to whether I could intergrate ...
1
vote
1answer
2k views

Using several add_action with parameters inside a class

I'm creating a theme framework and using a class to initiate all basic function of the theme (adding theme support, menus, etc). I've got stuck when I tried to enqueue the scripts and styles though: ...
0
votes
1answer
31 views

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. ...
3
votes
1answer
35 views

Where is the “ancestors” post object attribute?

I usually work with the ancestors attribute of the post object: if ( in_array( $target_id, $post->ancestors ) ) { // do whatever } But while debugging the post object I've seen that there is ...
4
votes
1answer
166 views

What is the best way to instantiate a class of a plugin in your WordPress theme?

What is the best way to instantiate a class of a plugin in your WordPress theme? To be clear, let's say that there is a class called Get_Meta_Data() and it is being used to get the metadata from DB ...
0
votes
1answer
34 views

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. ...
9
votes
2answers
2k 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 ...
0
votes
0answers
28 views

Code works on a page but not in a widget

I have some code that I am using with Advanced Custom Fields, I have created a Featured post type and within that there is a dropdown to select Posts. The code (between the lines) is then suppose to ...
2
votes
1answer
500 views

Query set using tax_query with relation 'OR' modifies category object?

(Update: Please see the edits far below.) The code: function itsme_better_editions( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( '...
5
votes
2answers
101 views

syntax for remove_filter in parent theme with class

I'm trying to remove a filter on the register_url hook a parent theme added, that seems to have a class nomenclature I can't figure out. Ordinarily, a filter for this hook would be easily added like ...
0
votes
1answer
95 views

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 ...
2
votes
2answers
106 views

Initiate only latest version of a class

We have a class which is common to few plugins that we develop. As time goes we improve the class and add new functions so we have class variable which is the class version. Because multiple plugins ...
0
votes
0answers
62 views

How to get variable IDs from OOP in jQuery?

I created image widget and tried to use $variable ($this->get_field_id('widget_image') in jQuery. Unfortunately, I cannot get it in jQuery. It shows Uncaught ReferenceError: object_name is not ...
0
votes
1answer
160 views

PHP calling function within a class

I'm writing my own php class and I have multiple functions within the class. Something like this: class JSON_API_Hello_Controller { public function test_cat(){ global $json_api; ...
0
votes
0answers
23 views

Meta Box not being added in plugin

I am attempting to create a simple oop plugin that registers a few custom post types and then adds meta boxes to that custom post type. It is currently adding the post type but it's not adding the ...
1
vote
3answers
2k views

How to initialize $wpdb?

I have a .php page in the theme root to check the data of one CUSTOM form. After receiving this data I need to do a query in a custom mysql table, so I need $wpdb, but I can't use it directly (or ...
0
votes
0answers
25 views

Why is this require statement not working?

I am faced with this strange issue when the script loads it gives me an error: [04-Oct-2015 18:36:04 UTC] PHP Warning: require(../main/otherfile.php): failed to open stream: No such file or ...
0
votes
0answers
40 views

What is wrong with assigning values to a WP_List_Table class?

I was trying to fix a use of the Wordpress list with 4.3 update, when I noticed some odd behavior when subclassing the list class. As a minimal example: class Another_List_Table extends WP_List_Table ...
1
vote
2answers
399 views

Adding the hook 'vc_before_init' inside a object

I'm working on my first OOP (MVC) based plugin. Everything works perfect, enqueue front/back-end styles, admin menu pages, shortcodes creation, etc... I load my main plugin class using the init hook....
4
votes
3answers
4k views

Does an activated plugin automatically mean its methods are available to other WP functions?

I made a WordPress plugin like this: Class MY_CLASS { //codes } Global $myclass; $myclass = New MY_CLASS (); After installed and activated the plugin, can I use this class in other plugins without ...
2
votes
1answer
159 views

Adding an admin page - OOP approach not working

I have a parent class, which contains the following: use app\My_Dashboard; class My_Class { public function __construct() { add_action('admin_menu', array($this, 'setup_dashboard_page'));...
0
votes
0answers
59 views

Creating menu not working with OOP Plugin

I am trying to create a test plugin to practice my OOP with WordPress, I am trying to simple add a menu item into the WordPress admin section. When I activate the plugin it should add the menu item ...
0
votes
2answers
86 views

How to prevent PHP fatal error if plugin hasn't been enabled and a method is called in theme file?

I created a WordPress plugin using OOP. If the plugin hasn't been activated and a method is called in a theme file, it throws the PHP fatal error "call to undefined function". What is the correct way ...
0
votes
0answers
54 views

Class is not supporting Ajax

I'm trying to make a plugin table which extends the existing WP_List_Table but I can't call my Ajax function with a hook: add_action( "wp_ajax_test_response", array( $this, "my_function" ) ); Here ...
0
votes
0answers
36 views

why is this ajax function not working as expected?

so my class looks like this: class Myclass{ private $nonce; public function __construct(){ if( get_current_screen()->id == 'nav-menus' ){ $this->nonce = 'my-plugin-...
0
votes
1answer
54 views

wpdb insert working in one function, but not another

I have the following function: function addToShortlist($propref) { global $wpdb; if (isset($_SESSION['shortlist'])) { $shortlist = new Namespace\Shortlist($_SESSION['shortlist']); ...
3
votes
1answer
194 views

Namespaces in WordPress - How do I initiate the main class?

I have very basic knowledge of OOP in PHP and am trying to learn to use namespaces in WordPress plugins. Followed some instructions from these 2 sources: WPSE 63668 Paulund This is how my current ...
0
votes
0answers
33 views

Loading custom class in a template

I’m taking a modular approach to building a Wordpress theme. And I’m trying include the class below on more than one of the different php template files that make up my front-page.php. Here’s the ...
1
vote
1answer
117 views

Current user in plugin returns NULL

I am currently developing a plugin and I am trying to make use of the $current_user global. class Something { public function __construct() { $this->get_user(); var_dump( $this->user )...
7
votes
3answers
3k views

PHP error with shortcode handler from a class

Currently i am using the following generic flow for adding the shortcode for a plugin. class MyPlugin { private $myvar; function baztag_func() { print $this->myvar; ...
1
vote
3answers
1k 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
0answers
31 views

Cannot access $post object - no matter what I try

Here is the code: <?php // Plugin Name: Lohman Supply Product Hover class LohmanProductHover { public function __construct() { add_action('wp_loaded', array($this, 'lohman_hover'...
3
votes
0answers
203 views

Extending WP_User class and using this sub-class during the whole lifecycle

I am currently struggling with this software design issue I can't seem to get hold of. What I am trying to achieve is the following: for every user on our website, I want to do an API request to a ...
0
votes
1answer
72 views

Custom meta box using OOP way doesn't save data

This is the first time I'm building meta box using OOP way, the problem is when I save the post (product) or update it the input text is not saved to the database. Here is my code: <?php /** * *...
0
votes
0answers
51 views

Best way to access variables in template markup

I am making my own mini OOP wrapper for working with wordpress themes. I have a main $settings variable that contains all of the information like definitions, scripts, menus etc.. I then pass this ...
1
vote
1answer
508 views

Load classes using spl_autoload_register

I have a problem with loading classes in a "includes" folder. Tried on a few WP installations and always same result. I've made a simple plugin to see if the problem is somewhere else but again, it ...
-1
votes
2answers
56 views

Method not receiving attributes from shortcode call, general OOP problems

The method OpenMods that you see below, is supposed to take an array generated by an fgetcsv function, and put it into an HTML table. __construct is supposed to, as is typically the case, define the ...
2
votes
1answer
99 views

Getting headers property from WP_Theme object

Using wp_get_theme returns an object holding the properties of the current theme. The headers property contains any array of information I wish to access. I can access the other properties using ...
0
votes
2answers
147 views

Accessing a protected property of a post

Fatal error: Cannot access protected property Some_Plugin::$_some_property What is the best/least-destructive way of accessing a protected property attached to a post. The property is being ...
0
votes
1answer
74 views

The writing ( with foreach) of the keys of an array of objects to a new array produces fatal error

I have the following problem, i've queried the attached media to a post with: function abc_attachments( $post_id ) { $query = array( 'post_parent' => $post_id, '...
0
votes
1answer
106 views

Class property seems to lose scope, attached to save_post action?

This may be more suited for StackExchange, so if you think that would be the right place to direct my question - please let me know :). So, I have a class with a property of save_list. This is an 2D ...
0
votes
0answers
328 views

Object oriented programming, add_action in constructor not firing

I am trying to write a class that adds an action to the save_post hook, but the post_updated function never gets called. I tried some variations, but it never gets called. Am I doing something wrong? ...
1
vote
2answers
216 views

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

I'm getting the following error in my debug.log: PHP Notice: Trying to get property of non-object in /my-wesbite/wp-content/themes/express/header.php on line 36 This is line 36 of header.php in my ...