Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
Added 'admin_column_title' CPT-onomy setting
Browse files Browse the repository at this point in the history
  • Loading branch information
bamadesigner committed Feb 19, 2015
1 parent b9a1627 commit 0841c97
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
5 changes: 5 additions & 0 deletions admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
79 changes: 49 additions & 30 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {

/**
Expand All @@ -1035,31 +1036,41 @@ 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
* to remove the column by returning false.
*/
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 ) );
Expand All @@ -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;

}

}

}
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit 0841c97

Please sign in to comment.