first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?php
namespace FcfVendor\WPDesk\Helper\Debug;
/**
* Can gather info about used libraries
*
* @package WPDesk\Helper\Debug
*/
class LibraryDebug
{
const COMPOSER_KEY_VERSION = 'version';
const COMPOSER_KEY_NAME = 'name';
const COMPOSER_KEY_PACKAGES = 'packages';
const REPORT_KEY_LIBRARY_NAME = 'library_name';
const REPORT_KEY_LIBRARY_VERSION = 'library_version';
const LIBRARY_VERSION_UNKNOWN = 'unknown';
/**
* Prepares array with report about used libraries
*
* @param array $vendor_files_report
*
* @return array
*/
public function get_libraries_report(array $vendor_files_report)
{
$libraries = [];
foreach ($vendor_files_report as $file) {
$library_name = $file[self::REPORT_KEY_LIBRARY_NAME];
if (isset($libraries[$library_name])) {
$libraries[$library_name][] = $file[self::REPORT_KEY_LIBRARY_VERSION];
} else {
$libraries[$file[self::REPORT_KEY_LIBRARY_NAME]] = [$file[self::REPORT_KEY_LIBRARY_VERSION]];
}
$libraries[$library_name] = \array_unique($libraries[$library_name]);
}
return $libraries;
}
/**
* Returns array with used wpdesk files from vendor dir
*
* @return array
*/
private function get_used_wpdesk_vendor_files()
{
$all_files = \get_included_files();
$vendor_files = \array_filter($all_files, function ($filename) {
return \preg_match('/\\/vendor\\/wpdesk\\//', $filename);
});
return $vendor_files;
}
/**
* Returns array with report about used files
*
* @return array
*/
public function get_wpdesk_vendor_files_report()
{
$vendor_files = $this->get_used_wpdesk_vendor_files();
$loaded = [];
foreach ($vendor_files as $vendor_file) {
$library_name = \preg_match('/\\/wpdesk\\/([^\\/]+)/', $vendor_file, $matches) ? $matches[1] : '';
$plugin_path = \preg_match('/(.+\\/plugins\\/[^\\/]+)/', $vendor_file, $matches) ? $matches[1] : '';
$loaded[] = ['plugin_name' => \preg_match('/\\/plugins\\/([^\\/]+)/', $vendor_file, $matches) ? $matches[1] : '', 'plugin_path' => $plugin_path, self::REPORT_KEY_LIBRARY_NAME => $library_name, self::REPORT_KEY_LIBRARY_VERSION => $this->get_library_version($plugin_path, $library_name), 'file' => $vendor_file];
}
return $loaded;
}
/**
* @param string $plugin_path Path to the plugin that loads the library
* @param string $library_name Library name without vendor ie. wp-logs
*
* @return string Returns 'unknown' when version can't be found
*/
private function get_library_version($plugin_path, $library_name)
{
$lock_file = $plugin_path . '/composer.lock';
static $cache;
if (\file_exists($lock_file)) {
if (!\is_array($cache)) {
$cache = [];
}
if (!isset($cache[$lock_file])) {
$cache[$lock_file] = \json_decode(\file_get_contents($lock_file), \true);
}
$library_version = \array_reduce($cache[$lock_file][self::COMPOSER_KEY_PACKAGES], function ($carry, $package_info) use($library_name) {
if ($package_info[self::COMPOSER_KEY_NAME] === 'wpdesk/' . $library_name) {
return $package_info[self::COMPOSER_KEY_VERSION];
}
return $carry;
});
if ($library_version) {
return $library_version;
}
}
return self::LIBRARY_VERSION_UNKNOWN;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace FcfVendor\WPDesk\Helper;
use FcfVendor\WPDesk\Notice\Notice;
/**
* Know if helper is active/installed and can show notices about it
*
* @package WPDesk\Helper
*/
class HelperRemoveInfo
{
private $plugin_file = 'wpdesk-helper/wpdesk-helper.php';
/**
* Is helper active? We should disable
*
* @return bool
*/
public function is_helper_active()
{
return \FcfVendor\WPDesk_Basic_Requirement_Checker::is_wp_plugin_active($this->plugin_file);
}
/**
* Is helper installed? We should delete
*
* @return bool
*/
public function is_helper_installed()
{
return \FcfVendor\WPDesk_Basic_Requirement_Checker::is_wp_plugin_installed($this->plugin_file);
}
/**
* Show notice with disable helper info and url
*
* @return void
*/
public function show_deactivate_helper_notice()
{
$remove_url = \self_admin_url('plugins.php?action=deactivate&plugin=' . $this->plugin_file);
if (\function_exists('wp_nonce_url') && \function_exists('wp_create_nonce')) {
$remove_url = \wp_nonce_url($remove_url, 'deactivate-plugin_' . $this->plugin_file);
}
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(\__('We recommend to <a href="%s">deactivate and remove</a> the "WP Desk Helper" plugin as it is no longer required by WP Desk plugins', 'flexible-checkout-fields'), $remove_url));
}
/**
* Show notice with remove helper info and url
*
* @return void
*/
public function show_remove_helper_notice()
{
$remove_url = \self_admin_url('plugins.php?action=delete-selected&amp;checked[]=' . $this->plugin_file);
if (\function_exists('wp_nonce_url') && \function_exists('wp_create_nonce')) {
$remove_url = \wp_nonce_url($remove_url, 'bulk-plugins');
}
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(\__('We recommend to <a href="%s">remove</a> the "WP Desk Helper" plugin as it is no longer required by WP Desk plugins', 'flexible-checkout-fields'), $remove_url));
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace FcfVendor\WPDesk\Helper;
use WP_Hook;
use FcfVendor\WPDesk\Helper\Integration\LicenseIntegration;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Storage\Exception\ClassNotExists;
use FcfVendor\WPDesk\PluginBuilder\Storage\StorageFactory;
/**
* Tries to remove all traces of helper
*
* @package WPDesk\Helper
*/
class HelperRemover implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const DEFAULT_FILTER_PRIORITY = 10;
const MAIN_WPDESK_MENU_POSITION = 99.99941337;
const CALLBACK_KEY = 'function';
const CALLBACK_KEY_WITH_FUNCTION_NAME = 1;
const REMOVE_WPDESK_MENU_PRIORITY = 11;
/**
* Prevents attaching hooks more than once when used in many plugins
*
* @var bool
*/
private static $already_hooked;
public function hooks()
{
if (!self::$already_hooked && \is_admin()) {
self::$already_hooked = \true;
$this->hide_notice_about_helper_need();
$this->remove_helper_updates();
$this->remove_wpdesk_menu();
$this->remove_message_about_log();
}
}
/**
* Hides notice from plugin that helper is needed
*
* @return void
*/
private function hide_notice_about_helper_need()
{
\remove_action('admin_notices', 'wpdesk_helper_notice');
$this->remove_object_action_by_name('admin_notices', 10, 'wpdesk_helper_notice');
}
/**
* Removes action/filter using object method callbacks name. You don't need an object instance to use this.
*
* @param string $action_name
* @param int $priority
* @param string $function_name
*/
private function remove_object_action_by_name($action_name, $priority, $function_name)
{
global $wp_filter;
if (isset($wp_filter[$action_name]) && isset($wp_filter[$action_name]->callbacks[$priority])) {
/** @var WP_Hook $admin_notices_tag */
$admin_notices_tag = $wp_filter[$action_name];
$default_priority_callbacks = $admin_notices_tag->callbacks[$priority];
foreach ($default_priority_callbacks as $callback) {
if (\is_array($callback) && \is_array($callback[self::CALLBACK_KEY]) && isset($callback[self::CALLBACK_KEY][self::CALLBACK_KEY_WITH_FUNCTION_NAME])) {
$found_function_name = $callback[self::CALLBACK_KEY][self::CALLBACK_KEY_WITH_FUNCTION_NAME];
if ($found_function_name === $function_name) {
$admin_notices_tag->remove_filter($action_name, $callback[self::CALLBACK_KEY], $priority);
}
}
}
}
}
/**
* Removes wpdesk helper menu if was added by helper.
*
* @return void
*/
private function remove_wpdesk_menu()
{
\add_action('admin_menu', function () {
$this->handle_remove_wpdesk_menu();
}, self::REMOVE_WPDESK_MENU_PRIORITY);
}
/**
* Removes wpdesk helper update routines if was added by helper.
*
* @return void
*/
private function remove_helper_updates()
{
// have to be in plugins_loaded because helper is loaded simultaneously with this plugin
\add_action('plugins_loaded', function () {
\remove_action('plugins_loaded', [$this->get_helper_instance(), 'init_helper_plugins'], \FcfVendor\WPDesk\Helper\Integration\LicenseIntegration::PRIORITY_HELPER_UPDATE);
});
}
/**
* @return void
*/
private function handle_remove_wpdesk_menu()
{
$wpdesk_helper = $this->get_helper_instance();
if ($wpdesk_helper) {
\remove_submenu_page('wpdesk-helper', 'wpdesk-licenses');
\remove_action('wp-desk_page_wpdesk-licenses', [$wpdesk_helper, 'wpdesk_licenses']);
\remove_submenu_page('wpdesk-helper', 'wpdesk-helper-settings');
\remove_action('wp-desk_page_wpdesk-helper-settings', [$wpdesk_helper, 'wpdesk_helper_settings']);
\remove_menu_page('wpdesk-helper');
}
}
/**
* @return void
*/
private function remove_message_about_log()
{
\add_filter('wpdesk_helper_show_log_notices', '__return_false');
}
/**
* Fetches WPDesk_Helper instance if it's available.
*
* @return \WPDesk_Helper|null
*/
private function get_helper_instance()
{
$storage = new \FcfVendor\WPDesk\PluginBuilder\Storage\StorageFactory();
try {
return $storage->create_storage()->get_from_storage('WPDesk_Helper');
} catch (\FcfVendor\WPDesk\PluginBuilder\Storage\Exception\ClassNotExists $e) {
return null;
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace FcfVendor\WPDesk\Helper\Integration;
use FcfVendor\WPDesk\License\Page\LicensePage;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\License\InstalledPlugins;
/**
* Integrates WP Desk licenses with WordPress
*
* @package WPDesk\Helper
*/
class LicenseIntegration implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/** @var LicensePage */
private $license_page;
/** @var InstalledPlugins */
private $plugin_registry;
const PRIORITY_HELPER_UPDATE = 9999999;
const PRIORITY_AFTER_WPDESK_NEW_MENU_ADDED = 20;
public function __construct()
{
$plugin_registry = new \FcfVendor\WPDesk\License\InstalledPlugins();
$this->license_page = new \FcfVendor\WPDesk\License\Page\LicensePage($plugin_registry);
$this->plugin_registry = $plugin_registry;
}
/**
* @return void
*/
public function hooks()
{
$this->license_page->hooks();
$this->add_helper_updates();
$this->add_license_page();
}
/**
* @return void
*/
private function add_helper_updates()
{
// have to be in plugins_loaded because helper is loaded simultaneously with this plugin
\add_action('plugins_loaded', function () {
\add_action('plugins_loaded', [$this->plugin_registry, 'refresh_plugin_update_info'], self::PRIORITY_HELPER_UPDATE);
});
}
/**
* Replace licenses page if helper exists or add that page if helper not exists.
*
* @return void
*/
private function add_license_page()
{
\add_action('admin_menu', function () {
$this->license_page->handle_add_page_submenu_item();
}, self::PRIORITY_AFTER_WPDESK_NEW_MENU_ADDED);
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace FcfVendor\WPDesk\Helper\Integration;
use FcfVendor\Monolog\Logger;
use FcfVendor\WPDesk\Helper\Page\SettingsPage;
use FcfVendor\WPDesk\Logger\WPDeskLoggerFactory;
use FcfVendor\WPDesk\Notice\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Integrates WP Desk log with WordPress
*
* @package WPDesk\Helper
*/
class LogsIntegration implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const DEBUG_LOG_SETTING_KEY = 'debug_log';
/** @var SettingsPage */
private $settings_page;
/** @var Logger */
private $logger;
public function __construct(\FcfVendor\WPDesk\Helper\Page\SettingsPage $settings_page)
{
$this->settings_page = $settings_page;
}
public function hooks()
{
\add_action('admin_init', function () {
$this->handle_page_settings_logs_section();
});
$this->wpdesk_log_init();
$this->maybe_show_logging_notice();
}
private function handle_page_settings_logs_section()
{
\add_settings_section('wpdesk_helper_debug', \__('Debug', 'flexible-checkout-fields'), null, $this->settings_page->get_page_name());
\add_settings_field(self::DEBUG_LOG_SETTING_KEY, \__('WP Desk Debug Log', 'flexible-checkout-fields'), function () {
$this->handle_render_page_settings_log_section();
}, $this->settings_page->get_page_name(), 'wpdesk_helper_debug');
}
private function handle_render_page_settings_log_section()
{
$options = $this->settings_page->get_saved_options();
if (empty($options[self::DEBUG_LOG_SETTING_KEY])) {
$options[self::DEBUG_LOG_SETTING_KEY] = '0';
}
?>
<input type="checkbox" id="wpdesk_helper_options[<?php
echo self::DEBUG_LOG_SETTING_KEY;
?>]"
name="wpdesk_helper_options[<?php
echo self::DEBUG_LOG_SETTING_KEY;
?>]"
value="1" <?php
\checked(1, $options[self::DEBUG_LOG_SETTING_KEY], \true);
?>>
<label for="wpdesk_helper_options[<?php
echo self::DEBUG_LOG_SETTING_KEY;
?>]"><?php
\_e('Enable', 'flexible-checkout-fields');
?></label>
<p class="description" id="admin-email-description">
<?php
echo \sprintf(\__('Writes error log to %s.', 'flexible-checkout-fields'), '<a target="_blank" href="' . \content_url('uploads/wpdesk-logs/wpdesk_debug.log') . '">' . \content_url('uploads/wpdesk-logs/wpdesk_debug.log') . '</a>');
?>
</p>
<?php
}
private function is_logger_active()
{
$options = $this->settings_page->get_saved_options();
return isset($options[self::DEBUG_LOG_SETTING_KEY]) && '1' === $options[self::DEBUG_LOG_SETTING_KEY];
}
private function wpdesk_log_init()
{
$logger_factory = new \FcfVendor\WPDesk\Logger\WPDeskLoggerFactory();
/** support for very old FS*/
if (\property_exists($logger_factory, 'shouldLoggerBeActivated')) {
$logger_factory::$shouldLoggerBeActivated = $this->is_logger_active();
$this->logger = $logger_factory->createWPDeskLogger();
} else {
$this->logger = new \FcfVendor\Monolog\Logger('fallback');
}
}
private function maybe_show_logging_notice()
{
$debug_log_enabled = $this->is_logger_active();
if ($debug_log_enabled) {
if (\apply_filters('wpdesk_helper_show_log_notices_library', \true)) {
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(
// Translators: link.
\__('WP Desk Debug Log is enabled. %1$sPlease disable it after testing%2$s.', 'flexible-checkout-fields'),
'<a href="' . \admin_url('admin.php?page=wpdesk-helper-settings') . '">',
'</a>'
), \FcfVendor\WPDesk\Notice\Notice::NOTICE_TYPE_INFO);
}
}
}
public function get_logger()
{
return $this->logger;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace FcfVendor\WPDesk\Helper\Integration;
use FcfVendor\WPDesk\Helper\Page\SettingsPage;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
/**
* Integrates WP Desk main settings page with WordPress
*
* @package WPDesk\Helper
*/
class SettingsIntegration implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable, \FcfVendor\WPDesk\PluginBuilder\Plugin\HookableCollection
{
use HookableParent;
/** @var SettingsPage */
private $settings_page;
public function __construct(\FcfVendor\WPDesk\Helper\Page\SettingsPage $settingsPage)
{
$this->add_hookable($settingsPage);
}
/**
* @return void
*/
public function hooks()
{
$this->hooks_on_hookable_objects();
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace FcfVendor\WPDesk\Helper\Integration;
use FcfVendor\WPDesk\Helper\Page\SettingsPage;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Integrates WP Desk tracker with WordPress
*
* @package WPDesk\Helper
*/
class TrackerIntegration implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/** @var SettingsPage */
private $settings_page;
/** @var \WPDesk_Tracker */
private $tracker;
public function __construct(\FcfVendor\WPDesk\Helper\Page\SettingsPage $settings_page)
{
$this->settings_page = $settings_page;
}
public function hooks()
{
$tracker_enabled = \apply_filters('wpdesk_tracker_enabled', \true);
if ($tracker_enabled) {
\add_action('admin_init', function () {
$this->handle_page_settings_track_section();
});
$this->tracker = $this->initialize_main_tracker();
}
}
/**
* @return \WPDesk_Tracker_Interface
*/
private function initialize_main_tracker()
{
return \apply_filters('wpdesk_tracker_instance', null);
}
/**
* @return \WPDesk_Tracker_Interface
*/
public function get_tracker()
{
return $this->tracker;
}
/**
* @return void
*/
private function handle_page_settings_track_section()
{
\add_settings_section('wpdesk_helper_tracking', \__('Plugin usage tracking', 'flexible-checkout-fields'), null, $this->settings_page->get_page_name());
\add_settings_field('wpdesk_tracker_agree', \__('Allow WP Desk to track plugin usage', 'flexible-checkout-fields'), function () {
$this->handle_render_page_settings_track_section();
}, $this->settings_page->get_page_name(), 'wpdesk_helper_tracking');
}
/**
* @return void
*/
private function handle_render_page_settings_track_section()
{
$options = $this->settings_page->get_saved_options();
if (empty($options['wpdesk_tracker_agree'])) {
$options['wpdesk_tracker_agree'] = '0';
}
?>
<input type="checkbox" id="wpdesk_helper_options[wpdesk_tracker_agree]"
name="wpdesk_helper_options[wpdesk_tracker_agree]" value="1" <?php
\checked(1, $options['wpdesk_tracker_agree'], \true);
?>>
<label for="wpdesk_helper_options[wpdesk_tracker_agree]"><?php
\_e('Enable', 'flexible-checkout-fields');
?></label>
<p class="description" id="admin-email-description">
<?php
$terms_url = \get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/dane-uzytkowania/' : 'https://www.wpdesk.net/usage-tracking/';
\printf(\__('No sensitive data is tracked, %sread more%s.', 'flexible-checkout-fields'), '<a target="_blank" href="' . $terms_url . '">', '</a>');
?>
</p>
<?php
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace FcfVendor\WPDesk\Helper\Logs;
use FcfVendor\Monolog\Processor\ProcessorInterface;
use FcfVendor\WPDesk\Helper\Debug\LibraryDebug;
/**
* Can add context with libraries to the logs
*
* @package WPDesk\Helper\Logs
*/
class LibraryInfoProcessor implements \FcfVendor\Monolog\Processor\ProcessorInterface
{
/** @var LibraryDebug */
private $library_debug;
public function __construct(\FcfVendor\WPDesk\Helper\Debug\LibraryDebug $library_debug)
{
$this->library_debug = $library_debug;
}
/*
* @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#using-processors
*/
public function __invoke(array $record)
{
try {
$files_report = $this->library_debug->get_wpdesk_vendor_files_report();
$record['extra']['library_report'] = $this->library_debug->get_libraries_report($files_report);
} catch (\Exception $e) {
$record['extra']['library_report'] = 'Exception ' . $e->getMessage();
}
return $record;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace FcfVendor\WPDesk\Helper\Page;
use FcfVendor\WPDesk\Helper\Debug\LibraryDebug;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Adds library debug page to the admin panel
*
* @package WPDesk\Helper
*/
class LibraryDebugPage implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const PRIOTITY_LONG_AFTER_ALL_IS_LOADED = 999;
/** @var LibraryDebug */
private $library_debug;
public function __construct(\FcfVendor\WPDesk\Helper\Debug\LibraryDebug $library_debug)
{
$this->library_debug = $library_debug;
}
public function hooks()
{
\add_action('admin_menu', function () {
$menu_visible = $this->is_wpdesk_user();
$parent_slug = null;
if ($menu_visible) {
$parent_slug = 'wpdesk-helper';
}
\add_submenu_page($parent_slug, \__('Library report', 'flexible-checkout-fields'), \__('Library report', 'flexible-checkout-fields'), 'manage_options', 'wpdesk-helper-library-report', function () {
$this->handle_render_library_report_page();
});
}, self::PRIOTITY_LONG_AFTER_ALL_IS_LOADED);
}
/**
* @return void
*/
private function handle_render_library_report_page()
{
$vendor_files_report = $this->library_debug->get_wpdesk_vendor_files_report();
echo '<pre>';
/** @noinspection ForgottenDebugOutputInspection */
\print_r(['used_libraries' => $this->library_debug->get_libraries_report($vendor_files_report), 'used_files' => $vendor_files_report]);
echo '</pre>';
}
/**
* Checks if user from WPDesk domain is logged in
*
* @return bool
*/
private function is_wpdesk_user()
{
$userdata = \get_userdata(\get_current_user_id());
return \preg_match('/@wpdesk\\..+/', $userdata->user_email) >= 1;
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace FcfVendor\WPDesk\Helper\Page;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Can render and manage license page.
*
* @package WPDesk\Helper
*/
class SettingsPage implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const PRIORITY_AFTER_LICENSE = 25;
public function hooks()
{
\add_action('admin_init', function () {
$this->handle_register_settings();
});
\add_action('admin_menu', function () {
$this->handle_add_settings_menu();
}, self::PRIORITY_AFTER_LICENSE);
}
/**
* Register WordPress settings that can be used on settings page
*
* @return void
*/
private function handle_register_settings()
{
\register_setting($this->get_option_name(), $this->get_option_name());
}
/**
* Unique settings option id
*
* @return string
*/
public function get_option_name()
{
return 'wpdesk_helper_options';
}
/**
* @return void
*/
private function handle_add_settings_menu()
{
\add_submenu_page('wpdesk-helper', \__('Settings', 'flexible-checkout-fields'), \__('Settings', 'flexible-checkout-fields'), 'manage_options', 'wpdesk-helper-settings', function () {
$this->handle_render_wpdesk_helper_settings();
});
}
/**
* @return void
*/
private function handle_render_wpdesk_helper_settings()
{
?>
<div class="wrap">
<h1><?php
\_e('WP Desk Helper Settings', 'flexible-checkout-fields');
?></h1>
<form method="post" action="options.php">
<?php
\settings_fields('wpdesk_helper_options');
\do_settings_sections($this->get_page_name());
\submit_button();
?>
</form>
</div>
<?php
}
/**
* Unique page id
*
* @return string
*/
public function get_page_name()
{
return 'wpdesk_helper';
}
/**
* Options saved in settings as array
*
* @return array
*/
public function get_saved_options()
{
$options = \get_option($this->get_option_name(), []);
if (!\is_array($options)) {
$options = [];
}
return $options;
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace FcfVendor\WPDesk\Helper;
use Psr\Log\LoggerInterface;
use FcfVendor\WPDesk\Helper\Debug\LibraryDebug;
use FcfVendor\WPDesk\Helper\Integration\LicenseIntegration;
use FcfVendor\WPDesk\Helper\Integration\LogsIntegration;
use FcfVendor\WPDesk\Helper\Integration\SettingsIntegration;
use FcfVendor\WPDesk\Helper\Integration\TrackerIntegration;
use FcfVendor\WPDesk\Helper\Logs\LibraryInfoProcessor;
use FcfVendor\WPDesk\Helper\Page\LibraryDebugPage;
use FcfVendor\WPDesk\Helper\Page\SettingsPage;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Manager all functionalities understood as helper
*
* @package WPDesk\Helper
*/
class PrefixedHelperAsLibrary implements \FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const LIBRARY_TEXT_DOMAIN = 'flexible-checkout-fields';
const MAIN_WPDESK_MENU_POSITION = 99.99941337;
const PRIORITY_AFTER_WPDESK_MENU_REMOVAL = 15;
const PRIORITY_AFTER_ALL = 200;
/** @var LoggerInterface */
private static $logger;
/** @var \WPDesk_Tracker */
private static $tracker;
public function hooks()
{
if (\is_admin() && !$this->is_already_hooked_touch()) {
$this->initialize();
\do_action('wpdesk_helper_initialized', $this);
}
}
/**
* Check if prefixed helpers is not already hooked. Also touch flag so we know that is hooked now
*
* @return bool
*/
private function is_already_hooked_touch()
{
$is_loaded = \apply_filters('wpdesk_prefixed_helper_is_loaded', \false);
\add_filter('wpdesk_prefixed_helper_is_loaded', function () {
return \true;
});
return $is_loaded;
}
/**
* Show info about installed helper plugin
*/
private function show_notices_about_old_helper()
{
$helper_info = new \FcfVendor\WPDesk\Helper\HelperRemoveInfo();
if ($helper_info->is_helper_active()) {
$helper_info->show_deactivate_helper_notice();
} elseif ($helper_info->is_helper_installed()) {
$helper_info->show_remove_helper_notice();
}
}
private function initialize()
{
$this->add_wpdesk_menu();
$subscription_integration = new \FcfVendor\WPDesk\Helper\Integration\LicenseIntegration();
$subscription_integration->hooks();
$settingsPage = new \FcfVendor\WPDesk\Helper\Page\SettingsPage();
$settings_integration = new \FcfVendor\WPDesk\Helper\Integration\SettingsIntegration($settingsPage);
$tracker_integration = new \FcfVendor\WPDesk\Helper\Integration\TrackerIntegration($settingsPage);
$logger_integration = new \FcfVendor\WPDesk\Helper\Integration\LogsIntegration($settingsPage);
$settings_integration->add_hookable($logger_integration);
$settings_integration->add_hookable($tracker_integration);
$settings_integration->hooks();
self::$tracker = $tracker_integration->get_tracker();
self::$logger = $logger_integration->get_logger();
(new \FcfVendor\WPDesk\Helper\UpgradeSoonNotice())->show_info_about_upgrade_if_old_env();
$this->clean_wpdesk_menu();
$library_debug_info = new \FcfVendor\WPDesk\Helper\Debug\LibraryDebug();
(new \FcfVendor\WPDesk\Helper\Page\LibraryDebugPage($library_debug_info))->hooks();
self::$logger->pushProcessor(new \FcfVendor\WPDesk\Helper\Logs\LibraryInfoProcessor($library_debug_info));
$this->show_notices_about_old_helper();
}
/**
* Adds WP Desk to main menu
*/
private function add_wpdesk_menu()
{
\add_action('admin_menu', function () {
$this->handle_add_wpdesk_menu();
}, self::PRIORITY_AFTER_WPDESK_MENU_REMOVAL);
}
/**
* @return void
*/
private function handle_add_wpdesk_menu()
{
\add_menu_page('WP Desk', 'WP Desk', 'manage_options', 'wpdesk-helper', function () {
}, 'dashicons-controls-play', self::MAIN_WPDESK_MENU_POSITION);
}
/**
* Removed unnecessary submenu item for WP Desk
*/
private function clean_wpdesk_menu()
{
\add_action('admin_menu', static function () {
\remove_submenu_page('wpdesk-helper', 'wpdesk-helper');
}, self::PRIORITY_AFTER_ALL);
}
/**
* @return \WPDesk_Tracker
*/
public function get_tracker()
{
return self::$tracker;
}
/**
* @return LoggerInterface
*/
public function get_logger()
{
return self::$logger;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace FcfVendor\WPDesk\Helper;
use FcfVendor\WPDesk\Notice\Notice;
use FcfVendor\WPDesk_Basic_Requirement_Checker;
/**
* Shows notice that you should upgrade your environment soon.
*
* @package WPDesk\Helper
*/
class UpgradeSoonNotice
{
const SUPPORTED_PHP = '7.0';
const SUPPORTED_WC = '4.0';
const SUPPORTED_WP = '5.0';
/**
* @return bool
*/
private function is_old_wc()
{
if (!\defined('WC_VERSION')) {
// when there is no WC, assume it is not old.
return \false;
}
return !\FcfVendor\WPDesk_Basic_Requirement_Checker::is_wc_at_least(self::SUPPORTED_WC);
}
/**
* @return bool
*/
private function is_old_wp()
{
return !\FcfVendor\WPDesk_Basic_Requirement_Checker::is_wp_at_least(self::SUPPORTED_WP);
}
/**
* @return bool
*/
private function is_old_php()
{
return !\FcfVendor\WPDesk_Basic_Requirement_Checker::is_php_at_least(self::SUPPORTED_PHP);
}
/**
* Returns true only first time per WP request.
*
* @return bool
*/
private function has_not_shown_earlier()
{
$mutex_filter = 'wpdesk_helper_upgrade_notice_already_shown';
if (\apply_filters($mutex_filter, \true)) {
\add_filter($mutex_filter, static function () {
return \false;
});
return \true;
}
return \false;
}
/**
* Shows notice that you should upgrade your environment soon. Notice will be shown only once per WP request.
*/
public function show_info_about_upgrade_if_old_env()
{
\add_action('plugins_loaded', function () {
if ($this->has_not_shown_earlier()) {
if ($this->is_old_php()) {
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(\__('The PHP version your shop is currently using is deprecated. We highly advise to upgrade it to at least %s since the support for this one will be dropped soon.', 'flexible-checkout-fields'), self::SUPPORTED_PHP));
}
if ($this->is_old_wc()) {
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(\__('The WooCommerce version your shop is currently using is deprecated. We highly advise to upgrade it to at least %s since the support for this one will be dropped soon.', 'flexible-checkout-fields'), self::SUPPORTED_WC));
}
if ($this->is_old_wp()) {
new \FcfVendor\WPDesk\Notice\Notice(\sprintf(\__('The WordPress version your shop is currently using is deprecated. We highly advise to upgrade it to at least %s since the support for this one will be dropped soon.', 'flexible-checkout-fields'), self::SUPPORTED_WP));
}
}
});
}
}