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/' ); } /** * Handle database changes for upgrades * * @since 1.2.0 */ public function archive_control_handle_updates() { include_once('db/update.php' ); } /** * 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() { $load_archive_control_scripts = false; if (isset($_GET['page'])) { if ($_GET['page'] == 'archive-control' || strpos($_GET['page'], 'edit-archive-') !== false) { $load_archive_control_scripts = true; } } if (isset($_GET['taxonomy'])) { $load_archive_control_scripts = true; } if ($load_archive_control_scripts == true) { if ( ! did_action( 'wp_enqueue_media' ) ) { wp_enqueue_media(); } 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', array($this,'archive_control_options') ); $custom_post_types = $this->archive_control_get_cpts(); if (!empty($custom_post_types)) { foreach($custom_post_types as $post_type) { $options = get_option('archive_control_cpt_' . $post_type->name . '_options'); if ($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->name; } add_submenu_page( $parent_slug, __('Edit Archive Page', 'archive-control'), __('Edit Archive Page', 'archive-control'), 'edit_posts', 'edit-archive-' . $post_type->name, array($this,'archive_control_edit_page_callback') ); } //has title, image, before or after value } //has options } //for each post type } // if not empty } /** * Register the necessary settings to store for plugin use. * * @since 1.0.0 */ public function archive_control_settings() { register_setting( 'archive-control-tax-options-group', 'archive_control_tax_category_options' ); register_setting( 'archive-control-tax-options-group', 'archive_control_tax_post_tag_options' ); $custom_post_types = $this->archive_control_get_cpts(); if (!empty($custom_post_types)) { foreach($custom_post_types as $post_type) { register_setting( 'archive-control-cpt-options-group', 'archive_control_cpt_' . $post_type->name . '_options' ); register_setting( 'archive-control-' . $post_type->name . '-group', 'archive_control_cpt_' . $post_type->name . '_title' ); register_setting( 'archive-control-' . $post_type->name . '-group', 'archive_control_cpt_' . $post_type->name . '_image' ); register_setting( 'archive-control-' . $post_type->name . '-group', 'archive_control_cpt_' . $post_type->name . '_before' ); register_setting( 'archive-control-' . $post_type->name . '-group', 'archive_control_cpt_' . $post_type->name . '_after' ); } } $custom_taxonomies = $this->archive_control_get_taxes(); if (!empty($custom_taxonomies)) { foreach($custom_taxonomies as $taxonomy) { register_setting( 'archive-control-tax-options-group', 'archive_control_tax_' . $taxonomy->name . '_options' ); } } } /** * Add an Edit link to the WP Admin Toolbar * * @since 1.1.1 */ public function archive_control_archive_edit_link($wp_admin_bar) { if (is_post_type_archive() && !is_admin()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); $edit_url = get_admin_url() . 'edit.php?post_type=' . $post_type . '&page=edit-archive-' . $post_type; $args = array( 'id' => 'edit', 'title' => __('Edit Archive Page', 'archive-control'), 'href' => $edit_url, 'meta' => array( 'class' => 'ab-item', 'title' => __('Edit Custom Post Type Archive', 'archive-control') ) ); $wp_admin_bar->add_node($args); } } /** * Get only the custom post types that we want * * @since 1.2.0 */ public function archive_control_get_cpts() { $custom_post_types = array(); $args = array( 'public' => true, '_builtin' => false ); $post_types = get_post_types($args, 'objects' ); foreach ($post_types as $post_type ) { if($post_type->has_archive) { $custom_post_types[$post_type->name] = $post_type; } } return $custom_post_types; } /** * Get only the custom post types that we want * * @since 1.2.0 */ public function archive_control_get_taxes($with_cats_tags = false) { $custom_taxonomies = array(); $args = array( 'public' => true, '_builtin' => false ); $custom_taxonomies = get_taxonomies($args, 'objects' ); if ($with_cats_tags === true) { $default_taxonomies = array(); $category_tax_object = get_taxonomy( 'category' ); $default_taxonomies['category'] = $category_tax_object; $post_tag_tax_object = get_taxonomy( 'post_tag' ); $default_taxonomies['post_tag'] = $post_tag_tax_object; $custom_taxonomies = array_merge($default_taxonomies,$custom_taxonomies); } return $custom_taxonomies; } /** * Add actions for each custom taxonomy * * @since 1.3.0 */ public function archive_control_handle_taxonomy_fields() { $custom_taxonomies = $this->archive_control_get_taxes(true); if (!empty($custom_taxonomies)) { foreach($custom_taxonomies as $taxonomy) { $options = get_option('archive_control_tax_' . $taxonomy->name . '_options'); $image_val = isset($options['image']) ? $options['image'] : null; $before_val = isset($options['before']) ? $options['before'] : null; $after_val = isset($options['after']) ? $options['after'] : null; $term_order_pagination_val = isset($options['term_order_pagination']) ? $options['term_order_pagination'] : null; if ($image_val == 'enabled' || $before_val == 'textarea' || $after_val == 'textarea' || $term_order_pagination_val == 'enabled') { add_action( $taxonomy->name . '_add_form_fields', array( $this, 'archive_control_add_taxonomy_fields'), 10, 2 ); add_action( $taxonomy->name . '_edit_form_fields', array( $this, 'archive_control_edit_taxonomy_fields'), 10, 2 ); add_action( 'edited_' . $taxonomy->name, array( $this, 'archive_control_edit_taxonomy_meta'), 10, 2 ); } $hide_description = isset($options['hide_description']) ? $options['hide_description'] : null; if ($hide_description == 'hidden') { add_filter( 'manage_edit-' . $taxonomy->name . '_columns', array( $this, 'archive_control_remove_taxonomy_description_column' ) ); } } } } /** * Remove the taxonomy description column if set * * @since 1.3.0 */ public function archive_control_remove_taxonomy_description_column($columns) { if( isset( $columns['description'] ) ) unset( $columns['description'] ); return $columns; } /** * Add term meta when a term is saved * * @since 1.3.0 */ public function archive_control_edit_taxonomy_meta( $term_id, $tt_id ){ if( isset( $_POST['archive_control_term_meta']['image'] ) && $_POST['archive_control_term_meta']['image'] !== '' ){ if (is_numeric($_POST['archive_control_term_meta']['image']) && is_object( get_post( $_POST['archive_control_term_meta']['image'] ))) { $archive_control_term_image = $_POST['archive_control_term_meta']['image']; update_term_meta( $term_id, 'archive_control_term_image', $archive_control_term_image ); } } if( isset( $_POST['archive_control_term_meta']['before'] ) && $_POST['archive_control_term_meta']['before'] !== '' ){ $archive_control_term_before = wp_kses_post( $_POST['archive_control_term_meta']['before'] ); update_term_meta( $term_id, 'archive_control_term_before', $archive_control_term_before ); } if( isset( $_POST['archive_control_term_meta']['after'] ) && $_POST['archive_control_term_meta']['after'] !== '' ){ $archive_control_term_after = wp_kses_post( $_POST['archive_control_term_meta']['after'] ); update_term_meta( $term_id, 'archive_control_term_after', $archive_control_term_after ); } $archive_control_term_meta = array(); if( isset( $_POST['archive_control_term_meta']['orderby'] ) && $_POST['archive_control_term_meta']['orderby'] !== '' ){ $archive_control_term_meta['orderby'] = sanitize_text_field( $_POST['archive_control_term_meta']['orderby'] ); } if( isset( $_POST['archive_control_term_meta']['meta_key'] ) && $_POST['archive_control_term_meta']['meta_key'] !== '' ){ $archive_control_term_meta['meta_key'] = sanitize_text_field( $_POST['archive_control_term_meta']['meta_key'] ); } if( isset( $_POST['archive_control_term_meta']['order'] ) && $_POST['archive_control_term_meta']['order'] !== '' ){ $archive_control_term_meta['order'] = sanitize_text_field( $_POST['archive_control_term_meta']['order'] ); } if( isset( $_POST['archive_control_term_meta']['pagination'] ) && $_POST['archive_control_term_meta']['pagination'] !== '' ){ $archive_control_term_meta['pagination'] = sanitize_text_field( $_POST['archive_control_term_meta']['pagination'] ); } if( isset( $_POST['archive_control_term_meta']['posts_per_page'] ) && $_POST['archive_control_term_meta']['posts_per_page'] !== '' ){ $archive_control_term_meta['posts_per_page'] = sanitize_text_field( $_POST['archive_control_term_meta']['posts_per_page'] ); } if (!empty($archive_control_term_meta)) { update_term_meta( $term_id, 'archive_control_term_meta', $archive_control_term_meta ); } } /** * Hide fields from the add taxonomy screen * * @since 1.3.0 */ public function archive_control_add_taxonomy_fields($taxonomy) { $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { $hide_parent_val = isset($options['hide_parent']) ? $options['hide_parent'] : null; if ($hide_parent_val == 'hidden') { ?>base == 'post') { $custom_taxonomies = $this->archive_control_get_taxes(true); if (!empty($custom_taxonomies)) { foreach($custom_taxonomies as $taxonomy) { $options = get_option('archive_control_tax_' . $taxonomy->name . '_options'); $hide_parent = isset($options['hide_parent']) ? $options['hide_parent'] : null; if ($hide_parent == 'hidden') { echo ""; } } } } } /** * Add custom fields to the edit taxonomy screen * * @since 1.3.0 */ public function archive_control_edit_taxonomy_fields($term, $taxonomy) { $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { $hide_parent_val = isset($options['hide_parent']) ? $options['hide_parent'] : null; if ($hide_parent_val == 'hidden') { ?>
term_id, 'archive_control_term_image', true ); $featured_img_src = wp_get_attachment_image_src( $archive_control_term_image, 'full' ); $featured_img = is_array( $featured_img_src ); ?>

term_id, 'archive_control_term_before', true ); ?> 'archive_control_term_meta[before]', 'textarea_rows' => 10 );?> term_id, 'archive_control_term_after', true ); ?> 'archive_control_term_meta[after]', 'textarea_rows' => 10 );?> term_id, 'archive_control_term_meta', true ); $this->archive_control_add_field_orderby( $archive_control_term_meta, 'archive_control_term_meta' ); $this->archive_control_add_field_order( $archive_control_term_meta, 'archive_control_term_meta' ); $this->archive_control_add_field_pagination( $archive_control_term_meta, 'archive_control_term_meta' ); } } } /** * 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; $options = get_option('archive_control_cpt_' . $current_post_type . '_options'); $archive_control_cpt_title = get_option('archive_control_cpt_' . $current_post_type . '_title'); $archive_control_cpt_image = get_option('archive_control_cpt_' . $current_post_type . '_image'); $archive_control_cpt_before = get_option('archive_control_cpt_' . $current_post_type . '_before'); $archive_control_cpt_after = get_option('archive_control_cpt_' . $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($options) ? $options : null; ?>

label); ?>

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

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

name == 'category') { $label = __('Category Titles', 'archive-control'); $remove_label = __('Remove Label (Category:)', 'archive-control'); } elseif ($taxonomy->name == 'post_tag') { $label = __('Tag Titles', 'archive-control'); $remove_label = __('Remove Label (Tag:)', 'archive-control'); } else { $label = __('Term Titles', 'archive-control'); $remove_label = __('Remove Label (Taxonomy:)', 'archive-control'); } } else { $allow_custom = true; $label = __('CPT Archive Title', 'archive-control'); $remove_label = __('Remove Label (Archive:)', 'archive-control'); } $title_val = isset($options['title']) ? $options['title'] : null; ?> /> />


archive_control_get_cpts(); if (!empty($custom_post_types)) { foreach($custom_post_types as $post_type) { $edit_url = get_admin_url() . 'edit.php?post_type=' . $post_type->name . '&page=edit-archive-' . $post_type->name; $options = get_option('archive_control_cpt_' . $post_type->name . '_options'); ?>

label; ?>

archive_control_add_field_titles( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_image( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_before( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_after( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_orderby( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_order( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); $this->archive_control_add_field_pagination( $options, 'archive_control_cpt_' . $post_type->name . '_options' ); ?>

archive_control_get_taxes(true); if (!empty($taxonomies)) { foreach($taxonomies as $taxonomy) { $options = get_option('archive_control_tax_' . $taxonomy->name . '_options'); ?>

label; ?>

archive_control_add_field_titles( $options, 'archive_control_tax_' . $taxonomy->name . '_options', $taxonomy ); $this->archive_control_add_field_image( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_before( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_after( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_orderby( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_order( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_pagination( $options, 'archive_control_tax_' . $taxonomy->name . '_options' ); $this->archive_control_add_field_term_options( $options, 'archive_control_tax_' . $taxonomy->name . '_options', $taxonomy->name ); ?>

is_main_query() ){ if (is_post_type_archive()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); if ($options) { $order_val = isset($options['order']) ? $options['order'] : null; if ($order_val !== 'default' && $order_val !== null) { $query->set( 'order', $options['order'] ); } //has order value $orderby_val = isset($options['orderby']) ? $options['orderby'] : null; if ($orderby_val !== 'default' && $orderby_val !== 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 $pagination_val = isset($options['pagination']) ? $options['pagination'] : null; if ($pagination_val !== 'default' && $pagination_val !== 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 } //has options } // is_post_type_artchive if (is_tax() || is_category() || is_tag()) { $taxonomy = $query->tax_query->queries[0]['taxonomy']; $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { $order_val = isset($options['order']) ? $options['order'] : null; if ($order_val !== 'default' && $order_val !== null) { $query->set( 'order', $options['order'] ); } //has order value $orderby_val = isset($options['orderby']) ? $options['orderby'] : null; if ($orderby_val !== 'default' && $orderby_val !== 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 $pagination_val = isset($options['pagination']) ? $options['pagination'] : null; if ($pagination_val !== 'default' && $pagination_val !== 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 } //if options $term_slug = $query->tax_query->queries[0]['terms'][0]; $term = get_term_by( 'slug', $term_slug, $taxonomy ); $term_options = get_term_meta( $term->term_id, 'archive_control_term_meta', true ); if ($term_options) { $order_val = isset($term_options['order']) ? $term_options['order'] : null; if ($order_val !== 'default' && $order_val !== null) { $query->set( 'order', $term_options['order'] ); } //has order value $orderby_val = isset($term_options['orderby']) ? $term_options['orderby'] : null; if ($orderby_val !== 'default' && $orderby_val !== null) { $query->set( 'orderby', $term_options['orderby'] ); if ($term_options['orderby'] == 'meta_value' || $term_options['orderby'] == 'meta_value_num') { if ($term_options['meta_key'] !== null) { $query->set( 'meta_key', $term_options['meta_key'] ); } //has meta_key value } //meta_key value is needed } //has orderby value $pagination_val = isset($term_options['pagination']) ? $term_options['pagination'] : null; if ($pagination_val !== 'default' && $pagination_val !== null) { if ($term_options['pagination'] == 'custom') { if ($term_options['posts_per_page'] !== null) { $query->set( 'posts_per_page', $term_options['posts_per_page'] ); } } if ($term_options['pagination'] == 'none') { $query->set( 'posts_per_page', -1 ); } } //has pagination value }//has term options } // is_tax } //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_post_type_archive()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); if ($options) { 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($html); }//handle page all/first options } //before textarea is enabled } //has options } // is_post_type_archive if (is_tax() || is_category() || is_tag()) { $taxonomy = null; if (is_tax()) $taxonomy = get_query_var('taxonomy'); if (is_category()) $taxonomy = 'category'; if (is_tag()) $taxonomy = 'post_tag'; $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { 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($html); }//handle page all/first options } //before textarea is enabled } //has options } //is_tax, cat, tag } /** * 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_slug A post type slug that the content belongs to */ public static function archive_control_archive_top_content($html = true, $post_type_slug = null, $term_id = null) { $content = Archive_Control::archive_control_get_archive_top_content($post_type_slug, $term_id); 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_slug A post type slug that the content belongs to * @param string $term_id A taxonomy term id that the content belongs to */ public static function archive_control_get_archive_top_content($post_type_slug = null, $term_id = null) { if ($post_type_slug === null && $term_id === null) { if (is_post_type_archive()) { $post_type_slug = get_query_var('post_type', null); } if (is_tax() || is_category() || is_tag()) { $term = get_queried_object(); $term_id = $term->term_id; } } $archive_control_cpt_before = null; if ($post_type_slug) { $archive_control_cpt_before = get_option('archive_control_cpt_' . $post_type_slug . '_before'); } elseif ($term_id) { $archive_control_cpt_before = get_term_meta( $term_id, 'archive_control_term_before', true ); } 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_post_type_archive()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); if ($options) { 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 } //has options } // is_post_type_archive if (is_tax() || is_category() || is_tag()) { $taxonomy = null; if (is_tax()) $taxonomy = get_query_var('taxonomy'); if (is_category()) $taxonomy = 'category'; if (is_tag()) $taxonomy = 'post_tag'; $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { 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 } //has options } //is_tax, cat, tag } /** * Echo the archive thumbnail with markup * * @since 1.1.0 * * @param string $size The image size that you want displayed * @param string $post_type_slug A post type slug that the content belongs to * @param string $term_id A taxonomy term id that the content belongs to */ public static function archive_control_the_archive_thumbnail($size = 'large', $post_type_slug = null, $term_id = null) { // if ($post_type_slug === null) { // if (is_post_type_archive()) { // $post_type_slug = get_query_var('post_type', null); // } // } $featured_img_id = Archive_Control::archive_control_get_archive_thumbnail_id($post_type_slug, $term_id); 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_slug A post type slug that the content belongs to * @param string $term_id A taxonomy term id that the content belongs to */ public static function archive_control_get_archive_thumbnail_src($size = 'large', $post_type_slug = null, $term_id = null) { $featured_img_id = Archive_Control::archive_control_get_archive_thumbnail_id($post_type_slug, $term_id); if ($featured_img_id) { $featured_img_src = wp_get_attachment_image_src( $featured_img_id, $size ); if (is_array($featured_img_src)) { $src = $featured_img_src[0]; return $src; } } } /** * Get the archive thumbnail id * * @since 1.1.0 * * @param string $post_type_slug A post type slug that the content belongs to * @param string $term_id A taxonomy term id that the content belongs to */ public static function archive_control_get_archive_thumbnail_id($post_type_slug = null, $term_id = null) { if ($post_type_slug === null && $term_id === null) { if (is_post_type_archive()) { $post_type_slug = get_query_var('post_type', null); } if (is_tax() || is_category() || is_tag()) { $term = get_queried_object(); $term_id = $term->term_id; } } $archive_control_image_id = null; if ($post_type_slug) { $archive_control_image_id = get_option('archive_control_cpt_' . $post_type_slug . '_image'); } elseif ($term_id) { $archive_control_image_id = get_term_meta( $term_id, 'archive_control_term_image', true ); } if ($archive_control_image_id) { if ( wp_attachment_is_image( $archive_control_image_id ) ) { return $archive_control_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_post_type_archive()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); if ($options) { 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($html); }//handle page all/first options } //after textarea is enabled } //has options } // is_post_type_archive if (is_tax() || is_category() || is_tag()) { $taxonomy = null; if (is_tax()) $taxonomy = get_query_var('taxonomy'); if (is_category()) $taxonomy = 'category'; if (is_tag()) $taxonomy = 'post_tag'; $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { 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($html); }//handle page all/first options } //after textarea is enabled } //has options } //is_tax, cat, tag } /** * 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_slug A post type slug that the content belongs to */ public static function archive_control_archive_bottom_content($html = true, $post_type_slug = null, $term_id = null) { $content = Archive_Control::archive_control_get_archive_bottom_content($post_type_slug, $term_id); 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_slug A post type slug that the content belongs to * @param string $term_id A taxonomy term id that the content belongs to */ public static function archive_control_get_archive_bottom_content($post_type_slug = null, $term_id = null) { if ($post_type_slug === null && $term_id === null) { if (is_post_type_archive()) { $post_type_slug = get_query_var('post_type', null); } if (is_tax() || is_category() || is_tag()) { $term = get_queried_object(); $term_id = $term->term_id; } } $archive_control_cpt_after = null; if ($post_type_slug) { $archive_control_cpt_after = get_option('archive_control_cpt_' . $post_type_slug . '_after'); } elseif ($term_id) { $archive_control_cpt_after = get_term_meta( $term_id, 'archive_control_term_after', true ); } 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_post_type_archive()) { $post_type = get_query_var('post_type', null); $options = get_option('archive_control_cpt_' . $post_type . '_options'); if ($options) { if ($options['title'] == 'custom') { $archive_control_cpt_title = get_option('archive_control_cpt_' . $post_type . '_title'); if ($archive_control_cpt_title) { $title = $archive_control_cpt_title; } //has title } //custom title setting if ($options['title'] == 'no-labels') { $title = post_type_archive_title( '', false ); } //custom title set } //has options } // is_post_type_archive if (is_tax()) { $taxonomy = get_query_var('taxonomy'); $options = get_option('archive_control_tax_' . $taxonomy . '_options'); if ($options) { if ($options['title'] == 'no-labels') { $title = single_term_title( '', false ); } } //has options } //is_tax if (is_category()) { $options = get_option('archive_control_tax_category_options'); if ($options) { if ($options['title'] == 'no-labels') { $title = single_term_title( '', false ); } } //has options } //is_category if (is_tag()) { $options = get_option('archive_control_tax_post_tag_options'); if ($options) { if ($options['title'] == 'no-labels') { $title = single_term_title( '', false ); } } //has options } //is_tag 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_slug = null, $term_id = null) { Archive_Control::archive_control_archive_top_content($html, $post_type_slug, $term_id); } } if ( ! function_exists( 'get_archive_top_content' ) ) { function get_archive_top_content($post_type_slug = null, $term_id = null) { return Archive_Control::archive_control_get_archive_top_content($post_type_slug, $term_id); } } 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_slug = null, $term_id = null) { Archive_Control::archive_control_archive_bottom_content($html, $post_type_slug, $term_id); } } if ( ! function_exists( 'get_archive_bottom_content' ) ) { function get_archive_bottom_content($post_type_slug = null, $term_id = null) { return Archive_Control::archive_control_get_archive_bottom_content($post_type_slug, $term_id); } } if ( ! function_exists( 'get_archive_thumbnail_id' ) ) { function get_archive_thumbnail_id($post_type_slug = null, $term_id = null) { return Archive_Control::archive_control_get_archive_thumbnail_id($post_type_slug, $term_id); } } if ( ! function_exists( 'get_archive_thumbnail_src' ) ) { function get_archive_thumbnail_src($size = null, $post_type_slug = null, $term_id = null) { return Archive_Control::archive_control_get_archive_thumbnail_src($size, $post_type_slug, $term_id); } } if ( ! function_exists( 'the_archive_thumbnail' ) ) { function the_archive_thumbnail($size = null, $post_type_slug = null, $term_id = null) { Archive_Control::archive_control_the_archive_thumbnail($size, $post_type_slug, $term_id); } }