WordPress site URL changed; how to fix it without database access?

See Changing The Site URL « WordPress Codex for recovery instructions on how to reset the URLs without database access, i.e. by editing either the wp-config.php file or the theme’s functions.php file with FTP: 1) by adding lines to wp-config.php (which can be left in place): define(‘WP_HOME’,’http://example.com’); define(‘WP_SITEURL’,’http://example.com’); 2) or the theme’s functions.php file (but … Read more

Inner Join user tables to select users with roles

The Problems You risk SQL injection, with your current setup: $wpdb->users.display_name LIKE ‘$ltr%’ The following could also be a problematic part in your SQL query: AND $wpdb->usermeta.meta_value = %artist% i.e. using = instead of LIKE. You’re also missing the quotes: %\”artist\”%, to exclude e.g. bartist or fartist 😉 But you don’t need to construct this … Read more

What’s the proper way to sanitize checkbox value sent to the database

I would use the filter_var() function. It has some predefined filters that you can use depending on what kind of data you are expecting such as string, number, etc. So to sanitize for a number: $sanitizedNum = filter_var($yourVar, FILTER_SANITIZE_NUMBER_INT); For a string you would just change “_NUM_INT” to “_STRING”. Wrap those in a custom function … Read more

Change options table prefix only

This is actually not that hard, but you will have to excuse me for keeping it high level because this is just a stupid thing to do as all things which are security by obscurity. All you need to do is write your WPDB driver, which inherits the WPDB class. Place it in /wp-content/db.php file … Read more

How to combine multiple wp_insert_post into one in order to gain better performance

I would advise using wp_insert_post() and putting you text files into a CSV CSV Post Title,Post Content, “title”, “content”, “title”, “content”… PHP $path = “/posts.csv”; //require __DIR__ . “$path”; $file = fopen(__DIR__ . $path, ‘r’); while (($line = fgetcsv($file)) !== FALSE) { //$line is an array of the csv elements $post[“id”] = wp_insert_post( array( “post_title” … Read more

Duplicated site isn’t recognized as a site

Error is from the last command wp search-replace “${domain}” “test” –allow-root. Your WordPress site is not yet installed and you want to execute command which require WordPress to be installed. Earlier in script you are dropping test database and creating new one, but you have to fill it with WordPress tables. Without this tables WordPress … Read more