View more plugins'; } return array_merge( $links, $add_links ); } /** * Adds css HTML; echo $output; } /** * Adds jquery HTML; echo $output; } public function admin_title_check_ajax_handler() { // Verify nonce. Dies if cannot be verified. check_ajax_referer( 'atcheck_ajax_nonce', 'nonce' ); /** * Data validation and sanitization */ if ( ! isset( $_POST['title'] ) || ! isset( $_POST['id'] ) ) { wp_send_json_error( 'title or id not found' ); wp_die(); } $title_input = trim( stripslashes_deep( $_POST['title'] ) ); $title_input = sanitize_text_field( $title_input ); $id = intval( $_POST['id'] ); /** * Find posts matching the received title */ // try an exact match global $wpdb; $searchable_post_types = get_post_types( array('exclude_from_search' => false) ); $searchable_post_types = "'" . implode( "','", $searchable_post_types ) . "'"; $search = "SELECT id, post_title, post_status, post_name, post_type FROM {$wpdb->posts} WHERE post_title LIKE %s AND post_type IN ({$searchable_post_types}) AND ( post_status = 'publish' OR post_status = 'private' ) AND id <> %d ORDER BY post_title = %s DESC, post_title LIKE %s DESC, post_title ASC LIMIT 5"; $wp_prepare = $wpdb->prepare( $search, '%' . $title_input . '%', $id, $title_input, '%' . $title_input . '%' ); $matching_posts = $wpdb->get_results( $wp_prepare ); $output = ''; $output .= "
No content with titles similar to \"{$title_input}\" were found.
"; $output .= "No content with similar titles were found."; $output .= "