404page – your smart custom 404 error page - Version 1.0

Version Description

(2013-09-30) = * Initial Release

Download this release

Release Info

Developer smartware.cc
Plugin Icon 128x128 404page – your smart custom 404 error page
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (2) hide show
  1. 404page.php +122 -0
  2. readme.txt +34 -0
404page.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: 404page
4
+ Plugin URI: http://smartware.cc/wp-404page
5
+ Description: Define any of your pages as 404 page
6
+ Version: 1.0
7
+ Author: smartware.cc
8
+ Author URI: http://smartware.cc
9
+ License: GPL2
10
+ */
11
+
12
+ /* Copyright 2013 smartware.cc (email : sw@smartware.cc)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License, version 2, as
16
+ published by the Free Software Foundation.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+
28
+ // redirect 404 page
29
+ function swcc_404page( $template ) {
30
+ global $wp_query;
31
+ $template404 = $template;
32
+ $pageid = swcc_404page_get_page_id();
33
+ if ( $pageid > 0 ) {
34
+ $wp_query = null;
35
+ $wp_query = new WP_Query();
36
+ $wp_query->query( 'page_id=' . $pageid );
37
+ $wp_query->the_post();
38
+ $template404 = get_page_template();
39
+ rewind_posts();
40
+ }
41
+ return $template404;
42
+ }
43
+
44
+ // show admin page
45
+ function swcc_404page_admin() {
46
+ if ( !current_user_can( 'manage_options' ) ) {
47
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
48
+ }
49
+ ?>
50
+ <div class="wrap">
51
+ <div id="icon-tools" class="icon32"></div>
52
+ <h2>404page</h2>
53
+ <div class="metabox-holder has-right-sidebar">
54
+ <div class="inner-sidebar">
55
+ <div class="postbox">
56
+ <h3><span>the 404page plugin</span></h3>
57
+ <div class="inside">
58
+ <ul>
59
+ <li><a href="http://wordpress.org/extend/plugins/404page/">Please rate the plugin</a></li>
60
+ <li><a href="http://smartware.cc/wp-404page/">Plugin homepage</a></li>
61
+ <li><a href="http://smartware.cc/">Author homepage</a></li>
62
+ </ul>
63
+ </div>
64
+ </div>
65
+ </div>
66
+ <div id="post-body">
67
+ <div id="post-body-content">
68
+ <form method="post">
69
+ <p>
70
+ <?php
71
+ if( !empty( $_POST['submit'] ) ) {
72
+ $pageid = swcc_404page_get_page_id();
73
+ if ( $_POST['404pageid'] != $pageid ) {
74
+ if ( update_option( '404page_page_id', $_POST['404pageid'] ) ) {
75
+ add_settings_error( 'swcc_404page_err', esc_attr( 'settings_updated' ), __('Settings saved.'), 'updated' );
76
+ } else {
77
+ add_settings_error( 'swcc_404page_err', esc_attr( 'settings_updated' ), 'An unexpected error occured while saving the settings!', 'error' );
78
+ }
79
+ }
80
+ }
81
+ $pageid = swcc_404page_get_page_id();
82
+ if ( $pageid < 0 ) {
83
+ add_settings_error( 'swcc_404page_err', esc_attr( 'settings_updated' ), 'The page you have selected as 404 page does not exist anymore. Please choose another page.', 'error' );
84
+ }
85
+ settings_errors( 'swcc_404page_err' );
86
+ ?>
87
+ <label for="404pageid">Page to be displayed as 404 page: </label>
88
+ <?php
89
+ wp_dropdown_pages( array( 'name' => '404pageid', 'echo' => 1, 'show_option_none' => '&mdash; NONE (WP Default) &mdash;', 'option_none_value' => '0', 'selected' => $pageid ) );
90
+ ?>
91
+ </p>
92
+ <p class="submit">
93
+ <input type="submit" name="submit" class="button-primary" value="<?php _e('Save'); ?>" />
94
+ </p>
95
+ </form>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+ <?php
101
+ }
102
+
103
+ // init backend
104
+ function swcc_404page_adminmenu() {
105
+ add_submenu_page( 'options-general.php', '404page', '404page', 'manage_options', '404page', 'swcc_404page_admin' );
106
+ }
107
+
108
+ // returns the id of the 404 page if one is defined, returns 0 if none is defined, returns -1 if the defined page id does not exist
109
+ function swcc_404page_get_page_id() {
110
+ $pageid = get_option( '404page_page_id', 0 );
111
+ if ( $pageid != 0 ) {
112
+ $page = get_post( $pageid );
113
+ if ( !$page || $page->post_status != 'publish' ) {
114
+ $pageid = -1;
115
+ }
116
+ }
117
+ return $pageid;
118
+ }
119
+
120
+ add_filter( '404_template', 'swcc_404page' );
121
+ add_action( 'admin_menu', 'swcc_404page_adminmenu' );
122
+ ?>
readme.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: smartware.cc
3
+ Tags: page, 404, error, error page, 404 page, page not found, page not found error, 404 error page
4
+ Requires at least: 3.0
5
+ Tested up to: 3.6.1
6
+ Stable tag: 1.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Define any of your WordPress pages as 404 error page
11
+
12
+ == Description ==
13
+
14
+ Create your 404 Page as a normal WordPress Page using the full power of WordPress. You can use a Custom Page Template or Custom Fields, you can set a Featured Image - everything like on every other Page.
15
+
16
+ The go to Settings -> 404page from your WordPress Dashbord and select the created Page as 404 error page.
17
+
18
+ [Plugin Homepage](http://smartware.cc/wp-404page)
19
+
20
+ == Installation ==
21
+
22
+ 1. Upload the "404page" folder to your "/wp-content/plugins/" directory.
23
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
24
+ 1. Select desired 404 page
25
+
26
+ == Screenshots ==
27
+
28
+ 1. Create your 404 Page as a normal WordPress Page
29
+ 2. Define the created Page as 404 Error Page
30
+
31
+ == Changelog ==
32
+
33
+ = 1.0 (2013-09-30) =
34
+ * Initial Release