The tag has no usage guidance.

learn more… | top users | synonyms (1)

0
votes
0answers
16 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
7 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 ...
1
vote
0answers
25 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 ...
0
votes
1answer
42 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 ...
0
votes
1answer
28 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
33 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
147 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. ...
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 ...
5
votes
2answers
90 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
72 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
104 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
56 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
140 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 ...
0
votes
0answers
24 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
351 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 ...
2
votes
1answer
139 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, ...
0
votes
0answers
56 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
82 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
53 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
34 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 = ...
0
votes
1answer
52 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
182 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
105 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 ...
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, ...
2
votes
0answers
184 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
67 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
49 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
444 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
55 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
96 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
115 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
71 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
105 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
310 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
203 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 ...
0
votes
0answers
82 views

Creating a register settings class that supports extended classes

I am having some trouble implementing a class structure to use for plugins I am developing. What I am trying to do is create a class I can just re-use for each plugin. I want it to be able to be ...
1
vote
1answer
373 views

Extending the WP_Widget_Text class

I am trying to alter the output of the default WordPress text widget. Since the widget is written in OOP I hoped it could be a simple deal of extending the class and overwriting one method – but it ...
0
votes
0answers
145 views

Storing PHP structure data in the wp_options table?

I searched too much about that but can't find resonable answer of that question I am creating a WordPress plugin that has so many options that I need to store so to store data using option API which ...
-1
votes
1answer
674 views

Strict Standards: Non-static method in sidebar generator

I used this sidebar generator in my theme functions.php and this plugin work perfectly! No errors. But when I open define('WP_DEBUG', true) I got some error. I know that I have to set wp_debug to ...
0
votes
0answers
357 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 ...
0
votes
1answer
1k views

Retrieve featured image as object

I want to retrieve the featured image of a post as an object (array) in order to have all image sizes available. The get_the_post_thumbnail() function doesn't do this, any ideas?
1
vote
1answer
98 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
416 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', ...
4
votes
2answers
576 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 ...
1
vote
0answers
178 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
52 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 ...