plugin_slug; $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); } /** * Load up custom css and js used in the admin panels for this plugin * * @since 1.0.0 */ public function archive_control_custom_admin_style_scripts() { wp_register_style( 'archive_control_admin_css', plugin_dir_url( __FILE__ ) . '/css/admin-style.css', false, self::VERSION ); wp_enqueue_style( 'archive_control_admin_css' ); wp_register_script( 'archive_control_admin_js', plugin_dir_url( __FILE__ ) . '/js/admin-scripts.js', 'jquery', self::VERSION, true ); $js_translations = array( 'media_upload_title_text' => __( 'Archive Featured Image', 'archive-control' ), 'media_upload_button_text' => __( 'Set featured image', 'archive-control' ) ); wp_localize_script( 'archive_control_admin_js', 'archive_control', $js_translations ); wp_enqueue_script( 'archive_control_admin_js' ); } /** * Used to insert a "Settings" link on the Plugin activation screen * * @since 1.0.0 * * @param array $links The array of existing links for the plugin */ public function archive_control_action_link( $links ) { $mylinks = array( '' . __('Settings', 'archive-control') . '', ); return array_merge( $links, $mylinks ); } /** * Activate the settings screens for the plugin * * @since 1.0.0 */ public function archive_control_menu() { add_options_page( __('Archive Control', 'archive-control'), __('Archive Control', 'archive-control'), 'manage_options', 'archive-control.php', array($this,'archive_control_options') ); $archive_control_options = get_option('archive_control_options'); if ($archive_control_options) { foreach($archive_control_options as $post_type => $options) { $title_val = isset($options['title']) ? $options['title'] : null; $image_val = isset($options['image']) ? $options['image'] : null; $before_val = isset($options['before']) ? $options['before'] : null; $after_val = isset($options['after']) ? $options['after'] : null; if ($title_val == 'custom' || $image_val == 'enabled' || $before_val == 'textarea' || $after_val == 'textarea') { if ($post_type == 'post') { $parent_slug = 'edit.php'; } else { $parent_slug = 'edit.php?post_type=' . $post_type; } add_submenu_page( $parent_slug, __('Edit Archive Page', 'archive-control'), __('Edit Archive Page', 'archive-control'), 'edit_posts', 'edit-archive-' . $post_type, array($this,'archive_control_edit_page_callback') ); } //has before or after value } } } /** * Register the necessary settings to store for plugin use. * * @since 1.0.0 */ public function archive_control_settings() { register_setting( 'archive-control-options-group', 'archive_control_options' ); $archive_control_options = get_option('archive_control_options'); if ($archive_control_options) { foreach($archive_control_options as $post_type => $options) { register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_title' ); register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_image' ); register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_before' ); register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_after' ); } } } /** * The variable settings screen that can be activated per custom post type * * @since 1.0.0 */ public function archive_control_edit_page_callback() { $screen = get_current_screen(); $current_post_type = $screen->post_type; $archive_control_options = get_option('archive_control_options'); $archive_control_cpt_title = get_option('archive_control_' . $current_post_type . '_title'); $archive_control_cpt_image = get_option('archive_control_' . $current_post_type . '_image'); $archive_control_cpt_before = get_option('archive_control_' . $current_post_type . '_before'); $archive_control_cpt_after = get_option('archive_control_' . $current_post_type . '_after'); if ($screen->post_type == '' && $screen->parent_file == 'edit.php') { $current_post_type = 'post'; } $current_post_type_object = get_post_type_object($current_post_type); $current_post_type_options = isset($archive_control_options[$current_post_type]) ? $archive_control_options[$current_post_type] : null; ?>

label); ?>

'archive_control_' . $current_post_type . '_before', 'textarea_rows' => 10 );?>

'archive_control_' . $current_post_type . '_after', 'textarea_rows' => 10 );?>

Found a bug or have a feature request? Let us know on the WordPress plugin directory, or send a pull request with GitHub.

true, '_builtin' => false ); $post_types = get_post_types($args, 'objects' ); $archive_control_options = get_option('archive_control_options'); foreach ($post_types as $post_type ) { if($post_type->has_archive) { $edit_url = get_admin_url() . 'edit.php?post_type=' . $post_type->name . '&page=edit-archive-' . $post_type->name; ?>

label; ?>

name]['title']) ? $archive_control_options[$post_type->name]['title'] : null; ?>
name]['image']) ? $archive_control_options[$post_type->name]['image'] : null; $image_placement_val = isset($archive_control_options[$post_type->name]['image-placement']) ? $archive_control_options[$post_type->name]['image-placement'] : null; $image_pages_val = isset($archive_control_options[$post_type->name]['image-pages']) ? $archive_control_options[$post_type->name]['image-pages'] : null; ?>
name]['before']) ? $archive_control_options[$post_type->name]['before'] : null; $before_placement_val = isset($archive_control_options[$post_type->name]['before-placement']) ? $archive_control_options[$post_type->name]['before-placement'] : null; $before_pages_val = isset($archive_control_options[$post_type->name]['before-pages']) ? $archive_control_options[$post_type->name]['before-pages'] : null; ?>
name]['after']) ? $archive_control_options[$post_type->name]['after'] : null; $after_placement_val = isset($archive_control_options[$post_type->name]['after-placement']) ? $archive_control_options[$post_type->name]['after-placement'] : null; $after_pages_val = isset($archive_control_options[$post_type->name]['after-pages']) ? $archive_control_options[$post_type->name]['after-pages'] : null; ?>
name]['orderby']) ? $archive_control_options[$post_type->name]['orderby'] : null; $meta_key_val = isset($archive_control_options[$post_type->name]['meta_key']) ? $archive_control_options[$post_type->name]['meta_key'] : null; ?> />
name]['order']) ? $archive_control_options[$post_type->name]['order'] : null; ?>
name]['pagination']) ? $archive_control_options[$post_type->name]['pagination'] : null; $posts_per_page_val = isset($archive_control_options[$post_type->name]['posts_per_page']) ? $archive_control_options[$post_type->name]['posts_per_page'] : null; ?> />

is_main_query() ){ if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['order'] !== 'default' && $options['order'] !== null) { $query->set( 'order', $options['order'] ); } //has order value if ($options['orderby'] !== 'default' && $options['orderby'] !== null) { $query->set( 'orderby', $options['orderby'] ); if ($options['orderby'] == 'meta_value' || $options['orderby'] == 'meta_value_num') { if ($options['meta_key'] !== null) { $query->set( 'meta_key', $options['meta_key'] ); } //has meta_key value } //meta_key value is needed } //has orderby value if ($options['pagination'] !== 'default' && $options['pagination'] !== null) { if ($options['pagination'] == 'custom') { if ($options['posts_per_page'] !== null) { $query->set( 'posts_per_page', $options['posts_per_page'] ); } } if ($options['pagination'] == 'none') { $query->set( 'posts_per_page', -1 ); } } //has pagination value } //is_post_type_artchive } //foreach } // is_archive } //is_main_query } //is not admin return; } /** * Insert some content above the WordPress loop on certain archive pages * * @since 1.1.0 * * @param object $query The existing WordPress query object */ public function archive_control_loop_start_content( $query ) { if( $query->is_main_query() ){ $this->archive_control_the_archive_top_content(true,'automatic'); } //is_main_query } /** * Insert some content above the WordPress loop on certain archive pages * * @since 1.1.0 * * @param boolean $html Whether to show the optional html markup surrounding the textarea * @param string $placement Whether the content will be placed automatically or by a theme function */ public static function archive_control_the_archive_top_content($html = true, $placement = 'function') { if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['before'] == 'textarea' && $options['before-placement'] == $placement) { $paged = get_query_var( 'paged', 0); if($options['before-pages'] == 'all-pages' || ($options['before-pages'] == 'first' && $paged == 0)) { Archive_Control::archive_control_archive_top_content(true, $post_type); }//handle page all/first options } //before textarea is enabled } //is_post_type_artchive } //foreach } // is_archive } /** * Insert the top content * * @since 1.1.0 * * @param boolean $html Whether to show the optional html markup surrounding the textarea * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_archive_top_content($html = true, $post_type = null) { $content = Archive_Control::archive_control_get_archive_top_content($post_type); if ($content) { if ($html === true) { echo "
"; echo "
"; } echo $content; if ($html === true) { echo "
"; echo "
"; } } } /** * Return the top content * * @since 1.1.0 * * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_get_archive_top_content($post_type = null) { if ($post_type === null) { if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); } } $archive_control_cpt_before = get_option('archive_control_' . $post_type . '_before'); if ($archive_control_cpt_before) { return apply_filters( 'the_content', $archive_control_cpt_before ); } //if has before content } /** * Insert some content above the WordPress loop * * @since 1.1.0 * * @param object $query The existing WordPress query object */ public function archive_control_loop_start_image( $query ){ if( $query->is_main_query() ){ $this->archive_control_display_archive_top_image(); } //is_main_query } /** * Decide if the archive featured image should be automatically placed * * @since 1.1.0 */ public static function archive_control_display_archive_top_image() { if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['image'] == 'enabled' && $options['image-placement'] == 'automatic') { $paged = get_query_var( 'paged', 0); if($options['image-pages'] == 'all-pages' || ($options['image-pages'] == 'first' && $paged == 0)) { Archive_Control::archive_control_the_archive_thumbnail(); }//handle page all/first options } //image is enabled } //is_post_type_artchive } //foreach } // is_archive } /** * Echo the archive thumbnail with markup * * @since 1.1.0 * * @param string $size The image size that you want displayed * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_the_archive_thumbnail($size = 'large', $post_type = null) { if ($post_type === null) { if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); } } $featured_img_id = Archive_Control::archive_control_get_archive_thumbnail_id($post_type); if ($featured_img_id) { echo "
"; echo wp_get_attachment_image($featured_img_id, $size); echo "
"; } } /** * Echo the archive thumbnail with html markup * * @since 1.1.0 * * @param string $size The image size that you want displayed * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_get_archive_thumbnail_src($size = 'large', $post_type = null) { if ($post_type === null) { if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); } } $featured_img_id = Archive_Control::archive_control_get_archive_thumbnail_id($post_type); if ($featured_img_id) { $featured_img_src = wp_get_attachment_image_src( $featured_img_id, $size ); if (is_array($featured_img_src)) { $thing = $featured_img_src[0]; return $thing; } } } /** * Get the archive thumbnail id * * @since 1.1.0 * * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_get_archive_thumbnail_id($post_type = null) { if ($post_type === null) { if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); } } $archive_control_cpt_image_id = get_option('archive_control_' . $post_type . '_image'); if ($archive_control_cpt_image_id) { if ( wp_attachment_is_image( $archive_control_cpt_image_id ) ) { return $archive_control_cpt_image_id; } } } /** * Insert some content below the WordPress loop on certain archive pages * * @since 1.1.0 * * @param object $query The existing WordPress query object */ public function archive_control_loop_end_content( $query ) { if( $query->is_main_query() ){ $this->archive_control_the_archive_bottom_content(true,'automatic'); } //is_main_query } /** * Insert some content below the WordPress loop on certain archive pages * * @since 1.1.0 * * @param boolean $html Whether to show the optional html markup surrounding the textarea * @param string $placement Whether the content will be placed automatically or by a theme function */ public static function archive_control_the_archive_bottom_content($html = true, $placement = 'function') { if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['after'] == 'textarea' && $options['after-placement'] == $placement) { $paged = get_query_var( 'paged', 0); if($options['after-pages'] == 'all-pages' || ($options['after-pages'] == 'first' && $paged == 0)) { Archive_Control::archive_control_archive_bottom_content(true, $post_type); }//handle page all/first options } //before textarea is enabled } //is_post_type_artchive } //foreach } // is_archive } /** * Insert the bottom content * * @since 1.1.0 * * @param boolean $html Whether to show the optional html markup surrounding the textarea * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_archive_bottom_content($html = true, $post_type = null) { $content = Archive_Control::archive_control_get_archive_bottom_content($post_type); if ($content) { if ($html === true) { echo "
"; echo "
"; } echo $content; if ($html === true) { echo "
"; echo "
"; } } } /** * Return the bottom content * * @since 1.1.0 * * @param string $post_type A post type slug that the content belongs to */ public static function archive_control_get_archive_bottom_content($post_type = null) { if ($post_type === null) { if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); } } $archive_control_cpt_after = get_option('archive_control_' . $post_type . '_after'); if ($archive_control_cpt_after) { return apply_filters( 'the_content', $archive_control_cpt_after ); } //if has after content } /** * Modify the archive title based on the user settings * * @since 1.0.0 * * @param string $title The existing archive page title */ public function archive_control_title_filter($title) { if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['title'] == 'custom') { $archive_control_cpt_title = get_option('archive_control_' . $post_type . '_title'); if ($archive_control_cpt_title) { $title = $archive_control_cpt_title; } //has title } //custom title setting if ($options['title'] == 'no-labels') { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '' . get_the_author() . ''; } elseif ( is_post_type_archive() ) { $title = post_type_archive_title( '', false ); } elseif ( is_tax() ) { $title = single_term_title( '', false ); } } //custom title set } //is_post_type_artchive } //foreach } // is_archive return $title; } } if ( ! function_exists( 'the_archive_top_content' ) ) { function the_archive_top_content($html = true) { Archive_Control::archive_control_the_archive_top_content($html); } } if ( ! function_exists( 'archive_top_content' ) ) { function archive_top_content($html = true, $post_type = null) { Archive_Control::archive_control_archive_top_content($html, $post_type); } } if ( ! function_exists( 'get_archive_top_content' ) ) { function get_archive_top_content($post_type = null) { return Archive_Control::archive_control_get_archive_top_content($post_type); } } if ( ! function_exists( 'the_archive_bottom_content' ) ) { function the_archive_bottom_content($html = true) { Archive_Control::archive_control_the_archive_bottom_content($html); } } if ( ! function_exists( 'archive_bottom_content' ) ) { function archive_bottom_content($html = true, $post_type = null) { Archive_Control::archive_control_archive_bottom_content($html, $post_type); } } if ( ! function_exists( 'get_archive_bottom_content' ) ) { function get_archive_bottom_content($post_type = null) { return Archive_Control::archive_control_get_archive_bottom_content($post_type); } } if ( ! function_exists( 'get_archive_thumbnail_id' ) ) { function get_archive_thumbnail_id($post_type = null) { return Archive_Control::archive_control_get_archive_thumbnail_id($post_type); } } if ( ! function_exists( 'get_archive_thumbnail_src' ) ) { function get_archive_thumbnail_src($size = null, $post_type = null) { return Archive_Control::archive_control_get_archive_thumbnail_src($size, $post_type); } } if ( ! function_exists( 'the_archive_thumbnail' ) ) { function the_archive_thumbnail($size = null, $post_type = null) { Archive_Control::archive_control_the_archive_thumbnail($size, $post_type); } }