Esempio n. 1
0
 /**
  * Step 2: handle the custom Bulk Action
  * 
  * Based on the post http://wordpress.stackexchange.com/questions/29822/custom-bulk-action
  */
 function custom_bulk_action()
 {
     global $typenow;
     $post_type = $typenow;
     /*if($post_type == 'post') {*/
     // get the action
     $wp_list_table = _get_list_table('WP_Posts_List_Table');
     // depending on your resource type this could be WP_Users_List_Table, WP_Comments_List_Table, etc
     $action = $wp_list_table->current_action();
     $allowed_actions = array("approve");
     if (!in_array($action, $allowed_actions)) {
         return;
     }
     // security check
     check_admin_referer('bulk-posts');
     // make sure ids are submitted.  depending on the resource type, this may be 'media' or 'ids'
     if (isset($_REQUEST['post'])) {
         $post_ids = array_map('intval', $_REQUEST['post']);
     }
     if (empty($post_ids)) {
         return;
     }
     // this is based on wp-admin/edit.php
     //$sendback = remove_query_arg( array('exported', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
     if (!$sendback) {
         $sendback = admin_url("edit.php?post_type={$post_type}");
     }
     $pagenum = $wp_list_table->get_pagenum();
     $sendback = add_query_arg('paged', $pagenum, $sendback);
     switch ($action) {
         case 'approve':
             // if we set up user permissions/capabilities, the code might look like:
             //if ( !current_user_can($post_type_object->cap->export_post, $post_id) )
             //	wp_die( __('You are not allowed to export this post.') );
             $exported = 0;
             foreach ($post_ids as $post_id) {
                 if (!$this->perform_export($post_id)) {
                     wp_die(__('Error exporting post.'));
                 }
                 change_post_status($post_id, 'publish');
                 $exported++;
             }
             break;
         default:
             return;
     }
     wp_redirect($sendback);
     exit;
     /*}*/
 }
Esempio n. 2
0
function init_postmoddare()
{
    if (current_user_can('edit_others_posts')) {
        // Responses to Post Status Changes //
        if (isset($_POST['FE_PUBLISH']) && $_POST['FE_PUBLISH'] == 'FE_PUBLISH') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                change_post_status((int) $_POST['pid'], 'publish');
            }
        }
        if (isset($_POST['FE_TRASH']) && $_POST['FE_TRASH'] == 'FE_TRASH') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                change_post_status((int) $_POST['pid'], 'trash');
            }
        }
        // Responses to User Level Changes //
        if (isset($_POST['FE_USER_PROMOTE_PUBLISH']) && $_POST['FE_USER_PROMOTE_PUBLISH'] == 'FE_USER_PROMOTE_PUBLISH') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                $current_post = get_post((int) $_POST['pid'], 'ARRAY_A');
                change_user_level($current_post['post_author'], 'author');
                change_post_status((int) $_POST['pid'], 'publish');
            }
        }
        if (isset($_POST['FE_USER_PROMOTE']) && $_POST['FE_USER_PROMOTE'] == 'FE_USER_PROMOTE') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                $current_post = get_post((int) $_POST['pid'], 'ARRAY_A');
                change_user_level($current_post['post_author'], 'author');
            }
        }
        if (isset($_POST['FE_USER_DEMOTE']) && $_POST['FE_USER_DEMOTE'] == 'FE_USER_DEMOTE') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                $current_post = get_post((int) $_POST['pid'], 'ARRAY_A');
                change_user_level($current_post['post_author'], 'subscriber');
            }
        }
        if (isset($_POST['FE_USER_RESET']) && $_POST['FE_USER_RESET'] == 'FE_USER_RESET') {
            if (isset($_POST['pid']) && !empty($_POST['pid'])) {
                $current_post = get_post((int) $_POST['pid'], 'ARRAY_A');
                change_user_level($current_post['post_author'], 'contributor');
            }
        }
    }
}