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(preg_replace('/\?.*/', '', 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"; } 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( esc_url(preg_replace('/\?.*/', '', urldecode(esc_url($_SERVER['REQUEST_URI']))))); $displayed = 0; foreach ($permalinkSuggestions as $idAndType => $linkScore) { $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($idAndType, $linkScore, $rowType); // 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');