Changeset 3161639
- Timestamp:
- 10/02/2024 05:48:35 PM (15 months ago)
- Location:
- 404page/trunk
- Files:
-
- 6 edited
-
404page.php (modified) (1 diff)
-
block.php (modified) (2 diffs)
-
functions.php (modified) (9 diffs)
-
inc/class-404page.php (modified) (45 diffs)
-
loader.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
404page/trunk/404page.php
r3152985 r3161639 3 3 * Plugin Name: Smart Custom 404 Error Page 4 4 * Description: Custom 404 the easy way! Set any page as a custom 404 error page -- no coding needed. <a href="https://www.nerdpress.net/announcing-404-page/">Now managed by NerdPress!</a> 5 * Version: 11.4. 75 * Version: 11.4.8 6 6 * Requires at least: 4.0 7 7 * Requires PHP: 5.4 -
404page/trunk/block.php
r3152985 r3161639 7 7 * 8 8 **/ 9 9 10 10 if ( ! defined( 'ABSPATH' ) ) { 11 11 exit; // Exit if accessed directly … … 13 13 14 14 add_action( 'init', function() { 15 15 16 16 if ( function_exists('register_block_type_from_metadata' ) ) { 17 17 18 18 register_block_type_from_metadata( __DIR__, [ 19 19 'render_callback' => function( $atts ) { -
404page/trunk/functions.php
r3152985 r3161639 7 7 * 8 8 **/ 9 9 10 10 if ( ! defined( 'ABSPATH' ) ) { 11 11 exit; // Exit if accessed directly 12 12 } 13 13 14 14 15 15 // this function can be used by a theme to check if there's an active custom 404 page 16 16 function pp_404_is_active() { 17 17 18 18 return pp_404page()->pp_404_is_active(); 19 19 20 20 } 21 21 … … 23 23 // this function can be used by a theme to activate native support 24 24 function pp_404_set_native_support() { 25 25 26 26 pp_404page()->pp_404_set_native_support(); 27 27 28 28 } 29 29 … … 31 31 // this function can be used by a theme to get the title of the custom 404 page in native support 32 32 function pp_404_get_the_title() { 33 33 34 34 return pp_404page()->pp_404_get_the_title(); 35 35 36 36 } 37 37 … … 39 39 // this function can be used by a theme to print out the title of the custom 404 page in native support 40 40 function pp_404_the_title() { 41 41 42 42 pp_404page()->pp_404_the_title(); 43 43 44 44 } 45 45 … … 47 47 // this function can be used by a theme to get the content of the custom 404 page in native support 48 48 function pp_404_get_the_content() { 49 49 50 50 return pp_404page()->pp_404_get_the_content(); 51 51 52 52 } 53 53 … … 55 55 // this function can be used by a theme to print out the content of the custom 404 page in native support 56 56 function pp_404_the_content() { 57 57 58 58 return pp_404page()->pp_404_the_content(); 59 59 60 60 } 61 61 … … 63 63 // this function returns the page id of the selected 404 page - in a multilingual environment this returs the id of the page in the current language 64 64 function pp_404_get_page_id() { 65 65 66 66 return pp_404page()->get_page_id(); 67 67 68 68 } 69 69 … … 71 71 // this function returns an array of page ids in all languages 72 72 function pp_404_get_all_page_ids() { 73 73 74 74 return pp_404page()->get_all_page_ids(); 75 75 76 76 } 77 77 … … 84 84 * @param string $type 85 85 * @return string 86 */ 86 */ 87 87 function pp_404_get_the_url( $type ) { 88 88 89 89 $url = ''; 90 90 91 91 if ( is_array( $type ) ) { 92 92 93 93 $type = $type[0]; 94 94 95 95 } 96 96 97 97 if ( 'page' == $type ) { 98 98 99 99 $url = trim( pp_404page()->get_404_url( 'path' ), '/' ); 100 100 101 101 } elseif ( 'domainpath' == $type ) { 102 102 103 103 $url = pp_404page()->get_404_url( 'host' ) . pp_404page()->get_404_url( 'path' ); 104 104 105 105 } else { 106 106 107 107 $url = pp_404page()->get_404_url( 'full' ); 108 108 109 109 } 110 111 112 return $url;113 110 111 112 return esc_url( $url ); 113 114 114 } -
404page/trunk/inc/class-404page.php
r3152985 r3161639 20 20 */ 21 21 if ( !class_exists( 'PP_404Page' ) ) { 22 23 22 23 24 24 class PP_404Page extends PPF09_Plugin { 25 26 25 26 27 27 /** 28 28 * Native Mode … … 33 33 */ 34 34 private $native; 35 35 36 36 private $template; 37 37 private $postid; 38 39 38 39 40 40 /** 41 41 * Admin Class … … 47 47 */ 48 48 private $admin; 49 50 49 50 51 51 /** 52 52 * Block Editor Class … … 58 58 */ 59 59 private $blockeditor; 60 61 60 61 62 62 /** 63 63 * Classic Editor Class … … 69 69 */ 70 70 private $classiceditor; 71 72 71 72 73 73 /** 74 74 * Deprecated Class … … 80 80 */ 81 81 private $deprecated; 82 83 82 83 84 84 /** 85 85 * URL that caused the 404 error … … 90 90 */ 91 91 private $error_url; 92 93 94 /** 95 * Init the Class 92 93 94 /** 95 * Init the Class 96 96 * 97 97 * @since 11.0.0 … … 99 99 */ 100 100 public function plugin_init() { 101 101 102 102 // settings defaults 103 103 // @since 11.0.0 … … 112 112 'method' => 'STD' 113 113 ); 114 114 115 115 // since 11.0.0 we use add_settings_class() to load the settings 116 116 $this->add_settings_class( 'PP_404Page_Settings', 'class-404page-settings', $this, $defaults ); 117 117 118 118 // @since 11.0.0 119 119 $this->add_action( 'init' ); 120 } 121 122 123 /** 124 * do plugin init 120 } 121 122 123 /** 124 * do plugin init 125 125 * this runs after init action has fired to ensure everything is loaded properly 126 126 * was init() before 11.0.0 127 127 */ 128 128 function action_init() { 129 129 130 130 // moved from add_text_domain() in v 11.0.0 131 131 load_plugin_textdomain( '404page' ); 132 133 132 133 134 134 // change old stuff to new stuff for backward compatibility 135 135 // since v 11.0.0 136 136 $this->deprecated = $this->add_sub_class_always( 'PP_404Page_Deprecated', 'class-404page-deprecated', $this ); 137 137 138 138 // load the following subclasses only on backend 139 // using add_sub_class_backend() sinde v 11 139 // using add_sub_class_backend() sinde v 11 140 140 $this->admin = $this->add_sub_class_backend( 'PP_404Page_Admin', 'class-404page-admin', $this, $this->settings() ); 141 141 $this->blockeditor = $this->add_sub_class_backend( 'PP_404Page_BlockEditor', 'class-404page-block-editor', $this, $this->settings() ); 142 142 $this->classiceditor = $this->add_sub_class_backend( 'PP_404Page_ClassicEditor', 'class-404page-classic-editor', $this, $this->settings() ); 143 143 144 144 // as of v 2.2 always call set_mode 145 145 // as of v 2.4 we do not need to add an init action hook 146 146 147 147 if ( !is_admin() && $this->settings()->get( 'page_id' ) > 0 ) { 148 148 149 149 // as of v 3.0 we once check if there's a 404 page set and not in all functions separately 150 150 $this->set_mode(); 151 151 add_action( 'pre_get_posts', array ( $this, 'exclude_404page' ) ); 152 152 add_filter( 'get_pages', array ( $this, 'remove_404page_from_array' ), 10, 2 ); 153 153 154 154 // Stop URL guessing if activated 155 155 if ( $this->settings()->get( 'no_url_guessing' ) ) { 156 156 add_filter( 'redirect_canonical' ,array ( $this, 'no_url_guessing' ) ); 157 157 } 158 159 158 159 160 160 // Remove 404 error page from XML sitemaps 161 161 // only if "Send an 404 error if the page is accessed directly by its URL" is active 162 162 if ( $this->settings()->get( 'fire_error' ) ) { 163 163 164 164 // YOAST sitemap 165 165 // @since 6 166 166 167 167 // we do not need to check if Yoast Sitemap feature is activated because the filter only fires if it is active 168 168 add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function ( $alreadyExcluded ) { … … 171 171 return array_merge( $alreadyExcluded, $this->get_all_page_ids() ); 172 172 }, 999 ); 173 174 173 174 175 175 // Jetpack sitemap 176 176 // @since 11.1.2 177 177 178 178 // we do not need to check if Jetpack Sitemap feature is activated because the filter only fires if it is active 179 179 add_filter( 'jetpack_sitemap_skip_post', function ( $skip, $post ) { … … 183 183 return $skip; 184 184 }, 999, 2 ); 185 186 } 187 188 } 189 190 185 186 } 187 188 } 189 190 191 191 if ( class_exists( 'PP_404Page_Admin' ) ) { 192 192 193 193 // load classes only if in admin 194 194 // @since 10 195 195 // using class_exists( 'PP_404Page_Admin' ) instead of is_admin() as of v 10.3 for compatibilty with iThemes Sync 196 196 197 197 //$this->admin = new PP_404Page_Admin( $this, $this->settings ); 198 198 //$this->blockeditor = new PP_404Page_BlockEditor( $this ); 199 199 //$this->classiceditor = new PP_404Page_ClassicEditor( $this ); 200 200 201 201 // Remove 404 page from post list if activated 202 202 // not moved to PP_404Page_Admin because we also need exclude_404page() in frontend … … 204 204 add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page' ) ); 205 205 } 206 207 } 208 209 } 210 211 212 /** 213 * init filters 206 207 } 208 209 } 210 211 212 /** 213 * init filters 214 214 */ 215 215 function set_mode() { 216 216 217 217 $this->settings()->set_method(); 218 218 219 219 if ( defined( 'CUSTOMIZR_VER' ) ) { 220 221 // Customizr Compatibility Mode 220 221 // Customizr Compatibility Mode 222 222 223 223 // @since 3.1 224 224 add_filter( 'body_class', array( $this, 'add_404_body_class_customizr_mode' ) ); 225 225 226 226 add_filter( 'tc_404_header_content', array( $this, 'show404title_customizr_mode' ), 999 ); 227 227 add_filter( 'tc_404_content', array( $this, 'show404_customizr_mode' ), 999 ); 228 228 add_filter( 'tc_404_selectors', array( $this, 'show404articleselectors_customizr_mode' ), 999 ); 229 229 230 230 // send http 410 instead of http 404 if requested resource is in trash 231 231 // @since 3.2 … … 233 233 // @since 11.3.0 234 234 if ( $this->settings()->get( 'http410_if_trashed' ) || $this->settings()->get( 'http410_always' ) ) { 235