Plugin Directory

Changeset 2448994


Ignore:
Timestamp:
01/02/2021 02:29:52 AM (5 years ago)
Author:
uniquelylost
Message:

v4.5

Location:
equivalent-mobile-redirect/trunk
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • equivalent-mobile-redirect/trunk/equivalent-mobile-redirect.php

    r2339155 r2448994  
    11<?php
    2 /*
    3 Plugin Name: Equivalent Mobile Redirect
    4 Description: Detect and redirect mobile visitors to the equivalent page on your mobile site.
    5 Version: 4.4
    6 Text Domain: emr-redirect
    7 Author: uniquelylost
    8 Author URI: https://ndstud.io/
    9 License: GPL3
    10 License URI: http://www.gnu.org/licenses/gpl-3.0.txt
    11 
    12 */
     2/**
     3 * Plugin Name: Equivalent Mobile Redirect
     4 * Description: Detect and redirect mobile visitors to the equivalent page on your mobile site.
     5 * Version: 4.5
     6 * Author: uniquelylost
     7 * Author URI: https://ndstud.io/
     8 * Text Domain: emr-redirect
     9 * Requires at least: 3.0
     10 * License: GPL3
     11 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     12 */
    1313
    1414// Exit if accessed directly.
     
    1616
    1717// Admin panel.
    18 require_once 'includes/emr-options.php';
     18require_once plugin_dir_path( __FILE__ ) . 'includes/emr-options.php';
    1919
    2020// Equivalent mobile redirect class.
    21 require_once 'includes/class-emr.php';
     21require_once plugin_dir_path( __FILE__ ) . 'includes/class-emr.php';
  • equivalent-mobile-redirect/trunk/includes/class-emr.php

    r2339155 r2448994  
    1010     * @const string
    1111     */
    12     const VERSION = '4.4';
     12    const VERSION = '4.5';
    1313
    1414    /**
     
    238238        if ( empty( $full_site_cookie ) ) {
    239239            if ( ! class_exists( 'Mobile_Detect' ) ) {
    240                 require_once __DIR__ . '/Mobile_Detect.php';
     240                require_once plugin_dir_path( __FILE__ ) . 'Mobile_Detect.php';
    241241            }
    242242            $detect = new Mobile_Detect();
    243243            // EMR option page settings.
    244244            $options = get_option( 'emr_settings' );
    245             if ( isset( $options['emr_on_off'] ) ) {
    246                 $emr_enabled = $options['emr_on_off'];
    247                 if ( $emr_enabled == 'off' ) {
    248                     return;
    249                 }
    250             }
    251             $tablets_redirect            = $options['emr_tablets'];
    252             $mobile_to_one_url           = $options['emr_all_select'];
    253             $mobile_all_url              = $options['emr_redir_all_url'];
    254             $nonstatic_homepage_redirect = $options['emr_front_page'];
    255             $nonstatic_redirect_url      = $options['emr_redir_front_url'];
     245
     246            $emr_enabled = isset( $options['emr_on_off'] ) ? $options['emr_on_off'] : 'on';
     247            if ( $emr_enabled == 'off' ) {
     248                return;
     249            }
     250
     251            $tablets_redirect            = isset( $options['emr_tablets'] ) ? $options['emr_tablets'] : 'yes';
     252            $mobile_to_one_url           = isset( $options['emr_all_select'] ) ? $options['emr_all_select'] : 'no';
     253            $mobile_all_url              = isset( $options['emr_redir_all_url'] ) ? $options['emr_redir_all_url'] : '';
     254            $nonstatic_homepage_redirect = isset( $options['emr_front_page'] ) ? $options['emr_front_page'] : 'no';
     255            $nonstatic_redirect_url      = isset( $options['emr_redir_front_url'] ) ? $options['emr_redir_front_url'] : '';
    256256
    257257            if ( $detect->isMobile() && $mobile_to_one_url == 'yes' ) {
    258258                if ( $detect->isTablet() && $tablets_redirect == 'no' ) {
    259259                    $detect = 'false';
    260                 } elseif ( $mobile_all_url != '' ) {
     260                } elseif ( ! empty( $mobile_all_url ) ) {
    261261                    // Redirect all and quit.
    262262                    wp_redirect( $mobile_all_url, 302 );
     
    266266                if ( $detect->isTablet() && $tablets_redirect == 'no' ) {
    267267                    $detect = 'false';
    268                 } elseif ( $nonstatic_redirect_url != '' ) {
     268                } elseif ( ! empty( $nonstatic_redirect_url ) ) {
    269269                    wp_redirect( $nonstatic_redirect_url, 302 );
    270270                    exit;
     
    301301        // Get options.
    302302        $options                     = get_option( 'emr_settings' );
    303         $tablets_redirect            = $options['emr_tablets'];
    304         $mobile_to_one_url           = $options['emr_all_select'];
    305         $mobile_all_url              = $options['emr_redir_all_url'];
    306         $nonstatic_homepage_redirect = $options['emr_front_page'];
    307         $nonstatic_redirect_url      = $options['emr_redir_front_url'];
     303        $tablets_redirect            = isset( $options['emr_tablets'] ) ? $options['emr_tablets'] : 'yes';
     304        $mobile_to_one_url           = isset( $options['emr_all_select'] ) ? $options['emr_all_select'] : 'no';
     305        $mobile_all_url              = isset( $options['emr_redir_all_url'] ) ? $options['emr_redir_all_url'] : '';
     306        $nonstatic_homepage_redirect = isset( $options['emr_front_page'] ) ? $options['emr_front_page'] : 'no';
     307        $nonstatic_redirect_url      = isset( $options['emr_redir_front_url'] ) ? $options['emr_redir_front_url'] : '';
    308308
    309309        // Check mobile redirects are enabled.
    310         if ( isset( $options['emr_on_off'] ) ) {
    311             $emr_enabled = $options['emr_on_off'];
    312             if ( $emr_enabled == 'off' ) {
    313                 return;
    314             }
     310        $emr_enabled = isset( $options['emr_on_off'] ) ? $options['emr_on_off'] : 'on';
     311        if ( $emr_enabled == 'off' ) {
     312            return;
    315313        }
    316314
     
    322320        } elseif ( ( is_page() || is_single() || is_front_page() ) && ( isset( $this->post_types[ (string) get_post_type( $post ) ] ) ) ) {
    323321            $data            = $this->get_post_data( $post->ID );
    324             $mobile_rel_link = $data['url'];
     322            $mobile_rel_link = isset( $data['url'] ) ? $data['url'] : '';
    325323        }
    326324
    327325        // Check to make sure mobile link isn't blank before continuing.
    328         if ( $mobile_rel_link == '' )
     326        if ( empty( $mobile_rel_link ) )
    329327            return;
    330328
  • equivalent-mobile-redirect/trunk/includes/emr-options.php

    r2339155 r2448994  
    9898                        <select name="emr_settings[emr_on_off]">
    9999                            <?php
    100                             $selected = $options['emr_on_off'];
    101                             $p        = '';
    102                             $r        = '';
     100                            $selected = isset( $options['emr_on_off'] ) ? $options['emr_on_off'] : 'on';
     101                            $a        = '';
     102                            $b        = '';
    103103
    104104                            foreach ( $emr_active as $option ) {
    105105                                $label = $option['label'];
    106                                 if ( $selected == $option['value'] ) { // Make default first in list.
    107                                     $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    108                                 } else {
    109                                     $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    110                                 }
    111                             }
    112                             echo $p . $r;
     106                                if ( $selected == $option['value'] ) {
     107                                    $a = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     108                                } else {
     109                                    $b .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     110                                }
     111                            }
     112                            echo $a . $b; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped earlier
    113113                            ?>
    114114                        </select>
     
    120120                        <select name="emr_settings[emr_tablets]">
    121121                            <?php
    122                             $selected = $options['emr_tablets'];
    123                             $p        = '';
    124                             $r        = '';
     122                            $selected = isset( $options['emr_tablets'] ) ? $options['emr_tablets'] : 'yes';
     123                            $c        = '';
     124                            $d        = '';
    125125
    126126                            foreach ( $emr_redir_tablets as $option ) {
    127127                                $label = $option['label'];
    128                                 if ( $selected == $option['value'] ) { // Make default first in list.
    129                                     $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    130                                 } else {
    131                                     $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    132                                 }
    133                             }
    134                             echo $p . $r;
     128                                if ( $selected == $option['value'] ) {
     129                                    $c = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     130                                } else {
     131                                    $d .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     132                                }
     133                            }
     134                            echo $c . $d; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped earlier
    135135                            ?>
    136136                        </select>
     
    142142                        <select name="emr_settings[emr_all_select]">
    143143                            <?php
    144                             $selected = $options['emr_all_select'];
    145                             $p        = '';
    146                             $r        = '';
     144                            $selected = isset( $options['emr_all_select'] ) ? $options['emr_all_select'] : 'no';
     145                            $e        = '';
     146                            $f        = '';
    147147
    148148                            foreach ( $emr_redir_all_select as $option ) {
    149149                                $label = $option['label'];
    150                                 if ( $selected == $option['value'] ) { // Make default first in list.
    151                                     $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    152                                 } else {
    153                                     $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    154                                 }
    155                             }
    156                             echo $p . $r;
     150                                if ( $selected == $option['value'] ) {
     151                                    $e = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     152                                } else {
     153                                    $f .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     154                                }
     155                            }
     156                            echo $e . $f; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped earlier
    157157                            ?>
    158158                        </select>
     
    162162                <tr valign="top"><th scope="row"><?php esc_html_e( 'Redirect All Mobile to URL', 'emr-redirect' ); ?></th>
    163163                    <td>
    164                         <input id="emr_settings[emr_redir_all_url]" class="regular-text" type="text" name="emr_settings[emr_redir_all_url]" value="<?php esc_attr_e( $options['emr_redir_all_url'] ); ?>" placeholder="https://google.com" />
     164                        <input id="emr_settings[emr_redir_all_url]" class="regular-text" type="text" name="emr_settings[emr_redir_all_url]" value="<?php echo esc_attr( isset( $options['emr_redir_all_url'] ) ? $options['emr_redir_all_url'] : '' ); ?>" placeholder="https://google.com" />
    165165                        <br><label class="description" for="emr_settings[emr_redir_all_url]"><?php esc_html_e( 'Enter URL to redirect all mobile to ex. http://google.com', 'emr-redirect' ); ?></label>
    166166                    </td>
     
    171171                        <select name="emr_settings[emr_front_page]">
    172172                            <?php
    173                             $selected = $options['emr_front_page'];
    174                             $p        = '';
    175                             $r        = '';
     173                            $selected = isset( $options['emr_front_page'] ) ? $options['emr_front_page'] : 'no';
     174                            $g        = '';
     175                            $h        = '';
    176176
    177177                            foreach ( $emr_redir_front_page as $option ) {
    178178                                $label = $option['label'];
    179                                 if ( $selected == $option['value'] ) { // Make default first in list.
    180                                     $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    181                                 } else {
    182                                     $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
    183                                 }
    184                             }
    185                             echo $p . $r;
     179                                if ( $selected == $option['value'] ) {
     180                                    $g = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     181                                } else {
     182                                    $h .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
     183                                }
     184                            }
     185                            echo $g . $h; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped earlier
    186186                            ?>
    187187                        </select>
     
    191191                <tr valign="top"><th scope="row"><?php esc_html_e( 'Redirect non-static homepage to what URL', 'emr-redirect' ); ?></th>
    192192                    <td>
    193                         <input id="emr_settings[emr_redir_front_url]" class="regular-text" type="text" name="emr_settings[emr_redir_front_url]" value="<?php esc_attr_e( $options['emr_redir_front_url'] ); ?>" placeholder="https://google.com" />
     193                        <input id="emr_settings[emr_redir_front_url]" class="regular-text" type="text" name="emr_settings[emr_redir_front_url]" value="<?php echo esc_attr( isset( $options['emr_redir_front_url'] ) ? $options['emr_redir_front_url'] : '' ); ?>" placeholder="https://google.com" />
    194194                        <br><label class="description" for="emr_settings[emr_redir_front_url]"><?php esc_html_e( 'Enter URL to redirect the non-static homepage to ex. http://google.com', 'emr-redirect' ); ?></label>
    195195                    </td>
  • equivalent-mobile-redirect/trunk/readme.txt

    r2339155 r2448994  
    44Tags: mobile redirect, mobile detect, equivalent, mobile, redirection
    55Requires at least: 3.0
    6 Tested up to: 5.4.2
    7 Stable tag: 4.4
     6Tested up to: 5.6
     7Stable tag: 4.5
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     
    8383== Changelog ==
    8484
     85= 4.5 =
     86* Fix: Better empty check for $mobile_rel_link, $nonstatic_redirect_url, $mobile_all_url variables.
     87* Fix: PHP 7.4 compatibility.
     88* Fix: If no options are saved use default.
     89* Updated: Load files with plugin_dir_path.
     90* Tested: Compatibility with WordPress 5.6
     91
    8592= 4.4 release =
    8693* New: add automatic desktop link rel="alternate" annotations.
Note: See TracChangeset for help on using the changeset viewer.