Skip to content

Commit

Permalink
Merge pull request #316 from alleyinteractive/remove-author-dropdown-…
Browse files Browse the repository at this point in the history
…filter

Allow filtering of post types to remove author dropdown
  • Loading branch information
juliobranha authored Apr 22, 2024
2 parents c2359e5 + 6a20f81 commit 4af6ebc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion byline-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://alley.com
* Text Domain: byline-manager
* Domain Path: /languages
* Version: 0.2.8
* Version: 0.3.0
* Requires WP: 5.9
* Requires PHP: 8.0
* Tested up to: 6.4
Expand Down
20 changes: 20 additions & 0 deletions inc/admin-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,23 @@ function render_posts_column( $column, $post_id ): void {
}
}
add_action( 'manage_profile_posts_custom_column', __NAMESPACE__ . '\render_posts_column', 10, 2 );

/**
* Remove the author support from post types.
* This is done to prevent the author dropdown from being displayed in the post editor.
*/
function remove_author_support() {
/**
* Filter the list of post types that should not have author support.
* Defaults to all post types that support Byline Manager.
*
* @param string[] $post_types Post types with author support removed.
*/
$post_types = apply_filters( 'byline_manager_remove_author_support', Utils::get_supported_post_types() );

// Remove author support from the provided post types.
foreach ( $post_types as $post_type ) {
remove_post_type_support( $post_type, 'author' );
}
}
add_action( 'admin_init', __NAMESPACE__ . '\remove_author_support' );
5 changes: 4 additions & 1 deletion inc/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Utils {
* @return string[] Post types with author support.
*/
public static function get_supported_post_types(): array {
$post_types = get_post_types_by_support( 'author' );
static $post_types;
if ( ! isset( $post_types ) ) {
$post_types = get_post_types_by_support( 'author' );
}

/**
* Filter the list of supported post types. Defaults to all post types
Expand Down
10 changes: 0 additions & 10 deletions tests/feature/test-profile-byline-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,9 @@ public function test_byline_relationships() {
]
);

$post_type_with_author = 'test-with-author';
register_post_type(
$post_type_with_author,
[
'public' => true,
'supports' => [ 'title', 'editor', 'author' ],
]
);

unregister_taxonomy( BYLINE_TAXONOMY );
register_byline();

$this->assertFalse( is_object_in_taxonomy( $post_type_no_author, BYLINE_TAXONOMY ) );
$this->assertTrue( is_object_in_taxonomy( $post_type_with_author, BYLINE_TAXONOMY ) );
}
}

0 comments on commit 4af6ebc

Please sign in to comment.