Skip to content

Commit f07002e

Browse files
committed
Initial commit.
1 parent 521e546 commit f07002e

12 files changed

+621
-0
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
## 1.2
4+
5+
* Fixed a bug that displayed all comments of the WordPress database on the generated error page.
6+
* Added the translation of the plugin in "French (France)" language.
7+
8+
## 1.1
9+
10+
* Fixed a bug that displayed the thumbnail of Post ID 1
11+
* Reduced repetitive code with inheritance
12+
* Compatibility check with WordPress 3.8
13+
14+
## 1.0
15+
16+
* Initial version

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Custom Error Pages
2+
3+
Create custom `401` and `403` error pages with any **WordPress** theme without
4+
writing a single line of code, set it up and forget it.
5+
6+
## Description
7+
8+
**WordPress** offers inbuilt support for custom `404` pages on all themes. But
9+
what about custom pages for other common errors like `401` and `403`? You end up
10+
seeing a bland error page of the Web Server.
11+
12+
With this plugin you can easily create custom `401` and `403` error pages with
13+
any theme without writing a single line of code!!! And the best part is that you
14+
set it and forget it. Yes, you don't have to do any changes even if you change
15+
themes. The heading and text you want on `401` and `403` error pages are
16+
displayed on the currently active theme.
17+
18+
## Further Reading
19+
* [Create WordPress 401 and 403 error pages](https://websistent.com/WordPress-custom-403-401-error-page/) WITHOUT using this plugin.
20+
* The [Custom Error Pages Plugin](https://websistent.com/WordPress-plugins/custom-error-pages/) official homepage.
21+
22+
## Installation
23+
24+
1. Install and activate the custom error pages plugin.
25+
2. From the **wp-admin** go to *Settings > Custom Error Pages*, fill in the
26+
heading and content boxes, save the changes and preview it.
27+
3. Configure your web server to use a custom error page.
28+
29+
Apache users edit your `.htaccess` file and add the following lines.
30+
31+
ErrorDocument 403 /index.php?status=403
32+
ErrorDocument 401 /index.php?status=401
33+
34+
Nginx users edit your `nginx.conf` file and add the following lines.
35+
36+
error_page 403 = /index.php?status=403
37+
error_page 401 = /index.php?status=401
38+
39+
Try accessing a file or directory which is forbidden like
40+
41+
http://www.example.com/.htaccess
42+
43+
http://www.example.com/wp-includes/
44+
45+
Did you see a custom `403` page in all the glory of your theme?
46+
47+
## Frequently Asked Questions
48+
49+
### Should I do anything if I change themes?
50+
No not at all. You just install the plugin set it and forget it. The plugin
51+
isn't theme bound so it'll work even after switching themes.
52+
53+
### I noticed define( 'DONOTCACHEPAGE', TRUE ); in the plugin code what is it for?
54+
This tells caching plugins like W3 Total Cache and WP Super Cache not to cache
55+
the `401` and `403` error pages. This does **NOT** affect the cacheability any
56+
other pages of your site.
57+
58+
### Does this plugin automatically edit the .htaccess or nginx.conf file?
59+
No it doesn't. You have to manually edit it and add the necessary configuration
60+
specified in the plugin's option page.
61+
62+
## Credits
63+
64+
This plugin was written by @jesinwp.
65+
66+
Version `1.2` in that repository was made by @sizious, so it's unofficial.

src/admin_options.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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>', '&quot;', '&quot;' );
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>', '&quot;', '&quot;' );
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+
}

src/comments_disabler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
//This is a empty template made to hide comments for generated "Virtual Pages".
3+
?>
2.05 KB
Binary file not shown.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: Custom Error Pages v1.2\n"
4+
"POT-Creation-Date: 2013-11-01 18:04+0530\n"
5+
"PO-Revision-Date: 2017-08-12 16:41+0100\n"
6+
"Last-Translator: SiZiOUS <sizious@gmail.com>\n"
7+
"Language-Team: SiZiOUS <sizious@gmail.com>\n"
8+
"Language: fr_FR\n"
9+
"MIME-Version: 1.0\n"
10+
"Content-Type: text/plain; charset=UTF-8\n"
11+
"Content-Transfer-Encoding: 8bit\n"
12+
"X-Generator: Poedit 2.0.3\n"
13+
"X-Poedit-Basepath: .\n"
14+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
15+
16+
#: ../admin_options.php:24 ../admin_options.php:122
17+
msgid "Custom Error Pages"
18+
msgstr "Custom Error Pages"
19+
20+
#: ../admin_options.php:36
21+
#, php-format
22+
msgid "If you find this plugin useful please consider giving it a %sfive star%s rating."
23+
msgstr "Si vous trouvez ce plugin utile, pensez à lui donner %sune note de cinq étoiles%s, merci d'avance."
24+
25+
#: ../admin_options.php:42
26+
msgid "Settings"
27+
msgstr "Réglages"
28+
29+
#: ../admin_options.php:43
30+
msgid "More Plugins"
31+
msgstr "Plus de plugins"
32+
33+
#: ../admin_options.php:51 ../admin_options.php:55
34+
#, php-format
35+
msgid "%s Error Page"
36+
msgstr "Page d'erreur %s"
37+
38+
#: ../admin_options.php:52 ../admin_options.php:56
39+
msgid "Page Title"
40+
msgstr "Titre de la page"
41+
42+
#: ../admin_options.php:53 ../admin_options.php:57
43+
msgid "Page Content"
44+
msgstr "Contenu de la page"
45+
46+
#: ../admin_options.php:71 ../admin_options.php:77
47+
#, php-format
48+
msgid "%sPreview%s this page. (Changes will apply only after you click %sSave Changes%s)"
49+
msgstr ""
50+
"%sPrévisualiser%s cette page (les modifications s'appliqueront seulement après avoir cliqué sur le bouton %sEnregistrer les "
51+
"modifications%s)."
52+
53+
#: ../admin_options.php:125 ../admin_options.php:129
54+
#, php-format
55+
msgid "%s users place the following in your %s file."
56+
msgstr "Les utilisateurs du serveur %s doivent ajouter les lignes suivantes dans le fichier %s."
57+
58+
#: ../plugin.php:29
59+
msgid "HTTP 401 Unauthorized"
60+
msgstr "HTTP 401 Non autorisé"
61+
62+
#: ../plugin.php:30
63+
msgid "Access denied due to invalid HTTP credentials"
64+
msgstr "Accès refusé en raison d'informations d'identification HTTP non valides"
65+
66+
#: ../plugin.php:31
67+
msgid "HTTP 403 Forbidden"
68+
msgstr "HTTP 403 Interdit"
69+
70+
#: ../plugin.php:32
71+
msgid "You don't have permission to access this resource"
72+
msgstr "Vous n'avez pas la permission d'accéder à cette ressource"
73+
74+
#: ../plugin.php:5
75+
msgid "Create custom 401 and 403 error pages with any WordPress theme without writing a single line of code, set it up and forget it."
76+
msgstr ""
77+
"Créez des pages d'erreur 401 et 403 personnalisées avec n'importe quel thème WordPress sans écrire une seule ligne de code. "
78+
"Configurez-ce plugin puis oubliez-le."

src/languages/custom-error-pages.mo

387 Bytes
Binary file not shown.

src/languages/custom-error-pages.pot

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: Custom Error Pages v1.2\n"
4+
"POT-Creation-Date: 2013-11-01 18:04+0530\n"
5+
"PO-Revision-Date: 2017-08-12 12:00+0100\n"
6+
"Last-Translator: Jesin <me@jesin.in>\n"
7+
"Language-Team: Jesin <me@jesin.in>\n"
8+
"Language: English\n"
9+
"MIME-Version: 1.0\n"
10+
"Content-Type: text/plain; charset=UTF-8\n"
11+
"Content-Transfer-Encoding: 8bit\n"
12+
"X-Generator: Poedit 1.5.7\n"
13+
"X-Poedit-KeywordsList: __;_e\n"
14+
"X-Poedit-Basepath: .\n"
15+
"X-Poedit-SearchPath-0: ..\n"
16+
17+
#: ../admin_options.php:24 ../admin_options.php:122
18+
msgid "Custom Error Pages"
19+
msgstr ""
20+
21+
#: ../admin_options.php:36
22+
#, php-format
23+
msgid ""
24+
"If you find this plugin useful please consider giving it a %sfive star%s "
25+
"rating."
26+
msgstr ""
27+
28+
#: ../admin_options.php:42
29+
msgid "Settings"
30+
msgstr ""
31+
32+
#: ../admin_options.php:43
33+
msgid "More Plugins"
34+
msgstr ""
35+
36+
#: ../admin_options.php:51 ../admin_options.php:55
37+
#, php-format
38+
msgid "%s Error Page"
39+
msgstr ""
40+
41+
#: ../admin_options.php:52 ../admin_options.php:56
42+
msgid "Page Title"
43+
msgstr ""
44+
45+
#: ../admin_options.php:53 ../admin_options.php:57
46+
msgid "Page Content"
47+
msgstr ""
48+
49+
#: ../admin_options.php:71 ../admin_options.php:77
50+
#, php-format
51+
msgid ""
52+
"%sPreview%s this page. (Changes will apply only after you click %sSave "
53+
"Changes%s)"
54+
msgstr ""
55+
56+
#: ../admin_options.php:125 ../admin_options.php:129
57+
#, php-format
58+
msgid "%s users place the following in your %s file."
59+
msgstr ""
60+
61+
#: ../plugin.php:29
62+
msgid "HTTP 401 Unauthorized"
63+
msgstr ""
64+
65+
#: ../plugin.php:30
66+
msgid "Access denied due to invalid HTTP credentials"
67+
msgstr ""
68+
69+
#: ../plugin.php:31
70+
msgid "HTTP 403 Forbidden"
71+
msgstr ""
72+
73+
#: ../plugin.php:32
74+
msgid "You don't have permission to access this resource"
75+
msgstr ""
76+
77+
#: ../plugin.php:5
78+
msgid "Create custom 401 and 403 error pages with any WordPress theme without writing a single line of code, set it up and forget it."
79+
msgstr ""

0 commit comments

Comments
 (0)