Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [oop]

The tag has no usage guidance, but it has a tag wiki.

0
votes
0answers
13 views

How to do a sql like query on serialized data of user meta data

As long I don't need to do a query with the data of all users, storing data like the zip code or city in the meta data as an serialized object works fine. But now I have to do a lot of different ...
0
votes
1answer
20 views

Check class_exists before class definition / Doxygen problem

Currently when I create a class for my WordPress, I start the class with if ( ! class_exist( 'class_i_want_create' ) ) : .... class_definition .... endif; But now I want to create a ...
0
votes
0answers
10 views

Treat an object like an array to get a value

I'm trying to access the value of [product_id] with a foreach in the following object. I appreciate I can't treat it like an array but none of the answers I'm getting seems to work eg. $package = ...
0
votes
2answers
18 views

Remove an action by extending class and replacing it

I'm trying to override a method (my_packages) from the WP Job Manager Paid Listings plugin by extending it's class from within a custom plugin Here is how the source code (none-related code removed) ...
1
vote
0answers
125 views

Basic Object Oriented plugin question

I'm looking to create a plugin that displays a custom posts label for posts that belong to selected categories. And since I'm new to OOP, I'm struggling to understand whether to use arrays instead of ...
-1
votes
2answers
45 views

Using add action for class with construct

i have this i answer in reference but seems have upvoted by many https://wordpress.stackexchange.com/a/48094/145078 but not sure why it is not working for me.. in answer class MyClass { ...
1
vote
1answer
24 views

How to run query inside a class with namespace?

I tried to run a query inside a class this was the structure namespace NCK{ class Runquery{ public function execute(){ $query= new WP_Query(array(..............)); ...
0
votes
1answer
72 views

Extend Woocommerce Widget Class - WC_Widget_Product_Categories

I'm trying to extend the woocommerce class used to create the product categories widget in my own plugin which adds a new taxonomy for woo commerce products called "departments". When I extend ...
0
votes
0answers
61 views

How can I access the updated value of a class variable that changes after add_filter is run?

First, thanks in advance for any assistance. I'm working on an existing project where we're running a filter on the_content to insert ads after a specific number of paragraphs. Recently, we ...
0
votes
1answer
90 views

OOP development and hooks

I'm currently working on writing my first OOP Plugin for Wordpress. To help out a little bit with structure I looked for, and found, a boiler plate that sets up the basics for me. In Main.php there'...
0
votes
1answer
30 views

How to properly setup an activation hook

I am trying to register an activation hook for my plugin. The plugin is using classes and the actual activation method is held in a separate admin class. Reading the documentation for ...
0
votes
0answers
10 views

How to set a public variable in someone else's plugin class

Say there is a class in someone else's plugin that sends mail using wp_mail(). It has a public variable for the reply-to address, but it is never set. I am adding the settings field to the WordPress ...
0
votes
0answers
11 views

HowTo: Properly Use a Classname in register_activation/deactivation_hook [duplicate]

I'm using Composer PSR-4 to autoload classes, but when I try to call register_activation_hook using a classname if get the following error (same for register_deactivation_hook): call_user_func_array()...
0
votes
1answer
34 views

Static vs Dynamic methods in WordPress

This question is about the famous debate on using Dynamic methods over static methods in classes. According to my research the widely acknowledged idea is to limit the use of static methods as much as ...
1
vote
1answer
59 views

database interactions using OOP

I'm developing wordpress plugin which store data in database. I tried to start OOP way for my plugin according to boilerplate from Best Practicies: https://github.com/DevinVinson/WordPress-Plugin-...
0
votes
0answers
32 views

modify/extend plugin class or function

I've got simple function within the class in a plugin, which looks like that : class LP_Certificate_Student_Name_Layer extends LP_Certificate_Layer { public function apply( $data ) { ...
0
votes
0answers
16 views

Integration tests test script enqueue/register fails

This question is related to this SO post I'm testing a plugin, and in it I have public function enqueue_scripts() { $main_style = 'public/scripts/application.js'; wp_register_script( '...
0
votes
1answer
124 views

Override static method in WC_Shortcodes class (shortcode) [closed]

I'm trying to override product_categories shortcode from WooCommerce, so that I can add additional classes to the wrapper [product_categories number="0" parent="0" class="container"] So I looked at ...
0
votes
1answer
71 views

Undefined method class::construct() when creating a plugin

I try to create a simple plugin following by the guid http://docs.layerswp.com/plugin-creation-guide So I've created main file functions.php <?php /* * Plugin Name: Layers - Demo Extension * ...
0
votes
2answers
29 views

How to wait for Wordpress Core to load when writing OOP?

I want to create a helper redirect function that looks like the following: /** * Just an example of using redirect() */ public function validate_something() { if (1 == 0) { $this->...
3
votes
1answer
45 views

WP Plugin + OOP: Adding Menu Page doesn't create required effect

So, I've been staring at this problem for a few days now. I am attempting to push my skills further in PHP development, and decided to tackle a WP plugin with an OOP approach. I know that WP isn't ...
0
votes
1answer
38 views

Code does not work in class implementation but works fine in functions.php file

I am trying to clean up my codes and separate them in class files. I have this block of code that works perfectly fine where it sets the status of events older than a week to trash when I add it in ...
0
votes
0answers
38 views

Declare a class instance globally without using global

I have a custom class : class User { private $email; private $username; private $userrole; public function __construct() { //Do something } public function ...
0
votes
2answers
81 views

How can I access string value in an array?

currently I am developing a site using the Dokan multivendor plugin. I added a custom field in the registration form and The below code is being used to add the custom field in the registration form ...
1
vote
0answers
43 views

Instantiating classes in constructor vs in a method [duplicate]

I'm writing a plugin, and for the most part I'm following the plugin boilerplate with the addition of autoloading and namespacing. When running the main class, where you include methods to run in the ...
0
votes
1answer
233 views

Admin submenu does not call function to load the page

Context I'm making a big plugin with a complex architecture. I would like in my plugin architecture split pages and menus building on admin side. So I have these classes : Menu.php, Submenu.php and ...
0
votes
1answer
35 views

How to access classes in theme of a plugin?

Below is my folder structure. I need to access the class inside a controller on the WordPress theme. Controller->WP_Db_connection.php Controller->WP_Product.php samplePlugin.php -> WP_Db_connection....
0
votes
1answer
106 views

How to implement AJAX within a class storing shortcode atts as class variables

I'm trying to write an OOP plugin, pass my shortcode arguments to the class, store them as class variables and then use them in an AJAX call. Here is an example: class WPAJAXClassTest { private $...
0
votes
2answers
750 views

How to Create database table when Plugin installed/activated, and delete database when Plugin deleted

I am trying to create new WordPress plugin with object oriented programming.I want to create database when plugin activation and delete database when plugin deleting.Below is my code its not working ...
0
votes
1answer
55 views

Loop through an array inside a class using foreach [closed]

I'm creating a class in my WordPress template and I have a multidimensional array as protected member. The array at second level contains some email addresses as string and I want to get those emails ...
0
votes
1answer
42 views

Cannot remove meta box added through OOP

Please do no mark this question as duplicated or downvote as I tried every code found on all docs (old and new), all the websites, forums etc, but nothing worked for me... I added the meta box ...
0
votes
1answer
139 views

Autoloader not finding classes from my plugin

I am trying to work with autoloader in my plugin. In the main file of my plugin I have use My_Plugin\Includes; require_once( plugin_dir_path( __FILE__ ) . 'includes/class-autoloader.php' ); $...
2
votes
2answers
2k views

add_action in namespace not working

I decided to namespace my plugin, and I got it all to work, except in my main plugin file. I added two actions in that plugin, before calling the init method of the plugin. <?php namespace ...
0
votes
1answer
214 views

Calling WordPress hook from within a class: call to undefined function error

I am new to OOP with WordPress and could use some help with debugging this issue. I have been searching for an answer and been trying to debug myself, but could use a hand. I am trying to create admin ...
0
votes
1answer
40 views

How to Maintain url on form submit

In my case I have to submit form on same file which is a class without using any javascript or hook, the form action is action="<?php echo $_SERVER['PHP_SELF']; ?>". It is submitting the form ...
0
votes
2answers
53 views

profile_update hook doesn't works inside a class

When I try to use profile_update hook inside a class the callback function is not called. public function __construct() { add_action('profile_update', array( $this, 'user_profile_update', 10, 2) ); ...
0
votes
1answer
37 views

Class called in template, AJAX not registering

I have a custom plugin that consists of various classes, with one class being called in a page template: $chart = new MyCharts\Chart(); $csv = get_field( 'csv' ); // URI to .csv file $chart->init( ...
-1
votes
1answer
40 views

Global Handle to Class unavailable in Plugin?

I am writing a custom plugin and calling the plugin functions using short codes on my wordpress page. global $db_handle; below declares the handle to the class 'DBController' global. if (isset($...
1
vote
2answers
44 views

Using plugin functions/methods within templates

I've created a plugin using various classes. I want to be able to access the methods on several of the different classes from within the page templates of my custom theme. The method I'm currently ...
0
votes
1answer
105 views

update_option does not work in this scenario - how do I fix?

I am attempting to use update_option to add or update an option. I have created a test below which creates a settings page and when loaded it runs my awd_do_sync function, but the option does not get ...
0
votes
1answer
38 views

Cannot modify class property from shortcode handler function

I'm trying to store data from a shortcode attribute in a class property, so I can use it later in other functions. But somehow I'm always ending up with the initial value of the property. Here's a ...
1
vote
2answers
95 views

Extend a class of a plugin

There is a plugin that uses a class; and create an object like this: class WC_Disability_VAT_Exemption { public function __construct() { add_action( 'woocommerce_after_order_notes', ...
0
votes
1answer
12 views

How is construct function working even when variable is assigned null value?

I'm unable to understand the function of __construct here. I know that in any class __construct runs anytime the class is instantiated. However, my curiosity is, when $marks is defined as null in the ...
0
votes
1answer
52 views

Cannot access class properties from ajax call in wpordrpess

I have a problem with calling a class method from inside a wp_ajax_function. My code looks like this: class Cart { public $cart_content; public $cart_id; public $db; public ...
0
votes
1answer
135 views

Class property not visible inside ajax callback function?

I have a class that has ajax callbacks inside it, as well as actions set in the __construct() of that class. I am also passing the property to the class when instantiating it. It looks kinda like this ...
1
vote
1answer
34 views

Customizer - Prefix Class Extension

I have a basic question to beautiful working code I've found (paulund) for making a Custom Control by extending the 'WP_Customize_Control' Class. I am new to PHP, Programming and especially to OOP. So ...
1
vote
1answer
519 views

WordPress Ajax callback function from plugin - OOP

Using PluginBoilerplate to write a plugin. I need to make an ajax call. I added to main plugin.php file, class to register scripts and handle ajax calls. if ( ! class_exists( 'PoorMansNameSpaceAJAX' ...
0
votes
0answers
21 views

one file used by multi-object

I’m developing a plugin I have a class in this plugin, that I’ve created several object from this class That each of these objects by sending a value to a file (.js) They want the same operation ...
0
votes
1answer
39 views

Reorganization of namespaces

First of all thank You for Your time. I use autoload in my 2 plugins. They have to different namespaces but i want to build one main plugin with autoload for this two plugins. In future i am going to ...
0
votes
1answer
618 views

WordPress Object Oriented plugin development [closed]

Hello I am creating a plugin using WordPress, because the scale of this plugin is pretty big I am attempting to use OOP to implement what I need. The way I am using it is that in the main plugin file ...