Making WordPress.org

Changeset 9974


Ignore:
Timestamp:
06/19/2020 12:40:05 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Ensure cron tasks are run as expected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php

    r9973 r9974  
    3030                // Register the wildcard cron hook tasks.
    3131                if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    32                         add_action( 'pre_option_cron', array( $this, 'register_colon_based_hook_handlers' ), 100 );
    33                 }
     32                        //add_action( 'pre_option_cron', array( $this, 'register_colon_based_hook_handlers' ), 100 );
     33                }
     34                add_action( 'wporg_after_cron_event_run', array( $this, 'after_cron_event_run' ), 10, 2 );
    3435        }
    3536
    … …  
    276277         *
    277278         * These cron tasks are in the form of 'import_plugin:$slug', this maps them to their expected handlers.
     279         */
     280        public function after_cron_event_run( $hook, $args ) {
     281                if ( has_action( $hook ) ) {
     282                        return;
     283                }
     284                list( $base, ) = explode( ':', $hook, 2 );
     285
     286                $wildcard_cron_tasks = array(
     287                        'import_plugin'      => array( __NAMESPACE__ . '\Plugin_Import', 'cron_trigger' ),
     288                        'import_plugin_i18n' => array( __NAMESPACE__ . '\Plugin_i18n_Import', 'cron_trigger' ),
     289                        'tide_sync'          => array( __NAMESPACE__ . '\Tide_Sync', 'cron_trigger' ),
     290                );
     291
     292                if ( isset( $wildcard_cron_tasks[ $base ] ) ) {
     293                        call_user_func_array( $wildcard_cron_tasks[ $base ], $args );
     294                }
     295        }
     296
     297        /**
     298         * The WordPress Cron implementation isn't great at determining if a job is already enqueued,
     299         * as a result, we use a "fake" hook to encode the plugin slug into the job name to allow us to
     300         * detect if a cron task for that plugin has already been registered.
     301         *
     302         * These cron tasks are in the form of 'import_plugin:$slug', this maps them to their expected handlers.
    278303         *
    279304         * @param array $cron_array The Cron array.
Note: See TracChangeset for help on using the changeset viewer.