Skip to content

Commit

Permalink
Merge branch '0.6' of https://github.com/Automattic/amp-wp into fix/0…
Browse files Browse the repository at this point in the history
….7-vip-review
  • Loading branch information
westonruter committed Apr 26, 2018
2 parents ac936d3 + e18d560 commit 62f19c1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
1 change: 0 additions & 1 deletion includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static function maybe_flush_rewrite_rules( $old_options, $new_options ) {
sort( $new_post_types );
if ( $old_post_types !== $new_post_types ) {
flush_rewrite_rules( false );
do_action( 'rri_flush_rules' );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
*/
class AMP_Analytics_Options_Submenu_Page {

/**
* Render entry.
*
* @param string $id Entry ID.
* @param string $type Entry type.
* @param string $config Entry config as serialized JSON.
*/
private function render_entry( $id = '', $type = '', $config = '' ) {
$is_existing_entry = ! empty( $id );

if ( $is_existing_entry ) {
$entry_slug = sprintf( '%s%s', ( $type ? $type . '-' : '' ), substr( $id, -6 ) );
$entry_slug = sprintf( '%s%s', ( $type ? $type . '-' : '' ), substr( $id, - 6 ) );
/* translators: %s is the entry slug */
$analytics_title = sprintf( __( 'Analytics: %s', 'amp' ), $entry_slug );
} else {
$analytics_title = __( 'Add new entry:', 'amp' );
}

if ( ! $is_existing_entry ) {
$id = '__new__';
$id = '__new__';
}

$id_base = sprintf( '%s[analytics][%s]', AMP_Options_Manager::OPTION_NAME, $id );
Expand Down Expand Up @@ -55,9 +60,9 @@ private function render_entry( $id = '', $type = '', $config = '' ) {
<p>
<?php
wp_nonce_field( 'analytics-options', 'analytics-options' );
submit_button( __( 'Save', 'amp' ), 'primary', 'save', false );
submit_button( esc_html__( 'Save', 'amp' ), 'primary', 'save', false );
if ( $is_existing_entry ) {
submit_button( __( 'Delete', 'amp' ), 'delete button-primary', $id_base . '[delete]', false );
submit_button( esc_html__( 'Delete', 'amp' ), 'delete button-primary', esc_attr( $id_base . '[delete]' ), false );
}
?>
</p>
Expand All @@ -78,6 +83,9 @@ public function render_title() {
<?php
}

/**
* Render.
*/
public function render() {
$analytics_entries = AMP_Options_Manager::get_option( 'analytics', array() );

Expand Down
8 changes: 7 additions & 1 deletion includes/templates/class-amp-post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ public function __construct( $post ) {
} else {
$this->post = get_post( $post );
}
$this->ID = $this->post->ID;

// Make sure we have a post, or bail if not.
if ( is_a( $this->post, 'WP_Post' ) ) {
$this->ID = $this->post->ID;
} else {
return;
}

$content_max_width = self::CONTENT_MAX_WIDTH;
if ( isset( $GLOBALS['content_width'] ) && $GLOBALS['content_width'] > 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Enable Accelerated Mobile Pages (AMP) on your WordPress site.
**Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile)
**Requires at least:** 4.7
**Tested up to:** 4.9
**Stable tag:** 0.6.0
**Stable tag:** 0.6.2
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
**Requires PHP:** 5.3

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp
Tags: amp, mobile
Requires at least: 4.7
Tested up to: 4.9
Stable tag: 0.6.0
Stable tag: 0.6.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires PHP: 5.3
Expand Down
38 changes: 37 additions & 1 deletion tests/test-class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,43 @@ public function test_register_settings() {
$this->assertArrayHasKey( AMP_Options_Manager::OPTION_NAME, $registered_settings );
$this->assertEquals( 'array', $registered_settings[ AMP_Options_Manager::OPTION_NAME ]['type'] );

$this->assertEquals( 10, has_action( 'update_option_' . AMP_Options_Manager::OPTION_NAME, 'flush_rewrite_rules' ) );
$this->assertEquals( 10, has_action( 'update_option_' . AMP_Options_Manager::OPTION_NAME, array( 'AMP_Options_Manager', 'maybe_flush_rewrite_rules' ) ) );
}

/**
* Test maybe_flush_rewrite_rules.
*
* @covers AMP_Options_Manager::maybe_flush_rewrite_rules()
*/
public function test_maybe_flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->init();
AMP_Options_Manager::register_settings();
$dummy_rewrite_rules = array( 'previous' => true );

// Check change to supported_post_types.
update_option( 'rewrite_rules', $dummy_rewrite_rules );
AMP_Options_Manager::maybe_flush_rewrite_rules(
array( 'supported_post_types' => array( 'page' ) ),
array()
);
$this->assertEmpty( get_option( 'rewrite_rules' ) );

// Check update of supported_post_types but no change.
update_option( 'rewrite_rules', $dummy_rewrite_rules );
update_option( AMP_Options_Manager::OPTION_NAME, array(
array( 'supported_post_types' => array( 'page' ) ),
array( 'supported_post_types' => array( 'page' ) ),
) );
$this->assertEquals( $dummy_rewrite_rules, get_option( 'rewrite_rules' ) );

// Check changing a different property.
update_option( 'rewrite_rules', array( 'previous' => true ) );
update_option( AMP_Options_Manager::OPTION_NAME, array(
array( 'foo' => 'new' ),
array( 'foo' => 'old' ),
) );
$this->assertEquals( $dummy_rewrite_rules, get_option( 'rewrite_rules' ) );
}

/**
Expand Down

0 comments on commit 62f19c1

Please sign in to comment.