Hi there!
I recently updated my site to PHP 8.2 and I’m now receiving a fatal error page when I go to any URL that typically Smart404 would have helped with.
Can’t be 100% certain it’s due to the update (you’re more savvy with this than I am, to be sure), but wanted to share regardless just in case.
Here’s the error:
PHP Fatal error: Uncaught Error: Call to undefined function create_function() in /home/willolov/public_html/wp-content/plugins/smart-404/smart404.php:57\nStack trace:\n#0 /home/willolov/public_html/wp-includes/class-wp-hook.php(324): smart404_redirect()\n#1 /home/willolov/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#2 /home/willolov/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()\n#3 /home/willolov/public_html/wp-includes/template-loader.php(13): do_action()\n#4 /home/willolov/public_html/wp-blog-header.php(19): require_once('...')\n#5 /home/willolov/public_html/index.php(17): require('...')\n#6 {main}\n thrown in /home/willolov/public_html/wp-content/plugins/smart-404/smart404.php on line 57\n
I’ve now deactivated the plugin, so that my visitors at least get to a 404 page instead of a fatal error page… but sure would love a fix!
Many thanks
]]>This plugin seems to do exactly what I need, but I’m hesitant to install due to its age. Can anyone verify whether the plugin works with the current version of WordPress?
]]>Hi all,
@michaeltyson gave me commit access a long time ago and I’d forgotten to do anything with it. Just checked on plugin and merged in that fix for the deprecation notice from @heddesheimer, thanks for that!
I’ve added a GitHub repo for easier reporting and tracking of issues or feature requests, please feel free to add in whatever comes to mind there.
I gave 0.6 a quick test and expected smart redirection behaviour working as I expect it to, but please let me know any issues you discover.
Cheers,
Leon
]]>A big thank you to Marian Heddesheimer!
This solves the problem. The Smart 4040 plugin is an essential plugin for me, so I’m very grateful!
]]>When I activate this plugin I get:
Notice: has_cap was called with an argument that is deprecated since version 2.0!
Since my client likes the plugin, I fixed this part of the plugin. Maybe it’s helpful for other users too:
Look for this line in the code:
add_options_page( ‘Smart 404’, ‘Smart 404’, 5, __FILE__, ‘smart404_options_page’ );
replace it with this:
add_options_page( ‘Smart 404’, ‘Smart 404’, ‘manage_options’, __FILE__, ‘smart404_options_page’ );
It’s just replacing the deprecated number argument “5” with a string “manage_options” which is the logical capability you need to add an options page.
Please let me know if I may be wrong or if it can be improved.
]]>Look at your PHP error log. If you see references to things like “tter.name” then Search Everything is probably to blame. Disable it and try again.
]]>This patch tries to improve the abandoned Smart404 plugin. The main change is to not redirect if a post or page matches the request unless only one post or page matches. This is different from the default behavior where if only one post matches but many pages match, the post will still be redirected to. Other tweaks are to remove unnecessary exit commands, and to try to to exclude sticky posts from the recommendation list (although this seems to fail in WP3.5).
--- /tmp/smart-404/smart404.php 2010-09-14 14:22:33.000000000 -0500
+++ smart404.php 2012-12-20 09:53:26.000000000 -0600
@@ -3,7 +3,7 @@
Plugin Name: Smart 404
Plugin URI: https://atastypixel.com/blog/wordpress/plugins/smart-404/
Description: Rescue your viewers from site errors! When content cannot be found, Smart 404 will use the current URL to attempt to find matching content, and redirect to it automatically. Smart 404 also supplies template tags which provide a list of suggestions, for use on a 404.php template page if matching content can't be immediately discovered.
-Version: 0.5
+Version: 0.5 PATCHED: don't redirect when one page matches if multiple posts have also matched, try to avoid sticky posts in recommendations
Author: Michael Tyson
Author URI: https://atastypixel.com/blog/
*/
@@ -75,10 +75,9 @@
switch ( $group ) {
case "posts":
// Search for posts with exact name, redirect if one found
- $posts = get_posts( array( "name" => $search, "post_type" => "post" ) );
+ $posts = get_posts( array( "name" => $search, "post_type" => "post" ) );
if ( count( $posts ) == 1 ) {
wp_redirect( get_permalink( $posts[0]->ID ) . $get_params, 301 );
- exit();
}
break;
@@ -87,7 +86,6 @@
$posts = get_posts( array( "name" => $search, "post_type" => "page" ) );
if ( count( $posts ) == 1 ) {
wp_redirect( get_permalink( $posts[0]->ID ) . $get_params, 301 );
- exit();
}
break;
@@ -96,7 +94,6 @@
$tags = get_tags( array ( "name__like" => $search ) );
if ( count($tags) == 1) {
wp_redirect(get_tag_link($tags[0]->term_id) . $get_params, 301);
- exit();
}
break;
@@ -105,7 +102,6 @@
$categories = get_categories( array ( "name__like" => $search ) );
if ( count($categories) == 1) {
wp_redirect(get_category_link($categories[0]->term_id) . $get_params, 301);
- exit();
}
break;
}
@@ -113,28 +109,22 @@
// Now perform general search
foreach ( $search_groups as $group ) {
+ #We could do away with this switch if the stored option was singular
switch ( $group ) {
case "posts":
$posts = smart404_search($search, "post");
- if ( count( $posts ) == 1 ) {
- wp_redirect( get_permalink( $posts[0]->ID ) . $get_params, 301 );
- exit();
- }
-
- $GLOBALS["__smart404"]["suggestions"] = array_merge ( (array)$GLOBALS["__smart404"]["suggestions"], $posts );
+ $GLOBALS["__smart404"]["suggestions"] = array_merge ( (array)$GLOBALS["__smart404"]["suggestions"], $posts );
break;
case "pages":
$posts = smart404_search($search, "page");
- if ( count( $posts ) == 1 ) {
- wp_redirect( get_permalink( $posts[0]->ID ) . $get_params, 301 );
- exit();
- }
-
- $GLOBALS["__smart404"]["suggestions"] = array_merge ( (array)$GLOBALS["__smart404"]["suggestions"], $posts );
- break;
+ $GLOBALS["__smart404"]["suggestions"] = array_merge ( (array)$GLOBALS["__smart404"]["suggestions"], $posts );
+ break;
}
}
+ if( count($GLOBALS["__smart404"]["suggestions"]) == 1 ){
+ wp_redirect( get_permalink( $GLOBALS["__smart404"]["suggestions"][0] ) . $get_params, 301 );
+ }
}
@@ -149,7 +139,15 @@
*/
function smart404_search($search, $type) {
$search_words = trim(preg_replace( "@[_-]@", " ", $search));
- $posts = get_posts( array( "s" => $search_words, "post_type" => $type ) );
+ $posts = get_posts( array( "s" => $search_words,
+ "post_type" => $type,
+
+ #Alas, neither of these seem to work in 3.5
+ 'ignore_sticky_posts' => true,
+# 'post__not_in' => get_option('sticky_posts')
+ )
+ );
+
if ( count( $posts ) > 1 ) {
// See if search phrase exists in title, and prioritise any single match
$titlematches = array();
A work-around for the failure to exclude sticky posts is to do so in your 404 template e.g;
<?php if (smart404_loop()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php #Work-around get_posts ignoring post__not_in and ignore_sticky_posts
if( ! is_sticky() ){ ?>
<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
<small><?php the_excerpt(); ?></small>
<?php }
endwhile; ?>
<?php endif; ?>
</div>
<?php } ?>
]]>
If you place /- at the end of your url, you will receive:
Warning: strpos() [function.strpos]: Empty delimiter in […] /wp-content/plugins/smart-404/smart404.php on line 157
I did a Google Search for web sites that have the Smart 404
plugin installed, and they are receiving the same warnings:
https://www.beautytalk.com.hk/-
https://www.cafezones.com/-
https://www.educationalgamesrio.com/-
I was wondering if the redirects are 301 redirects, as that is what I am after. Thanks!
]]>Hello,
The suggestion on page 404 is not showing.
I have put <?php smart404_suggestions(); ?>
I recently posted a question in the WordPress support forums asking how to override a WordPress page address by adding a ?p= parameter to it, to target ClickBank affiliate hoplinks. After a little more testing I’ve discovered that WordPress already supports exactly the functionality I want, but the Smart404 plugin causes a redirection loop when I use it.
With Smart404 disabled, a link like this:
https://confidentman.net/confident-man-ebook/?p=112
Displays:
https://confidentman.net/?p=112
Instead of:
https://confidentman.net/confident-man-ebook/
Which is exactly the behaviour I want.
But with Smart404 enabled on my site a get an error message from Firefox saying: “The page isn’t redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete.”
I have my permalinks set to: /%category%/%postname%
Anyone else noticed a redirection loop using Smart404 with ?p= ?
Thanks,
Graham
I just installed it on my new wp setup because I previously used it on my old blog.
1 Thing I do not like about the current version:
It searches all posts and pages for the url typed in, if it doesn’t find the keywords in any posts or pages, it shows a blank page. I’ve adjusted mine to default to the last post on the blog if a 404 should happen.
Unpredictable redirects do not save visitors from 404-page but confuse even the site owner.
Imagine what frustration it causes with searches, custom redirects and caching!
Why did not the guy just added smarttag, but decided to “improve” the site workflows? Who knows…
]]>Hi there
Just a silly question, where do the redirects get stored, so I can see all the URLS that are returning the 404?
]]>Hello,
I have just installed and activated the Smart 404 plugin. I have not detect any installation issues so far. However, my pages aren’t showing what the Smart 404 description said it would. Instead, I am getting the “Oops! This link appears to be broken” error, or a standard 404 error page, which I have been able to customize so far without any good luck. I’ve tried placing the two different code snippets in different parts (of course never at the same time) of the header.php file, but I still either get the 404 page, or the “Oops! This link appears to be broken” error. https://www.myshocker.com
Any ideas?
Thanks!
Nudo
I installed it, activated it and confirmed the default setting in admin.
But when I type a URL pointing nowhere, I still get the standard 404 page.
This plugin does a great job of finding relevant content based on the submitted URL. I noticed the smart404_redirect() had a slight issue with it. If it found exactly one search result within a specific search type (page, post, category or tag), it stopped doing any further searches and immediately redirected the visitor to the page it found.
I modified the function by commenting out all 4 instances of the following code. This resulted in the function going through all search categories and generating a complete list:
if ( count($tags) == 1) {
wp_redirect(get_tag_link($tags[0]->term_id) . $get_params, 301);
exit();
}
I also changed the smart404_suggestions() parameter from ‘flat’ to ‘list’ so the search results would come up in a bulleted list.
]]>I have a page on my site whose permalink is:
<mydomain>/blog/2009/07/team-bhp-harassment-for-new-joinees.html
Today I was checking my 404 logs, and I saw an entry like this:
<mydomain>/blog/2009/07/team-bhp-harassment-for-new-joinees.htm
Everything is correct except that it has a ‘l’ missing in the page extension.
But Smart 404 was not able to reroute it to the correct page.
And the worst part is, it did not even offer any “smart” suggestions!!!
Please help here… this seems to be a pretty basic problem!
Regards
Vijay
]]>When the smart 404 plugin is on, many short link stop to work when you have pretty links activated.
]]>While using Smart 404, if I type a url like:
apexprd.org/ice
it goes directly to:
apexprd.org/board-of-directors-study-session-notice
even though I have many pages about ice skating/hockey
In fact it works like that for any page where the end of the url is the same as the end of a valid url.
Is this the way it should work because I was under the impression that it should take ‘ice’ and search for it. If only one result then go to that page.
]]>