commit cf03c388c3154ac4ae0ccae6be8c30ed1c6206a1 Author: d5admin Date: Mon Nov 16 12:20:03 2026 -0500 Initial import of 404 Enhacer diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17d1c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ +dist/ +.kilocode/ +.env +.env.* +*.local +.DS_Store diff --git a/404-enhancer.php b/404-enhancer.php new file mode 100644 index 0000000..e299f93 --- /dev/null +++ b/404-enhancer.php @@ -0,0 +1,54 @@ + 'administrator', 'number' => 1, 'fields' => 'ID' ) )[0]; +} +wp_set_current_user( $admin_id ); + +$_POST['s'] = 'hello'; +$_POST['nonce'] = wp_create_nonce( 'fe_admin_nonce' ); +$_REQUEST['nonce'] = $_POST['nonce']; +$_REQUEST['s'] = $_POST['s']; +$_REQUEST['action'] = 'fe_search_posts'; + +FE_Settings::ajax_search_posts(); // Echoes JSON and dies. diff --git a/_cli_debug.php b/_cli_debug.php new file mode 100644 index 0000000..987b571 --- /dev/null +++ b/_cli_debug.php @@ -0,0 +1,19 @@ +set_404(); +echo "is_404: " . var_export( is_404(), true ) . "\n"; +echo "plugin active: " . var_export( is_plugin_active( '404-enhancer/404-enhancer.php' ), true ) . "\n"; +echo "template_include filter result: " . apply_filters( 'template_include', 'x' ) . "\n"; +ob_start(); +include dirname( __DIR__ ) . '/templates/404.php'; +$html = ob_get_clean(); +echo "rendered len=" . strlen( $html ) . "\n"; +echo substr( $html, 0, 300 ) . "\n"; diff --git a/_cli_render.php b/_cli_render.php new file mode 100644 index 0000000..9bdfd97 --- /dev/null +++ b/_cli_render.php @@ -0,0 +1,48 @@ +set_404(); +status_header( 404 ); + +update_option( 'fe_custom_message', '

Sorry, we moved things around.

' ); +update_option( 'fe_enabled_post_types', array( 'post', 'page' ) ); +update_option( 'fe_suggestions_per_page', 3 ); + +ob_start(); +include __DIR__ . '/templates/404.php'; +$html = ob_get_clean(); + +$fail = 0; +function check( $label, $cond, $extra = '' ) { + global $fail; + if ( ! $cond ) { + $fail++; + } + printf( "%s %-52s %s\n", $cond ? 'PASS' : 'FAIL', $label, $extra ); +} + +check( 'renders without fatal', strlen( $html ) > 500, 'len=' . strlen( $html ) ); +check( 'has .fe-404 wrapper', false !== strpos( $html, 'class="fe-404"' ) ); +check( 'has heading', false !== strpos( $html, 'fe-404-heading' ) ); +check( 'shows requested path', false !== strpos( $html, '/this-page-does-not-exist-2024/' ) ); +check( 'shows custom message', false !== strpos( $html, 'Sorry, we moved things around.' ) ); +check( 'has search form', false !== strpos( $html, 'fe-search-form' ) && false !== strpos( $html, 'name="s"' ) ); +check( 'search prefilled from URL tokens', false !== strpos( $html, 'value="this does exist 2024"' ), '' ); +check( 'has did-you-mean or sections container', false !== strpos( $html, 'fe-did-you-mean' ) || false !== strpos( $html, 'fe-section' ) ); +check( 'stylesheet enqueued on 404', wp_style_is( 'fe-404', 'enqueued' ), '' ); +check( 'no PHP warnings in output', false === strpos( $html, 'Warning:' ) && false === strpos( $html, 'Fatal error' ) && false === strpos( $html, 'Notice:' ) ); + +echo $fail ? "\nRENDER RESULT: $fail FAILURES\n" : "\nRENDER RESULT: ALL PASS\n"; +exit( $fail ? 1 : 0 ); diff --git a/_cli_test.php b/_cli_test.php new file mode 100644 index 0000000..2802a79 --- /dev/null +++ b/_cli_test.php @@ -0,0 +1,113 @@ + 'administrator', 'number' => 1, 'fields' => 'ID' ) )[0]; +} +wp_set_current_user( $admin_id ); + +$fail = 0; +function check( $label, $cond, $extra = '' ) { + global $fail; + if ( ! $cond ) { + $fail++; + } + printf( "%s %-52s %s\n", $cond ? 'PASS' : 'FAIL', $label, $extra ); +} + +// 1. Activation. +$already = is_plugin_active( '404-enhancer/404-enhancer.php' ); +if ( ! $already ) { + $result = activate_plugin( '404-enhancer/404-enhancer.php' ); + check( 'activate_plugin no WP_Error', ! is_wp_error( $result ), is_wp_error( $result ) ? $result->get_error_message() : '' ); +} +check( 'plugin active', is_plugin_active( '404-enhancer/404-enhancer.php' ) ); +check( 'post types option exists', is_array( get_option( 'fe_enabled_post_types' ) ), json_encode( get_option( 'fe_enabled_post_types' ) ) ); +check( 'per page option exists', is_numeric( get_option( 'fe_suggestions_per_page' ) ) ); + +// 2. Classes loaded. +check( 'FE_Settings loaded', class_exists( 'FE_Settings' ) ); +check( 'FE_Suggestions loaded', class_exists( 'FE_Suggestions' ) ); +check( 'FE_Template loaded', class_exists( 'FE_Template' ) ); +check( 'FE_Updater loaded', class_exists( 'FE_Updater' ) ); + +// 3. Options round-trip with sanitizers. +update_option( 'fe_custom_message', '

Hello 404

' ); +check( 'message saved', get_option( 'fe_custom_message' ) !== false ); +check( 'per page sanitize via register', FE_Settings::sanitize_per_page( 99 ) === 24 ); +check( 'post types sanitize', FE_Settings::sanitize_post_types( array( 'post', 'evil