Skip to content

Commit

Permalink
Issue/227 - Add widgets.php to Legacy loader (#228)
Browse files Browse the repository at this point in the history
* Legacy: add missing $order parameter to sc_get_events_list docs
* Legacy: rename $today variable to $now in sc_get_events_list().
* Load: add widgets.php to admin pages that load legacy files.

This change circumvents a fatal error with WordPress 5.8 by ensuring that all legacy functions are available in the new widgets UI.
  • Loading branch information
JJJ authored Jul 22, 2021
1 parent e4ea5d2 commit 9fcea4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions sugar-calendar/includes/themes/legacy/events-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
* @param null $category
* @param int $number
* @param array $show
* @param string $order
*
* @return string
*/
function sc_get_events_list( $display = 'upcoming', $category = null, $number = 5, $show = array(), $order = '' ) {

// Get today, to query before/after
$today = sugar_calendar_get_request_time( 'mysql' );
$now = sugar_calendar_get_request_time( 'mysql' );

// Mutate order to uppercase if not empty
if ( ! empty( $order ) ) {
Expand All @@ -51,7 +52,7 @@ function sc_get_events_list( $display = 'upcoming', $category = null, $number =
'number' => $number,
'end_query' => array(
'inclusive' => true,
'after' => $today
'after' => $now
)
);

Expand All @@ -65,7 +66,7 @@ function sc_get_events_list( $display = 'upcoming', $category = null, $number =
'number' => $number,
'end_query' => array(
'inclusive' => true,
'before' => $today
'before' => $now
)
);

Expand Down
22 changes: 18 additions & 4 deletions sugar-calendar/sugar-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,24 @@ private function include_admin() {
// Legacy
require_once SC_PLUGIN_DIR . 'includes/admin/settings.php';

// Maybe include front-end on AJAX or add/edit post page to load
// shortcodes, widgets, and more...
if ( wp_doing_ajax() || ( ! empty( $GLOBALS['pagenow'] ) && ( 'post.php' === $GLOBALS['pagenow'] ) ) ) {
// Maybe include front-end on AJAX, add/edit post page, or widgets, to
// load all shortcodes, widgets, assets, etc...
if (

// Admin AJAX
wp_doing_ajax()

||

// Specific admin pages
(
! empty( $GLOBALS['pagenow'] )

&&

in_array( $GLOBALS['pagenow'], array( 'post.php', 'widgets.php' ), true )
)
) {
$this->include_frontend();
}
}
Expand All @@ -417,7 +432,6 @@ private function include_frontend() {
require_once SC_PLUGIN_DIR . 'includes/themes/legacy/calendar.php';
require_once SC_PLUGIN_DIR . 'includes/themes/legacy/event-display.php';
require_once SC_PLUGIN_DIR . 'includes/themes/legacy/events-list.php';
require_once SC_PLUGIN_DIR . 'includes/themes/legacy/scripts.php';
}

/**
Expand Down

0 comments on commit 9fcea4c

Please sign in to comment.