/** * Add submenu items for archives under the post type menu item. * * Ensures the user has the capability to edit pages in general as well * as the individual page before displaying the submenu item. * * @since 1.0.0 */ function audiotheme_archives_admin_menu() { $archives = get_audiotheme_archive_ids(); if (empty($archives)) { return; } // Verify the user can edit audiotheme_archive posts. $archive_type_object = get_post_type_object('audiotheme_archive'); if (!current_user_can($archive_type_object->cap->edit_posts)) { return; } foreach ($archives as $post_type => $archive_id) { // Verify the user can edit the particular audiotheme_archive post in question. if (!current_user_can($archive_type_object->cap->edit_post, $archive_id)) { continue; } $parent_slug = 'audiotheme_gig' === $post_type ? 'audiotheme-gigs' : 'edit.php?post_type=' . $post_type; // Add the submenu item. add_submenu_page($parent_slug, $archive_type_object->labels->singular_name, $archive_type_object->labels->singular_name, $archive_type_object->cap->edit_posts, add_query_arg(array('post' => $archive_id, 'action' => 'edit'), 'post.php'), null); } }
/** * Save the active archive IDs. * * Determines when an archive has become inactive and moves it to a separate * option so that if it's activated again in the future, a new post won't be * created. * * Will flush rewrite rules if any changes are detected. * * @since 1.0.0 * * @param array $ids Associative array of post type slugs as keys and archive post IDs as the values. */ function audiotheme_archives_save_active_archives($ids) { $archives = get_audiotheme_archive_ids(); $diff = array_diff_key($archives, $ids); if (count($ids) !== count($archives) || $diff) { $inactive = (array) get_option('audiotheme_archives_inactive'); // Remove $ids from $inactive. $inactive = array_diff_key(array_filter($inactive), $ids); // Move the diff between the $ids parameter and the $archives option to the $inactive option. $inactive = array_merge($inactive, $diff); update_option('audiotheme_archives', $ids); update_option('audiotheme_archives_inactive', $inactive); // Update post type rewrite base options. foreach ($ids as $post_type => $id) { audiotheme_archives_update_post_type_rewrite_base($post_type, $id); } flush_rewrite_rules(); } }