| 1 |
<?php |
| 2 |
|
| 3 |
namespace GauchoPlugins\VersionInfo; |
| 4 |
|
| 5 |
class Plugin { |
| 6 |
/** @var AdminBar */ |
| 7 |
private $admin_bar; |
| 8 |
|
| 9 |
/** @var DashboardWidget */ |
| 10 |
private $dashboard_widget; |
| 11 |
|
| 12 |
/** @var SettingsPage */ |
| 13 |
private $settings_page; |
| 14 |
|
| 15 |
public function init() { |
| 16 |
$this->admin_bar = new AdminBar(); |
| 17 |
$this->dashboard_widget = new DashboardWidget(); |
| 18 |
$this->settings_page = new SettingsPage(); |
| 19 |
add_action( 'plugins_loaded', [$this, 'load_text_domain'] ); |
| 20 |
add_filter( 'update_footer', [$this, 'version_in_footer'], 11 ); |
| 21 |
$this->admin_bar->register(); |
| 22 |
$this->dashboard_widget->register(); |
| 23 |
$this->settings_page->register(); |
| 24 |
$this->maybe_init_pro(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Build a docs.versioninfoplugin.com link for use inside settings tabs. |
| 29 |
* |
| 30 |
* Returns an empty string when the Agency "Hide Doc Links" white-label |
| 31 |
* setting is enabled, so client-facing dashboards never expose our |
| 32 |
* documentation domain. |
| 33 |
* |
| 34 |
* @param string $slug Docs page slug, e.g. "pro-features-system-resources". |
| 35 |
* @param string $label Visible link text. |
| 36 |
* @return string Anchor HTML or empty string when suppressed. |
| 37 |
*/ |
| 38 |
public static function doc_link( $slug, $label = '' ) { |
| 39 |
if ( get_option( 'version_info_wl_hide_doc_links', false ) ) { |
| 40 |
return ''; |
| 41 |
} |
| 42 |
if ( '' === $label ) { |
| 43 |
$label = __( 'View documentation', 'version-info' ); |
| 44 |
} |
| 45 |
$url = 'https://docs.versioninfoplugin.com/' . ltrim( (string) $slug, '/' ) . '/'; |
| 46 |
return sprintf( '<a href="%1$s" target="_blank" rel="noopener" class="vi-doc-link" style="text-decoration:none;">%2$s <span class="dashicons dashicons-external" style="font-size:14px;line-height:inherit;vertical-align:text-bottom;"></span></a>', esc_url( $url ), esc_html( $label ) ); |
| 47 |
} |
| 48 |
|
| 49 |
public static function current_user_can_view() { |
| 50 |
$roles = (array) get_option( 'version_info_allowed_roles', ['administrator'] ); |
| 51 |
/** @var string[] $roles */ |
| 52 |
$roles = apply_filters( 'version_info_allowed_roles', $roles ); |
| 53 |
$user = wp_get_current_user(); |
| 54 |
if ( !$user->exists() ) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
return !empty( array_intersect( $roles, (array) $user->roles ) ); |
| 58 |
} |
| 59 |
|
| 60 |
public function load_text_domain() { |
| 61 |
load_plugin_textdomain( 'version-info', false, dirname( plugin_basename( VERSION_INFO_FILE ) ) . '/languages' ); |
| 62 |
} |
| 63 |
|
| 64 |
public function version_in_footer() { |
| 65 |
if ( !get_option( 'version_info_show_footer', true ) || !self::current_user_can_view() ) { |
| 66 |
return ''; |
| 67 |
} |
| 68 |
return $this->get_footer_version_details(); |
| 69 |
} |
| 70 |
|
| 71 |
private function get_footer_version_details() { |
| 72 |
$wp_version = apply_filters( 'version_info_wp_version', get_bloginfo( 'version' ) ); |
| 73 |
$update_message = ''; |
| 74 |
$updates = get_core_updates(); |
| 75 |
if ( !empty( $updates ) && !is_wp_error( $updates ) ) { |
| 76 |
foreach ( $updates as $update ) { |
| 77 |
if ( version_compare( $wp_version, $update->version, '<' ) ) { |
| 78 |
$update_message = sprintf( |
| 79 |
' (<a href="%s">%s %s</a>)', |
| 80 |
esc_url( admin_url( 'update-core.php' ) ), |
| 81 |
__( 'Get Version', 'version-info' ), |
| 82 |
esc_html( $update->version ) |
| 83 |
); |
| 84 |
break; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
global $wpdb; |
| 89 |
$server_software = apply_filters( 'version_info_server_software', sanitize_text_field( ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unknown', 'version-info' ) ) ) ); |
| 90 |
$mysql_version = apply_filters( 'version_info_mysql_version', (string) $wpdb->get_var( 'SELECT VERSION()' ) ); |
| 91 |
$php_version = apply_filters( 'version_info_php_version', phpversion() ); |
| 92 |
$details = sprintf( |
| 93 |
/* translators: %1$s: WP version, %2$s: update link, %3$s: PHP version, %4$s: server software, %5$s: MySQL version */ |
| 94 |
__( 'WordPress %1$s%2$s | PHP %3$s | Web Server %4$s | MySQL %5$s', 'version-info' ), |
| 95 |
esc_html( $wp_version ), |
| 96 |
$update_message, |
| 97 |
esc_html( $php_version ), |
| 98 |
esc_html( $server_software ), |
| 99 |
esc_html( $mysql_version ) |
| 100 |
); |
| 101 |
return apply_filters( 'version_info_footer_details', $details ); |
| 102 |
} |
| 103 |
|
| 104 |
private function maybe_init_pro() { |
| 105 |
} |
| 106 |
|
| 107 |
} |
| 108 |
|