|
| 1 | +<?php |
| 2 | +if( !class_exists( 'Custom_Error_Pages_Admin' ) ) |
| 3 | +{ |
| 4 | + class Custom_Error_Pages_Admin extends Custom_Error_Pages_Plugin |
| 5 | + { |
| 6 | + function __construct( ) |
| 7 | + { |
| 8 | + parent::__construct(); |
| 9 | + add_action( 'admin_menu' , array( $this, 'plugin_menu' ) ); |
| 10 | + add_action( 'admin_init' , array( $this, 'plugin_settings' ) ); |
| 11 | + } |
| 12 | + |
| 13 | + function plugin_menu() |
| 14 | + { |
| 15 | + add_filter( 'plugin_action_links_' . $this->basename, array( $this, 'settings_link' ) ); |
| 16 | + $plugin_page = add_options_page( __( 'Custom Error Pages', $this->slug ), __( 'Custom Error Pages', $this->slug ), 'manage_options', $this->slug, array( $this, 'plugin_options' ) ); |
| 17 | + add_action( 'admin_head-' . $plugin_page, array( $this, 'plugin_panel_styles' ) ); |
| 18 | + add_action( 'load-' . $plugin_page, array( $this, 'notice_hook' ) ); |
| 19 | + } |
| 20 | + |
| 21 | + function notice_hook() |
| 22 | + { |
| 23 | + add_action( 'admin_notices', array( $this, 'notice' ) ); |
| 24 | + } |
| 25 | + |
| 26 | + function notice() |
| 27 | + { |
| 28 | + echo '<div class="updated"><p>' . sprintf( __( 'If you find this plugin useful please consider giving it a %sfive star%s rating.', $this->slug ), '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/' . $this->slug . '?rate=5#postform">', '</a>' ) . '</p></div>'; |
| 29 | + } |
| 30 | + |
| 31 | + //Adds additional links under this plugin on the WordPress Plugins page |
| 32 | + function settings_link( $links ) |
| 33 | + { |
| 34 | + array_unshift( $links, '<a href="' . admin_url( 'options-general.php?page=' . $this->slug ) . '">' . __( 'Settings', $this->slug ) . '</a>' ); |
| 35 | + $links[] = '<a href="http://websistent.com/wordpress-plugins/" target="_blank">' . __( 'More Plugins', $this->slug ) . '</a>'; |
| 36 | + return $links; |
| 37 | + } |
| 38 | + |
| 39 | + function plugin_settings() |
| 40 | + { |
| 41 | + register_setting( $this->slug . '_options', 'jesin_' . $this->slug, array( $this, 'sanitize_input' ) ); |
| 42 | + |
| 43 | + add_settings_section( $this->slug.'_403_settings', sprintf( __( '%s Error Page', $this->slug ), '403' ), array( $this, 'callback_403' ), $this->slug ); |
| 44 | + add_settings_field( 'title_403', __( 'Page Title', $this->slug ), array( $this, 'title_403' ), $this->slug, $this->slug . '_403_settings', array( 'label_for' => 'title_403' ) ); |
| 45 | + add_settings_field( 'content_403', __( 'Page Content', $this->slug ), array( $this, 'content_403' ), $this->slug, $this->slug . '_403_settings', array( 'label_for' => 'content_403' ) ); |
| 46 | + |
| 47 | + add_settings_section( $this->slug.'_401_settings', sprintf( __( '%s Error Page', $this->slug ), '401' ), array( $this, 'callback_401' ), $this->slug ); |
| 48 | + add_settings_field( 'title_401', __( 'Page Title', $this->slug ), array( $this, 'title_401' ), $this->slug, $this->slug . '_401_settings', array( 'label_for' => 'title_401' ) ); |
| 49 | + add_settings_field( 'content_401', __( 'Page Content', $this->slug ), array( $this, 'content_401' ), $this->slug, $this->slug . '_401_settings', array( 'label_for' => 'content_401' ) ); |
| 50 | + } |
| 51 | + |
| 52 | + //Additional CSS for the plugin options page |
| 53 | + function plugin_panel_styles() |
| 54 | + { |
| 55 | + echo '<style type="text/css"> |
| 56 | + #title_403, #title_401 { margin-bottom:5px;padding:3px 8px;font-size:1.7em;line-height:100%;height:1.7em;width:100%;outline:0;margin:1px 0; } |
| 57 | + #icon-' . $this->slug . '{ background:transparent url(\'' . plugin_dir_url( __FILE__ ) . 'screen-icon.png\') no-repeat; }</style>'; |
| 58 | + } |
| 59 | + |
| 60 | + //Some instructions for the 403 page |
| 61 | + function callback_403() |
| 62 | + { |
| 63 | + echo sprintf( __( '%sPreview%s this page. (Changes will apply only after you click %sSave Changes%s)', $this->slug ), '<a href="' . home_url( '/?status=403' ) . '" target="_blank">', '</a>', '"', '"' ); |
| 64 | + } |
| 65 | + |
| 66 | + //Some instructions for the 401 page |
| 67 | + function callback_401() |
| 68 | + { |
| 69 | + echo sprintf( __( '%sPreview%s this page. (Changes will apply only after you click %sSave Changes%s)', $this->slug ), '<a href="' . home_url( '/?status=401' ) . '" target="_blank">', '</a>', '"', '"' ); |
| 70 | + } |
| 71 | + |
| 72 | + //Displays the title input box for the custom 403 error page |
| 73 | + function title_403() |
| 74 | + { |
| 75 | + $value = ( isset( $this->options['title_403'] ) && !empty( $this->options['title_403'] ) ) ? $this->options['title_403'] : $this->defaults['title_403']; |
| 76 | + echo '<input id="title_403" type="text" name="jesin_' . $this->slug . '[title_403]" value="' . $value . '"/>'; |
| 77 | + } |
| 78 | + |
| 79 | + //Displays a WordPress editor for entering content for the custom 403 page |
| 80 | + function content_403() |
| 81 | + { |
| 82 | + $value = ( isset( $this->options['content_403'] ) && !empty( $this->options['content_403'] ) ) ? $this->options['content_403'] : $this->defaults['content_403']; |
| 83 | + wp_editor( $value, 'content_403', array( 'textarea_name' => 'jesin_' . $this->slug . '[content_403]' ) ); |
| 84 | + } |
| 85 | + |
| 86 | + //Displays the title input box for the custom 403 error page |
| 87 | + function title_401() |
| 88 | + { |
| 89 | + $value = ( isset( $this->options['title_401'] ) && !empty( $this->options['title_401'] ) ) ? $this->options['title_401'] : $this->defaults['title_401']; |
| 90 | + echo '<input id="title_401" type="text" name="jesin_' . $this->slug . '[title_401]" value="' . $value . '"/>'; |
| 91 | + } |
| 92 | + |
| 93 | + //Displays a WordPress editor for entering content for the custom 401 page |
| 94 | + function content_401() |
| 95 | + { |
| 96 | + $value = ( isset( $this->options['content_401'] ) && !empty( $this->options['content_401'] ) ) ? $this->options['content_401'] : $this->defaults['content_401']; |
| 97 | + wp_editor( $value, 'content_401', array( 'textarea_name' => 'jesin_' . $this->slug . '[content_401]' ) ); |
| 98 | + } |
| 99 | + |
| 100 | + //Sanitizing the heading input fields |
| 101 | + function sanitize_input( $input ) |
| 102 | + { |
| 103 | + $input['title_403'] = esc_attr( $input['title_403'] ); |
| 104 | + $input['title_401'] = esc_attr( $input['title_401'] ); |
| 105 | + return $input; |
| 106 | + } |
| 107 | + |
| 108 | + // |
| 109 | + function plugin_options() |
| 110 | + { |
| 111 | + ?> |
| 112 | + <div class="wrap"> |
| 113 | + <?php screen_icon( $this->slug ); ?> |
| 114 | + <h2><?php _e( 'Custom Error Pages', $this->slug ); ?></h2> |
| 115 | + <form method="post" action="options.php"> |
| 116 | + <?php settings_fields( $this->slug . '_options' ); ?> |
| 117 | + <p><?php printf( __( '%s users place the following in your %s file.', $this->slug ), '<strong>Apache</strong>', '<code>' . get_home_path() . '.htaccess</code>' ); ?><br /> |
| 118 | + <pre>ErrorDocument 403 <?php echo str_replace( $_SERVER['DOCUMENT_ROOT'], '', get_home_path() ) . 'index.php?status=403'; ?> |
| 119 | + |
| 120 | +ErrorDocument 401 <?php echo str_replace( $_SERVER['DOCUMENT_ROOT'], '', get_home_path() ) . 'index.php?status=401'; ?></pre></p> |
| 121 | + <p><?php printf( __( '%s users place the following in your %s file.', $this->slug ), '<strong>Nginx</strong>', '<code>nginx.conf</code>' ); ?> |
| 122 | + <pre>error_page 403 = <?php echo str_replace( $_SERVER['DOCUMENT_ROOT'], '', get_home_path() ) . 'index.php?status=403;'; ?> |
| 123 | + |
| 124 | +error_page 401 = <?php echo str_replace( $_SERVER['DOCUMENT_ROOT'], '', get_home_path() ) . 'index.php?status=401;'; ?></pre></p> |
| 125 | + <?php do_settings_sections( $this->slug ); |
| 126 | + submit_button(); ?> |
| 127 | + </form> |
| 128 | + </div> |
| 129 | + <?php |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + //Admin options page begins here |
| 134 | + $custom_error_pages_admin = new Custom_Error_Pages_Admin; |
| 135 | +} |
0 commit comments