plugin_name = 'What3wordsSearchbox'; if (is_admin()) { $this->hook('plugins_loaded'); } } public static function get_instance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; } /** * "plugins_loaded" action hook; fired after active plugins and pluggable functions are * loaded. */ public function plugins_loaded() { $this->hook('admin_init'); $this->hook('admin_menu'); $this->hook('admin_enqueue_scripts'); } public function admin_enqueue_scripts() { $handle = 'what3words-expander-admin-js'; $src = WHAT3WORDS_SEARCHBOX_URL . 'assets/js/what3words-searchbox-admin.js'; $deps = ['jquery']; $ver = NULL; $in_footer = true; wp_enqueue_script($handle, $src, $deps, $ver, $in_footer); } /** * "plugin_action_links_[plugin-name]" filter hook; applied to the list of links to display * on the plugins page (beside the activate/deactivate links) */ public function action_links($actions, $plugin_file, $plugin_data, $context) { $settings = sprintf('%s', admin_url('options-general.php?page=3-word-address-validation-field/What3wordsSearchboxAdmin.php'), __('Settings', 'what3words-searchbox')); array_unshift($actions, $settings); return $actions; } /** * "admin_init" action hook; called after the admin panel is initialised. */ public function admin_init () { if (!empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] === 'plugins.php') { $errors = $this->check_plugin_requirements(); if (!empty($errors)) { unset($_GET['activate']); $name = get_file_data(WHAT3WORDS_SEARCHBOX_FILE, ['Plugin Name'], 'plugin'); printf( '
%1$s
%2$s has been deactivated.
', $errors), $name[0] ); deactivate_plugins(WHAT3WORDS_SEARCHBOX_NAME); return; } } $this->hook('plugin_action_links_' . WHAT3WORDS_SEARCHBOX_NAME, 'action_links'); $this->upgrade_settings(); $this->hook('admin_notices'); } /** * "admin_menu" action hook; called after the basic admin panel menu structure is in * place. */ public function admin_menu() { if (function_exists('add_options_page')) { $page = __('What3words Searchbox - Settings', 'what3words-searchbox'); $menu = __('What3words Searchbox', 'what3words-searchbox'); add_options_page($page, $menu, 'manage_options', __FILE__, [$this, 'display_settings']); } } /** * "admin_notices" action hook; displays notices near the top of the admin pages. */ public function admin_notices() { $meta = get_current_screen(); if (!empty($GLOBALS['pagenow']) && ($GLOBALS['pagenow'] === 'plugins.php' || ($GLOBALS['pagenow'] === 'options-general.php' && $meta->base !== 'settings_page_what3words-searchbox/What3wordsSearchboxAdmin'))) { $settings = $this->get_option(); if (current_user_can('manage_options')) { $notice = []; if (empty($settings['api_key'])) { $notice[] = __('You need to enter your what3words API key to use the What3words Searchbox plugin', 'what3words-searchbox'); } if (empty($settings['input_selectors']) && !$settings['woocommerce_enabled']) { $notice[] = __('You need to enter at least one input selector to use the What3words Searchbox plugin', 'what3words-searchbox'); } if (!empty($notice)) { $notice[] = sprintf('You can go to the What3words Searchbox Settings page to do this now', admin_url('options-general.php?page=3-word-address-validation-field/What3wordsSearchboxAdmin.php')); echo '
' . implode('. ', $notice) . '
' . __('You need to enter your what3words API key to use this plugin', 'what3words-searchbox') . '
' . __('You need to enter at least one input selector to use this plugin', 'what3words-searchbox') . '