plugin_name = '404page'; $this->version = '1.3'; $this->get_settings(); $this->init(); } // get all settings private function get_settings() { $this->settings = array(); $this->settings['404page_page_id'] = $this->get_404page_id(); } private function init() { add_action( 'init', array( $this, 'add_text_domains' ) ); add_filter( '404_template', array( $this, 'show404' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_head', array( $this, 'admin_css' ) ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_settings_link' ) ); } // redirect 404 page function show404( $template ) { global $wp_query; $template404 = $template; $pageid = $this->settings['404page_page_id']; if ( $pageid > 0 ) { $wp_query = null; $wp_query = new WP_Query(); $wp_query->query( 'page_id=' . $pageid ); $wp_query->the_post(); $template404 = get_page_template(); rewind_posts(); } return $template404; } // init the admin section function admin_init() { add_settings_section( '404page-settings', '', array( $this, 'admin_section_title' ), '404page_settings_section' ); register_setting( '404page_settings', '404page_page_id' ); add_settings_field( '404page_settings_404page', __( 'Page to be displayed as 404 page', '404page' ) , array( $this, 'admin_404page' ), '404page_settings_section', '404page-settings', array( 'label_for' => '404page_page_id' ) ); } // add css function admin_css() { echo ''; } // handle the settings field function admin_404page() { if ( $this->settings['404page_page_id'] < 0 ) { echo '
' . __( 'The page you have selected as 404 page does not exist anymore. Please choose another page.', '404page' ) . '
'; } wp_dropdown_pages( array( 'name' => '404page_page_id', 'id' => 'select404page', 'echo' => 1, 'show_option_none' => __( '— NONE (WP default 404 page) —', '404page'), 'option_none_value' => '0', 'selected' => $this->settings['404page_page_id'] ) ); } // echo title for settings section function admin_section_title() { echo '

' . __( 'Settings' ) . ':


'; } // adds the options page to admin menu function admin_menu() { add_options_page( __( '404 Error Page', "404page" ), __( '404 Error Page', '404page' ), 'manage_options', '404pagesettings', array( $this, 'admin_page' ) ); } // creates the options page function admin_page() { if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } ?>

404page Version version; ?>

show_meta_boxes(); } ?>

post_status != 'publish' ) { $pageid = -1; } } return $pageid; } // addd text domains function add_text_domains() { load_plugin_textdomain( '404page_general', false, basename( dirname( __FILE__ ) ) . '/languages' ); load_plugin_textdomain( '404page', false, basename( dirname( __FILE__ ) ) . '/languages' ); } // show meta boxes function show_meta_boxes() { ?>

  •   
  •   
  •   
  •   
  •   

  •   
  •   
  •   
' . __( 'Settings' ) . '') ); } } $smart404page = new Smart404Page(); ?>