Current user in plugin returns NULL

I am currently developing a plugin and I am trying to make use of the $current_user global. class Something { public function __construct() { $this->get_user(); var_dump( $this->user ); } private function get_user() { require_once( ABSPATH . ‘/wp-includes/pluggable.php’ ); $this->user = wp_get_current_user(); } } This actually works. However, I need to call pluggable.php file which shouldn’t … Read more

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 the included object within my plugin’s constructor. require_once (‘path/to/my/IncludedObject’); class MyPlugin { private $IncludedObject; public function __construct() { $this->IncludedObject = new … Read more

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 scenarios: Plugin for distribution (5.2 compatible) Theme for distribution Own project, with total control over the PHP version and dependencies 2 … Read more

Hooks are not executing

Based on my understanding of hooks, you create a hook, by doing do_action(‘hook_name’); then add something to said hook and call the method where you want it to do the hook, so: public function hook_name(){ do_action(‘hook_name’); } some where you do something like: add_action(‘hook_name’, ‘some_hook’); and then some where in the theme you call: hook_name(); … Read more

What is difference between functional and imperative programming languages?

Most of the mainstream languages, including object-oriented programming (OOP) languages such as C#, Visual Basic, C++, and Java were designed to primarily support imperative (procedural) programming, whereas Haskell/gofer like languages are purely functional. Can anybody elaborate on what is the difference between these two ways of programming? I know it depends on user requirements to … Read more

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’ ) ) { class PoorMansNameSpaceAJAX{ public static $instance = null; public $nonce=””; public $name=”ajaxexample”; public static function getInstance() { null === self::$instance AND … Read more