The tag has no usage guidance.

learn more… | top users | synonyms (1)

1
vote
1answer
386 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( ...
2
votes
1answer
27 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
12 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
33 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
39 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
20 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 = ...
2
votes
1answer
1k 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
20 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
99 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
24 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
60 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 ...
4
votes
3answers
2k 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; ...
0
votes
3answers
527 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
26 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, ...
1
vote
0answers
67 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
30 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
37 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
91 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
41 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 ...
1
vote
1answer
54 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
29 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
40 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
63 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
113 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? ...
0
votes
2answers
91 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
59 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 ...
0
votes
0answers
20 views

How do can I pass data retrieved from a filter to template files?

I wrote this class to display only the current top level menu item's children: class deseng_navSplit { var $sorted_menu_items; var $args; function __construct($x, $y) { ...
0
votes
1answer
166 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
94 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
461 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
67 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
446 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
58 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
224 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
276 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
103 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
2answers
160 views

When and Where is `global $post` Set and Available?

Usually when people think of the global $post object it's assumed that it's actually set whenever you enter The Loop. I started to play around with how early I could actually call global $post which ...
1
vote
0answers
42 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
156 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
1answer
59 views

How to Set Taxonomy Object Description?

I noticed when dealing with Post Type Objects (Using get_post_type_object();) and Taxonomy Objects (Using get_taxonomy();) there's a property called "description". How do you set this description ...
0
votes
2answers
467 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
64 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
176 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 ...
2
votes
1answer
71 views

array of objects to do_action, callback gets singular object?

So I was passing an array of objects through an action today, no biggy, and things were working fine. Until I was iterating over one of the arguments to a callback and started getting errors. The only ...
-1
votes
1answer
89 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 ...
1
vote
1answer
613 views

How to get media objects

I am busy with a loop to return all media in the medialibrary in objects. I figured out how to get the images ( with wp_get_attachment_image('$mediaID') where the $mediaID is the id of the image ) ...
0
votes
1answer
61 views

Same taxonomy for different object types

Starting with WP 2.3 we can do this: register_taxonomy('custom_taxonomy', array('user', 'post', 'link', 'comment')); Those are different object types that belong to different tables and hence can ...
2
votes
1answer
310 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 ...
2
votes
4answers
5k views

Get the object ID by URL

I have an URL (such as the URL /sample-page/), I need the corresponding object ID. How?
0
votes
1answer
79 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 = ...