Function to change post status IF current user and post author are the same

I was unable to find any action called wp_update_post. Are you sure it’s a valid one? Lets try the hook publish_post. add_action(‘publish_post’, ‘check_user_publish’, 10, 2); function check_user_publish ($post_id, $post) { $user_id = get_current_user_id(); if ($user_id != $post->post_author) return; $query = array( ‘ID’ => $post_id, ‘post_status’ => ‘draft’, ); wp_update_post( $query, true ); }} code not … Read more

Add a simple JS Alert Box on Post Submission

Note that when post is update WordPress redirect you from /wp-admin/post.php to /wp-admin/post.php?post=41&action=edit which mean it loads twice. Thus what you will do on transition status hooks that will be skipped before the content is printed. Solution:- In transition hook callback function store (post meta) some flag to display js popup Bind a new function … Read more

Modify Post Status Arguments

You can alter a post status after init by changing the global variable $wp_post_statusses: function alt_post_status() { global $wp_post_statuses; $wp_post_statuses[‘custom_status’]->public = true; } add_action( ‘init’, ‘alt_post_status’ ); register_post_status() (line 922) does the same thing: … global $wp_post_statuses; if (!is_array($wp_post_statuses)) $wp_post_statuses = array(); // Args prefixed with an underscore are reserved for internal use. $defaults = … Read more

“Publish immediately” with custom post status

Few notes We can get the “Publish immediately” notice within the post_submit_meta_box(() when the post_date_gmt is equal to ‘0000-00-00 00:00:00’. We can see here within wp_update_post() and here and here within wp_insert_post(), how draft-, pending- or auto-draft posts are not date stamped. It looks like if we had a filter on the post status array … Read more

Which is the better way to get the status of a post?

None of them. A, C and D all indicate that you’re inside a loop, and want the status for the current post. But if that’s the case then the first line on all of them is redundant. This is all you’d need if you want the status of the ‘current post’: $current_post_status = get_post_status(); get_post_status() … Read more

Include Drafts or Future posts with count_user_posts?

This will do what you want: $args = array( ‘author’ => $curauth->ID, ‘post_status’ => array( ‘publish’, ‘pending’, ‘draft’, ‘future’ ) ); $posts = new WP_Query(); $post_count = $posts->found_posts; It will include drafts, pending posts, published posts, and future posts. There are more you can set, such as trashed posts, and private posts, but that didn’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)