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; $search = "SELECT id, post_title, post_status, post_name, post_type FROM {$wpdb->posts} WHERE post_title LIKE %s 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"; $matching_posts = $wpdb->get_results( $wpdb->prepare( $search, '%' . $title_input . '%', $id, $title_input, $title_input . '%' ) ); $output = ''; $output .= "
"; $output .= ""; $output .= "
"; wp_send_json_success( $output ); // ajax handlers must die when finished. wp_die(); } } if ( is_admin() ) { $admin_title_check_plugin = new Admin_Title_Check_Plugin(); }