Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I run a multiple author platform where many users have editorial privileges. I'm in the process of moving all editorial tasks from the Post edit page to the front-end (Post preview).

I have added an Assistant Editor meta box to the post edit page: enter image description here

Here is the stripped down code for it (based on s_ha_dum's code):

add_action( 'add_meta_boxes', 'assistant_editor_box' );
function assistant_editor_box() {
    add_meta_box(
        'assistant_editor_box', // id, used as the html id att
        __( 'Assistant Editor' ), // meta box title
        'editor_tasks', // callback function, spits out the content
        'post', // post type or page. This adds to posts only
        'side', // context, where on the screen
        'high' // priority, where should this go in the context
    );

}

function editor_tasks( $post ) {
    global $wpdb;
    $value = get_post_meta($post->ID, 'edtasks', true);

    echo '<div class="misc-pub-section misc-pub-section-last"><span id="timestamp">Editorial Tasks: <br />';

    $edtasks = array(
        1 => ' <b>Proofread</b> (first)',
        2 => ' <b>Tags</b> ',
        3 => ' <b>Etc...</b> '
    );

    foreach ($edtasks as $id => $text) {
    $checked = (in_array($id,(array)$value)) ? ' checked="checked"' : '';
    echo '<label><input type="checkbox" name="edtasks[]" value="' . $id . '"'.  $checked . '/>'.$text.'</label><br />';
    }

    echo 'Assistant Editors: <br />';

    $qry['relation'] = 'OR';
    $qry[] = array(
      'key' => $wpdb->prefix.'capabilities',
      'value' => 'editor',
      'compare' => 'like'
    );
    $qry[] = array(
      'key' => $wpdb->prefix.'capabilities',
      'value' => 'administrator',
      'compare' => 'like'
    );
    $qry = array('fields' => 'all_with_meta','meta_query'=>$qry);

    $alleds = get_users($qry);

    $currenteds = get_post_meta($post->ID, 'currenteds', true);

    foreach ($alleds as $ed) {
    $checked = (in_array($ed->ID,(array)$currenteds)) ? ' checked="checked"' : '';
    $disabled = ( current_user_can( 'manage_options' ) ) ? '' : ( $ed->ID != get_current_user_id() ) ? ' style="display:none"' : '';
    echo '<label ' . $disabled . ' ><input type="checkbox" name="currenteds[]" value="' . $ed->ID . '"' . $checked . $disabled . '"/> '.$ed->user_nicename.'</label>';
    }

    echo '</span></div>';
}

add_action( 'save_post', 'save_metadata_ass_ed');

function save_metadata_ass_ed($postid)
{   
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
    if ( !current_user_can( 'edit_page', $postid ) ) return false;
    if( empty($postid) ) return false;

    if ( is_null($_REQUEST["edtasks"]) ) {
        delete_post_meta($postid, 'edtasks');
    } else {
        update_post_meta($postid, 'edtasks', $_REQUEST['edtasks']);
    }

    if ( is_null($_REQUEST["currenteds"]) ) {
    delete_post_meta($postid, 'currenteds');
    } else {
    update_post_meta($postid, 'currenteds', $_REQUEST['currenteds']);
    }
}

I want to add this meta box to the post preview page (frontend) and allow the editor to update it there, ideally by a Save button or link using Ajax. Is this possible and how?

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.