Making WordPress.org

Changeset 10209

Timestamp:
08/26/2020 07:25:50 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Cleanup the Cron hook:$plugin code.

File:
1 edited

Legend:

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

    r9974 r10209  
    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         }
    34         add_action( 'wporg_after_cron_event_run', array( $this, 'after_cron_event_run' ), 10, 2 );
     32            //
     33       
     34       
    3535    }
    3636
     
    278278     * These cron tasks are in the form of 'import_plugin:$slug', this maps them to their expected handlers.
    279279     */
    280     public function after_cron_event_run( $hook, $args ) {
    281         if ( has_action( $hook ) ) {
    282             return;
    283         }
    284         list( $base, ) = explode( ':', $hook, 2 );
     280    public function register_colon_based_hook_handlers() {
     281        $cron_array = get_option( 'cron' );
    285282
    286283        $wildcard_cron_tasks = array(
     
    290287        );
    291288
    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.
    303      *
    304      * @param array $cron_array The Cron array.
    305      * @return array The Cron array passed, unchanged.
    306      */
    307     public function register_colon_based_hook_handlers( $cron_array ) {
    308         $wildcard_cron_tasks = array(
    309             'import_plugin'      => array( __NAMESPACE__ . '\Plugin_Import', 'cron_trigger' ),
    310             'import_plugin_i18n' => array( __NAMESPACE__ . '\Plugin_i18n_Import', 'cron_trigger' ),
    311             'tide_sync'          => array( __NAMESPACE__ . '\Tide_Sync', 'cron_trigger' ),
    312         );
    313 
    314289        if ( is_array( $cron_array ) ) {
    315290            foreach ( $cron_array as $timestamp => $handlers ) {
     
    332307            }
    333308        }
    334 
    335         return $cron_array;
    336309    }
    337310
Note: See TracChangeset for help on using the changeset viewer.