WordPress.org

Plugin Directory

Changeset 1576681


Ignore:
Timestamp:
01/17/17 16:51:54 (8 months ago)
Author:
petersplugins
Message:

v 2.4 DEV

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 404page/trunk/404page.php

    r1537304 r1576681  
    44Plugin URI: http://petersplugins.com/free-wordpress-plugins/404page/ 
    55Description: Custom 404 the easy way! Set any page as custom 404 error page. No coding needed. Works with (almost) every Theme. 
    6 Version: 2.3 
     6Version: 2.4 DEV 
    77Author: Peter's Plugins, smartware.cc 
    88Author URI: http://petersplugins.com 
     
    351351        $pageid = $this->settings['404page_page_id']; 
    352352         
     353        // as of v 2.4 we hide all translations in admin 
    353354        if ( ! is_admin() ) { 
    354           $pageid = $this->get_page_id( $pageid ); 
     355          $pageid = array( $this->get_page_id( $pageid ) ); 
     356        } else { 
     357          $pageid = $this->get_page_id( $pageid, true ); 
    355358        } 
    356359         
    357360        // as of v 2.3 we add the ID of the 404 page to post__not_in 
    358361        // using just $query->set() overrides existing settings but not adds a new setting 
    359         $query->set( 'post__not_in', array_merge( (array)$query->get( 'post__not_in', array() ), array( $pageid ) ) ); 
     362        $query->set( 'post__not_in', array_merge( (array)$query->get( 'post__not_in', array() ), $pageid ) ); 
    360363         
    361364      } 
     
    458461   
    459462  // this function gets the id of the translated page if WPML or Polylang is active - otherwise the original pageid is returned 
    460   private function get_page_id( $pageid ) { 
     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 ) { 
    461466     
    462467    if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 
    463468           
    464469      // WPML is active 
    465       $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true ); 
     470       
     471      if ( $all ) { 
     472        // get an array for all translations 
     473        $pages = array( $pageid ); 
     474        $languages = apply_filters( 'wpml_active_languages', NULL ); 
     475        if ( !empty( $languages ) ) { 
     476          foreach( $languages as $l ) { 
     477            $p = apply_filters( 'wpml_object_id', $pageid, 'page', false, $l['language_code'] );  
     478            if ( $p ) { 
     479              $pages[] = $p; 
     480            } 
     481          } 
     482        } 
     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      } 
    466489       
    467490    } elseif ( defined( 'POLYLANG_VERSION' ) ) { 
Note: See TracChangeset for help on using the changeset viewer.