class Drafts_For_Friends { function __construct() { add_action( 'init', array( $this, 'init' ) ); } function init() { // ... add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); } /** * Performs any extra processing when a post is saved * @param int $post_id The ID of the current revision of the edited post * @param object $revision The full object of the current revision of the edited post */ public function save_post( $post_id, $post ) { if( 1 !== did_action( 'save_post' ) ) return; $ignored_actions = array( 'trash', 'untrash', 'restore' ); // 3.6-alpha-23646 passes the canonical $post, while previous versions passed the revision, so we need to check which one we have //if ( 'revision' == $post->post_type ) //$post = get_post( $post->post_parent ); // Avoid processing the post if it's not in the desired state if( isset( $_GET[ 'action' ] ) && in_array( $_GET[ 'action' ], $ignored_actions ) ) return; if( !$post || 'post' != $post->post_type || ! current_user_can( self::REQUIRED_CAPABILITY, $post_id ) ) return; if( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || 'auto-draft' == $post->post_status ) return; // Process the post $status_messages = $this->process_metabox_actions( $post->ID, $this->validate_metabox_actions( $_POST ) ); } /** * Processes actions triggered in metaboxes * * @since 2.3 * * @param int $post_id The ID of the canonical post that the current revision being saved is attached to * @param array $actions The metabox actions that were activated * @return string The status method from the action taken */ protected function process_metabox_actions( $post_id, $actions ) { $status_messages = array(); if ( isset( $actions['share'] ) ) $status_messages[] = $this->process_post_options( $post_id, $actions['share']['expires'], $actions['share']['measure'] ); if ( isset( $actions['extend'] ) ) $status_messages[] = $this->process_extend( $actions['extend']['key'], $actions['extend']['expires'], $actions['extend']['measure'] ); if ( isset( $actions['email'] ) ) $status_messages[] = $this->process_email_share_url( $actions['email']['key'], $actions['email']['guest_email_address'] ); if ( isset( $actions['unshare'] ) ) $status_messages[] = $this->process_delete( $actions['unshare']['key'] ); return $status_messages; } }