AMP for WP – Accelerated Mobile Pages - Version 1.0.10

Version Description

(10th January 2020) = * Improvement: Need a hook to use it in Woocomerce #4048 * Fixed: Scripts are not adding properly if user is adding the content through embed #4040 * Fixed: When Featured Image from The Content is turned on,the image is not displayed when Creating post from Gutenberg. #4022

Download this release

Release Info

Developer mohammed_kaludi
Plugin Icon 128x128 AMP for WP – Accelerated Mobile Pages
Version 1.0.10
Comparing to
See all releases

Code changes from version 1.0.9 to 1.0.10

README.md CHANGED
@@ -4,7 +4,7 @@ Tags: AMP, accelerated mobile pages, mobile, amp project, google amp, amp wp, go
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.3.2
7
- Stable tag: 1.0.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -191,6 +191,11 @@ You can contact us from [here](https://ampforwp.com/contact/)
191
 
192
  == Changelog ==
193
 
 
 
 
 
 
194
  = 1.0.9 (8th January 2020) =
195
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
196
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.3.2
7
+ Stable tag: 1.0.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
191
 
192
  == Changelog ==
193
 
194
+ = 1.0.10 (10th January 2020) =
195
+ * Improvement: Need a hook to use it in Woocomerce #4048
196
+ * Fixed: Scripts are not adding properly if user is adding the content through embed #4040
197
+ * Fixed: When Featured Image from The Content is turned on,the image is not displayed when Creating post from Gutenberg. #4022
198
+
199
  = 1.0.9 (8th January 2020) =
200
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
201
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
accelerated-moblie-pages.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Accelerated Mobile Pages
4
  Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
5
  Description: AMP for WP - Accelerated Mobile Pages for WordPress
6
- Version: 1.0.9
7
  Author: Ahmed Kaludi, Mohammed Kaludi
8
  Author URI: https://ampforwp.com/
9
  Donate link: https://www.paypal.me/Kaludi/25
@@ -20,7 +20,7 @@ define('AMPFORWP_PLUGIN_DIR_URI', plugin_dir_url(__FILE__));
20
  define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
21
  define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
22
  define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
23
- define('AMPFORWP_VERSION','1.0.9');
24
  define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
25
  if(!defined('AMPFROWP_HOST_NAME')){
26
  $urlinfo = get_bloginfo('url');
3
  Plugin Name: Accelerated Mobile Pages
4
  Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
5
  Description: AMP for WP - Accelerated Mobile Pages for WordPress
6
+ Version: 1.0.10
7
  Author: Ahmed Kaludi, Mohammed Kaludi
8
  Author URI: https://ampforwp.com/
9
  Donate link: https://www.paypal.me/Kaludi/25
20
  define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
21
  define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
22
  define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
23
+ define('AMPFORWP_VERSION','1.0.10');
24
  define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
25
  if(!defined('AMPFROWP_HOST_NAME')){
26
  $urlinfo = get_bloginfo('url');
changelog.txt CHANGED
@@ -1,5 +1,10 @@
1
  == Changelog ==
2
 
 
 
 
 
 
3
  = 1.0.9 (8th January 2020) =
4
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
5
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
1
  == Changelog ==
2
 
3
+ = 1.0.10 (10th January 2020) =
4
+ * Improvement: Need a hook to use it in Woocomerce #4048
5
+ * Fixed: Scripts are not adding properly if user is adding the content through embed #4040
6
+ * Fixed: When Featured Image from The Content is turned on,the image is not displayed when Creating post from Gutenberg. #4022
7
+
8
  = 1.0.9 (8th January 2020) =
9
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
10
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: AMP, accelerated mobile pages, mobile, amp project, google amp, amp wp, go
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.3.2
7
- Stable tag: 1.0.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -191,6 +191,11 @@ You can contact us from [here](https://ampforwp.com/contact/)
191
 
192
  == Changelog ==
193
 
 
 
 
 
 
194
  = 1.0.9 (8th January 2020) =
195
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
196
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
@@ -201,12 +206,4 @@ You can contact us from [here](https://ampforwp.com/contact/)
201
  = 1.0.8 (2nd January 2020) =
202
  * Fixed: Need to add Rankmath's "Nofollow External Links" feature. #3970 (updated the code)
203
 
204
- = 1.0.7 (2nd January 2020) =
205
- * Improvement: Need to add Rankmath's "Nofollow External Links" feature. #3970
206
- * Improvement: Need to add floating button in extension list #3972
207
- * Fixed: AMP theme framework GDPR module should be connected to GDPR Compliancy in option panel. #3963
208
- * Fixed: Breadcrumbs are not properly displaying and working in updated version #3917
209
- * Fixed: amp-auto-ads script is loading in AMP-pages when Google site kit plugin is enable. #4009
210
- * Fixed: wp-block CSS is heavily loading even when tree shaking is enabled in core. (Page builder is enabled) #4014
211
-
212
  Full changelog available [ at changelog.txt](https://plugins.svn.wordpress.org/accelerated-mobile-pages/trunk/changelog.txt)
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.3.2
7
+ Stable tag: 1.0.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
191
 
192
  == Changelog ==
193
 
194
+ = 1.0.10 (10th January 2020) =
195
+ * Improvement: Need a hook to use it in Woocomerce #4048
196
+ * Fixed: Scripts are not adding properly if user is adding the content through embed #4040
197
+ * Fixed: When Featured Image from The Content is turned on,the image is not displayed when Creating post from Gutenberg. #4022
198
+
199
  = 1.0.9 (8th January 2020) =
200
  * Fixed: Odd behaviour of Optimize CSS (Treeshaking),when turned off resolves the validation errors and when turned on adding unnecessary wp-block CSS. #4036
201
  * Fixed: After enable the Tree shaking feature the CSS not loading properly #4034
206
  = 1.0.8 (2nd January 2020) =
207
  * Fixed: Need to add Rankmath's "Nofollow External Links" feature. #3970 (updated the code)
208
 
 
 
 
 
 
 
 
 
209
  Full changelog available [ at changelog.txt](https://plugins.svn.wordpress.org/accelerated-mobile-pages/trunk/changelog.txt)
templates/design-manager/design-3/index.php CHANGED
@@ -154,7 +154,14 @@ if ( get_query_var( 'paged' ) ) {
154
  $thumb_width = ampforwp_get_setting('ampforwp-design-3-homepage-posts-width');
155
  $thumb_height = ampforwp_get_setting('ampforwp-design-3-homepage-posts-height');
156
  $thumb_url_modify = wp_get_attachment_image_src($thumb_id, 'full' , true);
157
- $thumb_crop_url = ampforwp_aq_resize( $thumb_url_modify[0], $thumb_width , $thumb_height , true, false );
 
 
 
 
 
 
 
158
  $thumb_url = $thumb_crop_url[0];
159
  }
160
  if($thumb_url){
154
  $thumb_width = ampforwp_get_setting('ampforwp-design-3-homepage-posts-width');
155
  $thumb_height = ampforwp_get_setting('ampforwp-design-3-homepage-posts-height');
156
  $thumb_url_modify = wp_get_attachment_image_src($thumb_id, 'full' , true);
157
+ $thumb_mod_url = $thumb_url_modify[0];
158
+ if($thumb_id==0 || $thumb_id==""){
159
+ if( true ==ampforwp_get_setting('ampforwp-featured-image-from-content') && ampforwp_get_featured_image_from_content('url') ){
160
+ $thumb_url = ampforwp_get_post_thumbnail('url');
161
+ $thumb_mod_url = $thumb_url;
162
+ }
163
+ }
164
+ $thumb_crop_url = ampforwp_aq_resize( $thumb_mod_url, $thumb_width , $thumb_height , true, false );
165
  $thumb_url = $thumb_crop_url[0];
166
  }
167
  if($thumb_url){
templates/design-manager/swift/header.php CHANGED
@@ -140,6 +140,7 @@ if( !ampforwp_levelup_compatibility('hf_builder_head') ){
140
  <a title="call telephone" href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
141
  </div>
142
  <?php } ?>
 
143
  </div>
144
  <div class="clearfix"></div>
145
  </div>
@@ -271,6 +272,7 @@ if( !ampforwp_levelup_compatibility('hf_builder_head') ){
271
  <a title="call telephone" href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
272
  </div>
273
  <?php } ?>
 
274
  </div>
275
  </div>
276
  </div>
@@ -396,6 +398,7 @@ if( !ampforwp_levelup_compatibility('hf_builder_head') ){
396
  <a href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
397
  </div>
398
  <?php } ?>
 
399
  <?php if(ampforwp_get_setting('ampforwp-amp-menu-swift') == true) {?>
400
  <div class="h-nav">
401
  <label for="offcanvas-menu" class="t-btn"></label>
140
  <a title="call telephone" href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
141
  </div>
142
  <?php } ?>
143
+ <?php do_action('ampforwp_header_elements') ?>
144
  </div>
145
  <div class="clearfix"></div>
146
  </div>
272
  <a title="call telephone" href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
273
  </div>
274
  <?php } ?>
275
+ <?php do_action('ampforwp_header_elements') ?>
276
  </div>
277
  </div>
278
  </div>
398
  <a href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']);?>"></a>
399
  </div>
400
  <?php } ?>
401
+ <?php do_action('ampforwp_header_elements') ?>
402
  <?php if(ampforwp_get_setting('ampforwp-amp-menu-swift') == true) {?>
403
  <div class="h-nav">
404
  <label for="offcanvas-menu" class="t-btn"></label>
templates/features.php CHANGED
@@ -4450,6 +4450,7 @@ function ampforwp_get_featured_image_from_content( $featured_image = "", $size="
4450
  // Match all the images from the content
4451
  if(is_object($post)){
4452
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*.+width=[\'"]([^\'"]+)[\'"].*.+height=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
 
4453
  // Match all the figure tags from the content
4454
  $output_fig = preg_match_all('/\[caption.+id=[\'"]([^\'"]+).*]/i', $post->post_content, $matches_fig);
4455
  if ( $output_fig && $matches_fig[0][0] ) {
@@ -4461,11 +4462,38 @@ function ampforwp_get_featured_image_from_content( $featured_image = "", $size="
4461
  }
4462
  }
4463
  //Grab the First Image
4464
- if (is_array($matches) && $matches[0] ) {
4465
- $image_url = $matches[1][0];
4466
- $image_html = $matches[0][0];
4467
- $image_width = $matches[2][0];
4468
- $image_height = $matches[3][0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4469
  // Sanitize it
4470
  $amp_html_sanitizer = new AMPFORWP_Content( $image_html, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Img_Sanitizer' => array(), 'AMP_Style_Sanitizer' => array() ) ) );
4471
  $amp_html = $amp_html_sanitizer->get_amp_content();
@@ -4476,7 +4504,7 @@ function ampforwp_get_featured_image_from_content( $featured_image = "", $size="
4476
  // Filter to remove that image from the content
4477
  add_filter('ampforwp_modify_the_content','featured_image_content_filter');
4478
 
4479
- if ( isset( $size ) && '' !== $size ) {
4480
  $image_id = attachment_url_to_postid( $image_url );
4481
  if ($image_id) {
4482
  $image_array = wp_get_attachment_image_src($image_id, $size, true);
@@ -7585,4 +7613,22 @@ if(!function_exists('ampforwp_transposh_plugin_rtl_css')){
7585
  }
7586
  }
7587
  }
7588
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4450
  // Match all the images from the content
4451
  if(is_object($post)){
4452
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*.+width=[\'"]([^\'"]+)[\'"].*.+height=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
4453
+
4454
  // Match all the figure tags from the content
4455
  $output_fig = preg_match_all('/\[caption.+id=[\'"]([^\'"]+).*]/i', $post->post_content, $matches_fig);
4456
  if ( $output_fig && $matches_fig[0][0] ) {
4462
  }
4463
  }
4464
  //Grab the First Image
4465
+ if ((is_array($matches) && $matches[0]) || $output==0 ) {
4466
+ if($output==1){
4467
+ $image_url = $matches[1][0];
4468
+ $image_html = $matches[0][0];
4469
+ $image_width = $matches[2][0];
4470
+ $image_height = $matches[3][0];
4471
+ }
4472
+ if($output==0){
4473
+ if(preg_match('/<figure\sclass="(.*?)">(<img\ssrc="(.*?)"(.*?)>)<\/figure>/', $post->post_content, $fm)){
4474
+ preg_match('/<figure\sclass="(.*?)">(<img\ssrc="(.*?)"(.*?)>)<\/figure>/', $post->post_content, $fb);
4475
+ if(isset( $fb[2])){
4476
+ $dom = new DOMDocument();
4477
+ $image_html = $fb[2];
4478
+ $dom->loadHTML($image_html);
4479
+ $x = new DOMXPath($dom);
4480
+ foreach($x->query("//img") as $node){
4481
+ $node->setAttribute("width","1366");
4482
+ $node->setAttribute("height","600");
4483
+ }
4484
+ $image_html = $dom->saveHtml();
4485
+ preg_match_all('/<img\ssrc="(.*?)">/', $image_html, $fimg);
4486
+ if(isset($fimg[0][0])){
4487
+ $image_html ='<figure class="'.esc_attr($fb[1]).'">'.$fimg[0][0].'</figure>';
4488
+ if(isset($fb[3])){
4489
+ $image_url = $fb[3];
4490
+ $image_width = 1366;
4491
+ $image_height = 600;
4492
+ }
4493
+ }
4494
+ }
4495
+ }
4496
+ }
4497
  // Sanitize it
4498
  $amp_html_sanitizer = new AMPFORWP_Content( $image_html, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Img_Sanitizer' => array(), 'AMP_Style_Sanitizer' => array() ) ) );
4499
  $amp_html = $amp_html_sanitizer->get_amp_content();
4504
  // Filter to remove that image from the content
4505
  add_filter('ampforwp_modify_the_content','featured_image_content_filter');
4506
 
4507
+ if ( isset( $size ) && '' !== $size) {
4508
  $image_id = attachment_url_to_postid( $image_url );
4509
  if ($image_id) {
4510
  $image_array = wp_get_attachment_image_src($image_id, $size, true);
7613
  }
7614
  }
7615
  }
7616
+ }
7617
+ add_filter('ampforwp_the_content_last_filter','ampforwp_add_required_script',12);
7618
+ function ampforwp_add_required_script($content){
7619
+ $exclude_el_arr = array('img','state','bind-macro','pixel');
7620
+ preg_match_all('/<\/amp-(.*?)>/', $content, $matches);
7621
+ if(isset($matches[1][0])){
7622
+ $amp_comp = $matches[1];
7623
+ for($i=0;$i<count($amp_comp);$i++){
7624
+ $comp = $amp_comp[$i];
7625
+ if(!in_array($comp, $exclude_el_arr)){
7626
+ if(!preg_match('/<script\scustom-element=\"amp-'.esc_attr($comp).'\"(.*?)><\/script>/', $content, $matches)){
7627
+ $script_tag = '<head><script custom-element="amp-'.esc_attr($comp).'" src="https://cdn.ampproject.org/v0/amp-'.esc_attr($comp).'-latest.js" async></script>';
7628
+ $content = str_replace('<head>', $script_tag, $content);
7629
+ }
7630
+ }
7631
+ }
7632
+ }
7633
+ return $content;
7634
+ }