Skip to content

Commit

Permalink
Merge pull request #953 from Automattic/fix/vip-review
Browse files Browse the repository at this point in the history
VIP Review Changes
  • Loading branch information
Thierry Muller authored Feb 28, 2018
2 parents 8edc415 + 664a2a1 commit e18d560
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 21 deletions.
4 changes: 2 additions & 2 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://github.com/automattic/amp-wp
* Author: Automattic
* Author URI: https://automattic.com
* Version: 0.6.1
* Version: 0.6.2
* Text Domain: amp
* Domain Path: /languages/
* License: GPLv2 or later
Expand All @@ -15,7 +15,7 @@

define( 'AMP__FILE__', __FILE__ );
define( 'AMP__DIR__', dirname( __FILE__ ) );
define( 'AMP__VERSION', '0.6.1' );
define( 'AMP__VERSION', '0.6.2' );

require_once AMP__DIR__ . '/includes/class-amp-autoloader.php';
AMP_Autoloader::register();
Expand Down
13 changes: 9 additions & 4 deletions assets/css/amp-post-meta-box.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
border-top-left-radius: 0;
border-bottom-left-radius: 0;
text-indent: -9999px;
padding-right: 7px;
padding-left: 7px;
padding-right: 14px;
padding-left: 14px;
position: relative;
}

.wp-core-ui #amp-post-preview.preview::after {
content: "icon";
width: 14px;
float: left;
background: no-repeat center url( '../images/amp-icon.svg' );
background-size: 14px !important;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: block;
position: absolute;
}

.wp-core-ui #amp-post-preview.preview.disabled::after {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"homepage": "https://github.com/Automattic/amp-wp",
"type": "wordpress-plugin",
"license": "GPL-2.0",
"version": "0.6.1"
"version": "0.6.2"
}
20 changes: 19 additions & 1 deletion includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@ public static function register_settings() {
)
);

add_action( 'update_option_' . self::OPTION_NAME, 'flush_rewrite_rules' );
add_action( 'update_option_' . self::OPTION_NAME, array( __CLASS__, 'maybe_flush_rewrite_rules' ), 10, 2 );
}

/**
* Flush rewrite rules if the supported_post_types have changed.
*
* @since 0.6.2
*
* @param array $old_options Old options.
* @param array $new_options New options.
*/
public static function maybe_flush_rewrite_rules( $old_options, $new_options ) {
$old_post_types = isset( $old_options['supported_post_types'] ) ? $old_options['supported_post_types'] : array();
$new_post_types = isset( $new_options['supported_post_types'] ) ? $new_options['supported_post_types'] : array();
sort( $old_post_types );
sort( $new_post_types );
if ( $old_post_types !== $new_post_types ) {
flush_rewrite_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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/Automattic/amp-wp.git"
},
"version": "0.6.1",
"version": "0.6.2",
"license": "GPL-2.0+",
"private": true,
"devDependencies": {
Expand Down
6 changes: 5 additions & 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.1
**Stable tag:** 0.6.2
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
**Requires PHP:** 5.2

Expand Down Expand Up @@ -56,6 +56,10 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve

## Changelog ##

### 0.6.2 (2018-02-12) ###
- Reduce frequency of flushing rewrite rules and harden, use escaped translation functions, and make minor changes to improve logic/style. See [#953](https://github.com/Automattic/amp-wp/pull/953). Props philipjohn, westonruter.
- Fix AMP preview icon in Firefox. See [#920](https://github.com/Automattic/amp-wp/pull/920). Props zigasancin.

### 0.6.1 (2018-02-09) ###
Bump version to re-release to ensure temporarily-broken 0.6.0 ZIP build is permanently fixed, without requiring a site to re-install the plugin.

Expand Down
7 changes: 6 additions & 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.1
Stable tag: 0.6.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires PHP: 5.2
Expand Down Expand Up @@ -38,6 +38,11 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve

== Changelog ==

= 0.6.2 (2018-02-12) =

- Reduce frequency of flushing rewrite rules and harden, use escaped translation functions, and make minor changes to improve logic/style. See [#953](https://github.com/Automattic/amp-wp/pull/953). Props philipjohn, westonruter.
- Fix AMP preview icon in Firefox. See [#920](https://github.com/Automattic/amp-wp/pull/920). Props zigasancin.

= 0.6.1 (2018-02-09) =

Bump version to re-release to ensure temporarily-broken 0.6.0 ZIP build is permanently fixed, without requiring a site to re-install the plugin.
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 e18d560

Please sign in to comment.