AMP for WordPress - Version 2.1.1

Version Description

Download this release

Release Info

Developer westonruter
Plugin Icon 128x128 AMP for WordPress
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.1.0 to 2.1.1

amp.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin URI: https://amp-wp.org
6
  * Author: AMP Project Contributors
7
  * Author URI: https://github.com/ampproject/amp-wp/graphs/contributors
8
- * Version: 2.1.0
9
  * License: GPLv2 or later
10
  * Requires at least: 4.9
11
  * Requires PHP: 5.6
@@ -15,7 +15,7 @@
15
 
16
  define( 'AMP__FILE__', __FILE__ );
17
  define( 'AMP__DIR__', dirname( __FILE__ ) );
18
- define( 'AMP__VERSION', '2.1.0' );
19
 
20
  /**
21
  * Errors encountered while loading the plugin.
5
  * Plugin URI: https://amp-wp.org
6
  * Author: AMP Project Contributors
7
  * Author URI: https://github.com/ampproject/amp-wp/graphs/contributors
8
+ * Version: 2.1.1
9
  * License: GPLv2 or later
10
  * Requires at least: 4.9
11
  * Requires PHP: 5.6
15
 
16
  define( 'AMP__FILE__', __FILE__ );
17
  define( 'AMP__DIR__', dirname( __FILE__ ) );
18
+ define( 'AMP__VERSION', '2.1.1' );
19
 
20
  /**
21
  * Errors encountered while loading the plugin.
includes/amp-helper-functions.php CHANGED
@@ -14,6 +14,28 @@ use AmpProject\AmpWP\Option;
14
  use AmpProject\AmpWP\QueryVar;
15
  use AmpProject\AmpWP\Services;
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  /**
18
  * Handle activation of plugin.
19
  *
@@ -23,7 +45,9 @@ use AmpProject\AmpWP\Services;
23
  * @param bool $network_wide Whether the activation was done network-wide.
24
  */
25
  function amp_activate( $network_wide = false ) {
26
- AmpWpPluginFactory::create()->activate( $network_wide );
 
 
27
  }
28
 
29
  /**
@@ -35,7 +59,9 @@ function amp_activate( $network_wide = false ) {
35
  * @param bool $network_wide Whether the activation was done network-wide.
36
  */
37
  function amp_deactivate( $network_wide = false ) {
38
- AmpWpPluginFactory::create()->deactivate( $network_wide );
 
 
39
  }
40
 
41
  /**
@@ -45,15 +71,7 @@ function amp_deactivate( $network_wide = false ) {
45
  * @internal
46
  */
47
  function amp_bootstrap_plugin() {
48
- /**
49
- * Filters whether AMP is enabled on the current site.
50
- *
51
- * Useful if the plugin is network activated and you want to turn it off on select sites.
52
- *
53
- * @since 0.2
54
- * @since 2.0 Filter now runs earlier at plugins_loaded (with earliest priority) rather than at the after_setup_theme action.
55
- */
56
- if ( false === apply_filters( 'amp_is_enabled', true ) ) {
57
  return;
58
  }
59
 
@@ -1846,7 +1864,17 @@ function amp_generate_script_hash( $script ) {
1846
  * @return string AMP URL.
1847
  */
1848
  function amp_add_paired_endpoint( $url ) {
1849
- return Services::get( 'paired_routing' )->add_endpoint( $url );
 
 
 
 
 
 
 
 
 
 
1850
  }
1851
 
1852
  /**
@@ -1858,7 +1886,17 @@ function amp_add_paired_endpoint( $url ) {
1858
  * @return bool True if the AMP query parameter is set with the required value, false if not.
1859
  */
1860
  function amp_has_paired_endpoint( $url = '' ) {
1861
- return Services::get( 'paired_routing' )->has_endpoint( $url );
 
 
 
 
 
 
 
 
 
 
1862
  }
1863
 
1864
  /**
@@ -1870,5 +1908,15 @@ function amp_has_paired_endpoint( $url = '' ) {
1870
  * @return string URL with AMP stripped.
1871
  */
1872
  function amp_remove_paired_endpoint( $url ) {
1873
- return Services::get( 'paired_routing' )->remove_endpoint( $url );
 
 
 
 
 
 
 
 
 
 
1874
  }
14
  use AmpProject\AmpWP\QueryVar;
15
  use AmpProject\AmpWP\Services;
16
 
17
+ /**
18
+ * Determine whether AMP is enabled on the current site.
19
+ *
20
+ * @since 2.1.1
21
+ * @internal
22
+ *
23
+ * @return bool Whether enabled.
24
+ */
25
+ function amp_is_enabled() {
26
+ /**
27
+ * Filters whether AMP is enabled on the current site.
28
+ *
29
+ * Useful if the plugin is network activated and you want to turn it off on select sites.
30
+ *
31
+ * @since 0.2
32
+ * @since 2.0 Filter now runs earlier at plugins_loaded (with earliest priority) rather than at the after_setup_theme action.
33
+ *
34
+ * @param bool $enabled Whether the AMP plugin's functionality should be enabled.
35
+ */
36
+ return (bool) apply_filters( 'amp_is_enabled', true );
37
+ }
38
+
39
  /**
40
  * Handle activation of plugin.
41
  *
45
  * @param bool $network_wide Whether the activation was done network-wide.
46
  */
47
  function amp_activate( $network_wide = false ) {
48
+ if ( amp_is_enabled() ) {
49
+ AmpWpPluginFactory::create()->activate( $network_wide );
50
+ }
51
  }
52
 
53
  /**
59
  * @param bool $network_wide Whether the activation was done network-wide.
60
  */
61
  function amp_deactivate( $network_wide = false ) {
62
+ if ( amp_is_enabled() ) {
63
+ AmpWpPluginFactory::create()->deactivate( $network_wide );
64
+ }
65
  }
66
 
67
  /**
71
  * @internal
72
  */
73
  function amp_bootstrap_plugin() {
74
+ if ( ! amp_is_enabled() ) {
 
 
 
 
 
 
 
 
75
  return;
76
  }
77
 
1864
  * @return string AMP URL.
1865
  */
1866
  function amp_add_paired_endpoint( $url ) {
1867
+ try {
1868
+ return Services::get( 'paired_routing' )->add_endpoint( $url );
1869
+ } catch ( InvalidService $e ) {
1870
+ if ( ! amp_is_enabled() ) {
1871
+ $reason = __( 'Function called while AMP is disabled via `amp_is_enabled` filter.', 'amp' );
1872
+ } else {
1873
+ $reason = __( 'Function cannot be called before services are registered.', 'amp' );
1874
+ }
1875
+ _doing_it_wrong( __FUNCTION__, esc_html( $reason ) . ' ' . esc_html( $e->getMessage() ), '2.1.1' );
1876
+ return $url;
1877
+ }
1878
  }
1879
 
1880
  /**
1886
  * @return bool True if the AMP query parameter is set with the required value, false if not.
1887
  */
1888
  function amp_has_paired_endpoint( $url = '' ) {
1889
+ try {
1890
+ return Services::get( 'paired_routing' )->has_endpoint( $url );
1891
+ } catch ( InvalidService $e ) {
1892
+ if ( ! amp_is_enabled() ) {
1893
+ $reason = __( 'Function called while AMP is disabled via `amp_is_enabled` filter.', 'amp' );
1894
+ } else {
1895
+ $reason = __( 'Function cannot be called before services are registered.', 'amp' );
1896
+ }
1897
+ _doing_it_wrong( __FUNCTION__, esc_html( $reason ) . ' ' . esc_html( $e->getMessage() ), '2.1.1' );
1898
+ return false;
1899
+ }
1900
  }
1901
 
1902
  /**
1908
  * @return string URL with AMP stripped.
1909
  */
1910
  function amp_remove_paired_endpoint( $url ) {
1911
+ try {
1912
+ return Services::get( 'paired_routing' )->remove_endpoint( $url );
1913
+ } catch ( InvalidService $e ) {
1914
+ if ( ! amp_is_enabled() ) {
1915
+ $reason = __( 'Function called while AMP is disabled via `amp_is_enabled` filter.', 'amp' );
1916
+ } else {
1917
+ $reason = __( 'Function cannot be called before services are registered.', 'amp' );
1918
+ }
1919
+ _doing_it_wrong( __FUNCTION__, esc_html( $reason ) . ' ' . esc_html( $e->getMessage() ), '2.1.1' );
1920
+ return $url;
1921
+ }
1922
  }
includes/validation/class-amp-validated-url-post-type.php CHANGED
@@ -492,6 +492,14 @@ class AMP_Validated_URL_Post_Type {
492
  return (int) $count;
493
  }
494
 
 
 
 
 
 
 
 
 
495
  $query = new WP_Query(
496
  [
497
  'post_type' => self::POST_TYPE_SLUG,
@@ -504,6 +512,11 @@ class AMP_Validated_URL_Post_Type {
504
  ]
505
  );
506
 
 
 
 
 
 
507
  $count = $query->found_posts;
508
 
509
  set_transient( static::NEW_VALIDATION_ERROR_URLS_COUNT_TRANSIENT, $count, DAY_IN_SECONDS );
492
  return (int) $count;
493
  }
494
 
495
+ // Make sure filter is added in REST API context which is otherwise only added via AMP_Validation_Error_Taxonomy::add_admin_hooks().
496
+ $callback = [ AMP_Validation_Error_Taxonomy::class, 'filter_posts_where_for_validation_error_status' ];
497
+ $priority = 10;
498
+ $has_filter = has_filter( 'posts_where', $callback );
499
+ if ( false === $has_filter ) {
500
+ add_filter( 'posts_where', $callback, $priority, 2 );
501
+ }
502
+
503
  $query = new WP_Query(
504
  [
505
  'post_type' => self::POST_TYPE_SLUG,
512
  ]
513
  );
514
 
515
+ // Remove filter if we added it in this method.
516
+ if ( false === $has_filter ) {
517
+ remove_filter( 'posts_where', $callback, $priority );
518
+ }
519
+
520
  $count = $query->found_posts;
521
 
522
  set_transient( static::NEW_VALIDATION_ERROR_URLS_COUNT_TRANSIENT, $count, DAY_IN_SECONDS );
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: google, xwp, automattic, westonruter, albertomedina, schlessera, s
3
  Tags: page experience, performance, amp, mobile, optimization, accelerated mobile pages
4
  Requires at least: 4.9
5
  Tested up to: 5.7
6
- Stable tag: 2.1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
3
  Tags: page experience, performance, amp, mobile, optimization, accelerated mobile pages
4
  Requires at least: 4.9
5
  Tested up to: 5.7
6
+ Stable tag: 2.1.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInite6709b1d44e0d31d2dd2d31a66c72b89::getLoader();
vendor/composer/InstalledVersions.php CHANGED
@@ -32,7 +32,7 @@ private static $installed = array (
32
  'aliases' =>
33
  array (
34
  ),
35
- 'reference' => 'd4b01c61e5ace3ced82205b55625a120660f98f4',
36
  'name' => 'ampproject/amp-wp',
37
  ),
38
  'versions' =>
@@ -53,7 +53,7 @@ private static $installed = array (
53
  'aliases' =>
54
  array (
55
  ),
56
- 'reference' => 'd4b01c61e5ace3ced82205b55625a120660f98f4',
57
  ),
58
  'fasterimage/fasterimage' =>
59
  array (
32
  'aliases' =>
33
  array (
34
  ),
35
+ 'reference' => 'b8b0cd975e6de002eefba7e1fc1da09ab4032836',
36
  'name' => 'ampproject/amp-wp',
37
  ),
38
  'versions' =>
53
  'aliases' =>
54
  array (
55
  ),
56
+ 'reference' => 'b8b0cd975e6de002eefba7e1fc1da09ab4032836',
57
  ),
58
  'fasterimage/fasterimage' =>
59
  array (
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a
6
  {
7
  private static $loader;
8
 
@@ -24,15 +24,15 @@ class ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
- spl_autoload_register(array('ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
- spl_autoload_unregister(array('ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
- call_user_func(\Composer\Autoload\ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
@@ -53,19 +53,19 @@ class ComposerAutoloaderInit4272c6f9b81fe26f79a51d33067bfd9a
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
- $includeFiles = Composer\Autoload\ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
- composerRequire4272c6f9b81fe26f79a51d33067bfd9a($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
- function composerRequire4272c6f9b81fe26f79a51d33067bfd9a($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInite6709b1d44e0d31d2dd2d31a66c72b89
6
  {
7
  private static $loader;
8
 
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
+ spl_autoload_register(array('ComposerAutoloaderInite6709b1d44e0d31d2dd2d31a66c72b89', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
+ spl_autoload_unregister(array('ComposerAutoloaderInite6709b1d44e0d31d2dd2d31a66c72b89', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
+ call_user_func(\Composer\Autoload\ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
+ $includeFiles = Composer\Autoload\ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
+ composerRequiree6709b1d44e0d31d2dd2d31a66c72b89($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
+ function composerRequiree6709b1d44e0d31d2dd2d31a66c72b89($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a
8
  {
9
  public static $files = array (
10
  'ffc2110a578b705d2022d1f7803373a6' => __DIR__ . '/../..' . '/includes/bootstrap.php',
@@ -371,9 +371,9 @@ class ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a
371
  public static function getInitializer(ClassLoader $loader)
372
  {
373
  return \Closure::bind(function () use ($loader) {
374
- $loader->prefixLengthsPsr4 = ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a::$prefixLengthsPsr4;
375
- $loader->prefixDirsPsr4 = ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a::$prefixDirsPsr4;
376
- $loader->classMap = ComposerStaticInit4272c6f9b81fe26f79a51d33067bfd9a::$classMap;
377
 
378
  }, null, ClassLoader::class);
379
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89
8
  {
9
  public static $files = array (
10
  'ffc2110a578b705d2022d1f7803373a6' => __DIR__ . '/../..' . '/includes/bootstrap.php',
371
  public static function getInitializer(ClassLoader $loader)
372
  {
373
  return \Closure::bind(function () use ($loader) {
374
+ $loader->prefixLengthsPsr4 = ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89::$prefixLengthsPsr4;
375
+ $loader->prefixDirsPsr4 = ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89::$prefixDirsPsr4;
376
+ $loader->classMap = ComposerStaticInite6709b1d44e0d31d2dd2d31a66c72b89::$classMap;
377
 
378
  }, null, ClassLoader::class);
379
  }
vendor/composer/installed.php CHANGED
@@ -6,7 +6,7 @@
6
  'aliases' =>
7
  array (
8
  ),
9
- 'reference' => 'd4b01c61e5ace3ced82205b55625a120660f98f4',
10
  'name' => 'ampproject/amp-wp',
11
  ),
12
  'versions' =>
@@ -27,7 +27,7 @@
27
  'aliases' =>
28
  array (
29
  ),
30
- 'reference' => 'd4b01c61e5ace3ced82205b55625a120660f98f4',
31
  ),
32
  'fasterimage/fasterimage' =>
33
  array (
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => 'b8b0cd975e6de002eefba7e1fc1da09ab4032836',
10
  'name' => 'ampproject/amp-wp',
11
  ),
12
  'versions' =>
27
  'aliases' =>
28
  array (
29
  ),
30
+ 'reference' => 'b8b0cd975e6de002eefba7e1fc1da09ab4032836',
31
  ),
32
  'fasterimage/fasterimage' =>
33
  array (