Articles of extend

PHP Helper Class to create shortcodes

I created a helper class to extend other classes for shortcodes. When I try to use $this in the add_shortcode() function I’m getting this error: Using $this when not in object context How can I solve this? Code below: Parent Class //shortcode-helper.php abstract class ShortcodeHelper { private $post_name_id; private $short_code_name; /** * ShortcodeHelper constructor. * […]

Add some fileds to the wp_posts table

I need to extend some wp tables (wp_posts, wp_comments, wp_users) to store some additional fields. I can’t use metadata because I need to query those values directly via MySQL. I need an help to choose if it’s better to extend the original table or to define an additional one with those fields, with a 1-1 […]

Extending core class in plugin

Hi I am writing a plugin and would like to extend a class in the wp-includes folder. I mean that literally like class my_class extends wp_includes_class_x{ … } However when attempting this I get a class x not found error but I know the class is being used by WordPress. So I try an include_once(path_to_class) […]

Extending Twenty Eleven Theme

In WP 3.3, how can I extend the Twenty Eleven theme such that I can make some custom additions or modifications but still take benefit in the updates that WP pushes out for the theme? Sort of like ‘overloading’ in programming, I guess. For now, I would like to include a custom css file and […]

how to extend a WP_widget twice

Has someone ever tried to extend calss WP_Widget, then extend it again ? Having to related widgets, I tried to create the first extending WP_Widget, : class FirstWidget extends WP_Widget { public function __construct(){ parent::__construct( etc and then extending the First to create the second one : class SecondWidget extends FirstWidget { public function __construct(){ […]

Extend walker – navigation, adding data attribute to a tag

I would a data attribute to the a tag in the menu, like have <a href=”#example” data-attribute=”attribute”>CLICK</a> I know that I have to extend the Walker BUT I tried in several times (finding some code on internet) and I never made it work. Here the code (I’ve still not tried to insert the data-attribute because […]

How to get private property in parent class into extended class?

I am not sure if my function is firing before another funciton or if I am having issues with the $this variable when I am extending my class. I am creating a function in my functions.php file. Here’s a link to my function. The specific function is extending a class that is an extension for […]

creating new field on mysql

I would like to add extra sections like “gender” on the WordPress user database. I would like to draw information from this information later. For example, let’s say I want to attract gender. I created custom registration pages using the “ultimate member” extensions for this, but nothing changed in the database. there is still information […]

Extending wordpress search to include excerpts and taxonomies?

Apologies for the lack of code, but I have no idea where to start with this – is it possible to extend WordPress’s search function to include excerpts and (custom) taxonomies as well as the standard title and post content in search results? i.e. search results don’t include posts that contain keywords found in excerpts […]

Better extend a class or use add filter/action hooks?

I got a “theorical” question here. I made a WordPress plugin that scrapes content from remote website. It as a Scraper_Class with generic “methods” to scrape remote content. eg. Scraper_Class { var $title; var $url; function fetch_content(){ $this->title = $this->get_remote_title(); } function get_remote_title(){ //… return $title; } } But I also want to have “presets” […]