Questions tagged [oop]

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

64 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
1answer
324 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 ...
2
votes
1answer
777 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' ...
1
vote
0answers
89 views

How to Get WP_Customize_Image_Control content?

I want to get WP_Customize_Manager controls from my frontend with ajax. This is possible? I looking for a solution on the internet, but I have not found so far any useful documentation about this... ...
1
vote
2answers
239 views

Adding Meta Boxes while Registering a Post Type in a Class

I am trying to add a few meta boxes for a Custom Post Type through a Class. I am using the "register_meta_box_cb" parameter while registering the Custom Post Type to specify the callback function for ...
1
vote
0answers
23 views

What is the downside of using a filter as a “poor man's” dependency injection?

First of all, I don't know whether or not "dependency injection" is the right term to use, what would be "dependencies" in my case are really objects that I use within other "parent". I have a big ...
1
vote
0answers
129 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
vote
3answers
2k 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 ...
1
vote
1answer
54 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
356 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
63 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 Comments{...
1
vote
0answers
1k views

How to handle cookies from a WordPress plugin on a cached page?

I'm attempting to write a plugin that can work with cookies on a WordPress site that uses page caching (why?). I've been following this tutorial on Esanctuary.net. I'm trying to write to the ...
1
vote
1answer
31 views

Register jQuery - OOP WP

I found this post that seems to make an Ajax script work in an OOP model. I found it interesting to add the script via a class function rather than a different file, it would be very useful to me. ...
0
votes
0answers
20 views

When developing WordPress plugin, is it a good idea to create my class object by hooking to existing class constructor?

I want to create my object when another object is made. Is it a good idea to create my object by hooking to existing class constructor? for example if the main class is class WordPress_Class { /** ...
0
votes
0answers
15 views

Advice on Designing Membership Plugin

I would like to develop a custom Membership Manager Plugin that lets members pay/invoice dues, RSVP for events, and have a public profile page displaying customization information. Each member has ...
0
votes
0answers
36 views

functions won't fire after I converted my code from procedural code to OOP

As stated in the title, I had written a plugin that was pulling a blog post from a blog and then created a new blog post with that same data in the blog where the plugin is installed. When I put ...
0
votes
1answer
20 views

How pass args to wp_list_comments callback?

i need to pass an arg to function that i am specifying as callback for wp_list_comments public function ggowl_comment_lister($ggowl_id,$icon_html){ $args = array ( 'post_type' => '...
0
votes
0answers
18 views

Child theme, how to cut the functions.php file into several classes?

The functions.php file of my Child Theme is a mess... I'd like to use classes in a separate folder (like /inc) but I would like to keep a maximum of security. For now everything works as excepted, but ...
0
votes
1answer
30 views

Custom Post Type works when registered in functions.php but not when registered in plugin

I am creating a plugin which registers a custom post type called 'news articles' see the class for this code below: <?php /** * This plugin class is used to register the necessary custom post ...
0
votes
0answers
40 views

Getting unexpected warnings from theme options code

Actually i have built my own class for registering theme options, and it works fine, but once i started to make some arrangements warnings started to show and i can't catch what wrong have i done. I ...
0
votes
0answers
23 views

Pass an argument into a function to extract from array

I feel like this should be possible. I have a function within my class which pulls a single row from my custom table: class Get_Data{ public static function get_data_single_db() { ...
0
votes
0answers
309 views

Access variable from another class that was passed in constructor

I'm coding a WP plugin using PHP OOP. I'm passing some classes to my main class, so that I will be able to access variables and methods from my main class to other classes. In fact I'm able to access ...
0
votes
0answers
25 views

How can I get the value of a customizer setting from within a custom control?

I'm attempting to create a custom customizer control where the user can define the setting to be whatever the setting is of a different control. For example, there is a setting for the theme's primary ...
0
votes
0answers
55 views

Woocommerce functions in custom class, avoid errors

How do I call Woocommerce functions in a custom class? I have the following class method which is getting called on a cron job action here is the code which fires my cron action ...
0
votes
0answers
28 views

How to add typehints to function in functions.php when argument is an object?

I have a function that is defined in functions.php of my theme and it makes use of the WP_User object. My problem is how do I let the PHP interpreter aware of its use. This doesn't work //function ...
0
votes
0answers
24 views

OOP WordPress - Update content of page at modification

I'm using for the first time an OOP model for plugin development and I'm kind of lost for the refresh of the page when I make a modification. I'm creating a page defined by its content in the ...
0
votes
1answer
54 views

Get post content inside plugin class method

I'm writing a simple SEO class that will add the various metatag to the header of wordpress. I've two little problems with the wordpress api. The first is that I need to remove the last comma from ...
0
votes
1answer
28 views

Performing ajax request in wordpress

I am trying to perform ajax request in my plugin. What I have done is: Class Someclass { public function __construct(){ } public function current_page_function(){ ...
0
votes
1answer
88 views

Error when activating a custom plugin on production server

I'm currently developing a custom plugin. All works well on my local dev environment (Local by Flywheel), but, on production environment, I'm unable to activate the plugin. I get this error message: ...
0
votes
0answers
16 views

Does &$this is really disallowed to use anywhere?

I got this message from the validator of plugins from Envato: When creating a callable, never use &$this, use $this instead: I think he may be wrong with his 'never use'. Are we ...
0
votes
0answers
21 views

Don't filters violate the a class' local variables visibility rules?

Pressume I have a class: class TestClass { protected $handle; } and in that class, I decide that my $handle will be set by a filter, in the constructor: class TestClass { private $handle ...
0
votes
0answers
46 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
183 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
0answers
22 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
1answer
656 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
201 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
1answer
89 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
1answer
63 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( ...
0
votes
1answer
13 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
78 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
42 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
17 views

accessibility of an object created in a plugin, from the header

I have a simple OOP plugin with a class $MyClass in it. I create the instance MyObject of this class in my theme 'functions.php' file. Thanks to this, I can use any method MyObject->MyMethod from my ...
0
votes
0answers
219 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 ...
0
votes
0answers
35 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 ...
0
votes
1answer
1k 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
117 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
65 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
78 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 ...
0
votes
1answer
160 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']); ...
0
votes
0answers
67 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 ...
0
votes
0answers
1k 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? ...