Plugin Directory

Changeset 1577075


Ignore:
Timestamp:
01/18/2017 07:41:34 AM (9 years ago)
Author:
smartware.cc
Message:

v 2.4 DEV current test version

File:
1 edited

Legend:

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

    r1576681 r1577075  
    112112   
    113113    global $wp_query;
    114     $pageid = $this->settings['404page_page_id'];
     114    $pageid = $this->get_page_id();
    115115    if ( $pageid > 0 ) {
    116116      if ( ! $this->settings['404page_native'] ) {
     
    135135    remove_filter( 'posts_results', array( $this, 'show404_compatiblity_mode' ), 999 );
    136136   
    137     $pageid = $this->settings['404page_page_id'];
     137    $pageid = $this->get_page_id();
    138138    if ( $pageid > 0 && ! $this->settings['404page_native'] ) {
    139139      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 page
    141        
    142         $pageid = $this->get_page_id( $pageid );
    143140       
    144141        // 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
     
    227224  function show404title_customizr_mode( $title ) {
    228225    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>';
    230227    } else {
    231228      return $title;
     
    236233  function show404_customizr_mode( $content ) {
    237234    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>';
    239236    } else {
    240237      return $content;
     
    246243  function show404articleselectors_customizr_mode( $selectors ) {
    247244    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() ) ) . '"';
    249246    } else {
    250247      return $selectors;
     
    273270    echo '<style type="text/css">#select404page {width: 100%; }';
    274271    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      }
    276275    }
    277276    echo '</style>';
     
    322321      echo '<p><span class="dashicons dashicons-info"></span>&nbsp;' . __( '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>';
    323322     
    324     } elseif ( defined( 'POLYLANG_VERSION' ) ) {
     323    } elseif ( defined( 'xxxPOLYLANG_VERSION' ) ) {
    325324   
    326325      echo '<p><span class="dashicons dashicons-info"></span>&nbsp;' . __( '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>';
     
    342341  // this function hides the selected page from the list of pages
    343342  function exclude_404page( $query ) {
    344     if ( $this->settings['404page_page_id'] > 0 ) {
     343    $pageid = $this->get_page_id();
     344    if ( $pageid > 0 ) {
    345345      global $pagenow;
    346346     
     
    349349      // as of v 2.3 we check the post_type on front end
    350350      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();
    356355        } else {
    357           $pageid = $this->get_page_id( $pageid, true );
     356          $pageids = array( $pageid );
    358357        }
    359358       
    360359        // as of v 2.3 we add the ID of the 404 page to post__not_in
    361360        // 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 ) );
    363362       
    364363      }
     
    368367  // this function removes the 404 page from get_pages result array
    369368  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 ) {
    372371      for ( $i = 0; $i < sizeof( $pages ); $i++ ) {         
    373372        if ( $pages[$i]->ID == $pageid ) {
     
    442441  // returns the selected method
    443442  private function get_404page_method() {
    444     if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'POLYLANG_VERSION' ) ) {
     443    if ( defined( 'ICL_SITEPRESS_VERSION' ) || defined( 'xxxPOLYLANG_VERSION' ) ) {
    445444      // WPML or Polylang is active
    446445      return 'CMP';
     
    460459  }
    461460 
    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() {
    466494   
    467495    if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
    468496         
    469497      // 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 ) {
    474503        $languages = apply_filters( 'wpml_active_languages', NULL );
    475504        if ( !empty( $languages ) ) {
     
    481510          }
    482511        }
    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;
    501522   
    502523  }
     
    598619    $title = '';
    599620    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() );
    601622    }
    602623    return $title;
     
    612633    $content = '';
    613634    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() ) );
    615636    }
    616637    return $content;
Note: See TracChangeset for help on using the changeset viewer.