-
Notifications
You must be signed in to change notification settings - Fork 382
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 9 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 |
---|---|---|
|
@@ -80,18 +80,29 @@ 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; | ||
} | ||
|
||
// Initialize settings. | ||
AMP_Settings::get_instance()->init(); | ||
AMP_Settings_Post_Types::get_instance()->init(); | ||
|
||
$amp_options = new AMP_Options_Menu(); | ||
$amp_options->init(); | ||
} | ||
|
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' ); | ||
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. I wonder if this shouldn't have a lower priority, like The _s starter theme and Twenty Seventeen among others do their So if they also do calls to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,33 @@ | ||
<?php | ||
|
||
require_once( AMP__DIR__ . '/includes/options/class-amp-analytics-options-submenu.php' ); | ||
require_once( AMP__DIR__ . '/includes/options/views/class-amp-options-menu-page.php' ); | ||
require_once( AMP__DIR__ . '/includes/options/views/class-amp-options-manager.php' ); | ||
|
||
/** | ||
* AMP Options. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
// Includes. | ||
require_once AMP__DIR__ . '/includes/options/class-amp-analytics-options-submenu.php'; | ||
require_once AMP__DIR__ . '/includes/options/views/class-amp-options-manager.php'; | ||
|
||
/** | ||
* AMP_Options_Menu class. | ||
*/ | ||
class AMP_Options_Menu { | ||
const ICON_BASE64_SVG = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iNjJweCIgaGVpZ2h0PSI2MnB4IiB2aWV3Qm94PSIwIDAgNjIgNjIiIHZlcnNpb249IjEuMSIgeG1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zMTY2NyA0MS44Nzc5LDI2LjgxOTEzMzMgNDEuODc3OSwyNy40NjkxIEM0MS44Nzc5LDI3LjczMjYgNDEuNzc0NTY2NywyNy45NjQwNjY3IDQxLjYyNzgzMzMsMjguMTYwNCBMNDEuNjI4ODY2NywyOC4xNjE0MzMzIFogTTMxLDAgQzEzLjg3ODcsMCAwLDEzLjg3OTczMzMgMCwzMSBDMCw0OC4xMjEzIDEzLjg3ODcsNjIgMzEsNjIgQzQ4LjEyMDI2NjcsNjIgNjIsNDguMTIxMyA2MiwzMSBDNjIsMTMuODc5NzMzMyA0OC4xMjAyNjY3LDAgMzEsMCBMMzEsMCBaIiBpZD0iRmlsbC0xIj48L3BhdGg+ICAgICAgICA8L2c+ICAgIDwvZz48L3N2Zz4='; | ||
|
||
private $menu_page; | ||
private $menu_slug; | ||
|
||
public function __construct() { | ||
$this->menu_page = new AMP_Options_Menu_Page(); | ||
$this->menu_slug = 'amp-plugin-options'; | ||
} | ||
|
||
/** | ||
* Initialize. | ||
*/ | ||
public function init() { | ||
add_action( 'admin_post_amp_analytics_options', 'AMP_Options_Manager::handle_analytics_submit' ); | ||
|
||
add_action( 'admin_menu', array( $this, 'add_menu_items' ) ); | ||
} | ||
|
||
/** | ||
* Add menu. | ||
*/ | ||
public function add_menu_items() { | ||
add_menu_page( | ||
__( 'AMP Options', 'amp' ), | ||
__( 'AMP', 'amp' ), | ||
'manage_options', | ||
$this->menu_slug, | ||
array( $this->menu_page, 'render' ), | ||
self::ICON_BASE64_SVG | ||
); | ||
|
||
$submenus = array( | ||
new AMP_Analytics_Options_Submenu( $this->menu_slug ), | ||
); | ||
|
||
// Create submenu items and calls on the Submenu Page object to render the actual contents of the page. | ||
foreach ( $submenus as $submenu ) { | ||
$submenu->init( $this->menu_slug ); | ||
} | ||
|
||
$this->remove_toplevel_menu_item(); | ||
$submenu = new AMP_Analytics_Options_Submenu( AMP_Settings::MENU_SLUG ); | ||
$submenu->init( AMP_Settings::MENU_SLUG ); | ||
} | ||
|
||
// Helper function to avoid having the top-level menu as | ||
// the first menu item | ||
function remove_toplevel_menu_item() { | ||
global $submenu; | ||
if ( isset( $submenu['amp-plugin-options'][0] ) ) { | ||
unset( $submenu['amp-plugin-options'][0] ); | ||
} | ||
} | ||
} |
This file was deleted.
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.
We should add hook docs for this filter here since we're touching it.
It was introduced in 0.3.2 via c486a1c