Viewing 1 replies (of 1 total)
  • Hi

    this is a simple snippet to use this plugin

    // create a new post status
    add_action('init','myplugin_init');
    function myplugin_init() {
      register_post_status( 'closed',
                             array(
    				'label' => 'Closed',
    				'public' => false,
    			) );
    }
    
    // hook to "available_status" to add new status in the select in "publish box"
    //add_filter('available_statuses','myplugin_liststatus');  // for a bug this don't work properly. use next hook, instead
    add_filter('myposttype_available_statuses','myplugin_liststatus'); // you can use this in you want edit select only for myposttype
    function myplugin_liststatus($statuses) {
        $statuses['closed'] = 'Closed';
        return $statuses;
    }
    
    // hook to "publish_action" to edit label in publish button when you want go in your new status
    add_filter('publish_action','myplugin_publish_action');
    //add_filter('myposttype_publish_action','myplugin_publish_action');
    function myplugin_publish_action($action) {
    global $post;
        switch ($post->post_status) {
        /*
          this is normal work-flow
            case 'draft'     :
            case 'auto-draft':
                               if (current_user_can('publish')) return array('label'=>'Publish', 'action'=>'publish');
                               else                             return array('label'=>'Pending', 'action'=>'publish');
            break;
            case 'pending' :
            					return array('label'=>'Publish', 'action'=>'publish');
            break;
        */
            case 'publish'   : if (current_user_can('publish_myposttype')) return array('label'=>'Close now', 'action'=>'publish');
                               else                                  return array('label'=>'Update', 'action'=>'publish');
            break;
            case 'closed'   :
            					return array('label'=>'Re-open', 'action'=>'publish');
            break;
    
        }
    
    }
    // You can use "save_action" hook to edit label in "save" button
    add_filter('save_action','myplugin_save_action');
    //add_filter('myposttype_save_action','myplugin_save_action');
    function myplugin_save_action($action) {
    global $post;
        if ($post->post_status=='closed') return array('label'=>'Save as closed', 'action'=>'save');
     }
    
    // REMEMBER : set the correct status in publish_post action because anoter filter/plugin can reset your status in "publish"
    add_action('publish_myposttype','myplugin_workflow');
    function myplugin_workflow() {
    global $post;
    
        $new_status = $post->post_status;
        if ($_POST['post_status']=='closed') $post->post_status = 'closed';
        if ($new_status!='publish') wp_update_post($post);
    
    }

    of course you can use only the hooks that you need

    if you need more explanation post another comment here,

    goodnight

Viewing 1 replies (of 1 total)
  • The topic ‘Documentation’ is closed to new replies.