Set post terms on post publish

The argument from pending_to_publish action, $post_id in your case, is not ID but array (callback to publish). I think it would be better to use the publish_post action, that way $post_id will actualy be the post id. Also this is a very general action so if you have multiple post types it would be wise … Read more

count the total number of comments the user has received for his published posts

You can use the get_comments() function like so: $total = get_comments( array( ‘post_author’ => get_current_user_id(), ‘post_status’ => ‘publish’, ‘type’ => ‘comment’, ‘count’ => true, ) ); echo ‘total comments of your all posts : ‘ . $total; Just customize the arguments based on your requirements/preferences, and in the above example, I’m retrieving the total number … Read more

How to rename “Publish” metabox title in post screen

The best way would be to remove the meta box and then add it back in with your new title: function change_publish_meta_box() { remove_meta_box( ‘submitdiv’, ‘post’, ‘side’ ); add_meta_box( ‘submitdiv’, ‘YOUR TITLE HERE’, ‘post_submit_meta_box’, null, ‘side’, ‘high’ ); } add_action( ‘add_meta_boxes_post’, ‘change_publish_meta_box’ ); (Change YOUR TITLE HERE to whatever you want)

Can we have private drafts?

I would probably create a custom field / check box for this for a draft stage. Then hook into post status transition (or around) and when post is published force it to only private, even if normal publish was pressed. From personal experience custom post statuses are a wreck. They seem like a good idea, … Read more

Error trying to publish immediately. Post status = future (Missed schedule error)

So the issue in this case was that PHP wasn’t displaying correct UTC Time. Thanks to @TomJNowell for pointing me in the right way. It seems to be a bug/error in some Plesk installation: https://talk.plesk.com/threads/utc-time-issue-plesk-php-7-3-7-4-on-centos7.356169/ To solve the issue we have replaced the UTC file usr/share/zoneinfo/UTC with another copy from another server. After that, UTC … Read more

Disable “preview changes” button

Please replace $post_type with your post_type in question, e.g. post, page, cpt_slug,… The function echoing the meta box with the preview button is called post_submit_meta_box. The condition to show the button is set with the function is_post_type_viewable. Following that: If the {$post_type}s flags publicly_queryable or _builtin and public are set to true the preview button … Read more

How can I create custom button in post.php

Use media_buttons action for it. Check below code. add_action(‘media_buttons’, ‘add_my_media_button’); function add_my_media_button(){ echo ‘<a href=”‘.get_site_url().’/wp-admin/customize.php” class=”button button-default”>Customize</a>’; } Hope this will helps you. Thanks!

How to run a function when post is edited or updated using publish post action?

With the post_updated hook you can trigger an action when the post is updated. He passes 3 parameters: $post_ID (the post ID), $post_after(the post object after the edit), $post_before (the post object before the edit) Here’s an example: <?php function check_values($post_ID, $post_after, $post_before){ echo ‘Post ID:’; var_dump($post_ID); echo ‘Post Object AFTER update:’; var_dump($post_after); echo ‘Post … Read more

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