Getting the action’s tag name within the action
Simple: current_filter(); (link to plugin.php) or global $wp_current_filter;.
Simple: current_filter(); (link to plugin.php) or global $wp_current_filter;.
You are more or less there already with the code, you just need to change the code slightly. You do not mention how you get the user id, but if you have the user ID you want to check, it is quite easy to do outside the loop. Here is a simple example: $userid=1; $comment_count … Read more
All you need is a table with class=”widefat” and get_posts(). Then you run through the results (if there are any) and print the table rows. Here is a very simple example as a dashboard widget. Note the lack of I18n – it is not ready to use! <?php /** * Plugin Name: Last posts table … Read more
Unit tests for WordPress are a tricky thing. If you need to test the code with a live database, etc. I would suggest using the official WordPress test suite. I’ve gotten unit tests running for a plugin using that method before, but it wasn’t pretty, and was fairly unreliable. If you need to do it … Read more
You can programmatically create posts and pages using wp_insert_post or insert content using WXR files via WordPress’s import feature. To use wp_insert_post see the documentation here: http://codex.wordpress.org/Function_Reference/wp_insert_post A simple example: $my_post = array( ‘post_title’ => ‘hello’, ‘post_content’ => ‘This is my post.’, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array(1), ‘post_type’ => ‘page’ ); … Read more
So I came back to this after practice and implemented some of the Alchemy setup, meaning all the inputs have names like name=”_movies[3]Metabox repeating fields – radio buttons not saving correctly” where 3 is the iteration we’re on in the loop. Create the Metabox // metaboxes should be registered on the add_meta_boxes hook add_action(‘add_meta_boxes’, ‘add_meta_boxes’ … Read more
If the classes are not in the same file, you’ll need to require it into the child class ( myCustomClass ). Are you doing that? Example : //get the base class if(!class_exists(‘MyParentClass’)) { require_once plugin_dir_path( __FILE__ ) . ‘/_inc/MyParentClass.php’; } /** * Class Definition */ class MyChildClass extends MyParentClass{ // class definition }
If you want to add custom page in WordPress, you need to add your custom PHP file into currently activated theme ( /wp-content/themes/ ) folder. Suppose you have child-theme. Put the file to child-theme folder. Then goto page section, Click Add New. In Page Attributes, Choose Template as your PHP File. Open the Page.php file, … Read more
Determining the current time There’s the current_time() function in core that allows to pass three different values as first argument and gmt (the offset) as second argument. About the 1st: mysql -> gmdate( ‘Y-m-d H:i:s’ ), human readable e.g 2004/07/8 13:35:19 timestamp -> time(), the UNIX timestamp for e.g. 1335939007 A custom argument that is … Read more
I doubt it would justify the effort of writing custom SQL queries for only 2500 posts. Within the wp_set_object_terms( $object_id, … ) function we have: $object_id = (int) $object_id; so it’s correct that it only takes a single post id as input. So you would need to loop over your $post_ids array but it might … Read more