Updated the plugin URI and author information in the 404 Enhancer plugin file, and updated the version number from 0.3 to 0.4. Also added new entries to the .gitignore file to ignore .kilocode/, .env, .env.*, *.local, and .DS_Store files.

This commit is contained in:
2026-11-16 12:40:26 -05:00
parent cf03c388c3
commit 78034d533a
8 changed files with 23 additions and 249 deletions
+3 -3
View File
@@ -1,12 +1,12 @@
<?php
/**
* Plugin Name: 404 Enhancer
* Plugin URI: https://example.com/404-enhancer
* Plugin URI: https://gitea.serverresources.info/d5admin/404-enhancer
* Description: Enhances the 404 page with a custom message, featured image, hand-picked content, a search form, URL-based suggestions, cross-links and a "did you mean" hint.
* Version: 0.3
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: Your Name
* Author: Duane Hass
* Text Domain: 404-enhancer
* Domain Path: /languages
*
@@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'FE_VERSION', '0.3' );
define( 'FE_VERSION', '0.4' );
define( 'FE_PLUGIN_FILE', __FILE__ );
define( 'FE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'FE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
-26
View File
@@ -1,26 +0,0 @@
<?php
/**
* Temporary CLI test for the FE_Settings AJAX endpoint. Run as its own process
* because wp_send_json_* calls wp_die. NOT part of the plugin. Delete after running.
*/
error_reporting( E_ALL );
ini_set( 'display_errors', '0' ); // Keep output pure JSON.
define( 'WP_USE_THEMES', false );
define( 'DOING_AJAX', true );
require dirname( __DIR__, 3 ) . '/wp-load.php';
$admin_id = 1;
if ( ! get_userdata( $admin_id ) ) {
$admin_id = (int) get_users( array( 'role' => '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.
-19
View File
@@ -1,19 +0,0 @@
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
define( 'WP_USE_THEMES', true );
$_SERVER['REQUEST_URI'] = '/this-page-does-not-exist-2024/';
$_SERVER['REQUEST_METHOD'] = 'GET';
require dirname( __DIR__, 3 ) . '/wp-load.php';
echo "loaded WP " . get_bloginfo( 'version' ) . "\n";
echo "stylesheet: " . get_stylesheet() . "\n";
echo "template: " . get_template() . "\n";
$GLOBALS['wp_query']->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";
-48
View File
@@ -1,48 +0,0 @@
<?php
/**
* Temporary CLI render test: boots WordPress with themes and renders templates/404.php
* as if a visitor hit a missing URL. NOT part of the plugin. Delete after running.
*/
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
define( 'WP_USE_THEMES', true );
$_SERVER['REQUEST_URI'] = '/this-page-does-not-exist-2024/';
$_SERVER['REQUEST_METHOD'] = 'GET';
require dirname( __DIR__, 3 ) . '/wp-load.php';
$GLOBALS['wp_query']->set_404();
status_header( 404 );
update_option( 'fe_custom_message', '<p>Sorry, we moved things around.</p>' );
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 );
-113
View File
@@ -1,113 +0,0 @@
<?php
/**
* Temporary CLI smoke test for 404 Enhancer. Boots WordPress and exercises the plugin.
* NOT part of the plugin. Delete after running.
*/
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
define( 'WP_USE_THEMES', false );
define( 'DOING_AJAX', true ); // Before wp-load so WPAjaxDieStopException exists.
require dirname( __DIR__, 3 ) . '/wp-load.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
// Act as the admin user so capability checks pass in CLI.
$admin_id = 1;
if ( ! get_userdata( $admin_id ) ) {
$admin_id = (int) get_users( array( 'role' => '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', '<p>Hello <script>alert(1)</script>404</p>' );
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<script>', '' ) ) === array( 'post' ) );
update_option( 'fe_enabled_post_types', array( 'post', 'page' ) );
update_option( 'fe_suggestions_per_page', 3 );
check( 'enabled types getter', FE_Settings::get_enabled_post_types() === array( 'post', 'page' ) );
check( 'per page getter', FE_Settings::get_per_page() === 3 );
// 4. Suggestions against the real DB.
$tokens = FE_Suggestions::tokenize( '/hello-world/' );
check( 'tokenize hello-world', $tokens === array( 'hello', 'world' ), json_encode( $tokens ) );
$related = FE_Suggestions::get_related( $tokens, array( 'post', 'page' ), 5 );
check( 'get_related returns array', is_array( $related ), 'count=' . count( $related ) );
foreach ( $related as $p ) {
echo ' related: [' . $p->post_type . '] ' . $p->post_title . ' -> ' . get_permalink( $p ) . "\n";
}
$random = FE_Suggestions::get_random( 'post', 3 );
check( 'get_random returns array', is_array( $random ), 'count=' . count( $random ) );
$ids = array_slice( wp_list_pluck( get_posts( array( 'post_type' => 'any', 'posts_per_page' => 5, 'fields' => 'ids' ) ), 'ID' ), 0, 3 );
$ids = array_map( 'intval', get_posts( array( 'post_type' => array( 'post', 'page' ), 'posts_per_page' => 3, 'fields' => 'ids' ) ) );
$featured = FE_Suggestions::get_featured( $ids, array( 'post', 'page' ) );
check( 'get_featured returns array', is_array( $featured ), 'ids=' . json_encode( $ids ) . ' count=' . count( $featured ) );
$did = FE_Suggestions::get_did_you_mean( 'hello-wrld', array( 'post', 'page' ) );
check( 'did_you_mean returns post|null', null === $did || $did instanceof WP_Post, null === $did ? 'null' : $did->post_name );
$cross = array();
if ( ! empty( $related ) ) {
$cross = FE_Suggestions::get_cross_links( $related[0]->ID, array( 'post', 'page' ), array( $related[0]->ID ), 3 );
check( 'get_cross_links returns array', is_array( $cross ), 'count=' . count( $cross ) );
} else {
check( 'get_cross_links skipped (no related)', true );
}
// 5. Updater no-op when unconfigured (must not fatal, must not inject).
$transient = new stdClass();
$transient->checked = array( '404-enhancer/404-enhancer.php' => '0.3' );
$transient->response = array();
$out = FE_Updater::check_for_updates( $transient );
check( 'updater no-op unconfigured', empty( $out->response ) );
// 6. Template include filter returns plugin template on 404.
$q = $GLOBALS['wp_query'];
$q->set_404();
$path = FE_Template::include_template( '/theme/404.php' );
check( 'template filter path', false !== strpos( $path, 'templates/404.php' ), $path );
$filtered = apply_filters( 'fe_404_template', '/custom/override.php' );
check( 'fe_404_template filter works', $filtered === '/custom/override.php' );
// 7. Settings page renders without fatal (admin_init never fires in CLI, so register manually;
// admin template functions are only loaded in admin context, so require them too).
require_once ABSPATH . 'wp-admin/includes/template.php';
FE_Settings::register_settings();
ob_start();
FE_Settings::render_settings_page();
$html = ob_get_clean();
check( 'settings page renders', false !== strpos( $html, 'fe_featured_image_id' ) && false !== strpos( $html, 'fe-post-search' ), 'len=' . strlen( $html ) );
// 8. AJAX handler is exercised by _cli_ajax.php in a separate process (wp_send_json* terminates).
echo $fail ? "\nRESULT: $fail FAILURES\n" : "\nRESULT: ALL PASS\n";
exit( $fail ? 1 : 0 );
-36
View File
@@ -1,36 +0,0 @@
<?php
define('ABSPATH', '/tmp/');
function absint($v){ return abs((int)$v); }
function sanitize_key($k){ return preg_replace('/[^a-z0-9_\-]/', '', strtolower($k)); }
function sanitize_title($t){ return strtolower(preg_replace('/[^a-z0-9]+/i', '-', trim($t))); }
function get_post_types($args=array(), $output='names'){ return array('post','page','attachment'); }
$dir = __DIR__ . '/includes/';
require $dir . 'class-fe-suggestions.php';
require $dir . 'class-fe-settings.php';
$fail = 0;
function check($label, $actual, $expected) {
global $fail;
$ok = $actual === $expected;
if (!$ok) $fail++;
printf("%s %-58s got=%s\n", $ok ? 'PASS' : 'FAIL', $label, json_encode($actual));
}
check('tokenize blog post', FE_Suggestions::tokenize('/blog/my-great-post-2024/'), array('blog','great','post','2024'));
check('tokenize strips ext+stopword', FE_Suggestions::tokenize('/products/sale-2024/index.html'), array('products','sale','2024'));
check('tokenize simple', FE_Suggestions::tokenize('/foo-bar/'), array('foo','bar'));
check('tokenize digit split', FE_Suggestions::tokenize('/top10tips/'), array('top','tips'));
check('tokenize empty', FE_Suggestions::tokenize('/'), array());
check('search term', FE_Suggestions::search_term_from_tokens(array('great','post')), 'great post');
check('slug from path', FE_Suggestions::slug_from_path('/a/b/My Page v2/'), 'my-page-v2');
check('slug from root', FE_Suggestions::slug_from_path('/'), '');
check('per_page clamp low', FE_Settings::sanitize_per_page(0), 1);
check('per_page clamp high', FE_Settings::sanitize_per_page(99), 24);
check('per_page normal', FE_Settings::sanitize_per_page('7'), 7);
check('post types filter', FE_Settings::sanitize_post_types(array('post','bogus','page','')), array('post','page'));
check('post ids sanitize', FE_Settings::sanitize_post_ids(array('5','0','abc','5','12')), array(5,12));
check('lev close', levenshtein('my-pge', 'my-page') <= max(2, (int)(strlen('my-pge')/3)), true);
check('lev far', levenshtein('totally-different', 'my-page') <= max(2, (int)(strlen('totally-different')/3)), false);
exit($fail ? 1 : 0);
+16
View File
@@ -106,6 +106,21 @@ final class FE_Suggestions {
if ( empty( $tokens ) ) {
return array();
}
// WP's default search ANDs the words; for fuzzy URL matching we want OR
// recall, then rank by matched tokens in PHP below.
$or_search = function ( $search, $query ) use ( $tokens ) {
global $wpdb;
if ( ! $query->is_search() ) {
return $search;
}
$likes = array();
foreach ( $tokens as $token ) {
$like = '%' . $wpdb->esc_like( $token ) . '%';
$likes[] = $wpdb->prepare( "($wpdb->posts.post_title LIKE %s OR $wpdb->posts.post_content LIKE %s)", $like, $like );
}
return ' AND (' . implode( ' OR ', $likes ) . ') ';
};
add_filter( 'posts_search', $or_search, 10, 2 );
$query = new WP_Query(
array(
's' => implode( ' ', $tokens ),
@@ -116,6 +131,7 @@ final class FE_Suggestions {
'update_post_term_cache' => false,
)
);
remove_filter( 'posts_search', $or_search, 10 );
if ( empty( $query->posts ) ) {
return array();
}
+4 -4
View File
@@ -40,9 +40,9 @@ final class FE_Updater {
*/
private static function config() {
$config = array(
'api_url' => defined( 'FE_GITEA_API_URL' ) ? (string) FE_GITEA_API_URL : '',
'owner' => defined( 'FE_GITEA_OWNER' ) ? (string) FE_GITEA_OWNER : '',
'repo' => defined( 'FE_GITEA_REPO' ) ? (string) FE_GITEA_REPO : '',
'api_url' => defined( 'FE_GITEA_API_URL' ) ? (string) FE_GITEA_API_URL : 'https://gitea.serverresources.info/api/v1',
'owner' => defined( 'FE_GITEA_OWNER' ) ? (string) FE_GITEA_OWNER : 'd5admin',
'repo' => defined( 'FE_GITEA_REPO' ) ? (string) FE_GITEA_REPO : '404-enhancer',
'token' => defined( 'FE_GITEA_TOKEN' ) ? (string) FE_GITEA_TOKEN : '',
);
/**
@@ -203,7 +203,7 @@ final class FE_Updater {
'name' => __( '404 Enhancer', '404-enhancer' ),
'slug' => FE_SLUG,
'version' => $release['version'],
'author' => 'Your Name',
'author' => 'Duane Hass',
'homepage' => $release['html_url'],
'download_link' => $release['package'],
'tested' => get_bloginfo( 'version' ),