Changeset 2448994
- Timestamp:
- 01/02/2021 02:29:52 AM (5 years ago)
- Location:
- equivalent-mobile-redirect/trunk
- Files:
-
- 7 added
- 4 edited
-
.gitattributes (added)
-
.gitignore (added)
-
.vscode (added)
-
.vscode/settings.json (added)
-
composer.json (added)
-
composer.lock (added)
-
equivalent-mobile-redirect.php (modified) (2 diffs)
-
includes/class-emr.php (modified) (5 diffs)
-
includes/emr-options.php (modified) (6 diffs)
-
phpcs.xml (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
equivalent-mobile-redirect/trunk/equivalent-mobile-redirect.php
r2339155 r2448994 1 1 <?php 2 /* 3 Plugin Name: Equivalent Mobile Redirect4 Description: Detect and redirect mobile visitors to the equivalent page on your mobile site.5 Version: 4.4 6 Text Domain: emr-redirect7 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 */ 13 13 14 14 // Exit if accessed directly. … … 16 16 17 17 // Admin panel. 18 require_once 'includes/emr-options.php';18 require_once plugin_dir_path( __FILE__ ) . 'includes/emr-options.php'; 19 19 20 20 // Equivalent mobile redirect class. 21 require_once 'includes/class-emr.php';21 require_once plugin_dir_path( __FILE__ ) . 'includes/class-emr.php'; -
equivalent-mobile-redirect/trunk/includes/class-emr.php
r2339155 r2448994 10 10 * @const string 11 11 */ 12 const VERSION = '4. 4';12 const VERSION = '4.5'; 13 13 14 14 /** … … 238 238 if ( empty( $full_site_cookie ) ) { 239 239 if ( ! class_exists( 'Mobile_Detect' ) ) { 240 require_once __DIR__ . '/Mobile_Detect.php';240 require_once plugin_dir_path( __FILE__ ) . 'Mobile_Detect.php'; 241 241 } 242 242 $detect = new Mobile_Detect(); 243 243 // EMR option page settings. 244 244 $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'] : ''; 256 256 257 257 if ( $detect->isMobile() && $mobile_to_one_url == 'yes' ) { 258 258 if ( $detect->isTablet() && $tablets_redirect == 'no' ) { 259 259 $detect = 'false'; 260 } elseif ( $mobile_all_url != '') {260 } elseif ( ! empty( $mobile_all_url ) ) { 261 261 // Redirect all and quit. 262 262 wp_redirect( $mobile_all_url, 302 ); … … 266 266 if ( $detect->isTablet() && $tablets_redirect == 'no' ) { 267 267 $detect = 'false'; 268 } elseif ( $nonstatic_redirect_url != '') {268 } elseif ( ! empty( $nonstatic_redirect_url ) ) { 269 269 wp_redirect( $nonstatic_redirect_url, 302 ); 270 270 exit; … … 301 301 // Get options. 302 302 $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'] : ''; 308 308 309 309 // 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; 315 313 } 316 314 … … 322 320 } elseif ( ( is_page() || is_single() || is_front_page() ) && ( isset( $this->post_types[ (string) get_post_type( $post ) ] ) ) ) { 323 321 $data = $this->get_post_data( $post->ID ); 324 $mobile_rel_link = $data['url'];322 $mobile_rel_link = isset( $data['url'] ) ? $data['url'] : ''; 325 323 } 326 324 327 325 // Check to make sure mobile link isn't blank before continuing. 328 if ( $mobile_rel_link == '')326 if ( empty( $mobile_rel_link ) ) 329 327 return; 330 328 -
equivalent-mobile-redirect/trunk/includes/emr-options.php
r2339155 r2448994 98 98 <select name="emr_settings[emr_on_off]"> 99 99 <?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 = ''; 103 103 104 104 foreach ( $emr_active as $option ) { 105 105 $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 113 113 ?> 114 114 </select> … … 120 120 <select name="emr_settings[emr_tablets]"> 121 121 <?php 122 $selected = $options['emr_tablets'];123 $ p= '';124 $ r= '';122 $selected = isset( $options['emr_tablets'] ) ? $options['emr_tablets'] : 'yes'; 123 $c = ''; 124 $d = ''; 125 125 126 126 foreach ( $emr_redir_tablets as $option ) { 127 127 $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 135 135 ?> 136 136 </select> … … 142 142 <select name="emr_settings[emr_all_select]"> 143 143 <?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 = ''; 147 147 148 148 foreach ( $emr_redir_all_select as $option ) { 149 149 $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 157 157 ?> 158 158 </select> … … 162 162 <tr valign="top"><th scope="row"><?php esc_html_e( 'Redirect All Mobile to URL', 'emr-redirect' ); ?></th> 163 163 <td> 164 <input id="emr_settings[emr_redir_all_url]" class="regular-text" type="text" name="emr_settings[emr_redir_all_url]" value="<?php e sc_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" /> 165 165 <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> 166 166 </td> … … 171 171 <select name="emr_settings[emr_front_page]"> 172 172 <?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 = ''; 176 176 177 177 foreach ( $emr_redir_front_page as $option ) { 178 178 $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 186 186 ?> 187 187 </select> … … 191 191 <tr valign="top"><th scope="row"><?php esc_html_e( 'Redirect non-static homepage to what URL', 'emr-redirect' ); ?></th> 192 192 <td> 193 <input id="emr_settings[emr_redir_front_url]" class="regular-text" type="text" name="emr_settings[emr_redir_front_url]" value="<?php e sc_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" /> 194 194 <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> 195 195 </td> -
equivalent-mobile-redirect/trunk/readme.txt
r2339155 r2448994 4 4 Tags: mobile redirect, mobile detect, equivalent, mobile, redirection 5 5 Requires at least: 3.0 6 Tested up to: 5. 4.27 Stable tag: 4. 46 Tested up to: 5.6 7 Stable tag: 4.5 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.txt … … 83 83 == Changelog == 84 84 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 85 92 = 4.4 release = 86 93 * New: add automatic desktop link rel="alternate" annotations.
Note: See TracChangeset
for help on using the changeset viewer.