addActions(); } protected function addActions() { add_action( 'admin_menu', array( $this, 'registerPage' ) ); add_action( 'admin_init', array( $this, 'registerSettingsGroups' ) ); add_action( 'admin_init', array( $this, 'registerFields' ) ); add_action( 'admin_init', array( $this, 'checkInstagramQueryURL' ) ); } public function getSettingsGroups() { return array( 'general' => array( 'title' => __( 'General', 'getwid' ), 'sections' => array( 'contact_from' => __( 'Contact Form Settings', 'getwid' ), ), ), 'appearance' => array( 'title' => __( 'Appearance', 'getwid' ), 'sections' => array(), ), 'blocks' => array( 'title' => __( 'Blocks', 'getwid' ), 'sections' => array(), ), 'post_templates' => array( 'title' => __( 'Post Templates', 'getwid' ), 'sections' => array(), ), ); } public function registerPage() { add_options_page( esc_html_x( 'Getwid Settings', 'Settings page title', 'getwid' ), esc_html_x( 'Getwid', 'Settings page title(in menu)', 'getwid' ), 'manage_options', 'getwid', array( $this, 'renderPage' ) ); } public function registerSettingsGroups() { $settings_groups = $this->getSettingsGroups(); foreach ( $settings_groups as $id => $group ) { add_settings_section( 'getwid_' . $id, '', '', 'getwid_' . $id ); foreach ( $group['sections'] as $section_id => $section ) { add_settings_section( 'getwid_' . $section_id, $section, '', 'getwid_' . $id ); } } } public function renderPage() { if ( ! current_user_can( 'manage_options' ) ) { return; } $active_tab_id = $this->getActiveTabID(); $settings_groups = $this->getSettingsGroups(); settings_errors( 'getwid_settings_errors' ); ?>

renderPostTemplatesTab(); else : ?>

instagramTokenManager()->schedule_token_refresh_event(); $redirect_url = add_query_arg( array( 'getwid-instagram-success' => true, ), $this->getTabUrl( 'general' ) ); } else { $redirect_url = add_query_arg( array( 'instagram-error' => true, ), $this->getTabUrl( 'general' ) ); } wp_redirect( $redirect_url ); } if ( isset( $_GET['getwid-instagram-success'] ) ) { add_action( 'admin_notices', array( $this, 'getwid_instagram_notice_success' ) ); } if ( isset( $_GET['instagram-error'] ) ) { add_action( 'admin_notices', array( $this, 'getwid_instagram_notice_error' ) ); } } public function registerFields() { /* #region Section Content Width */ add_settings_field( 'getwid_section_content_width', __( 'Section Content Width', 'getwid' ), array( $this, 'renderSectionContentWidth' ), 'getwid_appearance', 'getwid_appearance' ); register_setting( 'getwid_appearance', 'getwid_section_content_width', array( 'type' => 'number', 'default' => '', ) ); /* #endregion */ /* #region Animation */ add_settings_field( 'getwid_animation', __( 'Animation', 'getwid' ), array( $this, 'renderAnimation' ), 'getwid_appearance', 'getwid_appearance' ); register_setting( 'getwid_appearance', 'getwid_smooth_animation', array( 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', ) ); /* #endregion */ /* #region Instagram Access Token */ add_settings_field( 'getwid_instagram_token', __( 'Instagram Access Token', 'getwid' ), array( $this, 'renderInstagramToken' ), 'getwid_general', 'getwid_general' ); register_setting( 'getwid_general', 'getwid_instagram_token', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Instagram Cache Timeout */ add_settings_field( 'getwid_instagram_cache_timeout', __( 'Instagram Cache Timeout', 'getwid' ), array( $this, 'renderInstagramCacheTimeout' ), 'getwid_general', 'getwid_general' ); register_setting( 'getwid_general', 'getwid_instagram_cache_timeout', array( 'type' => 'number', 'default' => 30, ) ); /* #endregion */ /* #region Google API Key */ add_settings_field( 'getwid_google_api_key', __( 'Google Maps API Key', 'getwid' ), array( $this, 'renderGoogleApiKey' ), 'getwid_general', 'getwid_general' ); register_setting( 'getwid_general', 'getwid_google_api_key', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Recaptcha Site Key */ add_settings_field( 'getwid_contact_form_recipient_email', __( 'Recipient Email Address', 'getwid' ), array( $this, 'renderContactFormRecipientEmail' ), 'getwid_general', 'getwid_contact_from' ); register_setting( 'getwid_general', 'getwid_contact_form_recipient_email', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Recaptcha Site Key */ add_settings_field( 'getwid_recaptcha_v2_site_key', __( 'Recaptcha Site Key', 'getwid' ), array( $this, 'renderRecaptchaSiteKey' ), 'getwid_general', 'getwid_contact_from' ); register_setting( 'getwid_general', 'getwid_recaptcha_v2_site_key', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Recaptcha Secret Key */ add_settings_field( 'getwid_recaptcha_v2_secret_key', __( 'Recaptcha Secret Key', 'getwid' ), array( $this, 'renderRecaptchaSecretKey' ), 'getwid_general', 'getwid_contact_from' ); register_setting( 'getwid_general', 'getwid_recaptcha_v2_secret_key', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Mailchimp Api Key */ add_settings_field( 'getwid_mailchimp_api_key', __( 'Mailchimp API Key', 'getwid' ), array( $this, 'renderMailchimpApiKey' ), 'getwid_general', 'getwid_general' ); register_setting( 'getwid_general', 'getwid_mailchimp_api_key', array( 'type' => 'text', 'default' => '', ) ); /* #endregion */ /* #region Disabled Blocks */ add_settings_field( 'getwid_disabled_blocks', __( 'Disable Getwid Blocks', 'getwid' ), array( $this, 'renderDisabledBlocks' ), 'getwid_blocks', 'getwid_blocks' ); $blocks = getwid()->blocksManager()->getBlocks(); foreach ( $blocks as $name => $block ) { $option_name = $block->get_disabled_option_key(); register_setting( 'getwid_blocks', $option_name, array( 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', ) ); } /* #endregion */ } public function renderSectionContentWidth() { $field_val = get_option( 'getwid_section_content_width', '' ); ?>

decrypt( get_option( 'getwid_instagram_token', '' ) ); $connectURL = add_query_arg( array( 'nonce' => wp_create_nonce( 'getwid_nonce_save_instagram_token' ) ), admin_url( 'options-general.php' ) ); $refreshURL = add_query_arg( array( 'nonce' => wp_create_nonce( 'getwid_nonce_save_instagram_token' ) ), admin_url( 'options-general.php' ) ); ?> username ) ) { echo '

' . sprintf( //translators: %s is username or user id esc_html__( 'Account: %s', 'getwid' ), esc_html( $profile_data->username ) ) . '

'; } elseif ( isset( $profile_data->id ) ) { echo '

' . sprintf( //translators: %s is username or user id esc_html__( 'Account: %s', 'getwid' ), esc_html( $profile_data->id ) ) . '

'; } } } } catch ( \Exception $profile_data_exception ) { echo esc_html( $profile_data_exception->getMessage() ); } } ?>

blocksManager()->getControlledBlocks(); $disabledBlocks = getwid()->blocksManager()->getDisabledBlocks(); ksort( $blocks ); ?>


 / 

$block ) { $option_name = $block->get_disabled_option_key(); ?>

'getwid', 'active_tab' => $tab, ), admin_url( 'options-general.php' ) ); } private function getActiveTabID() { $tab_param_isset = isset( $_GET['active_tab'] ) && array_key_exists( $_GET['active_tab'], $this->getSettingsGroups() ); return $tab_param_isset ? sanitize_text_field( wp_unslash( $_GET['active_tab'] ) ) : 'general'; } }