Changeset 1577075
- Timestamp:
- 01/18/2017 07:41:34 AM (9 years ago)
- File:
-
- 1 edited
-
404page/trunk/404page.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
404page/trunk/404page.php
r1576681 r1577075 112 112 113 113 global $wp_query; 114 $pageid = $this-> settings['404page_page_id'];114 $pageid = $this->get_page_id(); 115 115 if ( $pageid > 0 ) { 116 116 if ( ! $this->settings['404page_native'] ) { … … 135 135 remove_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 ); 136 136 137 $pageid = $this-> settings['404page_page_id'];137 $pageid = $this->get_page_id(); 138 138 if ( $pageid > 0 && ! $this->settings['404page_native'] ) { 139 139 if ( empty( $posts ) && is_main_query() && !is_robots() && !is_home() && !is_feed() && !is_search() && !is_archive() && ( !defined('DOING_AJAX') || !DOING_AJAX ) ) { 140 // we need to get the 404 page141 142 $pageid = $this->get_page_id( $pageid );143 140 144 141 // 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 … … 227 224 function show404title_customizr_mode( $title ) { 228 225 if ( ! $this->settings['404page_native'] ) { 229 return '<h1 class="entry-title">' . get_the_title( $this-> settings['404page_page_id']) . '</h1>';226 return '<h1 class="entry-title">' . get_the_title( $this->get_page_id() ) . '</h1>'; 230 227 } else { 231 228 return $title; … … 236 233 function show404_customizr_mode( $content ) { 237 234 if ( ! $this->settings['404page_native'] ) { 238 return '<div class="entry-content">' . apply_filters( 'the_content', get_post_field( 'post_content', $this-> settings['404page_page_id']) ) . '</div>';235 return '<div class="entry-content">' . apply_filters( 'the_content', get_post_field( 'post_content', $this->get_page_id() ) ) . '</div>'; 239 236 } else { 240 237 return $content; … … 246 243 function show404articleselectors_customizr_mode( $selectors ) { 247 244 if ( ! $this->settings['404page_native'] ) { 248 return 'id="post-' . $this-> settings['404page_page_id'] . '" ' . 'class="' . join( ' ', get_post_class( 'row-fluid', $this->settings['404page_page_id']) ) . '"';245 return 'id="post-' . $this->get_page_id() . '" ' . 'class="' . join( ' ', get_post_class( 'row-fluid', $this->get_page_id() ) ) . '"'; 249 246 } else { 250 247 return $selectors; … … 273 270 echo '<style type="text/css">#select404page {width: 100%; }'; 274 271 if ( $this->settings['404page_page_id'] > 0 ) { 275 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;}'; 272 foreach ( $this->get_all_page_ids() as $pid ) { 273 echo ' #the-list #post-' . $pid . ' .column-title .row-title:before { content: "404"; background-color: #333; color: #FFF; display: inline-block; padding: 0 5px; margin-right: 10px; }'; 274 } 276 275 } 277 276 echo '</style>'; … … 322 321 echo '<p><span class="dashicons dashicons-info"></span> ' . __( 'This setting is not availbe because the 404page Plugin works in WPML Mode.', '404page' ) . ' (<a href="' . $this->dc_url . '/#special_modes">' . __( 'Read more', '404page' ) . '</a>)</p>'; 323 322 324 } elseif ( defined( ' POLYLANG_VERSION' ) ) {323 } elseif ( defined( 'xxxPOLYLANG_VERSION' ) ) { 325 324 326 325 echo '<p><span class="dashicons dashicons-info"></span> ' . __( 'This setting is not availbe because the 404page Plugin works in Polylang Mode.', '404page' ) . ' (<a href="' . $this->dc_url . '/#special_modes">' . __( 'Read more', '404page' ) . '</a>)</p>'; … … 342 341 // this function hides the selected page from the list of pages 343 342 function exclude_404page( $query ) { 344 if ( $this->settings['404page_page_id'] > 0 ) { 343 $pageid = $this->get_page_id(); 344 if ( $pageid > 0 ) { 345 345 global $pagenow; 346 346 … … 349 349 // as of v 2.3 we check the post_type on front end 350 350 if( ( is_admin() && ( 'edit.php' == $pagenow && !current_user_can( 'create_users' ) ) ) || ( ! is_admin() && ( !empty( $post_type) && ( ('page' === $post_type || 'any' === $post_type) || ( is_array( $post_type ) && in_array( 'page', $post_type ) ) ) )) ) { 351 $pageid = $this->settings['404page_page_id']; 352 353 // as of v 2.4 we hide all translations in admin 354 if ( ! is_admin() ) { 355 $pageid = array( $this->get_page_id( $pageid ) ); 351 352 // as of v 2.4 we hide all translations in admin for WPML 353 if ( is_admin() ) { 354 $pageids = $this->get_all_page_ids(); 356 355 } else { 357 $pageid = $this->get_page_id( $pageid, true);356 $pageids = array( $pageid ); 358 357 } 359 358 360 359 // as of v 2.3 we add the ID of the 404 page to post__not_in 361 360 // using just $query->set() overrides existing settings but not adds a new setting 362 $query->set( 'post__not_in', array_merge( (array)$query->get( 'post__not_in', array() ), $pageid ) );361 $query->set( 'post__not_in', array_merge( (array)$query->get( 'post__not_in', array() ), $pageids ) ); 363 362 364 363 } … … 368 367 // this function removes the 404 page from get_pages result array 369 368 function remove_404page_from_array( $pages, $r ) { 370 if ( $this->settings['404page_page_id'] > 0 ) {371 $pageid = $this->get_page_id( $this->settings['404page_page_id'] );369 $pageid = $this->get_page_id(); 370 if ( $pageid > 0 ) { 372 371 for ( $i = 0; $i < sizeof( $pages ); $i++ ) { 373 372 if ( $pages[$i]->ID == $pageid ) { … … 442 441 // returns the selected method 443 442 private function get_404page_method() { 444 if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( ' POLYLANG_VERSION' ) ) {443 if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'xxxPOLYLANG_VERSION' ) ) { 445 444 // WPML or Polylang is active 446 445 return 'CMP'; … … 460 459 } 461 460 462 // this function gets the id of the translated page if WPML or Polylang is active - otherwise the original pageid is returned 463 // parameter $all was added in v 2.4 464 // if $all is set to true the function returns an array of ids 465 private function get_page_id( $pageid, $all = false ) { 461 // as of version 2.4 this function returns the page id of the 404 page in the current language 462 // in previous versions this functions required a parameter and only did the translation if WPML or Polylang is active 463 // now we have all in one function 464 private function get_page_id() { 465 466 $pageid = $this->settings['404page_page_id']; 467 468 if ( $pageid > 0 ) { 469 470 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 471 472 // WPML is active 473 $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true ); 474 475 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 476 477 // Polylang is active 478 $translatedpageid = pll_get_post( $pageid ); 479 if ( !empty( $translatedpageid ) && 'publish' == get_post_status( $translatedpageid ) ) { 480 $pageid = $translatedpageid; 481 } 482 } 483 484 } 485 486 return $pageid; 487 488 } 489 490 // if WPML is active this function returns an array of all page ids in all available languages 491 // otherwise it returns the page id as array 492 // introduced in v 2.4 493 private function get_all_page_ids() { 466 494 467 495 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 468 496 469 497 // WPML is active 470 471 if ( $all ) { 472 // get an array for all translations 473 $pages = array( $pageid ); 498 // get an array for all translations 499 500 $pageid = $this->settings['404page_page_id']; 501 $pages = array( $pageid ); 502 if ( $pageid > 0 ) { 474 503 $languages = apply_filters( 'wpml_active_languages', NULL ); 475 504 if ( !empty( $languages ) ) { … … 481 510 } 482 511 } 483 $pageid = array_unique( $pages, SORT_NUMERIC ); 484 485 } else { 486 // get the id of the translated page for the current language 487 $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true ); 488 } 489 490 } elseif ( defined( 'POLYLANG_VERSION' ) ) { 491 492 // Polylang is active 493 $translatedpageid = pll_get_post( $pageid ); 494 if ( !empty( $translatedpageid ) && 'publish' == get_post_status( $translatedpageid ) ) { 495 $pageid = $translatedpageid; 496 } 497 498 } 499 500 return $pageid; 512 } 513 $pageids = array_unique( $pages, SORT_NUMERIC ); 514 515 } else { 516 517 $pageids = array( $this->get_page_id() ); 518 519 } 520 521 return $pageids; 501 522 502 523 } … … 598 619 $title = ''; 599 620 if ( $this->settings['404page_page_id'] > 0 && $this->settings['404page_native'] ) { 600 $title = get_the_title( $this-> settings['404page_page_id']);621 $title = get_the_title( $this->get_page_id() ); 601 622 } 602 623 return $title; … … 612 633 $content = ''; 613 634 if ( $this->settings['404page_page_id'] > 0 && $this->settings['404page_native'] ) { 614 $content = apply_filters( 'the_content', get_post_field( 'post_content', $this-> settings['404page_page_id']) );635 $content = apply_filters( 'the_content', get_post_field( 'post_content', $this->get_page_id() ) ); 615 636 } 616 637 return $content;
Note: See TracChangeset
for help on using the changeset viewer.