Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add more issues found to the Troubleshooting page [Innovation Day] #2153

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
286 changes: 190 additions & 96 deletions src/Tribe/Admin/Troubleshooting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
/**
* Admin Troubleshooting for TEC plugins.
*
* @since 4.14.2
*
* @package Tribe\Admin
* @since 4.14.2
*
*/

namespace Tribe\Admin;

use \Tribe__Settings;
use \Tribe__Main;
use \Tribe__Admin__Helpers;
Expand All @@ -18,9 +19,9 @@
/**
* Class Admin Troubleshooting.
*
* @since 4.14.2
*
* @package Tribe\Admin
* @since 4.14.2
*
*/
class Troubleshooting {
/**
Expand Down Expand Up @@ -101,6 +102,7 @@ public function get_required_capability() {
* @param static $troubleshooting The current instance of the class that handles this page.
*/
$capability = apply_filters( 'tec_troubleshooting_capability', 'install_plugins', $this );

return $capability;
}

Expand All @@ -119,30 +121,8 @@ public function admin_body_class( $classes ) {
}

$classes .= ' tec-troubleshooting';
return $classes;
}

/**
* Adds the troubleshooting menu to the the WP admin bar under events.
*
* @since 4.14.2
*
*/
public function add_toolbar_item() {
$capability = $this->get_required_capability();

if ( ! current_user_can( $capability ) ) {
return;
}

global $wp_admin_bar;

$wp_admin_bar->add_menu( [
'id' => 'tec-troubleshooting',
'title' => esc_html__( 'Troubleshooting', 'tribe-common' ),
'href' => Tribe__Settings::instance()->get_url( [ 'page' => static::MENU_SLUG ] ),
'parent' => 'tribe-events-settings-group',
] );
return $classes;
}

/**
Expand All @@ -163,6 +143,7 @@ public function is_current_page() {
'Function was called before it is possible to accurately determine what the current page is.',
'4.5.6'
);

return false;
}

Expand All @@ -176,6 +157,29 @@ public function is_current_page() {
return in_array( $current_screen->id, $troubleshooting_pages );
}

/**
* Adds the troubleshooting menu to the the WP admin bar under events.
*
* @since 4.14.2
*
*/
public function add_toolbar_item() {
$capability = $this->get_required_capability();

if ( ! current_user_can( $capability ) ) {
return;
}

global $wp_admin_bar;

$wp_admin_bar->add_menu( [
'id' => 'tec-troubleshooting',
'title' => esc_html__( 'Troubleshooting', 'tribe-common' ),
'href' => Tribe__Settings::instance()->get_url( [ 'page' => static::MENU_SLUG ] ),
'parent' => 'tribe-events-settings-group',
] );
}

/**
* Renders the Troubleshooting page.
*
Expand All @@ -198,9 +202,119 @@ public function do_menu_page() {
public function is_any_issue_active() {
$issues = $this->get_issues_found();
$active_issues = wp_list_pluck( $issues, 'active' );

return in_array( true, $active_issues );
}

/**
* Displays issues found in the UI.
*
* @since 4.14.2
*
* @return array of issues which are displayed on the troubleshooting page.
*/
public function get_issues_found() {
$issues_found = apply_filters( 'tec_help_troubleshooting_issues_found', [
[
'title' => __( 'Site time zone uses UTC', 'tribe-common' ),
'description' => __( 'When using The Events Calendar, we highly recommend that you use a geographic timezone such as "America/Los_Angeles" and avoid using a UTC timezone offset such as “UTC+9”. Choosing a UTC timezone for your site or individual events may cause problems when importing events or with Daylight Saving Time. Go to your the General WordPress settings to adjust your site timezone.', 'tribe-common' ),
'more_info' => 'http://evnt.is/1ad3',
'resolve_text' => __( 'Adjust your timezone', 'tribe-common' ),
'fix' => '/wp-admin/options-general.php',
'active' => $this->is_active_issue( 'timezone' ),
],
[
'title' => __( 'Install max has been reached', 'tribe-common' ),
'description' => __( 'License keys can only be used on a limited number of sites, which varies depending on your license level. You\'ll need to remove the license from one or more other site\'s in order to use it on this one.', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqz',
'resolve_text' => __( 'Manage your licenses', 'tribe-common' ),
'fix' => 'https://evnt.is/1aq-',
'active' => $this->is_active_issue( 'install-max' ),
],
[
'title' => __( 'Default Google Maps API key', 'tribe-common' ),
'description' => __( 'The Events Calendar comes with an API key for basic maps functionality. If you’d like to use more advanced features like custom map pins, dynamic map loads, or Events Calendar Pro\'s Location Search and advanced Map View, you’ll need to get your own Google Maps API key and add it to Events > Settings > Integrations', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqx',
'resolve_text' => __( 'Enter a custom API key', 'tribe-common' ),
'fix' => '/wp-admin/edit.php?page=tec-events-settings&tab=addons&post_type=tribe_events#tribe-field-google_maps_js_api_key',
'active' => $this->is_active_issue( 'geolocation' ),
],
[
'title' => __( 'Plugin(s) are out of date', 'tribe-common' ),
'description' => __( 'It\'s important to use the most recent versions of our plugins so that you have access to the latest features, bug fixes, and security updates. Plugin functionality can be comprimised if your site is running outdated or mis-matched versions.', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqy',
'resolve_text' => __( 'Check for updates', 'tribe-common' ),
'fix' => '/wp-admin/update-core.php',
'active' => $this->is_active_issue( 'out-of-date' ),
],
[
'title' => __( 'PHP version out of date', 'tribe-common' ),
'description' => __( 'The PHP version your site uses has reached its end of life of life on November 28, 2022. This means it no longer receives security updates or bug fixes. Users are encouraged to upgrade to newer versions of PHP to ensure continued support and security. Reach out to your hosting provider for assistance.', 'tribe-common' ),
'more_info' => 'https://evnt.is/tec-php-support',
'resolve_text' => false,
'fix' => false,
'active' => $this->is_active_issue( 'php-version' ),
],
[
'title' => __( 'Default PHP timezone is other than UTC', 'tribe-common' ),
'description' => __( 'The default PHP timezone of your server is set to something else than UTC. This can cause issues when displaying event times and time zones. We recommend you to set the default PHP time zone on your server to UTC. This is usually done with the `date.timezone` directive in the php.ini file.', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aql',
'resolve_text' => false,
'fix' => false,
'active' => $this->is_active_issue( 'php-timezone' ),
],
[
/* translators: %s: The name of the caching plugin. */
'title' => sprintf( __( 'Caching plugin detected: %s', 'tribe-common' ), $this->get_active_caching_plugin_name() ),
'description' => __( 'Caching can improve your site performance and speed up your site. Check out our Caching Guide to help you set up caching with our plugins correctly.', 'tribe-common' ),
'more_info' => 'https://evnt.is/tec-and-caching',
'resolve_text' => false,
'fix' => false,
'active' => $this->is_active_issue( 'caching' ),
],
] );

return $issues_found;
}

/**
* Checks if any of the issues defined are active.
*
* @since 4.14.2
*
* @param string $slug the slug of active issue.
*
* @return boolean returns a boolean value for each individual issue depending on whether it is active or not.
*/
public function is_active_issue( $slug ) {
if ( 'timezone' === $slug ) {
return Timezones::is_utc_offset( Timezones::wp_timezone_string() );
}
if ( 'geolocation' === $slug && class_exists( 'Tribe__Events__Google__Maps_API_Key' ) ) {
$key = \tribe_get_option( 'google_maps_js_api_key', false );

return empty( $key ) || Tribe__Events__Google__Maps_API_Key::$default_api_key === $key;
}
if ( 'out-of-date' === $slug ) {
return $this->is_any_tec_plugin_out_of_date();
}
if ( 'php-version' === $slug ) {
return version_compare( PHP_VERSION, '8.0.0', '<' );
}
if ( 'php-timezone' === $slug ) {
$php_timezone = date_default_timezone_get();

return $php_timezone != 'UTC';
}
if ( 'caching' === $slug ) {
$intersection = $this->get_active_caching_plugins();

return ! empty( $intersection );
}

return false;
}

/**
* Checks if any active TEC plugins require an update.
*
Expand Down Expand Up @@ -244,8 +358,9 @@ public function is_any_tec_plugin_out_of_date() {
if ( defined( 'IMAGE_WIDGET_PLUS_DIR' ) ) {
$plugins[] = IMAGE_WIDGET_PLUS_DIR;
}
$plugins = array_map( static function( $file ) {
$plugins = array_map( static function ( $file ) {
$file = \str_replace( WP_PLUGIN_DIR . '/', '', $file );

return $file;
}, $plugins );

Expand All @@ -258,78 +373,10 @@ public function is_any_tec_plugin_out_of_date() {
return true;
}
}
return false;
}

/**
* Checks if any of the issues defined are active.
*
* @since 4.14.2
*
* @param string $slug the slug of active issue.
*
* @return boolean returns a boolean value for each individual issue depending on whether it is active or not.
*/
public function is_active_issue( $slug ) {
if ( 'timezone' === $slug ) {
return Timezones::is_utc_offset( Timezones::wp_timezone_string() );
}
if ( 'geolocation' === $slug && class_exists( 'Tribe__Events__Google__Maps_API_Key' ) ) {
$key = \tribe_get_option( 'google_maps_js_api_key', false );
return empty( $key ) || Tribe__Events__Google__Maps_API_Key::$default_api_key === $key ;
}
if ( 'out-of-date' === $slug ) {
return $this->is_any_tec_plugin_out_of_date();
}
return false;
}

/**
* Displays issues found in the UI.
*
* @since 4.14.2
*
* @return array of issues which are displayed on the troubleshooting page.
*/
public function get_issues_found() {
$issues_found = apply_filters( 'tec_help_troubleshooting_issues_found', [
[
'title' => __( 'Site time zone uses UTC', 'tribe-common' ),
'description' => __( 'When using The Events Calendar, we highly recommend that you use a geographic timezone such as "America/Los_Angeles" and avoid using a UTC timezone offset such as “UTC+9”. Choosing a UTC timezone for your site or individual events may cause problems when importing events or with Daylight Saving Time. Go to your the General WordPress settings to adjust your site timezone.', 'tribe-common' ),
'more_info' => 'http://evnt.is/1ad3',
'resolve_text' => __( 'Adjust your timezone', 'tribe-common' ),
'fix' => '/wp-admin/options-general.php',
'active' => $this->is_active_issue( 'timezone' ),
],
[
'title' => __( 'Install max has been reached', 'tribe-common' ),
'description' => __( 'License keys can only be used on a limited number of sites, which varies depending on your license level. You\'ll need to remove the license from one or more other site\'s in order to use it on this one.', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqz',
'resolve_text' => __( 'Manage your licenses', 'tribe-common' ),
'fix' => 'https://evnt.is/1aq-',
'active' => $this->is_active_issue( 'install-max' ),
],
[
'title' => __( 'Default Google Maps API key', 'tribe-common' ),
'description' => __( 'The Events Calendar comes with an API key for basic maps functionality. If you’d like to use more advanced features like custom map pins, dynamic map loads, or Events Calendar Pro\'s Location Search and advanced Map View, you’ll need to get your own Google Maps API key and add it to Events > Settings > Integrations', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqx',
'resolve_text' => __( 'Enter a custom API key', 'tribe-common' ),
'fix' => '/wp-admin/edit.php?page=tec-events-settings&tab=addons&post_type=tribe_events#tribe-field-google_maps_js_api_key',
'active' => $this->is_active_issue( 'geolocation' ),
],
[
'title' => __( 'Plugin(s) are out of date', 'tribe-common' ),
'description' => __( 'It\'s important to use the most recent versions of our plugins so that you have access to the latest features, bug fixes, and security updates. Plugin functionality can be comprimised if your site is running outdated or mis-matched versions.', 'tribe-common' ),
'more_info' => 'https://evnt.is/1aqy',
'resolve_text' => __( 'Check for updates', 'tribe-common' ),
'fix' => '/wp-admin/update-core.php',
'active' => $this->is_active_issue( 'out-of-date' ),
],
] );

return $issues_found;
}

/**
* Defines common troubleshooting issues and displays them in the UI.
*
Expand Down Expand Up @@ -379,4 +426,51 @@ public function get_common_issues() {
public function admin_notice( $page ) {
do_action( 'tec_admin_notice_area', $page );
}

/**
* Check if any caching plugins are active on the site.
*
* @since TBD
*
* @return string[] An array of the active caching plugins.
*/
private function get_active_caching_plugins(): array {
$active_plugins = get_option( 'active_plugins' );
$caching_plugins = [
'litespeed-cache/litespeed-cache.php',
'wp-super-cache/wp-cache.php',
'autoptimize/autoptimize.php',
'wp-rocket/wp-rocket.php',
'sg-cachepress/sg-cachepress.php',
'breeze/breeze.php',
'wp-optimize/wp-optimize.php',
'wp-fastest-cache/wpFastestCache.php',
// 'wp-engine',
];

// Check if any of the above caching plugins are active.
$active_caching_plugins = array_intersect( $caching_plugins, $active_plugins );

return $active_caching_plugins;
}

/**
* Get the name of the first found active caching plugin.
*
* @since TBD
*
* @return string The name of the caching plugin.
*/
private function get_active_caching_plugin_name() {
$active_caching_plugins = $this->get_active_caching_plugins();

if ( empty( $active_caching_plugins ) ) {
return __( 'Plugin couldn\'t be identified.', 'tribe-common' );
}

$plugin = array_pop( $active_caching_plugins );
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false );

return $plugin_data['Name'];
}
}
Loading