From 0841c97c49222bdb5cef2cca317da2a54a9818d9 Mon Sep 17 00:00:00 2001 From: Rachel Carden Date: Thu, 19 Feb 2015 11:44:56 -0600 Subject: [PATCH] Added 'admin_column_title' CPT-onomy setting --- admin-settings.php | 5 +++ admin.php | 79 ++++++++++++++++++++++++++++------------------ manager.php | 5 +++ readme.txt | 2 ++ 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/admin-settings.php b/admin-settings.php index 9952dfd..d6972af 100644 --- a/admin-settings.php +++ b/admin-settings.php @@ -945,6 +945,11 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited 'default' => 1, 'data' => $true_false_data ), + 'admin_column_title' => (object) array( + 'label' => __( 'Admin Column Title', CPT_ONOMIES_TEXTDOMAIN ), + 'type' => 'text', + 'description' => sprintf( __( 'Title, or header, for the admin column. If not set, defaults to the %s "label".', CPT_ONOMIES_TEXTDOMAIN ), "CPT-onomy's" ) + ), 'has_cpt_onomy_archive' => (object) array( 'label' => __( 'Has Archive Page', CPT_ONOMIES_TEXTDOMAIN ), 'type' => 'radio', diff --git a/admin.php b/admin.php index fcb4045..ad2878f 100644 --- a/admin.php +++ b/admin.php @@ -1024,7 +1024,8 @@ public function restrict_manage_posts() { public function add_cpt_onomy_admin_column( $columns, $post_type='page' ) { global $cpt_onomies_manager; foreach( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { - // make sure its a registered CPT-onomy + + // Make sure its a registered CPT-onomy if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { /** @@ -1035,23 +1036,33 @@ public function add_cpt_onomy_admin_column( $columns, $post_type='page' ) { * column was added by default and you used the filter to remove it. */ if ( get_bloginfo( 'version' ) >= 3.5 ) { - - /** - * If the column already exists, i.e. added by WordPress, - * this filter allows you to remove the column by returning false. - */ - if ( array_key_exists( 'taxonomy-' . $taxonomy, $columns ) - && ! apply_filters( 'custom_post_type_onomies_add_cpt_onomy_admin_column', true, $taxonomy, $post_type ) ) { - - // remove the column - unset( $columns[ 'taxonomy-' . $taxonomy ] ); - } + // If the column already exists, i.e. added by WordPress... + if ( array_key_exists( 'taxonomy-' . $taxonomy, $columns ) ) { - } + // This filter allows you to remove the column by returning false + if ( ! apply_filters( 'custom_post_type_onomies_add_cpt_onomy_admin_column', true, $taxonomy, $post_type ) ) { + + // Remove the column + unset( $columns[ 'taxonomy-' . $taxonomy ] ); + + // Otherwise, if we're keeping the column, we can customize the title + } else { + + // Get the new column title/header - defaults to taxonomy's label + if ( $new_column_title = apply_filters( 'custom_post_type_onomies_cpt_onomy_admin_column_title', ( isset( $tax->admin_column_title ) && ! empty( $tax->admin_column_title ) ? $tax->admin_column_title : $tax->label ), $taxonomy, $post_type ) ) { + + // Set the new column title + $columns[ 'taxonomy-' . $taxonomy ] = $new_column_title; + + } + + } + + } - // backwards compatability - else { + // Backwards compatability + } else { /** * The column is added by default. This filter allows you @@ -1059,7 +1070,7 @@ public function add_cpt_onomy_admin_column( $columns, $post_type='page' ) { */ if ( apply_filters( 'custom_post_type_onomies_add_cpt_onomy_admin_column', ( isset( $tax->show_admin_column ) && ! $tax->show_admin_column ) ? false : true, $taxonomy, $post_type ) ) { - // want to add before comments and date + // We want to add before comments and date $split = -1; $comments = array_search( 'comments', array_keys( $columns ) ); $date = array_search( 'date', array_keys( $columns ) ); @@ -1075,22 +1086,31 @@ public function add_cpt_onomy_admin_column( $columns, $post_type='page' ) { } - // new column - $new_column = array( CPT_ONOMIES_UNDERSCORE . '_' . $taxonomy => __( $tax->label, CPT_ONOMIES_TEXTDOMAIN ) ); + // Set the column title/header - defaults to taxonomy's label + $new_column_title = apply_filters( 'custom_post_type_onomies_cpt_onomy_admin_column_title', ( isset( $tax->admin_column_title ) && ! empty( $tax->admin_column_title ) ? $tax->admin_column_title : $tax->label ), $taxonomy, $post_type ); + + // Create a new column + $new_column = array( CPT_ONOMIES_UNDERSCORE . '_' . $taxonomy => __( $new_column_title, CPT_ONOMIES_TEXTDOMAIN ) ); - // add somewhere in the middle + // Add somewhere in the middle if ( $split > 0 ) { + $beginning = array_slice( $columns, 0, $split ); $end = array_slice( $columns, $split ); $columns = $beginning + $new_column + $end; - } - // add at the beginning - else if ( $split == 0 ) + + // Add at the beginning + } else if ( $split == 0 ) { + $columns = $new_column + $columns; - // add at the end - else + + // Add at the end + } else { + $columns += $new_column; + } + } } @@ -1146,20 +1166,19 @@ public function add_cpt_onomy_admin_sortable_columns( $sortable_columns ) { if ( $post_type = isset( $current_screen->post_type ) ? $current_screen->post_type : NULL ) { foreach( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { - // make sure its a registered CPT-onomy - // get the taxonomy's query variable + // Make sure its a registered CPT-onomy and get the taxonomy's query variable if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) && ( $query_var = isset( $tax->query_var ) ? $tax->query_var : NULL ) ) { - // this filter allows you to remove the column by returning false - // all CPT-onomy admin columns are default-ly added as sortable + // This filter allows you to remove the column by returning false + // All CPT-onomy admin columns are default-ly added as sortable if ( apply_filters( 'custom_post_type_onomies_add_cpt_onomy_admin_sortable_column', true, $taxonomy, $post_type ) ) { - // if version >= 3.5 + // If version >= 3.5 if ( get_bloginfo( 'version' ) >= 3.5 ) $sortable_columns[ 'taxonomy-' . $taxonomy ] = $query_var; - // backwards compatibility + // Backwards compatibility else if ( strpos( $column_name, CPT_ONOMIES_UNDERSCORE ) !== false ) $sortable_columns[ CPT_ONOMIES_UNDERSCORE . '_' . $taxonomy ] = $query_var; diff --git a/manager.php b/manager.php index 57a4922..9a596ac 100644 --- a/manager.php +++ b/manager.php @@ -916,6 +916,7 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { 'meta_box_format' => NULL, 'meta_box_title' => NULL, 'show_admin_column' => true, + 'admin_column_title' => NULL, 'has_cpt_onomy_archive' => true, 'cpt_onomy_archive_slug' => '$post_type/tax/$term_slug', 'restrict_user_capabilities'=> array( 'administrator', 'editor', 'author' ) @@ -940,6 +941,7 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { 'show_ui' => false, 'show_tagcloud' => false, 'show_admin_column' => $show_admin_column, + 'admin_column_title' => $admin_column_title, 'rewrite' => false, 'meta_box_format' => $meta_box_format, 'meta_box_title' => $meta_box_title, @@ -1311,6 +1313,7 @@ public function register_custom_post_types_and_taxonomies() { 'meta_box_format' => ( isset( $cpt[ 'meta_box_format' ] ) && ! empty( $cpt[ 'meta_box_format' ] ) ) ? $cpt[ 'meta_box_format' ] : NULL, 'meta_box_title' => ( isset( $cpt[ 'meta_box_title' ] ) && ! empty( $cpt[ 'meta_box_title' ] ) ) ? $cpt[ 'meta_box_title' ] : NULL, 'show_admin_column' => ( isset( $cpt[ 'show_admin_column' ] ) && ! $cpt[ 'show_admin_column' ] ) ? false : true, + 'admin_column_title' => ( isset( $cpt[ 'admin_column_title' ] ) && ! empty( $cpt[ 'admin_column_title' ] ) ) ? $cpt[ 'admin_column_title' ] : NULL, 'has_cpt_onomy_archive' => ( isset( $cpt[ 'has_cpt_onomy_archive' ] ) && ! $cpt[ 'has_cpt_onomy_archive' ] ) ? false : true, 'cpt_onomy_archive_slug' => ( isset( $cpt[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt[ 'cpt_onomy_archive_slug' ] : NULL, 'restrict_user_capabilities' => ( isset( $cpt[ 'restrict_user_capabilities' ] ) && ! empty( $cpt[ 'restrict_user_capabilities' ] ) ) ? $cpt[ 'restrict_user_capabilities' ] : array(), @@ -1365,6 +1368,7 @@ public function register_custom_post_types_and_taxonomies() { 'meta_box_format' => ( isset( $cpt[ 'meta_box_format' ] ) && ! empty( $cpt[ 'meta_box_format' ] ) ) ? $cpt[ 'meta_box_format' ] : NULL, 'meta_box_title' => ( isset( $cpt[ 'meta_box_title' ] ) && ! empty( $cpt[ 'meta_box_title' ] ) ) ? $cpt[ 'meta_box_title' ] : NULL, 'show_admin_column' => ( isset( $cpt[ 'show_admin_column' ] ) && ! $cpt[ 'show_admin_column' ] ) ? false : true, + 'admin_column_title' => ( isset( $cpt[ 'admin_column_title' ] ) && ! empty( $cpt[ 'admin_column_title' ] ) ) ? $cpt[ 'admin_column_title' ] : NULL, 'has_cpt_onomy_archive' => ( isset( $cpt[ 'has_cpt_onomy_archive' ] ) && ! $cpt[ 'has_cpt_onomy_archive' ] ) ? false : true, 'cpt_onomy_archive_slug' => ( isset( $cpt[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt[ 'cpt_onomy_archive_slug' ] : NULL, 'restrict_user_capabilities' => ( isset( $cpt[ 'restrict_user_capabilities' ] ) && ! empty( $cpt[ 'restrict_user_capabilities' ] ) ) ? $cpt[ 'restrict_user_capabilities' ] : array(), @@ -1414,6 +1418,7 @@ public function register_custom_post_types_and_taxonomies() { 'meta_box_format' => ( isset( $cpt_settings[ 'meta_box_format' ] ) && ! empty( $cpt_settings[ 'meta_box_format' ] ) ) ? $cpt_settings[ 'meta_box_format' ] : NULL, 'meta_box_title' => ( isset( $cpt_settings[ 'meta_box_title' ] ) && ! empty( $cpt_settings[ 'meta_box_title' ] ) ) ? $cpt_settings[ 'meta_box_title' ] : NULL, 'show_admin_column' => ( isset( $cpt_settings[ 'show_admin_column' ] ) && ! $cpt_settings[ 'show_admin_column' ] ) ? false : true, + 'admin_column_title' => ( isset( $cpt_settings[ 'admin_column_title' ] ) && ! empty( $cpt_settings[ 'admin_column_title' ] ) ) ? $cpt_settings[ 'admin_column_title' ] : NULL, 'has_cpt_onomy_archive' => ( isset( $cpt_settings[ 'has_cpt_onomy_archive' ] ) && ! $cpt_settings[ 'has_cpt_onomy_archive' ] ) ? false : true, 'cpt_onomy_archive_slug' => ( isset( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt_settings[ 'cpt_onomy_archive_slug' ] : NULL, 'restrict_user_capabilities' => ( isset( $cpt_settings[ 'restrict_user_capabilities' ] ) && ! empty( $cpt_settings[ 'restrict_user_capabilities' ] ) ) ? $cpt_settings[ 'restrict_user_capabilities' ] : array(), diff --git a/readme.txt b/readme.txt index f4bdd3b..6526119 100644 --- a/readme.txt +++ b/readme.txt @@ -126,6 +126,7 @@ If FAQ didn't cover your problem, refer to the following resources: == Changelog == = 1.3.4 = +* Added 'admin_column_title' CPT-onomy setting. * Added 'name_admin_bar' custom post type label setting. * Added 'delete_with_user' custom post type setting. @@ -236,6 +237,7 @@ If FAQ didn't cover your problem, refer to the following resources: == Upgrade Notice == = 1.3.4 = +* Added 'admin_column_title' CPT-onomy setting. * Added 'name_admin_bar' custom post type label setting. * Added 'delete_with_user' custom post type setting.