The tag has no wiki summary.

learn more… | top users | synonyms

28
votes
3answers
2k views

How to remove a filter that is an anonymous object?

In my functions.php file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should remove_filter() look like? add_filter('comments_array',array( ...
24
votes
6answers
3k views

Using OOP in themes

I see a lot of plugins making use of object-oriented coding when there isn't really necessary. But what's even worse is that theme developers are starting to do the same thing. Commercial themes and ...
18
votes
5answers
1k views

Should all plugins be encapsulated in a Class?

When developing a plugin should the functions be grouped together into a Class to avoid namespace conflicts? Does using classes create performance overheads for PHP? If there is a performance hit, ...
10
votes
2answers
3k views

Will WordPress become completely OOP?

Is there any information about WordPress becoming completely OOP in future versions?
9
votes
1answer
2k views

Using classes instead of global functions in functions.php

In many themes I've seen (including TwentyEleven) and in the examples I've found online, when building the functions.php file for a theme all functionality is declared in a global scope. To clarify, ...
9
votes
2answers
3k views

Why do some hooks not work inside class context?

I'm pretty stumped on this one. I'm using add_action inside my plugin class to do certain things- add scripts & styles to the head, wp_ajax, etc. Here's the actions, in the __construct: function ...
9
votes
1answer
4k views

Plugin Form Submission Best Practice

I have done a lot of researching and haven't found quite what I am looking for, so I am hoping that I can be pointed in the right direction. I am developing an Events plugin that will book a ticket ...
8
votes
1answer
1k views

Registering Class methods as hook callbacks

I'm not sure if I have done this correctly. As I understand it: if I have a class foo and a static method bar I can register that as the callback by passing the array array("foo","bar") as the ...
6
votes
1answer
475 views

How to create a flexible abstraction for WP_Query?

My question is about php but it involves wordpress as i am creating a plugin. The case is that i have 5 questions, each question have 6 choices and one choice to choose from each. Now the person would ...
6
votes
2answers
871 views

What is the correct way to build a widget using OOP

I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version here). The plugin is working, but I am currently rewriting all the code using ...
4
votes
2answers
2k views

Does an activated plugin automatically mean its methods are available to other WP functions?

I made a WordPress plugin like this: Class MY_CLASS { //codes } Global $myclass; $myclass = New MY_CLASS (); After installed and activated the plugin, can I use this class in other plugins without ...
4
votes
1answer
137 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', ...
3
votes
2answers
1k 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; ...
3
votes
3answers
1k views

Plugin Architecture/Design Pattern - is better to use a private Observer/Mediator Pattern for plugin subclasses or WP add_action?

I'm coding a very complex plugin which it's organized as a parent "container" class and several subclasses, where each subclass is an optional/mandatory element which usually (but not always) maps to ...
3
votes
2answers
444 views

How do I use add_action from a class method?

For some context, we're building an activation system for new users of an app using WordPress as a framework. We've got a plugin driving most of our interactions, where all of this code resides. When ...
3
votes
3answers
391 views

scheduled event not getting executed

class checkPost{ function __construct() { if ( !wp_next_scheduled('my_task_hook') ) { wp_schedule_event( time(), 'hourly', 'my_task_hook' ); // hourly, daily and twicedaily } ...
3
votes
1answer
1k views

Using a plugin class inside a template

I am writing a plugin to send an invitation to a friend which opens up a form when a link is clicked. I encapsulated all the functions in class by following the code given in the Report Broken Video ...
3
votes
2answers
172 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 ...
3
votes
2answers
1k views

Using attachment_fields_to_edit filter inside plugin class

I'm writing a plugin using OOP. I realise that filters and action hooks need to be placed inside the constructor method in WordPress like so: add_action('wp_enqueue_scripts', array($this, ...
2
votes
3answers
3k views

Using Ajax with a Class file

At the moment I have an ajax that works (I get a success [200] response), but having an issue with the action hooks on the response. The JSON object is not coming back, instead I'm getting a 0. I ...
2
votes
1answer
243 views

Using a front controller in a Wordpress plugin, any suggestions?

My idea was to use a front controller in our plugin. has anyone done that already? The responsibilities of the controller should be initiate router class; provide access to objects registry, which ...
2
votes
1answer
106 views

Single Responsibility Principle and WP Classes

Still working my way through OOP and Solid principles. I’m having a hard time getting around having to have many new SomeClass(); calls, or adding them to an action hook ( add_action( 'init', array( ...
2
votes
1answer
485 views

PHP5, Inheritance, Singleton - action & filter hook limitations

I'm currently working on a plugin, which uses the builtin cron functionality of wordpress. Instead of using PHP4, I want to use PHP5 with inheritance and the singleton design pattern. I run in some ...
2
votes
2answers
650 views

Check to see if page exists problems

I've created a class to dynamically create pages. I'm checking to see if the page exists by comparing the new page's title to post_name. The comparison seems to work ok, but even if there is a match ...
2
votes
1answer
70 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
1answer
799 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 ...
1
vote
1answer
200 views

How to structure a plugin into multiple files using classes?

I am writing my first simple plugin from scratch so I'm looking for a bit of advice on structuring the classes within the plugin. I encapsulated some basic functions in a class in the main plugin file ...
1
vote
2answers
135 views

Conditional tags inside a class

I have a couple of functions that I now combined in a class. The reason for that was that all these functions go towards one goal, and it is more appropriate way to use the globals between these ...
1
vote
1answer
941 views

How to include one class/instance without using global variables

I would like to add http://mobiledetect.net/ class to my template. Which is the best approach to dynamically use this class in every part(s) of my template? For the moment I just loaded the class in ...
1
vote
2answers
554 views

problem with implementing widget via the_content()

hey guys, I really need you help with this one. I'm using the subscribe2 Plugin (for email subscriptions). I want to show the signup form as a widget. The plugin author recommends doing it the ...
1
vote
3answers
348 views

Trying to get logged-in user data inside php class

I am trying to get the current logged-in user data and use this in the parent class(I need it in several functions). In the example below I can get the userID in the first function but it will give ...
1
vote
2answers
1k views

How to use classes declared in another plugin?

I'm developing a Wordpress Woocommerce plugin. On my local environment it works fine but I have problems when adding the plugin to a replica of the prod environment. I am new to wordpress and not very ...
1
vote
1answer
70 views

Advice on plugin structure

I'm looking for a bit of advice on structuring the classes within a plugin I'm writing for my charity website. At the moment the plugin is OOP based with a single class. However, its becoming quite ...
1
vote
2answers
223 views

Applying OO patterns and principles to plugin development

I'm busy writing my first plugin, using PHP 5.3.5. I come from a C# environment, and I must say I'm more than happy with the level of support for good, solid OOP techniques in PHP. However, I'm a ...
1
vote
3answers
788 views

Ajax with OOP doesn't work

I have a small script within theme's functions.php file that uses ajax, principle like this: add_action('admin_head', 'rw_script'); function rw_script() { echo ' <script ...
1
vote
1answer
22 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 ...
1
vote
1answer
73 views

Plugin activation hook in an abstract class

I would like to create a common abstract class to use for every WordPress plugin that I develop. As a part of the class' initiation process, I would like to fire the activation hook which calls an ...
1
vote
1answer
117 views

How do I extend one plugin I'm writing with another I'm writing using classes?

I have a set of plugins that do different things. I'm wanting to write a plugin with a class I can extend in each of my custom plugins to meet a common goal. In my "socket" plugin I have something ...
1
vote
1answer
94 views

Create hooks based on an array of hook names?

I have this idea where I would create a class that would take in a set of hook names then create them, for me to use when ever, and where ever. Currently the way to create a hook is we do something ...
1
vote
2answers
590 views

uml diagrams of wordpess

Where can I find UML diagrams of WordPress (Data flow diagrams,State diagram, component diagram, use case diagram, deployment diagram)?
1
vote
0answers
28 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 ...
1
vote
1answer
60 views

accessing parent variables in child construct without executing action in parent

I am quite probably going about this the wrong way, but I cant figure out how to rectify this.... would be great if someone could point me in the right direction. happy to provide more details if ...
1
vote
0answers
38 views

remove class from code [closed]

How can I remove the class from the following code and use it without the functions. I tried removing the functions and class and add it in functions.php but it did not work. class someclass { ...
0
votes
2answers
101 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
1answer
286 views

Wp_update_post: Infinite loop even with remove_action solution, OOP

I have a quite complex PHP class, reponsible for creating and printing meta_boxes, generating and saving meta fields, ... Each meta_box (object of class) has its own save function, that updates meta ...
0
votes
1answer
631 views

Wordpress class, using add_action to call member function does not work

I'm learning to create a WP plugin as a class. However, it seems the add_action doesn't work when calling my function; it works when using $this->init(). Example: class test { public $age = ...
0
votes
1answer
29 views

A question about add_action()

I was following this ( http://codex.wordpress.org/Plugin_API ) tut on codex. The part where a class is created and is called in add_action. No argument was passed to emailer::send ? Why? It was ...
0
votes
2answers
407 views

register child class in another plugin

I think this should be relatively easy, but somehow I cannot figure out how to do this. essentially there's a preexisting plugin that does this: add_action('widgets_init', create_function('', ...
0
votes
3answers
181 views

Need oop for wordpress theme? [duplicate]

I know how to program in PHP, but I don't know OOPS(Object Oriented Programming). Is it better to make themes in OOPS(Object Oriented Programming) or with normal coding? Is it better for performances, ...
0
votes
2answers
72 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 ...