Skip to content

Commit

Permalink
Merge pull request #1338 from Automattic/fix/erroneous-post-type-notices
Browse files Browse the repository at this point in the history
Use all eligible post types when `all_templates_supported` is selected.
  • Loading branch information
westonruter authored Aug 14, 2018
2 parents 14d6e4b + 62f4f94 commit 6a7fd5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 6 additions & 2 deletions includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ public static function validate_options( $new_options ) {
* @see add_settings_error()
*/
public static function check_supported_post_type_update_errors() {
$supported_types = self::get_option( 'supported_post_types', array() );
foreach ( AMP_Post_Type_Support::get_eligible_post_types() as $name ) {
$all_eligible_post_types = AMP_Post_Type_Support::get_eligible_post_types();
$supported_types = self::get_option( 'all_templates_supported', false )
? $all_eligible_post_types
: self::get_option( 'supported_post_types', array() );

foreach ( $all_eligible_post_types as $name ) {
$post_type = get_post_type_object( $name );
if ( empty( $post_type ) ) {
continue;
Expand Down
21 changes: 15 additions & 6 deletions tests/test-class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,26 @@ public function test_get_and_set_options() {
public function test_check_supported_post_type_update_errors() {
global $wp_settings_errors;
add_theme_support( 'amp' );
AMP_Options_Manager::update_option( 'all_templates_supported', false );
foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'amp' );
}

register_post_type( 'foo', array(
'public' => true,
'label' => 'Foo',
) );
AMP_Options_Manager::update_option( 'supported_post_types', array( 'foo' ) );
AMP_Post_Type_Support::add_post_type_support();

// Test when 'all_templates_supported' is selected.
AMP_Options_Manager::update_option( 'all_templates_supported', true );
AMP_Options_Manager::update_option( 'supported_post_types', array( 'post' ) );
AMP_Options_Manager::check_supported_post_type_update_errors();
$this->assertEmpty( get_settings_errors() );

// Test when 'all_templates_supported' is not selected.
AMP_Options_Manager::update_option( 'all_templates_supported', false );
foreach ( get_post_types() as $post_type ) {
if ( 'foo' !== $post_type ) {
remove_post_type_support( $post_type, 'amp' );
}
}
AMP_Options_Manager::update_option( 'supported_post_types', array( 'foo' ) );
AMP_Options_Manager::check_supported_post_type_update_errors();
$this->assertEmpty( get_settings_errors() );

Expand Down

0 comments on commit 6a7fd5e

Please sign in to comment.