forked from lino/radar-wp
Tidied up code comments pre-release.
This commit is contained in:
parent
eab5592dd5
commit
65db102f6f
4 changed files with 224 additions and 81 deletions
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* Squat Radar Events Widget.
|
||||
*
|
||||
* @package squat-radar
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Squat_Radar_Widget extends WP_Widget {
|
||||
|
||||
|
@ -28,15 +36,26 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
add_option( 'squat_radar_widget_cron_run', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts callback, add CSS.
|
||||
*/
|
||||
static public function widget_style() {
|
||||
wp_register_style( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.css' );
|
||||
wp_enqueue_style( 'squat-radar-widget' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts callback, add JS.
|
||||
*/
|
||||
static public function widget_script() {
|
||||
wp_register_script( 'squat-radar-widget', SQUAT_RADAR_URL . '/assets/squat-radar.js', ['jquery'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cron action.
|
||||
*
|
||||
* Uses an option to keep track of when run, and updates any (experimental) widgets that update using a cron period instead of ajax.
|
||||
*/
|
||||
public static function cache_cron() {
|
||||
$now = time();
|
||||
$last_run = get_option('squat_radar_widget_cron_run', []);
|
||||
|
@ -50,6 +69,9 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
set_option('squat_radar_widget_cron_run', $last_run);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh an individual widget instance for cache_cron().
|
||||
*/
|
||||
protected static function cache_refresh($instance) {
|
||||
$connector = new Squat_Radar_Connector();
|
||||
|
||||
|
@ -58,6 +80,7 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
$languages = array_merge($instance['url']['keys']['language'], (array) $languages);
|
||||
foreach ($languages as $language) {
|
||||
try {
|
||||
// Force update. Don't set expire.
|
||||
$data = $connector->events($instance['url']['keys']['facets'], $instance['fields'], $language, $instance['limit'], 0, TRUE );
|
||||
}
|
||||
catch ( Squat_Radar_Connector_Exception $e ) {
|
||||
|
@ -68,7 +91,11 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of WP_Widget::widget().
|
||||
*
|
||||
* Outputs the events for the correct instance of the widget.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
$widget_id = 'squat_radar_widget_' . $this->number;
|
||||
|
||||
|
@ -104,6 +131,9 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Action callback for AJAX widget display.
|
||||
*/
|
||||
public static function ajax_callback() {
|
||||
if ( ! array_key_exists('instance', $_POST) ) {
|
||||
wp_die();
|
||||
|
@ -138,6 +168,11 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of WP_Widget::form().
|
||||
*
|
||||
* Widget options.
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
|
||||
//
|
||||
|
@ -269,7 +304,11 @@ class Squat_Radar_Widget extends WP_Widget {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of WP_Widget::update().
|
||||
*
|
||||
* Save widget options.
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$options = [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue