Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip check_supported_post_type_update_errors if all templates supported #1344

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ public static function validate_options( $new_options ) {
* @see add_settings_error()
*/
public static function check_supported_post_type_update_errors() {
$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 ) {
// If all templates are supported then skip check since all post types are also supported. This option only applies with native/paired theme support.
if ( self::get_option( 'all_templates_supported', false ) && 'disabled' !== self::get_option( 'theme_support' ) ) {
return;
}

$supported_types = self::get_option( 'supported_post_types', array() );
foreach ( AMP_Post_Type_Support::get_eligible_post_types() as $name ) {
$post_type = get_post_type_object( $name );
if ( empty( $post_type ) ) {
continue;
Expand Down
24 changes: 20 additions & 4 deletions tests/test-class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,44 @@ public function test_check_supported_post_type_update_errors() {
AMP_Post_Type_Support::add_post_type_support();

// Test when 'all_templates_supported' is selected.
AMP_Options_Manager::update_option( 'theme_support', 'native' );
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( 'theme_support', 'native' );
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' );
remove_post_type_support( $post_type, amp_get_slug() );
}
}
AMP_Options_Manager::update_option( 'supported_post_types', array( 'foo' ) );
AMP_Options_Manager::check_supported_post_type_update_errors();
$this->assertEmpty( get_settings_errors() );

// Test when 'all_templates_supported' is not selected, and theme support is also disabled.
add_post_type_support( 'post', amp_get_slug() );
AMP_Options_Manager::update_option( 'theme_support', 'disabled' );
AMP_Options_Manager::update_option( 'all_templates_supported', false );
AMP_Options_Manager::update_option( 'supported_post_types', array( 'post' ) );
AMP_Options_Manager::check_supported_post_type_update_errors();
$settings_errors = get_settings_errors();
$wp_settings_errors = array();
$this->assertCount( 1, $settings_errors );
$this->assertEquals( 'foo_deactivation_error', $settings_errors[0]['code'] );

// Activation error.
remove_post_type_support( 'post', amp_get_slug() );
remove_post_type_support( 'foo', amp_get_slug() );
AMP_Options_Manager::update_option( 'supported_post_types', array( 'foo' ) );
AMP_Options_Manager::update_option( 'theme_support', 'disabled' );
AMP_Options_Manager::check_supported_post_type_update_errors();
$errors = get_settings_errors();
$this->assertCount( 1, $errors );
$error = current( $errors );
$settings_errors = get_settings_errors();
$this->assertCount( 1, $settings_errors );
$error = current( $settings_errors );
$this->assertEquals( 'foo_activation_error', $error['code'] );
$wp_settings_errors = array();

Expand Down