__construct(); } function __construct() { if ( $_GET['page'] == 'anthologize/includes/class-new-project.php' ) $this->display(); } function save_project () { $post_data = array(); $post_data['post_title'] = $_POST['post_title']; $post_data['post_type'] = 'anth_project'; $post_data['post_status'] = $_POST['post_status']; $new_anthologize_meta = $_POST['anthologize_meta']; // print_r($_POST); die(); // If we're editing an existing project. if ( !empty($_POST['project_id'])) { $the_project = get_post( $_POST['project_id'] ); if ( $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); update_post_meta($new_post, 'anthologize_meta', $new_anthologize_meta ); } wp_redirect( get_bloginfo( 'url' ) . '/wp-admin/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']) ) { $project_id = $this->save_project(); } $project = get_post(@$_GET['project_id'] ); $meta = get_post_meta( $project->ID, 'anthologize_meta', TRUE ); ?>
