Plugin Directory

Changeset 1472214


Ignore:
Timestamp:
08/11/2016 10:34:07 AM (10 years ago)
Author:
smartware.cc
Message:

v 2.2 DEV

File:
1 edited

Legend:

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

    r1400463 r1472214  
    44Plugin URI: http://smartware.cc/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.1
     6Version: 2.2 DEV
    77Author: smartware.cc, Peter's Plugins
    88Author URI: http://smartware.cc
     
    4545        $this->plugin_name = '404page';
    4646    $this->plugin_slug = '404page';
    47         $this->version = '2.1';
     47        $this->version = '2.2 DEV';
    4848    $this->get_settings();
    4949    $this->init();
     
    6262  private function init() {
    6363   
    64     register_activation_hook( __FILE__, array( $this, 'init_admin_notice' ) );
    65    
    6664    if ( !is_admin() ) {
    6765     
    6866      add_action( 'init', array( $this, 'set_mode' ) );
     67      add_action( 'pre_get_posts' ,array ( $this, 'exclude_404page_from_search' ) );
    6968     
    7069    } else {
     
    7978      }
    8079     
    81       if ( 'NOT_DISMISSED' == get_option( '404page_notice_dismissed', 'NOT_DISMISSED' ) )  {
    82         add_action( 'admin_notices', array( $this, 'admin_notice' ) );
    83         add_action( 'wp_ajax_nopriv_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
    84         add_action( 'wp_ajax_404page_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) );
    85       }
    8680    }
    8781   
     
    171165        add_action( 'wp', array( $this, 'do_404_header' ) );
    172166        add_filter( 'body_class', array( $this, 'add_404_body_class' ) );
     167        add_filter( 'template_include', array( $this, 'change_404_template' ), 999 );
    173168       
    174169        $posts[] = get_post( $pageid );
     
    209204  }
    210205 
     206  // this function overrides the page template in compatibilty mode
     207  function change_404_template( $template ) {
     208    return $this->template;
     209  }
     210 
    211211  // send a 404 HTTP header - Standard Mode
    212212  function do_404_header_standard_mode() {
     
    335335    global $pagenow;
    336336    if( 'edit.php' == $pagenow && ( get_query_var( 'post_type' ) && 'page' == get_query_var( 'post_type' ) ) && !current_user_can( 'create_users' ) ) {
     337      $query->set( 'post__not_in', array( $this->settings['404page_page_id'] ) );
     338    }
     339    return $query;
     340  }
     341 
     342  // this function hides the selected page from search
     343  function exclude_404page_from_search( $query ) {
     344    if ( $query->is_search ) {
    337345      $query->set( 'post__not_in', array( $this->settings['404page_page_id'] ) );
    338346    }
     
    386394    </div>
    387395    <?php
    388   }
    389  
    390   // show a dismissible notice
    391   function admin_notice() {
    392     if ( current_user_can( 'manage_options' ) ) {
    393       echo '<div class="notice notice-info is-dismissible" id="404page_admin_notice"><p><strong>404page Plugin:</strong> ';
    394       if ( defined( 'CUSTOMIZR_VER' ) ) {
    395         // Customizr Theme
    396         _e( 'Customizr Theme detected. The 404page Plugin works in Customizr Compatibility Mode.', '404page' );
    397       } elseif ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
    398         // WPML
    399         _e( 'WPML Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with WPML.', '404page' );
    400       } elseif ( defined( 'POLYLANG_VERSION' ) ) {
    401         // Polylang
    402         _e( 'Polylang Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with Polylang.', '404page' );
    403       } elseif ( defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
    404         // Page Builder by SiteOrigin
    405         _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' );
    406       } elseif ( class_exists( 'bbPress' ) ) {
    407         // bbPress
    408         _e( 'bbPress Plugin detected. Operating Method is set to Compatibility Mode automatically to make the 404page Plugin work with bbPress.', '404page' );
    409       } elseif ( function_exists( 'wpsupercache_activate' ) ) {
    410         // WP Super Cache
    411         _e( 'WP Super Cache Plugin detected. Please check Settings!', '404page' );
    412       } else {
    413         _e( 'Please check Operating Method.', '404page' );
    414       }
    415       echo '<br /><a href="' . admin_url( 'themes.php?page=404pagesettings' ) . '">' . __( 'Settings', '404page' ) . '</a>';
    416       echo '</p></div>';
    417     }
    418   }
    419  
    420   // dismiss the notice (AJAX)
    421   function dismiss_admin_notice() {
    422     update_option( '404page_notice_dismissed', 'DISMISSED' );
    423   }
    424  
    425   // Reset dismiss state for notice on plugin activation
    426   function init_admin_notice( $network_wide ) {
    427     global $wpdb;
    428     if ( is_multisite() && $network_wide ) {
    429       $current_blog = $wpdb->blogid;
    430       $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
    431       foreach ( $blog_ids as $blog_id ) {
    432         switch_to_blog( $blog_id );
    433         delete_option( '404page_notice_dismissed' );
    434       }
    435       switch_to_blog( $current_blog );
    436     } else {
    437       delete_option( '404page_notice_dismissed' );
    438     }
    439396  }
    440397 
Note: See TracChangeset for help on using the changeset viewer.