Accessing a protected property of a post

The foolproof method here to grab a dynamic member variable is to use reflection! Lets say we have this class: class MyClass { private $myProperty = true; } We can use reflection to acquire the class, and the property: $class = new ReflectionClass(“MyClass”); $property = $class->getProperty(“myProperty”); We can then set that property to accessible: $property->setAccessible(true); … Read more

How to add category and subcategory in WordPress custom code?

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following… class MyPluginClass { public function __construct() { add_action( ‘init’, array( $this, ‘sample_insert_category’) ); } public function sample_insert_category() { if(!term_exists(‘sample-category’)) { wp_insert_term( ‘Sample Category’, ‘category’, array( ‘description’ => ‘This is an … Read more

Getting a list of the published posts

Which wp_get_recent_posts()do you retrieve the most recent posts. For meta data, like published date and modified date use additional functions. For the published date is the_date() helpful. For the modified date use the_modified_date(). The functions are a part of the Template Tags, useful for Theme and direct output. But she have also parameters to get … Read more

WordPress API functions not working at AJAX functions.php call

Your problem is probably because you do not return a json object but an html (actually mixed text and html), and you set jQuery to validate that the response is json, which it isn’t. your code at the ajax handler should be something like $catshtml = wp_dropdown_categories(…..echo=0); $ret = array(‘data’ => $catshtml); wp_send_json($ret); die(); on … Read more

Action on WordPress Install

The main component you are probably missing is dropping your customizations in an install.php file in the wp-content directory. If you look at the /wp-admin/includes/upgrade.php you will be able to see exactly how it is included and the installation functions you can override. I am not sure if that will be good enough to catch … Read more

Load plugin script in specific page

Just one thing to make sure of, you must put the page id in the brackets for the “is_page()” function. If your page ID was 12, you’d use it like this: if( ! is_page( 12 ) ){ You can find a page’s id by editing it and looking in the URL for “post=”. The Page … Read more