Skip to content

Commit

Permalink
* Improves the output of event dates
Browse files Browse the repository at this point in the history
* Adds `only_featured` parameter to `wsb_schedule` to show only featured workshops
* Fixes an issue with incorrect workshop dates in some border cases
* Adds two new shortcodes for `wsb_schedule`: `wsb_schedule_date` and `wsb_schedule_time`
* Improves the output for timezone abbreviations which have no abbreviations (adds GMT before them)
* Adds failed request logging with the ability to switch it off
  • Loading branch information
sery0ga committed May 6, 2020
1 parent 93e60a2 commit 67014d0
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 88 deletions.
4 changes: 2 additions & 2 deletions workshop-butler/admin/includes/class-sidebar-field.php
Expand Up @@ -47,8 +47,8 @@ class Sidebar_Field {
/**
* Sidebar_Field constructor
*
* @param string $type Type of the field.
* @param string $description Description of the field.
* @param string $type Type of the field.
* @param string $description Description of the field.
* @param string|boolean|int|null $default_value Default value of the field.
*/
public function __construct( $type, $description, $default_value = null ) {
Expand Down
7 changes: 7 additions & 0 deletions workshop-butler/admin/includes/class-wsb-settings.php
Expand Up @@ -288,6 +288,13 @@ protected function get_general_settings() {
'desc' => __( 'Log in to <a href="https://analytics.google.com/analytics/web/" target="_blank">Google Analytics</a> to get your API key', 'wsbintegration' ),
'validation' => 'not_empty',
),
array(
'id' => WSB_Options::REPORT_ERRORS,
'type' => 'switch',
'title' => 'Report failed requests',
'desc' => 'When a request to Workshop Butler API fails, the plugin sends this information to our logging servers helping us to find the source of the problem faster. We do not collect any personal information, only detailed error reports.',
'default' => true,
),
);
}

Expand Down
3 changes: 2 additions & 1 deletion workshop-butler/composer.json
Expand Up @@ -3,7 +3,8 @@
"twig/twig": "1.34.4",
"squizlabs/php_codesniffer": "3.5.3",
"wp-coding-standards/wpcs": "2.2.0",
"dealerdirect/phpcodesniffer-composer-installer": "v0.5.0"
"dealerdirect/phpcodesniffer-composer-installer": "v0.5.0",
"ext-json": "*"
},
"scripts": {
"phpcs": "phpcs --standard=WordPress"
Expand Down
14 changes: 12 additions & 2 deletions workshop-butler/includes/class-wsb-integration-upgrade.php
Expand Up @@ -38,7 +38,8 @@ public function upgrade() {
if ( empty( $new_key ) ) {
$self->transfer_settings();
}
$self->update_templates_2_7_1();
$self->update_templates();
$self->update_settings();
$self->save_internal_settings( $self->get_version() );

$event_page = WSB_Options::get_option( WSB_Options::EVENT_PAGE );
Expand Down Expand Up @@ -66,10 +67,19 @@ public function upgrade() {
}
}

/**
* Updates selected settings
*/
protected function update_settings() {
if ( $this->get_version() && $this->get_version() < '2.11.0' ) {
WSB_Options::set_option( WSB_Options::REPORT_ERRORS, true );
}
}

/**
* Updates the classes that changed in version 2.7.1 for all related pages
*/
protected function update_templates_2_7_1() {
protected function update_templates() {
if ( $this->get_version() && $this->get_version() < '2.7.1' ) {
$this->update_classes_2_7_1( WSB_Options::EVENT_TEMPLATE );
$this->update_classes_2_7_1( WSB_Options::TRAINER_TEMPLATE );
Expand Down
50 changes: 25 additions & 25 deletions workshop-butler/includes/class-wsb-options.php
Expand Up @@ -10,8 +10,7 @@

namespace WorkshopButler;

if ( ! class_exists( 'ReduxFramework' )
&& file_exists( dirname( __FILE__ ) . '/../lib/ReduxFramework/ReduxCore/framework.php' ) ) {
if ( ! class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/../lib/ReduxFramework/ReduxCore/framework.php' ) ) {
require_once dirname( __FILE__ ) . '/../lib/ReduxFramework/ReduxCore/framework.php';
}

Expand All @@ -25,44 +24,45 @@
*/
class WSB_Options {

const OLD_API_KEY = 'wb_token';
const OLD_API_KEY = 'wb_token';
const OLD_SCHEDULE_PAGE = 'wb_url';

const PLUGIN_SETTINGS = 'wsb-settings';
const PLUGIN_SETTINGS = 'wsb-settings';
const INTERNAL_SETTINGS = 'wsb-internal-settings';

const INT_STATE = '_state';
const INT_VERSION = '_version';
const INT_STATE = '_state';
const INT_VERSION = '_version';
const INT_TEMPLATE_VERSION = '_tmpl_version';

const API_KEY = 'api-key';

const SCHEDULE_TILE_TEMPLATE = 'schedule-tile-template';
const SCHEDULE_TILE_TEMPLATE = 'schedule-tile-template';
const SCHEDULE_TABLE_TEMPLATE = 'schedule-table-template';
const EVENT_TEMPLATE = 'event-template';
const REGISTRATION_TEMPLATE = 'registration-template';
const TRAINER_LIST_TEMPLATE = 'trainer-list-template';
const TRAINER_TEMPLATE = 'trainer-template';
const EVENT_TEMPLATE = 'event-template';
const REGISTRATION_TEMPLATE = 'registration-template';
const TRAINER_LIST_TEMPLATE = 'trainer-list-template';
const TRAINER_TEMPLATE = 'trainer-template';

const CUSTOM_CSS = 'custom-css';

const THEME = 'theme';
const CUSTOM_THEME = 'custom-theme';
const GA_API_KEY = 'google-analytics-key';

const CUSTOM_EVENT_DETAILS = 'custom-event-page';
const SHOW_EXPIRED_TICKETS = 'show-expired-tickets';
const SHOW_NUMBER_OF_TICKETS = 'show-number-of-tickets';
const SCHEDULE_NO_EVENTS = 'no-events-caption';
const SCHEDULE_LAYOUT = 'event-list-layout';
const SCHEDULE_PAGE = 'event-list-page-id';
const EVENT_PAGE = 'event-page-id';
const THEME = 'theme';
const CUSTOM_THEME = 'custom-theme';
const GA_API_KEY = 'google-analytics-key';
const REPORT_ERRORS = 'report-errors';

const CUSTOM_EVENT_DETAILS = 'custom-event-page';
const SHOW_EXPIRED_TICKETS = 'show-expired-tickets';
const SHOW_NUMBER_OF_TICKETS = 'show-number-of-tickets';
const SCHEDULE_NO_EVENTS = 'no-events-caption';
const SCHEDULE_LAYOUT = 'event-list-layout';
const SCHEDULE_PAGE = 'event-list-page-id';
const EVENT_PAGE = 'event-page-id';
const EVENT_PAGE_SIDEBAR_TYPE = 'event-page-sidebar-type';
const EVENT_PAGE_SIDEBAR_SIZE = 'event-page-sidebar-size';
const REGISTRATION_PAGE = 'registration-page-id';
const REGISTRATION_PAGE = 'registration-page-id';

const TRAINER_MODULE = 'trainer-module';
const TRAINER_LIST_PAGE = 'trainer-list-page-id';
const TRAINER_MODULE = 'trainer-module';
const TRAINER_LIST_PAGE = 'trainer-list-page-id';
const TRAINER_PROFILE_PAGE = 'trainer-page-id';

/**
Expand Down
2 changes: 2 additions & 0 deletions workshop-butler/public/class-wsb-integration-public.php
Expand Up @@ -256,6 +256,8 @@ public function init() {
add_shortcode( 'wsb_trainer', array( 'WorkshopButler\WSB_Trainer_Page', 'page' ) );

// Elements.
add_shortcode( 'wsb_schedule_date', array( 'WorkshopButler\WSB_Schedule_Page', 'tag' ) );
add_shortcode( 'wsb_schedule_time', array( 'WorkshopButler\WSB_Schedule_Page', 'tag' ) );
add_shortcode( 'wsb_schedule_filters', array( 'WorkshopButler\WSB_Schedule_Page', 'tag' ) );
add_shortcode( 'wsb_schedule_item', array( 'WorkshopButler\WSB_Schedule_Page', 'tag' ) );
add_shortcode( 'wsb_schedule_register', array( 'WorkshopButler\WSB_Schedule_Page', 'tag' ) );
Expand Down
46 changes: 23 additions & 23 deletions workshop-butler/public/includes/class-sidebar-widget.php
Expand Up @@ -92,25 +92,25 @@ public function form( $instance ) {

case 'eventtype':
?>
<p>
<label for="<?php echo $this->get_field_id( $name ); ?>"><?php echo $field->description; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( $name ); ?>"
name="<?php echo $this->get_field_name( $name ); ?>"
type="<?php echo $this->get_field_name( $field->type ); ?>"
value="<?php echo esc_attr( isset( $instance[ $name ] ) ? $instance[ $name ] : $field->default_value ); ?>"/>
</p>
<p>
<label for="<?php echo $this->get_field_id( $name ); ?>"><?php echo $field->description; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( $name ); ?>"
name="<?php echo $this->get_field_name( $name ); ?>"
type="<?php echo $this->get_field_name( $field->type ); ?>"
value="<?php echo esc_attr( isset( $instance[ $name ] ) ? $instance[ $name ] : $field->default_value ); ?>"/>
</p>
<?php
break;
default:
?>
<p>
<label for="<?php echo $this->get_field_id( $name ); ?>"><?php echo $field->description; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( $name ); ?>"
name="<?php echo $this->get_field_name( $name ); ?>"
type="<?php echo $this->get_field_name( $field->type ); ?>"
value="<?php echo esc_attr( isset( $instance[ $name ] ) ? $instance[ $name ] : $field->default_value ); ?>"/>
</p>
<?php
<p>
<label for="<?php echo $this->get_field_id( $name ); ?>"><?php echo $field->description; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( $name ); ?>"
name="<?php echo $this->get_field_name( $name ); ?>"
type="<?php echo $this->get_field_name( $field->type ); ?>"
value="<?php echo esc_attr( isset( $instance[ $name ] ) ? $instance[ $name ] : $field->default_value ); ?>"/>
</p>
<?php
}
}
}
Expand Down Expand Up @@ -182,9 +182,9 @@ public function render( $instance ) {
$fields = 'type,title,location,hashed_id,schedule,free,spoken_languages';

$query = array(
'dates' => 'future',
'public' => true,
'fields' => $fields,
'dates' => 'future',
'public' => true,
'fields' => $fields,
'per_page' => $instance['length'],
);

Expand All @@ -207,7 +207,7 @@ public function render( $instance ) {
*/
private function render_list( $response, $instance ) {
if ( $response->is_error() ) {
$html = '<h2>' . __( 'Workshop Butler API: Request failed', 'wsbintegration' ) . '</h2>';
$html = '<h2>' . __( 'Workshop Butler API: Request failed', 'wsbintegration' ) . '</h2>';
$html .= '<p>' . __( 'Reason : ', 'wsbintegration' ) . $response->error . '</p>';

return $html;
Expand All @@ -226,10 +226,10 @@ private function render_list( $response, $instance ) {
$target = ' target="_blank" ';
}
$events .= '<li>' .
Formatter::format( $event->schedule, 'full_short' ) . ', ' .
Formatter::format( $event->location ) . '<br>' .
'<a href="' . $event->url() . '" ' . $target . '>' .
$event->title . '</a></li>';
Formatter::format( $event->schedule, 'full_short' ) . ', ' .
Formatter::format( $event->location ) . '<br>' .
'<a href="' . $event->url() . '" ' . $target . '>' .
$event->title . '</a></li>';
}
$events .= '</ul>';

Expand Down
25 changes: 24 additions & 1 deletion workshop-butler/public/includes/class-wsb-requests.php
Expand Up @@ -15,6 +15,7 @@

define( 'WSB_API_END_POINT', 'https://api.workshopbutler.com/' );
require_once plugin_dir_path( __FILE__ ) . 'class-wsb-response.php';
require_once plugin_dir_path( __FILE__ ) . 'utils/log-error.php';

/**
* The request wrapper class
Expand Down Expand Up @@ -82,8 +83,10 @@ public function get( $method, $query ) {
'referer' => $this->get_referer(),
),
);
$resp = wp_remote_get( $url, $args );
$this->report_error( $resp, $query, $method );

return new WSB_Response( wp_remote_get( $url, $args ) );
return new WSB_Response( $resp );
}

/**
Expand Down Expand Up @@ -113,6 +116,7 @@ public function post( $method, $data ) {
'body' => $data_string,
)
);
$this->report_error( $resp, $data, $method );

return new WSB_Response( $resp );
}
Expand Down Expand Up @@ -215,4 +219,23 @@ protected function build_url( $method, $query ) {
protected function get_referer() {
return filter_input( INPUT_SERVER, 'HTTP_HOST' ) . filter_input( INPUT_SERVER, 'REQUEST_URI' );
}

/**
* If there is a error in response, report it to Workshop Butler
*
* @param array|WP_Error $resp Response.
* @param array $data Method data.
* @param string $method Method type (POST, GET).
*/
protected function report_error( $resp, $data, $method ) {
if ( is_a( $resp, 'WP_Error' ) ) {
$error_data = array();
$error_data['data'] = $data;
$error_data['method'] = $method;
$error_data['code'] = $resp->get_error_code();
$error_data['message'] = $resp->get_error_message();
$error_data['errors'] = $resp->get_error_data();
log_error( 'WSB_Requests', $method, $error_data );
}
}
}
9 changes: 9 additions & 0 deletions workshop-butler/public/includes/models/class-event.php
Expand Up @@ -154,6 +154,14 @@ class Event {
*/
public $description;

/**
* True if the event is featured.
*
* @var boolean $featured
* @since 2.11.0
*/
public $featured;

/**
* Registration form
*
Expand Down Expand Up @@ -246,6 +254,7 @@ public function __construct( $json_data, $event_page_url, $trainer_page_url, $re
$this->trainers = $this->get_trainers( $json_data, $trainer_page_url );
$this->state = new Event_State( $this );
$this->payment = Payment::from_json( $json_data->card_payment );
$this->featured = $json_data->featured;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions workshop-butler/public/includes/models/class-schedule.php
Expand Up @@ -51,6 +51,11 @@ public function __construct( $json_data ) {
}
$this->start = new \DateTime( $json_data->start );
$this->end = new \DateTime( $json_data->end );
if ( $this->timezone ) {
$timezone = new \DateTimeZone( $this->timezone );
$this->start->setTimezone( $timezone );
$this->end->setTimezone( $timezone );
}
}

/**
Expand All @@ -62,6 +67,7 @@ public function ended() {
$now = new \DateTime( 'now', $this->default_timezone() );
$end = clone $this->end;
$end->setTimezone( $this->default_timezone() );

return $end < $now;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
namespace WorkshopButler;

require_once plugin_dir_path( dirname( __FILE__ ) ) . 'class-wsb-page.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'utils/log-error.php';

/**
* Event Page class which handles the rendering and logic for the event page
Expand Down Expand Up @@ -63,6 +64,8 @@ private function load_dependencies() {
public function render( $attrs = array(), $content = null ) {
$id = get_query_var( 'id', 0 );
if ( 0 === $id ) {
log_error( 'WSB_Event_Page', 'Incorrect workshop ID', array() );

return $this->format_error( 'Incorrect workshop ID' );
}
$may_be_event = $this->dict->get_event();
Expand Down
Expand Up @@ -11,6 +11,7 @@
namespace WorkshopButler;

require_once plugin_dir_path( dirname( __FILE__ ) ) . 'class-wsb-page.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'utils/log-error.php';

/**
* Event Page class which handles the rendering and logic for the event page
Expand Down Expand Up @@ -84,6 +85,8 @@ private function load_dependencies() {
public function render( $attrs = array(), $content = null ) {
$id = get_query_var( 'id', 0 );
if ( 0 === $id ) {
log_error( 'WSB_Registration_Page', 'Incorrect workshop ID', array() );

return $this->format_error( 'Incorrect workshop ID' );
}
$may_be_event = $this->dict->get_event();
Expand Down

0 comments on commit 67014d0

Please sign in to comment.