display(); } function save_project () { $post_data = array( 'post_title' => 'Default Title', 'post_type' => 'anth_project', 'post_status' => '', 'post_date' => date( "Y-m-d G:H:i" ), 'post_date_gmt' => gmdate( "Y-m-d G:H:i" ), ); if (!empty($_POST['post_title'])) $post_data['post_title'] = $_POST['post_title']; if (!empty($_POST['post_status'])) $post_data['post_status'] = $_POST['post_status']; // If we're editing an existing project. if ( !empty($_POST['project_id'])) { if ( !$new_anthologize_meta = get_post_meta( $_POST['project_id'], 'anthologize_meta', true ) ) { $new_anthologize_meta = $_POST['anthologize_meta']; } else { foreach ( $_POST['anthologize_meta'] as $key => $value ) { $new_anthologize_meta[$key] = $value; } } $the_project = get_post( $_POST['project_id'] ); if ( !empty ($_POST['post_status']) && ($the_project->post_status != $_POST['post_status'] )) $this->change_project_status( $_POST['project_id'], $_POST['post_status'] ); $post_data['ID'] = $_POST['project_id']; wp_update_post($post_data); if ( is_null($new_anthologize_meta) ) { delete_post_meta( $post_data['ID'] ,'anthologize_meta' ); } else { update_post_meta( $post_data['ID'], 'anthologize_meta', $new_anthologize_meta ); } } else { // Otherwise, we're creating a new project $new_post = wp_insert_post($post_data); // Nothing to save if we are creating a new project //update_post_meta($new_post, 'anthologize_meta', $new_anthologize_meta ); } wp_redirect( get_admin_url() . 'admin.php?page=anthologize&project_saved=1' ); } function change_project_status( $project_id, $status ) { if ( $status != 'publish' && $status != 'draft' ) return; $args = array( 'post_status' => array( 'draft', 'publish' ), 'post_parent' => $project_id, 'nopaging' => true, 'post_type' => 'anth_part' ); $parts = get_posts( $args); foreach ( $parts as $part ) { if ( $part->post_status != $status ) { $update_part = array( 'ID' => $part->ID, 'post_status' => $status, ); wp_update_post( $update_part ); } $args = array( 'post_status' => array( 'draft', 'publish' ), 'post_parent' => $part->ID, 'nopaging' => true, 'post_type' => 'anth_library_item' ); $library_items = get_posts( $args ); foreach( $library_items as $item ) { if ( $item->post_status != $status ) { $update_item = array( 'ID' => $item->ID, 'post_status' => $status, ); wp_update_post( $update_item ); } } } } function display() { if ( isset($_POST['save_project']) ) { $this->save_project(); return; } if (!empty($_GET['project_id'])) { // We are editing a project $project_id = $_GET['project_id']; $project = get_post( $project_id ); if (empty($project)) { echo 'Unknown project ID'; return; } $meta = get_post_meta( $project->ID, 'anthologize_meta', TRUE ); } else { $project = NULL; } ?>

*/ ?>
post_status == 'publish' ) : ?>checked="checked" > Published
post_status != 'publish' ) : ?>checked="checked"> Draft