Created
March 31, 2022 08:24
-
-
Save dhaval-parekh/7c9f3d68d6e37e66314206ad0aceb15a to your computer and use it in GitHub Desktop.
AMP eligible post type test.
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
<?php | |
/** | |
* Plugin Name: AMP eligible post type test. | |
* Description: Plugin to test eligible post types for AMP | |
* Version: 0.1 | |
* | |
* @wordpress-plugin | |
* @author Dhaval Parekh | |
*/ | |
add_action( 'init', function () { | |
register_post_type( | |
'book', | |
[ | |
'label' => 'Book', | |
'publicly_queryable' => true, | |
] | |
); | |
register_post_type( | |
'car', | |
[ | |
'label' => 'Car', | |
'public' => false, | |
'publicly_queryable' => true, | |
] | |
); | |
register_post_type( | |
'secret', | |
[ | |
'label' => 'Secret', | |
'publicly_queryable' => false, | |
] | |
); | |
register_post_type( | |
'secret_book', | |
[ | |
'label' => 'Secret book', | |
'public' => true, | |
'publicly_queryable' => false, | |
] | |
); | |
register_post_type( | |
'secret_car', | |
[ | |
'label' => 'Secret Car', | |
'public' => false, | |
'publicly_queryable' => true, | |
] | |
); | |
} ); | |
add_filter( 'is_post_type_viewable', function ( $is_viewable, $post_type ) { | |
if ( 'secret_car' === $post_type->name ) { | |
return false; | |
} | |
return $is_viewable; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment