Useful Snippets

Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

July 2020
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


Force WordPress security upgrade to latest minor version

Stanislav KhromovStanislav Khromov

Create a file in the WP root directory called force-minor-update.php and call it via your web browser.

Use this code:

require( dirname(__FILE__) . '/wp-load.php' );

//Clear transients
global $wpdb;
$sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_%'";
$clean = $wpdb->query( $sql );

//Clear object cache
wp_cache_flush();

//Attempt auto update
wp_maybe_auto_update();

Original source

PHP

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 3
  • Richard Benn
    Posted on

    Richard Benn Richard Benn

    Reply Author

    I speak CSS and PHP at the kindergarten level. Is there an existing plugin that can do the work?


  • DrLightman
    Posted on

    DrLightman DrLightman

    Reply Author

    If you want to use the underscore in like sql statement as a literal, you have to escape it, otherwise it works as a single character wildcard. Maybe there you have to escape with two backslashes since it’s inside a php string too.


  • Seven
    Posted on

    Seven Seven

    Reply Author

    Thank you, used your script to upgrade an old WordPress, from 4.8 to 4.8.9 without any problem. Sometimes you don’t want to upgrade an old website to the last WordPress version because it can break plugins or themes. Upgrading to the last minor version takes advantage of security and bug updates, without the risk off breaking the website.