Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Automattic/amp-wp into f…
Browse files Browse the repository at this point in the history
…eature/709-block-amp-per-page
  • Loading branch information
westonruter committed Dec 6, 2017
2 parents e4f6c87 + c73f479 commit e66e2b2
Show file tree
Hide file tree
Showing 19 changed files with 887 additions and 148 deletions.
1 change: 1 addition & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SYNC_README_MD=0
48 changes: 34 additions & 14 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
* Plugin URI: https://github.com/automattic/amp-wp
* Author: Automattic
* Author URI: https://automattic.com
* Version: 0.5.1
* Version: 0.6.0-alpha
* Text Domain: amp
* Domain Path: /languages/
* License: GPLv2 or later
*
* @package AMP
*/

define( 'AMP__FILE__', __FILE__ );
define( 'AMP__DIR__', dirname( __FILE__ ) );
define( 'AMP__VERSION', '0.5.1' );
define( 'AMP__VERSION', '0.6.0-alpha' );

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__ . '/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/admin/class-amp-post-meta-box.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__ . '/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() {
Expand All @@ -48,20 +50,19 @@ function amp_deactivate() {
flush_rewrite_rules();
}

AMP_Post_Type_Support::init();

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' );

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' );
Expand All @@ -74,6 +75,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() {
/**
* 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 ) {
Expand Down
8 changes: 8 additions & 0 deletions includes/actions/class-amp-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public static function add_schemaorg_metadata( $template ) {}
public static function add_analytics_scripts( $template ) {}
public static function add_analytics_data( $template ) {}
public static function add_canonical_link( $template ) {}

/**
* Add AMP generator metadata.
*
* @param object $template AMP_Post_Template object.
* @since 0.6
*/
public static function add_generator_metadata( $template ) {}
}
13 changes: 13 additions & 0 deletions includes/actions/class-amp-paired-post-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class AMP_Paired_Post_Actions extends AMP_Actions {

public static function register_hooks() {
add_action( 'amp_post_template_head', 'AMP_Paired_Post_Actions::add_generator_metadata' );
add_action( 'amp_post_template_head', 'AMP_Paired_Post_Actions::add_title' );
add_action( 'amp_post_template_head', 'AMP_Paired_Post_Actions::add_canonical_link' );
add_action( 'amp_post_template_head', 'AMP_Paired_Post_Actions::add_scripts' );
Expand Down Expand Up @@ -104,4 +105,16 @@ public static function add_analytics_data( $amp_template ) {
echo AMP_HTML_Utils::build_tag( 'amp-analytics', $amp_analytics_attr, $script_element );
}
}

/**
* Add AMP generator metadata.
*
* @param object $amp_template AMP_Post_Template object.
* @since 0.6
*/
public static function add_generator_metadata( $amp_template ) {
?>
<meta name="generator" content="<?php echo esc_attr( $amp_template->get( 'generator_metadata' ) ); ?>" />
<?php
}
}
19 changes: 14 additions & 5 deletions includes/admin/functions.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
// Callbacks for adding AMP-related things to the admin.

require_once( AMP__DIR__ . '/includes/options/class-amp-options-menu.php' );
require_once( AMP__DIR__ . '/includes/options/views/class-amp-options-manager.php' );
require_once AMP__DIR__ . '/includes/options/class-amp-options-menu.php';
require_once AMP__DIR__ . '/includes/options/views/class-amp-options-manager.php';

define( 'AMP_CUSTOMIZER_QUERY_VAR', 'customize_amp' );

add_action( 'admin_init', 'AMP_Options_Manager::register_settings' );

/**
* Sets up the AMP template editor for the Customizer.
*/
Expand Down Expand Up @@ -80,15 +82,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.
*
* @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;
}

Expand Down
1 change: 1 addition & 0 deletions includes/class-amp-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private function sanitize( $content ) {
}
}

// @todo Split this class out into a separate file.
class AMP_Content_Sanitizer {
public static function sanitize( $content, array $sanitizer_classes, $global_args = array() ) {
$scripts = array();
Expand Down
1 change: 1 addition & 0 deletions includes/class-amp-post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct( $post_id ) {
'canonical_url' => get_permalink( $post_id ),
'home_url' => home_url(),
'blog_name' => get_bloginfo( 'name' ),
'generator_metadata' => 'AMP Plugin v' . AMP__VERSION,

'html_tag_attributes' => array(),
'body_class' => '',
Expand Down
66 changes: 66 additions & 0 deletions includes/class-amp-post-type-support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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 init() {
add_action( 'after_setup_theme', array( __CLASS__, 'add_post_type_support' ), 5 );
}

/**
* Get post types that plugin supports out of the box (which cannot be disabled).
*
* @return string[] Post types.
*/
public static function get_builtin_supported_post_types() {
return array_filter( array( 'post' ), 'post_type_exists' );
}

/**
* Get post types that are eligible for AMP support.
*
* @since 0.6
* @return string[] Post types eligible for AMP.
*/
public static function get_eligible_post_types() {
return array_merge(
self::get_builtin_supported_post_types(),
array_values( get_post_types(
array(
'public' => true,
'_builtin' => false,
),
'names'
) )
);
}

/**
* Declare support for 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_post_type_support() {
$post_types = array_merge(
self::get_builtin_supported_post_types(),
AMP_Options_Manager::get_option( 'supported_post_types', array() )
);
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, AMP_QUERY_VAR );
}
}
}
5 changes: 4 additions & 1 deletion includes/options/class-amp-analytics-options-submenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ private function add_submenu() {
public function amp_options_styles() {
?>
<style>
.analytics-data-container #delete {
.analytics-data-container .button.delete,
.analytics-data-container .button.delete:hover,
.analytics-data-container .button.delete:active,
.analytics-data-container .button.delete:focus {
background: red;
border-color: red;
text-shadow: 0 0 0;
Expand Down
Loading

0 comments on commit e66e2b2

Please sign in to comment.