Advertisement
Guest User

WP #23906 example

a guest
Apr 9th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. class Drafts_For_Friends {
  2.  
  3.     function __construct() {
  4.         add_action( 'init', array( $this, 'init' ) );
  5.     }
  6.  
  7.     function init() {
  8.         // ...
  9.         add_action( 'save_post',        array( $this, 'save_post' ), 10, 2 );
  10.     }
  11.    
  12.     /**
  13.      * Performs any extra processing when a post is saved
  14.      * @param int $post_id The ID of the current revision of the edited post
  15.      * @param object $revision The full object of the current revision of the edited post
  16.      */
  17.     public function save_post( $post_id, $post )
  18.     {
  19.         if( 1 !== did_action( 'save_post' ) )
  20.             return;
  21.            
  22.         $ignored_actions = array( 'trash', 'untrash', 'restore' );
  23.        
  24.         // 3.6-alpha-23646 passes the canonical $post, while previous versions passed the revision, so we need to check which one we have
  25.         //if ( 'revision' == $post->post_type )
  26.             //$post = get_post( $post->post_parent );
  27.        
  28.         // Avoid processing the post if it's not in the desired state
  29.         if( isset( $_GET[ 'action' ] ) && in_array( $_GET[ 'action' ], $ignored_actions ) )
  30.             return;
  31.  
  32.         if( !$post || 'post' != $post->post_type || ! current_user_can( self::REQUIRED_CAPABILITY, $post_id ) )
  33.             return;
  34.  
  35.         if( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || 'auto-draft' == $post->post_status )
  36.             return;
  37.        
  38.         // Process the post
  39.         $status_messages = $this->process_metabox_actions( $post->ID, $this->validate_metabox_actions( $_POST ) );
  40.     }
  41.  
  42.     /**
  43.      * Processes actions triggered in metaboxes
  44.      *
  45.      * @since 2.3
  46.      *
  47.      * @param int $post_id The ID of the canonical post that the current revision being saved is attached to
  48.      * @param array $actions The metabox actions that were activated
  49.      * @return string The status method from the action taken
  50.      */
  51.     protected function process_metabox_actions( $post_id, $actions )
  52.     {
  53.         $status_messages = array();
  54.        
  55.         if ( isset( $actions['share'] ) )
  56.             $status_messages[] = $this->process_post_options( $post_id, $actions['share']['expires'], $actions['share']['measure'] );
  57.        
  58.         if ( isset( $actions['extend'] ) )
  59.             $status_messages[] = $this->process_extend( $actions['extend']['key'], $actions['extend']['expires'], $actions['extend']['measure'] );
  60.        
  61.         if ( isset( $actions['email'] ) )
  62.             $status_messages[] = $this->process_email_share_url( $actions['email']['key'], $actions['email']['guest_email_address'] );
  63.                
  64.         if ( isset( $actions['unshare'] ) )
  65.             $status_messages[] = $this->process_delete( $actions['unshare']['key'] );
  66.        
  67.         return $status_messages;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement