Plugin Directory

Changeset 1765337


Ignore:
Timestamp:
11/13/2017 06:25:51 PM (8 years ago)
Author:
betterstudio
Message:

v1.6.2

Location:
better-amp/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • better-amp/trunk/better-amp.php

    r1764458 r1765337  
    55Description: Add FULL AMP support to your WordPress site.
    66Author: Better Studio
    7 Version: 1.6.1
     7Version: 1.6.2
    88Author URI: http://betterstudio.com
    99*/
     
    5353     * @since 1.0.0
    5454     */
    55     const VERSION = '1.6.1';
     55    const VERSION = '1.6.2';
    5656
    5757
     
    370370
    371371        $amp_qv = defined( 'AMP_QUERY_VAR' ) ? AMP_QUERY_VAR : 'amp';
     372
    372373        if ( get_query_var( $amp_qv, FALSE ) === FALSE ) {
    373             return;
    374         }
    375 
    376         $path = bf_get_wp_installation_slug();
    377 
    378         if ( preg_match( "#^$path/*(.*?)/$amp_qv/*$#", $_SERVER['REQUEST_URI'], $matched ) ) {
    379 
    380 
    381             $new_amp_url = Better_AMP_Content_Sanitizer::transform_to_amp_url( site_url( $matched[1] ) );
     374
     375            if ( ! is_404() ) { # /amp at the end of some urls cause 404 error
     376                return;
     377            }
     378        }
     379
     380        $is_amp_available = TRUE;
     381
     382        if ( is_singular() ) {
     383
     384            if ( $post_id = get_queried_object_id() ) {
     385
     386                $is_amp_available = ! get_post_meta( $post_id, 'disable-better-amp', TRUE ) && ! isset( $this->excluded_posts_id[ $post_id ] );
     387            }
     388        }
     389
     390        $path        = bf_get_wp_installation_slug();
     391        $request_url = str_replace( $path, '', $_SERVER['REQUEST_URI'] );
     392
     393        preg_match( "#^/*(.*?)/$amp_qv/*$#", $request_url, $automattic_amp_match );
     394
     395        if ( ! $is_amp_available ) {
     396
     397            if ( ! empty( $automattic_amp_match[1] ) ) {
     398
     399                $redirect_url = site_url( $automattic_amp_match[1] );
     400
     401            } elseif ( preg_match( "#^/*$amp_qv/+(.*?)/*$#", $request_url, $matched ) ) {
     402
     403                $redirect_url = site_url( $matched[1] );
     404
     405            } else {
     406
     407                $redirect_url = '';
     408            }
     409
     410            if ( $redirect_url ) {
     411
     412                // todo: use Better_AMP_Content_Sanitizer::transform_to_amp_url
     413                wp_redirect( $redirect_url );
     414                exit;
     415            }
     416        }
     417
     418        if ( ! empty( $automattic_amp_match[1] ) ) {
     419
     420
     421            $new_amp_url = Better_AMP_Content_Sanitizer::transform_to_amp_url( site_url( $automattic_amp_match[1] ) );
    382422            $new_amp_url = trailingslashit( $new_amp_url );
    383423
    384             if ( $new_amp_url && trim( str_replace( site_url(), '', $new_amp_url ), '/' ) !== trim( $_SERVER['REQUEST_URI'], '/' ) ) {
     424            if ( $new_amp_url && trim( str_replace( site_url(), '', $new_amp_url ), '/' ) !== trim( $request_url, '/' ) ) {
    385425
    386426                wp_redirect( $new_amp_url, 301 );
    387427                exit;
    388             }
    389         }
    390 
    391         if ( is_singular() ) {
    392             $post_id = get_queried_object_id();
    393 
    394             if (
    395                 get_post_meta( $post_id, 'disable-better-amp', TRUE )
    396                 ||
    397                 isset( $this->excluded_posts_id[ $post_id ] )
    398             ) {
    399 
    400                 if ( preg_match( "#^$path/*$amp_qv/+(.*?)/*$#", $_SERVER['REQUEST_URI'], $matched ) ) {
    401 
    402                     // todo: use Better_AMP_Content_Sanitizer::transform_to_amp_url
    403                     wp_redirect( site_url( $matched[1] ) );
    404                     exit;
    405                 }
    406428            }
    407429        }
  • better-amp/trunk/includes/functions/core-functions.php

    r1763773 r1765337  
    2525        }
    2626
    27         if ( did_action( 'template_redirect' ) ) {
     27        if ( did_action( 'template_redirect' ) && ! is_404() ) {
    2828
    2929            global $wp_query;
     
    4141            $amp_qv = defined( 'AMP_QUERY_VAR' ) ? AMP_QUERY_VAR : 'amp';
    4242
    43             return (bool) preg_match( "#^$path/*(.*?)/$amp_qv/+#", $_SERVER['REQUEST_URI'] );
     43            return (bool) preg_match( "#^$path/*(.*?)/$amp_qv/*#", $_SERVER['REQUEST_URI'] );
    4444        }
    4545    }
  • better-amp/trunk/includes/functions/theme-functions.php

    r1763773 r1765337  
    24302430        }
    24312431
    2432         $sites = array_intersect_key( $sites, array( // Valid sites
    2433                                                      'facebook'    => '',
    2434                                                      'twitter'     => '',
    2435                                                      'google_plus' => '',
    2436                                                      'pinterest'   => '',
    2437                                                      'linkedin'    => '',
    2438                                                      'tumblr'      => '',
    2439                                                      'reddit'      => '',
    2440                                                      'stumbleupon' => '',
     2432        $sites = array_intersect_key( $sites, array(
     2433            // Valid sites
     2434            'facebook'    => '',
     2435            'twitter'     => '',
     2436            'google_plus' => '',
     2437            'pinterest'   => '',
     2438            'linkedin'    => '',
     2439            'tumblr'      => '',
     2440            'reddit'      => '',
     2441            'stumbleupon' => '',
    24412442        ) );
    24422443
  • better-amp/trunk/readme.txt

    r1764458 r1765337  
    5151
    5252== Changelog ==
     53
     54= 1.6.2 =
     55- Improved: AMP codes improved.
     56- Fixed: Infinite redirect to AMP version in subdirectory wp installations.
     57
    5358
    5459= 1.6.1 =
Note: See TracChangeset for help on using the changeset viewer.