-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add admin screen for managing which post types have AMP support #811
Changes from 14 commits
c156501
5499ba6
c5d0c99
1b63cd5
2949f25
d66bc62
99e7bcf
68c5017
dcadc4f
cdf9058
f630062
fdc26b3
5b0e1cd
1befc79
5ea54e9
ad7c36b
febd02d
63a60bd
832c13b
3b922cb
8c14063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SYNC_README_MD=0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,15 @@ | |
define( 'AMP__DIR__', dirname( __FILE__ ) ); | ||
define( 'AMP__VERSION', '0.5.1' ); | ||
|
||
require_once( AMP__DIR__ . '/back-compat/back-compat.php' ); | ||
require_once( AMP__DIR__ . '/includes/amp-helper-functions.php' ); | ||
require_once( AMP__DIR__ . '/includes/admin/functions.php' ); | ||
require_once( AMP__DIR__ . '/includes/admin/class-amp-customizer.php' ); | ||
require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-settings.php' ); | ||
require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php' ); | ||
|
||
require_once( AMP__DIR__ . '/includes/actions/class-amp-frontend-actions.php' ); | ||
require_once( AMP__DIR__ . '/includes/actions/class-amp-paired-post-actions.php' ); | ||
require_once AMP__DIR__ . '/back-compat/back-compat.php'; | ||
require_once AMP__DIR__ . '/includes/amp-helper-functions.php'; | ||
require_once AMP__DIR__ . '/includes/class-amp-post-type-support.php'; | ||
require_once AMP__DIR__ . '/includes/admin/functions.php'; | ||
require_once AMP__DIR__ . '/includes/admin/class-amp-customizer.php'; | ||
require_once AMP__DIR__ . '/includes/settings/class-amp-customizer-settings.php'; | ||
require_once AMP__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php'; | ||
require_once AMP__DIR__ . '/includes/actions/class-amp-frontend-actions.php'; | ||
require_once AMP__DIR__ . '/includes/actions/class-amp-paired-post-actions.php'; | ||
|
||
register_activation_hook( __FILE__, 'amp_activate' ); | ||
function amp_activate() { | ||
|
@@ -47,20 +47,20 @@ function amp_deactivate() { | |
flush_rewrite_rules(); | ||
} | ||
|
||
AMP_Post_Type_Support::add_hooks(); | ||
|
||
add_action( 'init', 'amp_init' ); | ||
function amp_init() { | ||
if ( false === apply_filters( 'amp_is_enabled', true ) ) { | ||
return; | ||
} | ||
|
||
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) ); | ||
|
||
do_action( 'amp_init' ); | ||
add_action( 'admin_init', 'AMP_Options_Manager::register_settings' ); | ||
|
||
load_plugin_textdomain( 'amp', false, plugin_basename( AMP__DIR__ ) . '/languages' ); | ||
|
||
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK ); | ||
add_post_type_support( 'post', AMP_QUERY_VAR ); | ||
|
||
add_filter( 'request', 'amp_force_query_var_value' ); | ||
add_action( 'wp', 'amp_maybe_add_actions' ); | ||
|
@@ -73,6 +73,25 @@ function amp_init() { | |
} | ||
} | ||
|
||
/** | ||
* Define AMP query var. | ||
* | ||
* This function must be invoked through the 'after_setup_theme' action to allow | ||
* the AMP setting to declare the post types support earlier than plugins/theme. | ||
* | ||
* @since 0.6 | ||
*/ | ||
function define_query_var() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add hook docs for this filter here since we're touching it. It was introduced in 0.3.2 via c486a1c |
||
/** | ||
* Filter the AMP query variable. | ||
* | ||
* @since 0.3.2 | ||
* @param string $query_var The AMP query variable. | ||
*/ | ||
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) ); | ||
} | ||
add_action( 'after_setup_theme', 'define_query_var', 3 ); | ||
|
||
// Make sure the `amp` query var has an explicit value. | ||
// Avoids issues when filtering the deprecated `query_string` hook. | ||
function amp_force_query_var_value( $query_vars ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,15 +80,22 @@ function amp_add_customizer_link() { | |
} | ||
|
||
/** | ||
* Registers a top-level menu for AMP configuration options | ||
* Registers AMP settings. | ||
*/ | ||
function amp_add_options_menu() { | ||
if ( ! is_admin() ) { | ||
return; | ||
} | ||
|
||
$show_options_menu = apply_filters( 'amp_options_menu_is_enabled', true ); | ||
if ( true !== $show_options_menu ) { | ||
/** | ||
* Filter whether to enable the AMP settings. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you find when this filter was introduced and add a |
||
* @since 0.5 | ||
* @param bool $enable Whether to enable the AMP settings. Default true. | ||
*/ | ||
$short_circuit = apply_filters( 'amp_options_menu_is_enabled', true ); | ||
|
||
if ( true !== $short_circuit ) { | ||
return; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* AMP Post type support. | ||
* | ||
* @package AMP | ||
* @since 0.6 | ||
*/ | ||
|
||
/** | ||
* Class AMP_Post_Type_Support. | ||
*/ | ||
class AMP_Post_Type_Support { | ||
|
||
/** | ||
* Add hooks. | ||
*/ | ||
public static function add_hooks() { | ||
add_action( 'amp_init', array( __CLASS__, 'add_builtin_post_type_support' ) ); | ||
add_action( 'after_setup_theme', array( __CLASS__, 'add_elected_post_type_support' ), 5 ); | ||
} | ||
|
||
/** | ||
* Get post types that plugin supports out of the box (which cannot be disabled). | ||
* | ||
* @return array Post types. | ||
*/ | ||
public static function get_builtin_supported_post_types() { | ||
return array( 'post' ); | ||
} | ||
|
||
/** | ||
* Declare core post types support for built-in post types. | ||
* | ||
* @since 0.6 | ||
*/ | ||
public static function add_builtin_post_type_support() { | ||
foreach ( self::get_builtin_supported_post_types() as $post_type ) { | ||
add_post_type_support( $post_type, AMP_QUERY_VAR ); | ||
} | ||
} | ||
|
||
/** | ||
* Declare custom post types support. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is also add support of built-in post types. |
||
* | ||
* 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 | ||
*/ | ||
public static function add_elected_post_type_support() { | ||
$post_types = array_merge( | ||
array_keys( array_filter( AMP_Options_Manager::get_option( 'supported_post_types', array() ) ) ), | ||
self::get_builtin_supported_post_types() | ||
); | ||
foreach ( $post_types as $post_type ) { | ||
add_post_type_support( $post_type, AMP_QUERY_VAR ); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to move that to the
includes/admin/functions.php
file since all the other admin classes are booted in there?