/** * Filter audiotheme_archive permalinks to match the corresponding post type's * archive. * * @since 1.0.0 * * @param string $permalink Default permalink. * @param WP_Post $post Post object. * @param bool $leavename Optional, defaults to false. Whether to keep post name. * @return string Permalink. */ function audiotheme_archives_post_type_link($permalink, $post, $leavename) { global $wp_rewrite; if ('audiotheme_archive' === $post->post_type) { $post_type = is_audiotheme_post_type_archive_id($post->ID); $post_type_object = get_post_type_object($post_type); if (get_option('permalink_structure')) { $front = '/'; if ($wp_rewrite->using_index_permalinks()) { $front .= $wp_rewrite->index . '/'; } if (isset($post_type_object->rewrite) && $post_type_object->rewrite['with_front']) { $front = $wp_rewrite->front; } if ($leavename) { $permalink = home_url($front . '%postname%/'); } else { $permalink = home_url($front . $post->post_name . '/'); } } else { $permalink = add_query_arg('post_type', $post_type, home_url('/')); } } return $permalink; }
/** * Display archive settings meta box. * * The meta box needs to be activated first, then fields can be displayed using * one of the actions. * * @since 1.3.0 * * @param WP_Post $post Archive post. */ function audiotheme_archive_settings_meta_box($post, $args = array()) { $post_type = is_audiotheme_post_type_archive_id($post->ID); wp_nonce_field('save-archive-meta_' . $post->ID, 'audiotheme_archive_nonce'); do_action('audiotheme_archive_settings_meta_box', $post, $post_type, $args['args']['fields']); do_action('audiotheme_archive_settings_meta_box_' . $post_type, $post, $args['args']['fields']); }
/** * Add current screen ID as CSS class to the body element. * * @since 1.0.0 * * @param string $class Body class. * @return string */ function audiotheme_admin_body_class($classes) { global $post; $classes .= ' screen-' . sanitize_html_class(get_current_screen()->id); if ('audiotheme_archive' === get_current_screen()->id && ($post_type = is_audiotheme_post_type_archive_id($post->ID))) { $classes .= ' ' . $post_type . '-archive'; } return implode(' ', array_unique(explode(' ', $classes))); }
/** * Add an orderby setting to the record archive. * * Allows for changing the sort order of records. Custom would require a plugin * like Simple Page Ordering. * * @since 1.3.0 * * @param WP_Post $post Post object. */ function audiotheme_record_archive_settings($post) { $post_type = is_audiotheme_post_type_archive_id($post->ID); if ('audiotheme_record' !== $post_type) { return; } $options = array('release_year' => __('Release Year', 'audiotheme'), 'title' => __('Title', 'audiotheme'), 'custom' => __('Custom', 'audiotheme')); $orderby = get_audiotheme_archive_meta('orderby', true, 'release_year', 'audiotheme_record'); ?> <p> <label for="audiotheme-orderby"><?php _e('Order by:', 'audiotheme'); ?> </label> <select name="audiotheme_orderby" id="audiotheme-orderby"> <?php foreach ($options as $id => $value) { printf('<option value="%s"%s>%s</option>', esc_attr($id), selected($id, $orderby, false), esc_html($value)); } ?> </select> </p> <?php }
/** * Load the featured video template part. * * @since 1.0.0 */ function huesos_audiotheme_template_featured_video() { $post_type = is_audiotheme_post_type_archive_id(get_post()->ID); if ('audiotheme_video' === $post_type || !($featured_video = get_audiotheme_archive_meta('huesos_featured_video', true, '', $post_type))) { return; } include locate_template('audiotheme/parts/featured-video.php'); }
/** * Flush the rewrite rules when an archive post slug is changed. * * @since 1.0.0 * * @param int $post_id Post ID * @param WP_Post $post_after Updated post object. * @param WP_Post $post_before Post object before udpate. */ function audiotheme_archives_post_updated($post_id, $post_after, $post_before) { if (($post_type = is_audiotheme_post_type_archive_id($post_id)) && $post_after->post_name !== $post_before->post_name) { audiotheme_archives_update_post_type_rewrite_base($post_type, $post_id); flush_rewrite_rules(); } }