* * @version 1.0 * @date updated Feb 26, 2023 */ namespace wlurep; class Plugin { private static $_instance = null; /** * Plugin constructor. * * Initializing WL update real estates plugin. * * @since 1.0.0 * @access private */ private function __construct() { $this->register_autoloader(); $this->register_json_api(); if(is_admin()){ $this->register_admin_menu(); global $pagenow; if ( $pagenow === 'options.php' || $pagenow === 'options-general.php' && isset($_GET['page']) && $_GET['page'] == 'wl-urep-settings') { // WL settings page $this->register_settings_page(); } } } /** * Register autoloader. * * WL update real estate autoloader, that loads all the classes needed to run the plugin. * * @since 1.6.0 * @access private */ private function register_autoloader() { require_once WL_UREP_PATH . '/Loader.php'; Loader::registerAutoLoad(); } /** * Register json api class. * * * @since 1.6.0 * @access private */ private function register_json_api() { $jsonAPI = \wlurep\JSONAPI::getInstance(); } /** * Add function to admin_menu hook */ private function register_admin_menu() { add_action('admin_menu', array($this, 'addSettingsMenu')); } /** * Add function to admin_init hook */ private function register_settings_page() { add_action('admin_init', array($this, 'settingsPage')); } /** * Add menu */ public function addSettingsMenu() { // Add Role management page to user menu add_options_page( __('Automatic update real estates', 'wlurep'), __('Automatic update real estates', 'wlurep'), 'manage_options', 'wl-urep-settings', array($this, 'page')); } /* * Function that generate REST API settings page */ public function page() { if (!current_user_can('manage_options')) { return; } ?>
'.__('Here you can set all the options for using the REST API that automatic update real estate properties', 'wlurep').''; } /** * function that generate API token field */ public function wl_urep_setting_api_key() { $apiKey = wl_get_option('urep_api_key', ''); echo ""; } /** * function that generate API url field */ public function wl_urep_setting_api_url() { $apiUrl = wl_get_option('urep_api_url', ''); echo ""; } /** * function that validate saved fields */ public function wl_urep_settings_validate($input) { $api_key = trim($input['urep_api_key']); if (!preg_match('/^[a-z0-9-]+$/i', $api_key)) { $input['urep_api_key'] = ''; add_settings_error('urep_error', 'wl_urep_setting_api_key', __('The API key can contain lower letters, numbers and dash', 'wlurep'), 'error'); } $input['urep_api_url'] = sanitize_url($input['urep_api_url']); return $input; } /** * * @return \wlurep\Plugin */ public static function getInstance() { if (self::$_instance == null) { self::$_instance = new self; } return self::$_instance; } } Plugin::getInstance();