Plugin Directory

Changeset 2423998


Ignore:
Timestamp:
11/23/2020 11:19:49 PM (5 years ago)
Author:
joshf
Message:

Tested up to WordPress 5.6.

Location:
optimize-database
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • optimize-database/tags/1.0.4/optimize-database.php

    r1989405 r2423998  
    11<?php
    2 /*
    3 Plugin Name: Optimize Database
    4 Plugin URI: http://joshuafredrickson.com
    5 Description: Automatically optimize the database every day.
    6 Version: 1.0.3
    7 Author: Joshua Fredrickson
    8 Author URI: http://joshuafredrickson.com
    9 */
     2/**
     3 * Plugin Name: Optimize Database
     4 * Plugin URI: http://joshuafredrickson.com
     5 * Description: Automatically optimize the database every day.
     6 * Version: 1.0.4
     7 * Requires PHP: 5.6
     8 * Author: Joshua Fredrickson
     9 * Author URI: http://joshuafredrickson.com
     10 */
    1011
    11 register_activation_hook( __FILE__, 'op_optimize_plugin_activation' );
    12 register_deactivation_hook( __FILE__, 'op_optimize_plugin_deactivation' );
     12namespace OptimizeDatabase;
    1313
    14 add_action( 'op_optimize_cron', 'do_op_optimize_cron' );
     14use function add_action;
     15use function register_activation_hook;
     16use function register_deactivation_hook;
     17use function wp_next_scheduled;
     18use function wp_schedule_event;
    1519
    16 op_optimize_check_crons();
    17 
    18 function op_optimize_plugin_activation () {
    19     op_optimize_check_crons();
    20 }
    21 
    22 function op_optimize_plugin_deactivation () {
    23     // If our cron hook exists. remove it.
    24     if ( wp_next_scheduled( 'op_optimize_cron' ) ) {
    25         wp_clear_scheduled_hook( 'op_optimize_cron' );
     20/**
     21 * If the cron schedule doesn't yet exist, create it.
     22 */
     23function check_crons()
     24{
     25    if (! wp_next_scheduled('op_optimize_cron')) {
     26        wp_schedule_event(time(), 'daily', 'op_optimize_cron');
    2627    }
    2728}
    2829
    29 function op_optimize_check_crons() {
    30     // If our cron hook doesn't yet exist, create it.
    31     if ( ! wp_next_scheduled( 'op_optimize_cron' ) ) {
    32         wp_schedule_event( time(), 'daily', 'op_optimize_cron' );
     30/**
     31 * Plugin activation
     32 */
     33register_activation_hook(__FILE__, function () {
     34    \OptimizeDatabase\check_crons();
     35});
     36
     37/**
     38 * If the cron hook exists, remove it.
     39 */
     40register_deactivation_hook(__FILE__, function () {
     41    if (wp_next_scheduled('op_optimize_cron')) {
     42        wp_clear_scheduled_hook('op_optimize_cron');
    3343    }
    34 }
     44});
    3545
    36 function do_op_optimize_cron() {
    37 global $wpdb;
     46/**
     47 * Do the actual optimization.
     48 */
     49add_action('op_optimize_cron', function () {
     50    global $wpdb;
    3851
    3952    $sql = 'SHOW TABLE STATUS FROM ' . DB_NAME;
    40     $tables = $wpdb->get_results( $sql, ARRAY_A );
    41     foreach( $tables as $t ) {
    42         if( ! empty( $t['Data_free'] ) ) {
    43             $do_opt = $wpdb->query( "OPTIMIZE TABLE ".$t['Name'] );
     53    $tables = $wpdb->get_results($sql, ARRAY_A);
     54
     55    foreach ($tables as $t) {
     56        if (! empty($t['Data_free'])) {
     57            $wpdb->query("OPTIMIZE TABLE {$t['Name']}");
    4458        }
    4559    }
     60
    4661    return;
    47 }
     62});
     63
     64/**
     65 * Kick it all off.
     66 */
     67check_crons();
  • optimize-database/tags/1.0.4/readme.txt

    r1989405 r2423998  
    44Tags: database, optimize, cron, automatic
    55Requires at least: 3.7
    6 Tested up to: 5.0
     6Tested up to: 5.6
    77Stable tag: trunk
    88License: GPLv2 or later
     
    3131== Changelog ==
    3232
     33= 1.0.4 =
     34* Tested up to WordPress 5.6.
     35* Implement namespace.
     36
    3337= 1.0.3 =
    3438* Tested up to WordPress 5.0.
  • optimize-database/trunk/optimize-database.php

    r1989405 r2423998  
    11<?php
    2 /*
    3 Plugin Name: Optimize Database
    4 Plugin URI: http://joshuafredrickson.com
    5 Description: Automatically optimize the database every day.
    6 Version: 1.0.3
    7 Author: Joshua Fredrickson
    8 Author URI: http://joshuafredrickson.com
    9 */
     2/**
     3 * Plugin Name: Optimize Database
     4 * Plugin URI: http://joshuafredrickson.com
     5 * Description: Automatically optimize the database every day.
     6 * Version: 1.0.4
     7 * Requires PHP: 5.6
     8 * Author: Joshua Fredrickson
     9 * Author URI: http://joshuafredrickson.com
     10 */
    1011
    11 register_activation_hook( __FILE__, 'op_optimize_plugin_activation' );
    12 register_deactivation_hook( __FILE__, 'op_optimize_plugin_deactivation' );
     12namespace OptimizeDatabase;
    1313
    14 add_action( 'op_optimize_cron', 'do_op_optimize_cron' );
     14use function add_action;
     15use function register_activation_hook;
     16use function register_deactivation_hook;
     17use function wp_next_scheduled;
     18use function wp_schedule_event;
    1519
    16 op_optimize_check_crons();
    17 
    18 function op_optimize_plugin_activation () {
    19     op_optimize_check_crons();
    20 }
    21 
    22 function op_optimize_plugin_deactivation () {
    23     // If our cron hook exists. remove it.
    24     if ( wp_next_scheduled( 'op_optimize_cron' ) ) {
    25         wp_clear_scheduled_hook( 'op_optimize_cron' );
     20/**
     21 * If the cron schedule doesn't yet exist, create it.
     22 */
     23function check_crons()
     24{
     25    if (! wp_next_scheduled('op_optimize_cron')) {
     26        wp_schedule_event(time(), 'daily', 'op_optimize_cron');
    2627    }
    2728}
    2829
    29 function op_optimize_check_crons() {
    30     // If our cron hook doesn't yet exist, create it.
    31     if ( ! wp_next_scheduled( 'op_optimize_cron' ) ) {
    32         wp_schedule_event( time(), 'daily', 'op_optimize_cron' );
     30/**
     31 * Plugin activation
     32 */
     33register_activation_hook(__FILE__, function () {
     34    \OptimizeDatabase\check_crons();
     35});
     36
     37/**
     38 * If the cron hook exists, remove it.
     39 */
     40register_deactivation_hook(__FILE__, function () {
     41    if (wp_next_scheduled('op_optimize_cron')) {
     42        wp_clear_scheduled_hook('op_optimize_cron');
    3343    }
    34 }
     44});
    3545
    36 function do_op_optimize_cron() {
    37 global $wpdb;
     46/**
     47 * Do the actual optimization.
     48 */
     49add_action('op_optimize_cron', function () {
     50    global $wpdb;
    3851
    3952    $sql = 'SHOW TABLE STATUS FROM ' . DB_NAME;
    40     $tables = $wpdb->get_results( $sql, ARRAY_A );
    41     foreach( $tables as $t ) {
    42         if( ! empty( $t['Data_free'] ) ) {
    43             $do_opt = $wpdb->query( "OPTIMIZE TABLE ".$t['Name'] );
     53    $tables = $wpdb->get_results($sql, ARRAY_A);
     54
     55    foreach ($tables as $t) {
     56        if (! empty($t['Data_free'])) {
     57            $wpdb->query("OPTIMIZE TABLE {$t['Name']}");
    4458        }
    4559    }
     60
    4661    return;
    47 }
     62});
     63
     64/**
     65 * Kick it all off.
     66 */
     67check_crons();
  • optimize-database/trunk/readme.txt

    r1989405 r2423998  
    44Tags: database, optimize, cron, automatic
    55Requires at least: 3.7
    6 Tested up to: 5.0
     6Tested up to: 5.6
    77Stable tag: trunk
    88License: GPLv2 or later
     
    3131== Changelog ==
    3232
     33= 1.0.4 =
     34* Tested up to WordPress 5.6.
     35* Implement namespace.
     36
    3337= 1.0.3 =
    3438* Tested up to WordPress 5.0.
Note: See TracChangeset for help on using the changeset viewer.