-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declare post type support based on the admin setting and allow overwrite
- Loading branch information
Showing
8 changed files
with
250 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* AMP Post types support. | ||
* | ||
* @package AMP | ||
* @since 0.6 | ||
*/ | ||
|
||
/** | ||
* Declare core post types support. | ||
* | ||
* @since 0.6 | ||
*/ | ||
function amp_core_post_types_support() { | ||
add_post_type_support( 'post', AMP_QUERY_VAR ); | ||
} | ||
add_action( 'init', 'amp_core_post_types_support' ); | ||
|
||
/** | ||
* Declare custom post types support. | ||
* | ||
* This function should only be invoked through the 'after_setup_theme' action to | ||
* allow plugins/theme to overwrite the post types support. | ||
* | ||
* @since 0.6 | ||
*/ | ||
function amp_custom_post_types_support() { | ||
// Listen to post types settings. | ||
foreach ( AMP_Settings_Post_Types::get_instance()->get_settings() as $post_type => $enabled ) { | ||
if ( true === $enabled ) { | ||
add_post_type_support( $post_type, AMP_QUERY_VAR ); | ||
} | ||
} | ||
} | ||
add_action( 'after_setup_theme', 'amp_custom_post_types_support' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Tests for Post Types Support. | ||
* | ||
* @package AMP | ||
* @since 0.6 | ||
*/ | ||
|
||
/** | ||
* Tests for Post Types Support. | ||
*/ | ||
class Test_AMP_Post_Types_Support extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test amp_core_post_types_support. | ||
* | ||
* @see amp_core_post_types_support() | ||
*/ | ||
public function test_init() { | ||
amp_core_post_types_support(); | ||
$this->assertTrue( post_type_supports( 'post', AMP_QUERY_VAR ) ); | ||
remove_post_type_support( 'post', AMP_QUERY_VAR ); | ||
} | ||
|
||
/** | ||
* Test amp_custom_post_types_support. | ||
* | ||
* @see amp_custom_post_types_support() | ||
*/ | ||
public function test_amp_custom_post_types_support() { | ||
update_option( AMP_Settings::SETTINGS_KEY, array( | ||
'post_types_support' => array( | ||
'foo' => true, | ||
'bar' => true, | ||
), | ||
) ); | ||
amp_custom_post_types_support(); | ||
$this->assertTrue( post_type_supports( 'foo', AMP_QUERY_VAR ) ); | ||
$this->assertTrue( post_type_supports( 'bar', AMP_QUERY_VAR ) ); | ||
delete_option( AMP_Settings::SETTINGS_KEY ); | ||
remove_post_type_support( 'foo', AMP_QUERY_VAR ); | ||
remove_post_type_support( 'bar', AMP_QUERY_VAR ); | ||
} | ||
|
||
} |
Oops, something went wrong.