Add javascript when post is published

To enqueue scripts on the admin side, you should use the admin_enqueue_scripts hook. In this callback I check that are on the appropriate page (i.e. the page where you edit posts / post types), using the passed $hook argument. Optionally you can check if the post is of a specific type (in case this is … Read more

Publish post when edit post form submitted with enter/return pressed on keyboard

you may add a filter on wp_insert_post_data: add_filter( ‘wp_insert_post_data’, ‘my_force_publish_post’, 10, 2 ); function my_force_publish_post( $data, $postarr ) { if ( ! isset($postarr[‘ID’]) || ! $postarr[‘ID’] ) return $data; if ( $postarr[‘post_type’] !== ‘inventory’ ) return $data; $old = get_post( $postarr[‘ID’] ); // the post before update if( $old->post_status !== ‘draft’ ) { // force … Read more

WordPress prompt checklist before publish?

Create new plugin and add this as your the content: <?php /* Plugin Name: [CR]TestDropIn Plugin URI: http://bayu.freelancer.web.id/ Description: A barebone plugin to test whatever wordpress API you want to test Author: Arief Bayu Purwanto Version: 0.0.1 Author URI: http://bayu.freelancer.web.id */ add_action(‘admin_head’, ‘xxx_admin_hook’); function xxx_admin_hook(){ ?> <script language=”javascript” type=”text/javascript”> jQuery(document).ready(function() { jQuery(‘#post’).submit(function() { //alert(‘Handler for … Read more

Restrict the Number of Posts an Author can Publish (over time)?

Closest thing out there seems to be: http://www.spaw.it/359/wordpress-plugin-limit-post-creation/, but it only sets a single, hard limit. I think your best bet is to utilize this WordPress thread with code to limit number of posts for registered users: http://wordpress.org/support/topic/limit-the-number-of-posts-a-user-can-make?replies=18 You would need to change the $count_posts var to only count posts made within your time-frame…

In what sequence are the hooks fired when a post is “published”?

What exactly do you mean with “published”? One thing you can try is this : http://planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/ The script runs in your WordPress root (or in /wp-admin/ if you prefer) and enumerates filters that are loaded in your blog. Hooks are displayed alphabetically, and for each hook, active filters (or actions, they’re the same) are listed … Read more

How to change post status in hook?

You get the full post object as a second parameter on save_post. Use it to change the status just like the following code. add_action( ‘save_post’, ‘wpse_78351_status’, 10, 2 ); function wpse_78351_status( $post_ID, $post ) { remove_filter( current_filter(), __FUNCTION__ ); if ( ‘trash’ !== $post->post_status ) //adjust the condition { $post->post_status=”draft”; // use any post status … Read more

When a user creates a post (pending), send a confirmation link that allows them to publish

You need a function that hook into post status transitions and send and email containing a link with some verification variables and a function that takes that variables, check them and if all ok update posts status. Following code I think is self-explanatory, and comments give additional help: add_action(‘new_to_pending’, ‘send_approve_link’); add_action(‘draft_to_pending’, ‘send_approve_link’); add_action(‘auto-draft_to_pending’, ‘send_approve_link’); add_action(‘init’, … Read more

How to show an error message after publishing a post?

I wouldn’t use that hook. Here’s why Try something like this using admin_notices. function wpsites_admin_notice() { $screen = get_current_screen(); if( ‘post’ == $screen->post_type && ‘edit’ == $screen->base ){ ?> <div class=”error”> <p><?php _e( ‘Updated Demo Message!’, ‘wpsites’ ); ?></p> </div> <?php }} add_action( ‘admin_notices’, ‘wpsites_admin_notice’ ); Untested.