Questions tagged [oop]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
34 views

get_option / wp_localize_script Not Working in OOP Plug In

Got this working the other day in a single-file php plugin which only consisted of functions. Now I am trying it out with the WordPress Plugin Boilerplate which is an OOP approach with a lot of ...
0
votes
1answer
14 views

Wordpress plugin blog creation

I'm trying to create a custom plugin for my website. class SoaneNews { function __construct(){ add_action( 'init', array($this,'pluginprefix_setup_post_type')); } function ...
1
vote
2answers
28 views

Most efficient way to use classes to create admin pages using Settings API

I've built a class which creates admin pages with the Settings API. I'm trying to optimize it to run only where I need it. Most of the examples and tutorials I've seen say to instantiate it from the ...
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 ...
1
vote
1answer
37 views

Override WP Class Private Function

I'm new to community, I think you experts can help me in this. I have plugin installed and i want to its overwrite one function which is in class <?php class ...
2
votes
1answer
51 views

set_sale_price in WooCommerce [closed]

I need to set a WooCommerce sales price in a function. I'm using set_sale_price - but I don't think it is working. I'm trying it two different ways: Method one: update_post_meta( $theID, '...
1
vote
2answers
91 views

OOP Plugin Development. Including external object

I am developing a plugin by using classes and object oriented programming. Within my plugin I have included another object as I need to use the functionality of this other object. I am instantiating ...
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 ...
1
vote
1answer
46 views

Shortcode Inside Class Not Working

Working on my first WordPress plugin and using OOP. I'm trying to create a shortcode that works within a class and confused about how to set it up. With my current setup, the shortcode only prints ...
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 ...
1
vote
1answer
49 views

What is the proper method of using global $post?

I am using global $post multiple times in a class. These are my doubts Is that a bad practice? Can it result in slow websites? What's the proper way to use it inside a class class Test{ public ...
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
306 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
1answer
68 views

Proper use of Output Buffer for a whole php clas

For my ajax popup login i want to use Output Buffer for a whole oop php class. I just want to start buffering from the start of class and end it when the class is finished. class Wp_Ajax_Popup_Login {...
1
vote
1answer
24 views

Creating a shortcode, but getting tied up with OOP and Classes?

I have tried creating a new class that holds an action which creates a shortcode and the shortcode is on my site but doesn't appear to be working. Can anyone tell me where I appear to be going wrong ...
0
votes
1answer
96 views

WordPress plugin activation, deactivation and uninstall hook not being triggered

I am developing a WordPress plugin which requires certain rules to be added to the .htaccess file of the WordPress installation upon activation of the plugin. Initially, before I switched my code to ...
0
votes
1answer
51 views

Remove an action added within a class in a WordPress plugin

I'm trying to replace a function in a WordPress plugin (Easy property listing) without success at the moment. The action is added like that, in a class : <?php /** * Search Object * * @...
0
votes
1answer
27 views

Benefits over using object method over property from $product?

I'm grabbing products from wc_get_products() and looping through them to display information in a foreach. Are there any benefits (performance or otherwise) to using $product->get_name() over $...
5
votes
2answers
70 views

Using OOP plugin's methods throughout the website

I'm making a plugin for a website, which methods I'd like to use in a few different places, such as page templates, shortcodes etc. I don't want to make the plugin class global or create more than ...
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 ...
1
vote
1answer
27 views

Use Repository Pattern in WP theme

In my template files I have a lot of WP_Query to get posts of an author or from a specif category ecc... I'm thinking to use Repository Patter in order to have cleaner code and a layer between ...
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
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 ...
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... ...
0
votes
1answer
32 views

Built a second plugin but it overwrote the first one

I built a WordPress plugin following Alessandro Castellani's tutorials with no problem. However, when I built a second plugin and activate it, for some reason it overwrites the first one. In the ...
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(){ ...
1
vote
2answers
234 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 ...
0
votes
1answer
86 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: ...
1
vote
1answer
48 views

restore_current_blog required after switch_to_blog, if I use that in a function?

class Basics { public function build_frontend_post_form( $blog_object ) { switch_to_blog( $blog_object->blog_id ); if( !( current_user_can( 'administrator' ) and ...
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 ...
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
2answers
1k views

Creating a custom post type using a object oriented approach?

I am looking for a good approach regarding the creation of custom post types in WordPress, using object orientation. How can I create CPTs in an clean, organized way? Take into consideration these 3 ...
0
votes
0answers
45 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
106 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
2answers
107 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
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
votes
2answers
261 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
298 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
647 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
1answer
181 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
119 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
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 ...

1 2 3 4 5