/** * Enqueues the FZ Project meta styles. */ function enqueue_project_styles() { $screen = get_current_screen(); if (get_projects_post_type_name() !== $screen->post_type) { return; } if ('post' !== $screen->base) { return; } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.min' : ''; wp_enqueue_style('fz-project-meta', FZP_URL . "/assets/css/fz-project-meta{$min}.css", array(), FZP_VERSION); }
/** * Save the Project Meta Fields * * @param int $post_id The ID of the post we're saving meta for. */ function save_project_meta($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (get_projects_post_type_name() !== get_post_type($post_id)) { return; } if (!isset($_POST['fz_project_nonce']) || !wp_verify_nonce($_POST['fz_project_nonce'], 'fz_project_meta')) { return; } if (!current_user_can('edit_post', $post_id)) { return; } $meta_keys = array(get_project_tagline_meta_key()); foreach ($meta_keys as $meta_key) { if (!empty($_POST[$meta_key])) { update_post_meta($post_id, $meta_key, $_POST[$meta_key]); } else { delete_post_meta($post_id, $meta_key); } } }
/** * Save the Project Meta Fields * * @param int $post_id The ID of the post we're saving meta for. */ function save_project_meta($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (get_projects_post_type_name() !== get_post_type($post_id)) { return; } if (!isset($_POST['fz_project_nonce']) || !wp_verify_nonce($_POST['fz_project_nonce'], 'fz_project_meta')) { return; } if (!current_user_can('edit_post', $post_id)) { return; } $meta_keys = array(get_project_tagline_meta_key(), get_project_github_meta_key(), get_project_lead_meta_key()); foreach ($meta_keys as $meta_key) { if (!empty($_POST[$meta_key])) { update_post_meta($post_id, $meta_key, $_POST[$meta_key]); } else { delete_post_meta($post_id, $meta_key); } } $non_unique_meta_keys = array(get_project_team_members_meta_key()); foreach ($non_unique_meta_keys as $meta_key) { delete_post_meta($post_id, $meta_key); if (!empty($_POST[$meta_key])) { foreach ($_POST[$meta_key] as $meta_value) { if (empty($meta_value)) { continue; } add_post_meta($post_id, $meta_key, $meta_value, false); } } } }
/** * Registers the Projects Post Type. */ function register_projects_post_type() { $labels = array('name' => esc_html__('Projects', 'fzp'), 'singular_name' => esc_html__('Project', 'fzp'), 'add_new' => esc_html__('Add New', 'fzp'), 'add_new_item' => esc_html__('Add New Project', 'fzp'), 'edit_item' => esc_html__('Edit Project', 'fzp'), 'new_item' => esc_html__('New Project', 'fzp'), 'all_items' => esc_html__('All Projects', 'fzp'), 'view_item' => esc_html__('View Project', 'fzp'), 'search_items' => esc_html__('Search Projects', 'fzp'), 'not_found' => esc_html__('No Project found', 'fzp'), 'not_found_in_trash' => esc_html__('No Project found in Trash', 'fzp'), 'parent_item_colon' => '', 'menu_name' => esc_html__('Projects', 'fzp')); $args = array('labels' => $labels, 'public' => true, 'description' => esc_html__('Projects', 'jdrf'), 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'menu_position' => 21, 'menu_icon' => 'dashicons-portfolio', 'show_in_menu' => true, 'has_archive' => false, 'rewrite' => array('slug' => get_projects_post_type_slug(), 'with_front' => false), 'supports' => array('title', 'thumbnail', 'editor', 'author')); register_post_type(get_projects_post_type_name(), $args); }