function old_links_redirect() {
global $wpdb;
if (is_404()) {
$url = parse_url($_SERVER['REQUEST_URI']);
$path = $url['path'];
$path = str_replace('.html', '', $path);
$path = explode('/', $path);
$path = array_filter($path);
$path = array_merge($path, array());
$post_ID = $wpdb->get_row('SELECT wp_posts_ID FROM oldurls WHERE url = "' . fix_diacritics(urldecode($path[count($path) - 1])) . '" LIMIT 0,1');
if (!is_null($post_ID)) {
wp_redirect(get_post_permalink($post_ID->wp_posts_ID), 301);
exit;
} else {
$slug = NULL;
$slug_parts = explode('-', $path[count($path) - 1]);
if (is_numeric($slug_parts[0])) {
unset($slug_parts[0]);
}
$slug = sanitize_title(implode(' ', $slug_parts));
if (!is_null($slug)) {
$redirect_permalink = get_permalink(get_page_by_path($slug, OBJECT, 'post'));
if (!$redirect_permalink) {
$redirect_permalink = get_permalink(get_page_by_path(remove_stopwords($slug), OBJECT, 'post'));
}
if ($redirect_permalink) {
wp_redirect($redirect_permalink, 301);
exit;
}
}
}
}
}
add_action('template_redirect','old_links_redirect');
function disable_comment_url($fields) {
unset($fields['url']);
return $fields;
}
add_filter('comment_form_default_fields','disable_comment_url');
function my_opengraph_title($title) {
$title_parts = explode('|', $title);
unset($title_parts[count($title_parts) - 1]);
if (count($title_parts) === 0) {
return $title;
}
return implode('|', $title_parts);
}
add_filter('wpseo_opengraph_title', 'my_opengraph_title');
function wpartisan_set_no_found_rows(\WP_Query $wp_query) {
$wp_query->set('no_found_rows', true);
}
// add_filter('pre_get_posts', 'wpartisan_set_no_found_rows', 10, 1);
function wpartisan_set_found_posts($clauses, \WP_Query $wp_query) {
if ($wp_query->is_singular()) {
return $clauses;
}
global $wpdb;
$where = isset($clauses['where'] ) ? $clauses['where'] : '';
$join = isset($clauses['join']) ? $clauses['join'] : '';
$distinct = isset($clauses['distinct']) ? $clauses['distinct'] : '';
$wp_query->found_posts = $wpdb->get_var("SELECT $distinct COUNT(*) FROM {$wpdb->posts} $join WHERE 1=1 $where");
$posts_per_page = (!empty($wp_query->query_vars['posts_per_page']) ? absint($wp_query->query_vars['posts_per_page']) : absint(get_option('posts_per_page')));
$wp_query->max_num_pages = ceil($wp_query->found_posts / $posts_per_page);
return $clauses;
}
// add_filter('posts_clauses', 'wpartisan_set_found_posts', 10, 2);
function filter_comment_form_submit_button($submit_button, $args) {
$submit_before = '
';
return $submit_before . $submit_button;
};
add_filter('comment_form_submit_button', 'filter_comment_form_submit_button', 10, 2);