Skip to content

Instantly share code, notes, and snippets.

@ianmjones
Last active April 11, 2016 11:30
Show Gist options
  • Save ianmjones/6bd5243d51607cb7641d2ccf9304b5b6 to your computer and use it in GitHub Desktop.
Save ianmjones/6bd5243d51607cb7641d2ccf9304b5b6 to your computer and use it in GitHub Desktop.
Cron_Pixie::enqueue_scripts()
<?php
/**
* Enqueues the JS scripts when the main dashboard page is loading.
*
* @param string $hook_page
*/
public function enqueue_scripts( $hook_page ) {
if ( 'index.php' !== $hook_page ) {
return;
}
$script_handle = $this->plugin_meta['slug'] . '-main';
wp_enqueue_style(
$script_handle,
plugin_dir_url( $this->plugin_meta['file'] ) . 'css/main.css',
array(),
$this->plugin_meta['version']
);
wp_enqueue_script(
$script_handle,
plugin_dir_url( $this->plugin_meta['file'] ) . 'js/main.js',
array( 'jquery', 'backbone' ),
$this->plugin_meta['version'],
true // Load JS in footer so that templates in DOM can be referenced.
);
// Add initial data to CronPixie JS object so it can be rendered without fetch.
// Also add translatable strings for JS as well as reference settings.
$data = array(
'strings' => array(
'no_events' => _x( '(none)', 'no event to show', 'wp-cron-pixie' ),
'due' => _x( 'due', 'label for when cron event date', 'wp-cron-pixie' ),
'now' => _x( 'now', 'cron event is due now', 'wp-cron-pixie' ),
'passed' => _x( 'passed', 'cron event is over due', 'wp-cron-pixie' ),
'weeks_abrv' => _x( 'w', 'displayed in interval', 'wp-cron-pixie' ),
'days_abrv' => _x( 'd', 'displayed in interval', 'wp-cron-pixie' ),
'hours_abrv' => _x( 'h', 'displayed in interval', 'wp-cron-pixie' ),
'minutes_abrv' => _x( 'm', 'displayed in interval', 'wp-cron-pixie' ),
'seconds_abrv' => _x( 's', 'displayed in interval', 'wp-cron-pixie' ),
'run_now' => _x( 'Run event now.', 'Title for run now icon', 'wp-cron-pixie' ),
),
'nonce' => wp_create_nonce( 'cron-pixie' ),
'timer_period' => 5, // How often should display be updated, in seconds.
'data' => array(
'schedules' => $this->_get_schedules(),
),
);
wp_localize_script( $script_handle, 'CronPixie', $data );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment