Code to remove authors with no posts connected to them

<?php /** * Plugin Name: Delete Non Authors */ function delete_non_authors() { global $wpdb; $non_authors = $wpdb->get_col( “SELECT DISTINCT $wpdb->users.ID FROM $wpdb->users LEFT JOIN $wpdb->posts ON $wpdb->users.ID = $wpdb->posts.post_author WHERE $wpdb->posts.ID IS NULL” ); foreach ($non_authors as $user_ID) wp_delete_user($user_ID); } register_activation_hook(__FILE__, ‘delete_non_authors’); ?> Drop this in a file, name it something like delete-non-authors.php, upload it … Read more

WordPress SQL injection

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, … Read more

WordPress SQL Issue not returning correct reselts

Here is my answer in code form: <?php // Customer Details $args = array( ‘blog_id’ => $GLOBALS[‘blog_id’], ‘role’ => ‘customer’, ‘meta_key’ => ‘last_name’, ‘meta_value’ => ”, ‘meta_compare’ => ”, ‘meta_query’ => array(), ‘date_query’ => array(), ‘include’ => array(), ‘exclude’ => array(), ‘orderby’ => ‘last_name’, ‘order’ => ‘ASC’, ‘offset’ => ”, ‘search’ => ”, ‘number’ => … Read more

Connect to MySQL using Windows Authentication

This is just bad security method. Because the only way you can connect to the mysql database is via that pc you use. Where is if you username/pwd, you can move the site to another server, etc. So Windows Authentication is a bad idea, too easy to overcome, and honestly just not that secure. Where … Read more

Help with a $wpdb MySQL Query

is this what you’re after? Using the “Relation” for the Meta Query, you can select multiple Meta Keys. You can change the “Compare” to any of the operations available for that function. (From the Codex) compare (string) – Operator to test. Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT … Read more

Many slow queries post_type = ‘attachment’;

This is bug #31071: media / post_mime_type related queries are very slow on larger sites. It should have been fixed for version 4.8 now. You can try it on a test site that is a mirror of your production site. There are some very interesting ideas in that bug discussion. See if you can use … Read more