Changeset 1387440
- Timestamp:
- 04/05/2016 05:35:53 PM (10 years ago)
- Location:
- 404page/trunk
- Files:
-
- 3 edited
-
404page.js (modified) (1 diff)
-
404page.php (modified) (15 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
404page/trunk/404page.js
r1376500 r1387440 10 10 window.location.href = jQuery( '#404page_test_link' ).text(); 11 11 }); 12 jQuery( '#404page_admin_notice ' ).click( function() {12 jQuery( '#404page_admin_notice .notice-dismiss' ).click( function() { 13 13 jQuery.ajax({ 14 14 url: ajaxurl, -
404page/trunk/404page.php
r1376500 r1387440 4 4 Plugin URI: http://smartware.cc/free-wordpress-plugins/404page/ 5 5 Description: Custom 404 the easy way! Set any page as custom 404 error page. No coding needed. Works with (almost) every Theme. 6 Version: 2.1 DEV- 26 Version: 2.1 DEV-3 7 7 Author: smartware.cc, Peter's Plugins 8 8 Author URI: http://smartware.cc … … 26 26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 27 */ 28 29 30 /* As of Version 2.0 the 404page Plugin no longer uses the 404_template filter, because this does not work with WPML, bbPress and Customizr */31 /* The posts_results filter is the only solution that works for all of them */32 28 33 29 if ( ! defined( 'WPINC' ) ) { … … 46 42 $this->plugin_name = '404page'; 47 43 $this->plugin_slug = '404page'; 48 $this->version = '2.1 DEV- 2';44 $this->version = '2.1 DEV-3'; 49 45 $this->get_settings(); 50 46 $this->init(); … … 59 55 $this->settings['404page_method'] = $this->get_404page_method(); 60 56 } 61 57 58 // do plugin init 62 59 private function init() { 63 60 … … 65 62 66 63 if ( !is_admin() ) { 64 65 add_action( 'init', array( $this, 'set_mode' ) ); 66 67 } else { 68 69 add_action( 'admin_init', array( $this, 'admin_init' ) ); 70 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 71 add_action( 'admin_head', array( $this, 'admin_css' ) ); 72 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_settings_link' ) ); 73 74 if ( $this->settings['404page_hide'] and $this->settings['404page_page_id'] > 0 ) { 75 add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page' ) ); 76 } 77 78 if ( 'NOT_DISMISSED' == get_option( '404page_notice_dismissed', 'NOT_DISMISSED' ) ) { 79 add_action( 'admin_notices', array( $this, 'admin_notice' ) ); 80 add_action( 'wp_ajax_nopriv_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) ); 81 add_action( 'wp_ajax_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) ); 82 } 83 } 84 85 } 86 87 // init filters 88 function set_mode() { 89 90 if ( defined( 'CUSTOMIZR_VER' ) ) { 91 92 // Customizr Compatibility Mode 93 94 add_filter( 'tc_404_header_content', array( $this, 'show404title_customizr_mode' ), 999 ); 95 add_filter( 'tc_404_content', array( $this, 'show404_customizr_mode' ), 999 ); 96 add_filter( 'tc_404_selectors', array( $this, 'show404articleselectors_customizr_mode' ), 999 ); 97 98 } else { 99 67 100 if ( $this->settings['404page_method'] != 'STD' ) { 68 add_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 ); 101 102 // Compatibility Mode 103 add_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 ); 104 69 105 } else { 106 107 // Standard Mode 70 108 add_filter( '404_template', array( $this, 'show404_standard_mode' ), 999 ); 71 109 if ( $this->settings['404page_fire_error'] ) { 72 110 add_action( 'template_redirect', array( $this, 'do_404_header_standard_mode' ) ); 73 111 } 74 } 75 } else { 76 add_action( 'admin_init', array( $this, 'admin_init' ) ); 77 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 78 add_action( 'admin_head', array( $this, 'admin_css' ) ); 79 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_settings_link' ) ); 80 if ( $this->settings['404page_hide'] and $this->settings['404page_page_id'] > 0 ) { 81 add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page' ) ); 82 } 83 if ( 'NOT_DISMISSED' == get_option( '404page_notice_dismissed', 'NOT_DISMISSED' ) ) { 84 add_action( 'admin_notices', array( $this, 'admin_notice' ) ); 85 add_action( 'wp_ajax_nopriv_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) ); 86 add_action( 'wp_ajax_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) ); 87 } 88 } 89 90 } 91 92 // redirect 404 page - standard mode 112 113 } 114 } 115 116 } 117 118 // show 404 page - Standard Mode 93 119 function show404_standard_mode( $template ) { 120 94 121 global $wp_query; 95 122 $pageid = $this->settings['404page_page_id']; … … 104 131 } 105 132 return $template; 106 }107 108 // redirect 404 page - compatibility mode - introduced in version 2.0109 // as of v2.1 we do not alter the posts argument here because this does not work with SiteOrigin's Page Builder Plugin, template_include filter introduced133 134 } 135 136 // show 404 page - Compatibility Mode 110 137 function show404_compatiblity_mode( $posts ) { 138 111 139 // remove the filter so we handle only the first query - no custom queries 112 remove_filter( 'posts_results', array( $this, 'show404' ), 999 ); 140 remove_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 ); 141 113 142 $pageid = $this->settings['404page_page_id']; 114 143 if ( 0 != $pageid ) { … … 117 146 118 147 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 148 119 149 // WPML is active 120 150 $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true ); 151 152 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 153 154 // Polylang is active 155 $translatedpageid = pll_get_post( $pageid ); 156 if ( !empty( $translatedpageid ) && 'publish' == get_post_status( $translatedpageid ) ) { 157 $pageid = $translatedpageid; 158 } 121 159 } 160 161 // as of v2.1 we do not alter the posts argument here because this does not work with SiteOrigin's Page Builder Plugin, template_include filter introduced 122 162 $this->postid = $pageid; 123 163 $this->template = get_page_template_slug( $pageid ); … … 135 175 if ( $this->settings['404page_fire_error'] ) { 136 176 $curpageid = $posts[0]->ID; 177 137 178 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 138 // WPML is active - get the post ID of the default language 179 180 // WPML is active - get the post ID of the default language 139 181 global $sitepress; 140 182 $curpageid = apply_filters( 'wpml_object_id', $curpageid, 'page', $sitepress->get_default_language() ); 141 183 $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', $sitepress->get_default_language() ); 184 185 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 186 187 // Polylang is active - get the post ID of the default language 188 $curpageid = pll_get_post( $curpageid, pll_default_language() ); 189 $pageid = pll_get_post( $pageid, pll_default_language() ); 190 142 191 } 192 143 193 if ( $pageid == $curpageid ) { 144 194 add_action( 'wp', array( $this, 'do_404_header' ) ); … … 152 202 } 153 203 154 // send a 404 HTTP header - standard mode204 // send a 404 HTTP header - Standard Mode 155 205 function do_404_header_standard_mode() { 156 206 if ( is_page() && get_the_ID() == $this->settings['404page_page_id'] && !is_404() ) { 157 // we do not have to take care about WPML because WPML only works in compatibility mode158 207 status_header( 404 ); 159 208 nocache_headers(); … … 161 210 } 162 211 163 // send a 404 HTTP header - compatibility mode212 // send a 404 HTTP header - Compatibility Mode 164 213 function do_404_header() { 165 214 // remove the action so we handle only the first query - no custom queries … … 175 224 } 176 225 177 // here the real magic happens... 178 function template_include_404( $template ) { 179 // as of v2.1 we do not alter the posts in show404, because this does not work with SiteOrigin's Page Builder Plugin 180 global $wp_query; 181 $wp_query->posts = array(); 182 $wp_query->posts[] = get_post( $this->postid ); 183 $wp_query->queried_object_id = $this->postid; 184 $wp_query->queried_object = $wp_query->posts[0]; 185 $wp_query->post_count = 1; 186 $wp_query->found_posts = 1; 187 $wp_query->current_post = -1; 188 $wp_query->is_page = true; 189 $wp_query->is_single = false; 190 $wp_query->is_404 = false; 191 if ( $this->template != '' ) { 192 $template = $this->template; 193 } 194 return $template; 226 // show title - Customizr Compatibility Mode 227 function show404title_customizr_mode( $title ) { 228 return '<h1 class="entry-title">' . get_the_title( $this->settings['404page_page_id'] ) . '</h1>'; 229 } 230 231 // show content - Customizr Compatibility Mode 232 function show404_customizr_mode( $content ) { 233 return '<div class="entry-content">' . apply_filters( 'the_content', get_post_field( 'post_content', $this->settings['404page_page_id'] ) ) . '</div>'; 234 } 235 236 // change article selectors - Customizr Compatibility Mode 237 function show404articleselectors_customizr_mode( $selectors ) { 238 return 'id="post-' . $this->settings['404page_page_id'] . '" ' . 'class="' . join( ' ', get_post_class( 'row-fluid', $this->settings['404page_page_id'] ) ) . '"'; 195 239 } 196 240 … … 211 255 // add css 212 256 function admin_css() { 213 echo '<style type="text/css">#select404page" {width: 100%}</style>'; 257 echo '<style type="text/css">#select404page {width: 100%; }'; 258 if ( $this->settings['404page_page_id'] > 0 ) { 259 echo ' #the-list #post-' . $this->settings['404page_page_id'] . ' .column-title {min-height: 32px; background-position: left top; background-repeat: no-repeat; background-image: url(' . plugins_url( 'pluginicon.png', __FILE__ ) . '); padding-left: 40px;}'; 260 } 261 echo '</style>'; 214 262 } 215 263 … … 242 290 // handle the settings field method 243 291 function admin_method() { 244 echo '<p><input type="radio" id="404page_settings_method_standard" name="404page_method" value="STD"' . checked( 'STD', $this->settings['404page_method'], false ) . '/>'; 292 if ( defined( 'CUSTOMIZR_VER' ) || defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'POLYLANG_VERSION' ) || defined( 'SITEORIGIN_PANELS_VERSION' ) || class_exists( 'bbPress' ) ) { 293 $dis = ' disabled="disabled"'; 294 } else { 295 $dis = ''; 296 } 297 echo '<p><input type="radio" id="404page_settings_method_standard" name="404page_method" value="STD"' . checked( 'STD', $this->settings['404page_method'], false ) . $dis . ' />'; 245 298 echo '<label for="404page_settings_method_standard">' . __( 'Standard Mode', '404page' ) . '</label></p>'; 246 299 247 echo '<p><input type="radio" id="404page_settings_method_compatibility" name="404page_method" value="CMP"' . checked( 'CMP', $this->settings['404page_method'], false ) . '/>';300 echo '<p><input type="radio" id="404page_settings_method_compatibility" name="404page_method" value="CMP"' . checked( 'CMP', $this->settings['404page_method'], false ) . $dis . '/>'; 248 301 echo '<label for="404page_settings_method_compatibility">' . __( 'Compatibility Mode', '404page' ) . '</label></p>'; 249 302 250 echo '<p><span class="dashicons dashicons-info"></span> ' . __( 'Standard Mode uses the WordPress Template System and should work in most cases. If the 404page plugin does not work properly, probably you are using a theme or plugin that modifies the WordPress Template System. In this case the Compatibility Mode maybe can fix the problem, although it cannot be guaranteed that every possible configuration can be handled by Compatibility Mode. Standard Mode is the recommended method, only switch to Compatibility Mode if you have any problems.', '404page' ) . '</p>'; 303 if ( defined( 'CUSTOMIZR_VER' ) ) { 304 echo '<p><span class="dashicons dashicons-warning"></span> ' . __( 'Customizr Theme detected. The 404page Plugin works in Customizr Compatibility Mode.', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>'; 305 } elseif ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 306 echo '<p><span class="dashicons dashicons-warning"></span> ' . __( 'WPML Plugin detected. Operating Method set to Compatibility Mode automatically.', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>'; 307 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 308 echo '<p><span class="dashicons dashicons-warning"></span> ' . __( 'Polylang Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>'; 309 } elseif ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) { 310 echo '<p><span class="dashicons dashicons-warning"></span> ' . __( 'Page Builder by SiteOrigin Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>'; 311 } elseif ( class_exists( 'bbPress' ) ) { 312 echo '<p><span class="dashicons dashicons-warning"></span> ' . __( 'bbPress Plugin detected. Operating Method set to Compatibility Mode automatically', '404page' ) . ' (<a href="#">' . __( 'Read more', '404page' ) . '</a>)</p>'; 313 } else { 314 echo '<p><span class="dashicons dashicons-info"></span> ' . __( 'Standard Mode uses the WordPress Template System and should work in most cases. If the 404page plugin does not work properly, probably you are using a theme or plugin that modifies the WordPress Template System. In this case the Compatibility Mode maybe can fix the problem, although it cannot be guaranteed that every possible configuration can be handled by Compatibility Mode. Standard Mode is the recommended method, only switch to Compatibility Mode if you have any problems.', '404page' ) . '</p>'; 315 } 251 316 } 252 317 … … 312 377 if ( current_user_can( 'manage_options' ) ) { 313 378 echo '<div class="notice notice-info is-dismissible" id="404page_admin_notice"><p><strong>404page Plugin:</strong> '; 314 _e( 'Please check Operating Method in <a href="' . admin_url( 'themes.php?page=404pagesettings' ) . '">' . __( 'Settings', '404page' ) . '</a>', '404page' ); 379 if ( defined( 'CUSTOMIZR_VER' ) ) { 380 // Customizr Theme 381 _e( 'Customizr Theme detected. The 404page Plugin works in Customizr Compatibility Mode.', '404page' ); 382 } elseif ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 383 // WPML 384 _e( 'WPML Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with WPML.', '404page' ); 385 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 386 // Polylang 387 _e( 'Polylang Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with Polylang.', '404page' ); 388 } elseif ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) { 389 // Page Builder by SiteOrigin 390 _e( 'Page Builder by SiteOrigin Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with Page Builder by SiteOrigin.', '404page' ); 391 } elseif ( class_exists( 'bbPress' ) ) { 392 // bbPress 393 _e( 'bbPress Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with bbPress.', '404page' ); 394 } else { 395 _e( 'Please check Operating Method.', '404page' ); 396 } 397 echo '<br /><a href="' . admin_url( 'themes.php?page=404pagesettings' ) . '">' . __( 'Settings', '404page' ) . '</a>'; 315 398 echo '</p></div>'; 316 399 } … … 352 435 // returns the selected method 353 436 private function get_404page_method() { 354 return get_option( '404page_method', 'STD' ); 437 if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'POLYLANG_VERSION' ) || defined( 'SITEORIGIN_PANELS_VERSION' ) || class_exists( 'bbPress' ) ) { 438 // WPML or bbPress is active 439 return 'CMP'; 440 } else { 441 return get_option( '404page_method', 'STD' ); 442 } 355 443 } 356 444 -
404page/trunk/readme.txt
r1366885 r1387440 17 17 **See also [Plugin Homepage](http://smartware.cc/free-wordpress-plugins/404page/) and [Plugin Doc](http://smartware.cc/docs/404page/)** 18 18 19 = Version 2.0 Update Notice = 20 * The settings page was moved from 'Settings' to 'Appearance' menu. 21 * Version 2.0 is more or less a completely new development. This was necessary to solve several compatibility issues. 404page now works with the [WPML WordPress Multilingual Plugin](https://wpml.org/), the [bbPress Forum Plugin](https://wordpress.org/plugins/bbpress/) and the [Customizr Theme](https://wordpress.org/themes/customizr/). [Read more](http://smartware.cc/blog/2016/02/23/the-404page-plugin-now-works-with-wpml-and-other-enhancements/). 19 = Version 2.1 Update Notice = 20 Please take a look at the [release notes](LINK). 22 21 23 22 https://www.youtube.com/watch?v=VTL07Lf0IsY … … 80 79 == Changelog == 81 80 81 = 2.1 (2016-04-XX) = 82 * introduction of selectable Operating Methods 83 * several changes to Compatibility Mode for improved WPML and bbPress compatibility plus compatibility with Page Builder by SiteOrigin 84 * Polylang compatibility 85 * automatic switch to Compatibility Mode if WPML, bbPress, Polylang or Page Builder by SiteOrigin is detected 86 * completely new Customizr (automatically enabled if Customizr is detected) 87 * firing an 404 error in case of directly accessing the 404 error page can now be deactivated 88 * option to hide the 404 error page from the Pages list 89 * 404 error test 90 82 91 = 2.0 (2016-03-08) = 83 92 * WPML compatibility
Note: See TracChangeset
for help on using the changeset viewer.