*/ class Adplus_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The options name to be used in this plugin * * @since 1.0.0 * @access private * @var string $option_name Option name of this plugin */ public static $option_name = 'adplus'; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; if(isset($_POST['reload-blocks'])) { $this->reloadBlocks(); } } public function reloadBlocks() { $token = get_option(Adplus_Admin::$option_name . '_token'); $domain = get_option(Adplus_Admin::$option_name . '_domain'); if(!$token || !$domain) { Helper::alert('warning', 'Укажите домен и токен.'); } try { if(file_get_contents(rtrim($domain, '/') . '/site/reload-sait-blocks?token=' . $token . '&domain=' . Helper::parseHost(get_site_url())) === 'ok') { Helper::alert('success', 'Блоки обновлены.'); } else { Helper::alert('warning', 'Не удалось обновить блоки, возможно вы указали неверные данные.'); } } catch (Exception $e) { Helper::alert('error', 'Ошибка при отправке запроса. Ошибка - "' . $e->getMessage() . '"'); } } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Adplus_Loader as all of the hooks are defined * in that particular class. * * The Adplus_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/adplus-admin.css', [], $this->version, 'all'); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Adplus_Loader as all of the hooks are defined * in that particular class. * * The Adplus_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/adplus-admin.js', ['jquery'], $this->version, false); } /** * Add an options page under the Settings submenu * * @since 1.0.0 */ public function add_options_page() { $this->plugin_screen_hook_suffix = add_options_page( __('AdPlus.io Настройки', 'adplus'), __('AdPlus.io', 'adplus'), 'manage_options', $this->plugin_name, [$this, 'display_options_page'] ); } /** * Render the options page for plugin * * @since 1.0.0 */ public function display_options_page() { include_once 'partials/adplus-admin-display.php'; } /** * Register all related settings of this plugin * * @since 1.0.0 */ public function register_setting() { add_settings_section( self::$option_name . '_general', __('Настройки', 'adplus'), [$this, self::$option_name . '_general_cb'], $this->plugin_name ); add_settings_field( self::$option_name . '_token', __('Токен пользователя', 'adplus'), [$this, self::$option_name . '_token_cb'], $this->plugin_name, self::$option_name . '_general', ['label_for' => self::$option_name . '_token'] ); add_settings_field( self::$option_name . '_domain', __('Адрес сервиса', 'adplus'), [$this, self::$option_name . '_domain_cb'], $this->plugin_name, self::$option_name . '_general', ['label_for' => self::$option_name . '_domain'] ); register_setting($this->plugin_name, self::$option_name . '_token'); register_setting($this->plugin_name, self::$option_name . '_domain', 'esc_url'); } /** * Render the text for the general section * * @since 1.0.0 */ public function adplus_general_cb() { echo '
' . __('Заполните поля ниже.', 'adplus') . '
'; } public function adplus_token_cb() { $token = get_option(self::$option_name . '_token'); echo ''; echo 'Получить токен пользователя можно на странице профиля в личном кабинете вашей копии коробочной версии, если вы используете облачную версию, то на самом сайте https://adplus.io.
'; } public function adplus_domain_cb() { $domain = get_option(self::$option_name . '_domain'); echo ''; echo 'Укажите адрес сайта, на котором установлена ваша копия сервиса, либо же укажите "https://adplus.io", если вы используете облачную версию.
'; } }