client = $client; $this->name = strtolower( preg_replace( '/\s+/', '', $this->client->name ) ); $this->option_key = $this->name . '_license_options'; $this->notices = array(); } /** * Add the settings page. * * @param array $args Settings page args. * * @return void */ public function add_page( $args ) { // store menu args for proper menu creation. $this->menu_args = wp_parse_args( $args, array( 'type' => 'menu', // Can be: menu, options, submenu. 'page_title' => 'Manage License', 'menu_title' => 'Manage License', 'capability' => 'manage_options', 'menu_slug' => $this->client->slug . '-manage-license', 'icon_url' => '', 'position' => null, 'activated_redirect' => null, 'parent_slug' => '', ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); } /** * Form action URL */ private function form_action_url() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound return apply_filters( 'surecart_client_license_form_action', '' ); } /** * Set the option key. * * If someone wants to override the default generated key. * * @param string $key The option key. */ public function set_option_key( $key ) { $this->option_key = $key; return $this; } /** * Add the admin menu * * @return void */ public function admin_menu() { switch ( $this->menu_args['type'] ) { case 'menu': $this->create_menu_page(); break; case 'submenu': $this->create_submenu_page(); break; case 'options': $this->create_options_page(); break; } } /** * Add license menu page */ private function create_menu_page() { call_user_func( 'add_menu_page', $this->menu_args['page_title'], $this->menu_args['menu_title'], $this->menu_args['capability'], $this->menu_args['menu_slug'], array( $this, 'settings_output' ), $this->menu_args['icon_url'], $this->menu_args['position'] ); } /** * Add submenu page */ private function create_submenu_page() { call_user_func( 'add_submenu_page', $this->menu_args['parent_slug'], $this->menu_args['page_title'], $this->menu_args['menu_title'], $this->menu_args['capability'], $this->menu_args['menu_slug'], array( $this, 'settings_output' ), $this->menu_args['position'] ); } /** * Add submenu page */ private function create_options_page() { call_user_func( 'add_options_page', $this->menu_args['page_title'], $this->menu_args['menu_title'], $this->menu_args['capability'], $this->menu_args['menu_slug'], array( $this, 'settings_output' ), $this->menu_args['position'] ); } /** * Get all options * * @return array */ public function get_options() { return (array) get_option( $this->option_key, array() ); } /** * Clear out the options. * * @return bool */ public function clear_options() { return update_option( $this->option_key, array() ); } /** * Get a specific option * * @param string $name Option name. * * @return mixed */ public function get_option( $name ) { $options = $this->get_options(); return isset( $options[ $name ] ) ? $options[ $name ] : null; } /** * Set the option. * * @param string $name The option name. * @param mixed $value The option value. * * @return bool */ public function set_option( $name, $value ) { $options = (array) $this->get_options(); $options[ $name ] = $value; return update_option( $this->option_key, $options ); } /** * The settings page menu output. * * @return void */ public function settings_output() { $this->license_form_submit(); $assets = include QUICKWEBP_PLUGIN_PATH . 'public/assets/build/licensing.asset.php'; wp_enqueue_style( 'quickwebp-licensing', QUICKWEBP_PLUGIN_URL . 'public/assets/build/licensing.css', array(), $assets['version'] ); $activation = $this->get_activation(); $action = ! empty( $activation->id ) ? 'deactivate' : 'activate'; ?>