thereIsAUserSpecified404Page($dest404page)) { // get the user specified 404 page. $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($dest404page, 0, null, $options); // if the last part of the URL does not match the custom 404 page then // don't update the URL. if (!$f->endsWithCaseSensitive($permalink['link'], $_SERVER['REQUEST_URI']) && $permalink['status'] != 'trash') { $shouldUpdateURL = false; $debugMessage .= "do not update (not on custom 404 page (" . $permalink['link'] . ")), "; } else { $debugMessage .= "ok to update (displaying custom 404 page (" . $permalink['link'] . ")), "; } } else { // the 404 page is the default 404 page. so we shouldn't change the URL. $shouldUpdateURL = false; $debugMessage .= "do not update (no custom 404 page specified), "; } $content = ''; if ($shouldUpdateURL) { // replace the current URL with the user's actual requested URL. $requestedURL = $_REQUEST[$updateURLCookieName]; $userFriendlyURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $requestedURL; $content .= "window.history.replaceState({}, null, '" . $userFriendlyURL . "');\n"; $debugMessage .= "Updating the URL from " . $_SERVER['REQUEST_URI'] . " to " . $userFriendlyURL . ", "; } if ($content != '') { $content = '\n\n"; echo $content; } $debugMessage .= "is404: " . is_404() . ", " . esc_html('auto_redirects: ' . $options['auto_redirects'] . ', auto_score: ' . $options['auto_score'] . ', auto_cats: ' . $options['auto_cats'] . ', auto_tags: ' . $options['auto_tags'] . ', dest404page: ' . $options['dest404page']) . ", "; $debugMessage .= "is_single(): " . is_single() . " | " . "is_page(): " . is_page() . " | is_feed(): " . is_feed() . " | is_trackback(): " . is_trackback() . " | is_preview(): " . is_preview(); $abj404logging->debugMessage("updateURLbarIfNecessary: " . $debugMessage); } /** * @param array $atts */ static function shortcodePageSuggestions( $atts ) { $abj404logic = ABJ_404_Solution_PluginLogic::getInstance(); $abj404spellChecker = ABJ_404_Solution_SpellChecker::getInstance(); $f = ABJ_404_Solution_Functions::getInstance(); // Attributes $atts = shortcode_atts( array( ), $atts ); $options = $abj404logic->getOptions(); $content = "\n\n"; // get the slug that caused the 404 from the session. $urlRequest = ''; $cookieName = ABJ404_PP . '_REQUEST_URI'; if (isset($_COOKIE[$cookieName]) && !empty($_COOKIE[$cookieName])) { $urlRequest = esc_url($f->regexReplace('\?.*', '', esc_url($_COOKIE[$cookieName]))); // delete the cookie because the request was a one-time thing. // we use javascript to delete the cookie because the headers have already been sent. $content .= " \n"; } // we delete the UPDATE_URL cookie here, where the shortcode is used so that it won't // get deleted too early if multiple redirects happen. $updateURLCookieName = ABJ404_PP . '_REQUEST_URI'; $updateURLCookieName .= '_UPDATE_URL'; if (isset($_COOKIE[$updateURLCookieName]) && !empty($_COOKIE[$updateURLCookieName])) { // delete the cookie since we're done with it. it's a one-time use thing. $content .= " \n"; } if (array_key_exists(ABJ404_PP, $_REQUEST) && isset($_REQUEST[ABJ404_PP]) && array_key_exists($cookieName, $_REQUEST[ABJ404_PP]) && isset($_REQUEST[ABJ404_PP][$cookieName])) { $urlRequest = $_REQUEST[ABJ404_PP][$cookieName]; } if ($urlRequest == '') { // if no 404 was detected then we don't offer any suggestions return "\n"; } $urlSlugOnly = $abj404logic->removeHomeDirectory($urlRequest); $permalinkSuggestionsPacket = $abj404spellChecker->findMatchingPosts($urlSlugOnly, @$options['suggest_cats'], @$options['suggest_tags']); $permalinkSuggestions = $permalinkSuggestionsPacket[0]; $rowType = $permalinkSuggestionsPacket[1]; // allow some HTML. $content .= '
' . "\n"; $content .= wp_kses_post($options['suggest_title']) . "\n"; $currentSlug = $abj404logic->removeHomeDirectory( $f->regexReplace('\?.*', '', urldecode($_SERVER['REQUEST_URI']))); $displayed = 0; $commentPartAndQueryPart = $abj404logic->getCommentPartAndQueryPartOfRequest(); foreach ($permalinkSuggestions as $idAndType => $linkScore) { $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($idAndType, $linkScore, $rowType, $options); // only display the suggestion if the score is high enough // and if we're not currently on the page we're about to suggest. if ($permalink['score'] >= $options['suggest_minscore'] && basename($permalink['link']) != $currentSlug) { if ($displayed == 0) { //
    $content .= wp_kses_post($options['suggest_before']); } //
  1. $content .= wp_kses_post($options['suggest_entrybefore']); $content .= "" . esc_attr($permalink['title']) . ""; // display the score after the page link if (is_user_logged_in() && current_user_can('manage_options')) { $content .= " (" . esc_html($permalink['score']) . ")"; } //
  2. $content .= wp_kses_post(@$options['suggest_entryafter']) . "\n"; $displayed++; if ($displayed >= $options['suggest_max']) { break; } } else { break; } } if ($displayed >= 1) { //
$content .= wp_kses_post($options['suggest_after']) . "\n"; } else { $content .= wp_kses_post($options['suggest_noresults']); } $content .= "\n
"; $content .= "\n\n"; return $content; } } add_shortcode('abj404_solution_page_suggestions', 'ABJ_404_Solution_ShortCode::shortcodePageSuggestions');