├── assets └── screenshot-1.png ├── tests ├── test-test.php └── bootstrap.php ├── CHANGES.md ├── plugin.php ├── readme.txt ├── README.md └── includes ├── class-be-genesis-404-settings.php └── class-be-genesis-404.php /assets/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/billerickson/Genesis-404-Page/HEAD/assets/screenshot-1.png -------------------------------------------------------------------------------- /tests/test-test.php: -------------------------------------------------------------------------------- 1 | assertTrue( true ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Changes to Genesis 404 Page 2 | 3 | ## 1.5.0 (2015-04-17) 4 | * Add genesis layout support (Joshua David Nelson, @joshuadnelson) 5 | 6 | ## 1.4.0 (2013-11-29) 7 | * Add setup for unit tests (Gary Jones). 8 | * Add contextual help. 9 | * Add support for GitHub Updater plugin (Gary Jones). 10 | * Improved appearance of page title input field (Gary Jones). 11 | * Improved loading of language files (Gary Jones). 12 | * Improve support for activation on multi-sites (Gary Jones). 13 | * Improve documentation and code standards (Gary Jones). 14 | * Improve code organization by classes into their own files (Gary Jones). 15 | * Fix incorrect plugin URL (Gary Jones). 16 | * Fix incorrect textdomains (Gary Jones). 17 | 18 | ## 1.3.0 (2014-04-17) 19 | * Updated editor for WordPress 3.9, props @joshuadavidnelson. 20 | 21 | ## 1.2.0 (2012-05-25) 22 | * Add HTML5 Support (Bill Erickson). 23 | 24 | ## 1.1.0 (2013-01-11) 25 | * Add Search functionality (Bill Erickson). 26 | 27 | ## 1.0.0 (2012-03-27) 28 | * Initial release (Bill Erickson). 29 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | array( "genesis-404-page/plugin.php" ), 15 | ); 16 | 17 | // If the wordpress-tests repo location has been customized (and specified 18 | // with WP_TESTS_DIR), use that location. This will most commonly be the case 19 | // when configured for use with Travis CI. 20 | 21 | // Otherwise, we'll just assume that this plugin is installed in the WordPress 22 | // SVN external checkout configured in the wordpress-tests repo. 23 | 24 | if( false !== getenv( 'WP_TESTS_DIR' ) ) { 25 | require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php'; 26 | } else { 27 | // Maybe I'm testing this plugin in the wrong place, but I need a different path to get from here to 28 | // the core bootstrap.php, than what Jetpack and other prominent plugins seem to use. 29 | // require dirname( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) ) . '/includes/bootstrap.php'; 30 | require dirname( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) ) . '/tests/phpunit/includes/bootstrap.php'; 31 | 32 | } 33 | 34 | class BE_Genesis_404_TestCase extends WP_UnitTestCase { 35 | 36 | } 37 | -------------------------------------------------------------------------------- /plugin.php: -------------------------------------------------------------------------------- 1 | 404 Page. 24 | 25 | == Screenshots == 26 | 27 | 1. Admin screen showing the fields for custom 404 Not Found page title and content. 28 | 29 | == Changelog == 30 | 31 | = 1.5.0 (2015-04-17) = 32 | * Add genesis layout support (Joshua David Nelson, @joshuadnelson) 33 | 34 | = 1.4.0 (2014-10-08) = 35 | * Add setup for unit tests (Gary Jones). 36 | * Add support for GitHub Updater plugin (Gary Jones). 37 | * Improved appearance of page title input field (Gary Jones). 38 | * Improved loading of language files (Gary Jones). 39 | * Improve support for activation on multi-sites (Gary Jones). 40 | * Improve documentation and code standards (Gary Jones). 41 | * Improve code organization by classes into their own files (Gary Jones). 42 | * Fix incorrect plugin URL (Gary Jones). 43 | * Fix incorrect textdomains (Gary Jones). 44 | 45 | = 1.3.0 (2014-04-17) = 46 | * Updated editor for WordPress 3.9, props @joshuadnelson 47 | 48 | = 1.2.0 (2012-05-25) = 49 | * Add HTML5 Support (Bill Erickson). 50 | 51 | = 1.1.0 (2013-01-11) = 52 | * Add Search functionality (Bill Erickson). 53 | 54 | = 1.0.0 (2012-03-27) = 55 | * Initial release (Bill Erickson). 56 | 57 | == Upgrade Notice == 58 | 59 | = 1.5.0 = 60 | Add support for overriding the genesis layout on 404 pages. 61 | 62 | = 1.4.0 = 63 | Plugin mostly rewritten. Few small fixes made and improvements added. 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Genesis 404 Page 2 | 3 | Customize the content of the 404 Page within the Genesis Framework. 4 | 5 | ## Description 6 | 7 | Customizing the contents of the _Page Not Found_ page in any WordPress theme can be tricky, and usually involes editing the 404.php template file. The Genesis Framework already abstracts the default content of the page into a function, and this plugin can unhook that and replace it with your own custom title and content. 8 | 9 | ## Screenshots 10 | 11 | ![Screenshot showing input for custom 404 Not Found title and content](assets/screenshot-1.png) 12 | _Admin screen showing the fields for custom 404 Not Found page title and content._ 13 | 14 | ## Requirements 15 | * WordPress 3.0+ 16 | * Genesis Framework 1.8+ (supports HTML5 for Genesis Framework 2.0+) 17 | 18 | ## Installation 19 | 20 | ### WP .org repo 21 | 22 | 1. On the Add Plugin screen, search for _Genesis 404 Page_ and follow the usual steps. 23 | 24 | ### Upload 25 | 26 | 1. Download the latest tagged archive (choose the "zip" option). 27 | 2. Go to the __Plugins -> Add New__ screen and click the __Upload__ tab. 28 | 3. Upload the zipped archive directly. 29 | 4. Go to the Plugins screen and click __Activate__. 30 | 31 | ### Manual 32 | 33 | 1. Download the latest tagged archive (choose the "zip" option). 34 | 2. Unzip the archive. 35 | 3. Copy the folder to your `/wp-content/plugins/` directory. 36 | 4. Go to the Plugins screen and click __Activate__. 37 | 38 | Check out the Codex for more information about [installing plugins manually](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation). 39 | 40 | ### Git 41 | 42 | Using git, browse to your `/wp-content/plugins/` directory and clone this repository: 43 | 44 | `git clone git@github.com:billerickson/Genesis-404-Page.git` 45 | 46 | Then go to your Plugins screen and click __Activate__. 47 | 48 | ## Updates 49 | 50 | This plugin supports the [GitHub Updater](https://github.com/afragen/github-updater) plugin, so if you install that, this plugin becomes automatically updateable direct from GitHub. 51 | 52 | See [CHANGES.md](changes.md) for the plugin changelog. 53 | 54 | ## Usage 55 | 56 | Once installed, you can customize your 404 page's title and content in Genesis > 404 Page. 57 | 58 | Use the [genesis-404-search] shortcode to add a search form to the page. 59 | 60 | If you'd like to dynamically list content (ex: most recent posts), I recommend you install the [Display Posts Shortcode](http://www.wordpress.org/extend/plugins/display-posts-shortcode/) and use it in the 404 page's content. 61 | 62 | ## Credits 63 | 64 | Built by [Bill Erickson](http://twitter.com/BillErickson) and [Gary Jones](https://twitter.com/GaryJ) 65 | Copyright 2012 [Bill Erickson](http://www.billerickson.net) 66 | -------------------------------------------------------------------------------- /includes/class-be-genesis-404-settings.php: -------------------------------------------------------------------------------- 1 | array( 32 | 'parent_slug' => 'genesis', 33 | 'page_title' => __( 'Genesis 404 Page', 'genesis-404-page' ), 34 | 'menu_title' => __( '404 Page', 'genesis-404-page' ), 35 | ) 36 | ); 37 | 38 | // Set up page options. These are optional, so only uncomment if you want to change the defaults 39 | $page_ops = array( 40 | // 'screen_icon' => 'options-general', 41 | // 'save_button_text' => 'Save Settings', 42 | // 'reset_button_text' => 'Reset Settings', 43 | // 'save_notice_text' => 'Settings saved.', 44 | // 'reset_notice_text' => 'Settings reset.', 45 | ); 46 | 47 | // Give it a unique settings field. 48 | // You'll access them from genesis_get_option( 'option_name', 'child-settings' ); 49 | $settings_field = 'genesis-404'; 50 | 51 | // Set the default values 52 | $default_settings = array( 53 | 'title' => '', 54 | 'content' => '', 55 | ); 56 | 57 | // Create the Admin Page 58 | $this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings ); 59 | 60 | // Initialize the Sanitization Filter 61 | add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization_filters' ) ); 62 | } 63 | 64 | /** 65 | * Set up sanitization filters. 66 | * 67 | * See genesis/lib/classes/sanitization.php for all available filters. 68 | * 69 | * @since 1.0.0 70 | */ 71 | public function sanitization_filters() { 72 | genesis_add_option_filter( 73 | 'no_html', 74 | $this->settings_field, 75 | array( 76 | 'title', 77 | 'genesis_layout', 78 | ) 79 | ); 80 | 81 | genesis_add_option_filter( 82 | 'safe_html', 83 | $this->settings_field, 84 | array( 85 | 'content', 86 | ) 87 | ); 88 | } 89 | 90 | /** 91 | * Register metaboxes on admin page. 92 | * 93 | * @since 1.0.0 94 | */ 95 | public function metaboxes() { 96 | 97 | add_meta_box( 'metabox_404', __( '404 Page', 'genesis-404-page' ), array( $this, 'metabox_404' ), $this->pagehook, 'main', 'high' ); 98 | 99 | if( apply_filters( 'genesis_404_layout_box', true ) ) 100 | add_meta_box( 'genesis_404_layout_box', __( 'Layout Settings', 'genesis' ), array( $this, 'layout_box' ), $this->pagehook, 'main', 'high' ); 101 | 102 | } 103 | 104 | /** 105 | * The layout metabox for the 404 page. 106 | * 107 | * @since 1.5.0 108 | */ 109 | public function layout_box() { 110 | $layout = esc_attr( $this->get_field_value( 'genesis_layout' ) ); 111 | 112 | ?> 113 |
114 |

/>

115 | 116 |

$this->get_field_name( 'genesis_layout' ), 'selected' => $layout, 'type' => 'site' ) ); ?>

117 |
118 | 119 |
120 | 130 |

404 Page is the page shown when the intended page was not found. You can customise it here.', 'genesis-404-page' ); ?>

131 |

132 |
133 | 134 |

135 | 136 |

137 |
138 | $this->get_field_id( 'content' ), ) ); ?> 139 |

140 | ' . __( 'To customize the 404 Not Found page in your Genesis child theme, enter a title and content.', 'genesis-404-page' ) . '

' . 154 | '

' . __( 'If you want to display the search form, use the shortcode [genesis-404-search].', 'genesis-404-page' ) . '

'; 155 | 156 | $screen->add_help_tab( array( 157 | 'id' => $this->pagehook, 158 | 'title' => __( 'Genesis 404 Page', 'genesis' ), 159 | 'content' => $help, 160 | ) ); 161 | 162 | //* Add help sidebar 163 | $screen->set_help_sidebar( 164 | '

' . __( 'For more information:', 'genesis' ) . '

' . 165 | '

' . __( 'Get Support', 'genesis-404-page' ) . '

' . 166 | '

' . __( 'Plugin Source and Development', 'genesis-404-page' ) . '

' 167 | ); 168 | 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /includes/class-be-genesis-404.php: -------------------------------------------------------------------------------- 1 | blogs 140 | WHERE archived = '0' AND spam = '0' 141 | AND deleted = '0'"; 142 | return $wpdb->get_col( $sql ); 143 | } 144 | 145 | /** 146 | * Fired for each blog when the plugin is activated. 147 | * 148 | * @since 1.3.0 149 | */ 150 | private static function single_activate() { 151 | if ( 'genesis' !== basename( TEMPLATEPATH ) ) { 152 | deactivate_plugins( plugin_dir_path( plugin_basename( __FILE__ ) ) . 'plugin.php' ); 153 | wp_die( sprintf( __( 'Sorry, you can’t activate unless you have installed Genesis', 'genesis-404-page' ), 'http://www.billerickson.net/get-genesis' ) ); 154 | } 155 | } 156 | 157 | /** 158 | * Fired for each blog when the plugin is deactivated. 159 | * 160 | * @since 1.3.0 161 | */ 162 | private static function single_deactivate() { 163 | // TODO: Define deactivation functionality here 164 | } 165 | 166 | /** 167 | * Load the plugin text domain for translation. 168 | * 169 | * @since 1.3.0 170 | */ 171 | public function load_plugin_textdomain() { 172 | $domain = self::PLUGIN_SLUG; 173 | $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 174 | 175 | load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); 176 | load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages' ); 177 | } 178 | 179 | /** 180 | * Check if custom 404 should be used. 181 | * 182 | * @since 1.0.0 183 | * @author Bill Erickson 184 | */ 185 | public function maybe_custom_404() { 186 | if( !is_404() ) 187 | return; 188 | 189 | // Replace content 190 | if ( genesis_get_option( 'content', 'genesis-404' ) ) { 191 | remove_action( 'genesis_loop', 'genesis_404' ); 192 | add_action( 'genesis_loop', array( $this, 'loop' ) ); 193 | } 194 | 195 | // Set layout 196 | if ( genesis_get_option( 'genesis_layout', 'genesis-404' ) ) { 197 | add_filter( 'genesis_pre_get_option_site_layout', array( $this, 'custom_layout' ) ); 198 | } 199 | } 200 | 201 | /** 202 | * Genesis 404 Loop. 203 | * 204 | * Defers to markup-type specific methods. 205 | * 206 | * @since 1.0.0 207 | * @author Bill Erickson 208 | */ 209 | public function loop() { 210 | $title = genesis_get_option( 'title', 'genesis-404' ); 211 | $content = genesis_get_option( 'content', 'genesis-404' ); 212 | 213 | if ( function_exists( 'genesis_html5' ) && genesis_html5() ) { 214 | $this->loop_xhtml( $title, $content ); 215 | } else { 216 | $this->loop_html5( $title, $content ); 217 | } 218 | } 219 | 220 | /** 221 | * Echo 404 loop markup as XHTML. 222 | * 223 | * @since 1.3.0 224 | * 225 | * @param string $title Page title. 226 | * @param string $content Page content. 227 | */ 228 | protected function loop_xhtml( $title, $content ) { 229 | echo '
'; 230 | 231 | if ( ! empty( $title ) ) { 232 | echo '

' . esc_attr( $title ) . '

'; 233 | } 234 | 235 | do_action( 'genesis_404_before_content' ); 236 | 237 | if ( ! empty( $content ) ) { 238 | echo '
' . apply_filters( 'the_content', $content ) . '
'; 239 | } 240 | 241 | do_action( 'genesis_404_after_content' ); 242 | 243 | echo '
'; 244 | } 245 | 246 | /** 247 | * Echo 404 loop markup as HTML5. 248 | * 249 | * @since 1.3.0 250 | * 251 | * @param string $title Page title. 252 | * @param string $content Page content. 253 | */ 254 | protected function loop_html5( $title, $content ) { 255 | echo '
'; 256 | 257 | if ( ! empty( $title ) ) { 258 | echo '

' . esc_attr( $title ) . '

'; 259 | } 260 | 261 | do_action( 'genesis_404_before_content' ); 262 | 263 | if ( ! empty( $content ) ) { 264 | echo '
' . apply_filters( 'the_content', $content ) . '
'; 265 | } 266 | 267 | do_action( 'genesis_404_after_content' ); 268 | 269 | echo '
'; 270 | } 271 | 272 | /** 273 | * Set the custom genesis layout. 274 | * 275 | * @since 1.5.0 276 | * @author Joshua David Nelson, josh@joshuadnelson.com 277 | * 278 | * @param string $layout The current layout. 279 | * 280 | * @return string $layout The modified layout. 281 | */ 282 | public function custom_layout( $layout ) { 283 | $layout_404 = genesis_get_option( 'genesis_layout', 'genesis-404' ); 284 | 285 | // Return the original layout if 'default' is selected 286 | if ( $layout_404 == 'default' ) 287 | return $layout; 288 | 289 | // Return the custom layout 290 | return $layout_404; 291 | 292 | } 293 | 294 | /** 295 | * Search shortcode. 296 | * 297 | * @since 1.1.0 298 | * @author Bill Erickson 299 | */ 300 | public function search_shortcode() { 301 | return ''; 302 | } 303 | 304 | /** 305 | * Customizer settings 306 | * 307 | * @since 1.6.0 308 | */ 309 | public function customizer_settings( array $config ) { 310 | $config['genesis-404'] = array( 311 | 'active_callback' => false, 312 | 'title' => __( '404 Page Settings', 'genesis-404' ), 313 | 'description' => '', 314 | 'settings_field' => 'genesis-404', 315 | 'control_prefix' => 'genesis-404', 316 | 'sections' => array( 317 | 'genesis_404' => array( 318 | 'title' => __( '404 Page', 'genesis-404' ), 319 | 'panel' => 'genesis-404', 320 | 'controls' => array( 321 | 'title' => array( 322 | 'label' => __( 'Page Title', 'genesis-404' ), 323 | 'section' => 'genesis_404', 324 | 'type' => 'text', 325 | ), 326 | 'content' => array( 327 | 'label' => __( 'Content', 'genesis-404' ), 328 | 'section' => 'genesis_404', 329 | 'type' => 'textarea', 330 | ), 331 | 'genesis_layout' => array( 332 | 'label' => __( 'Layout', 'genesis-404' ), 333 | 'section' => 'genesis_404', 334 | 'type' => 'select', 335 | 'choices' => genesis_get_layouts_for_customizer(), 336 | 'settings' => array( 337 | 'default' => '', 338 | ), 339 | 340 | ) 341 | ) 342 | ) 343 | ) 344 | ); 345 | return $config; 346 | } 347 | } 348 | --------------------------------------------------------------------------------