addActions();
}
protected function addActions()
{
add_action('admin_menu', [$this, 'registerPage']);
add_action('admin_init', [$this, 'registerSettingsGroups']);
add_action('admin_init', [$this, 'registerFields']);
add_action('admin_init', [$this, 'checkInstagramQueryURL']);
}
public function getSettingsGroups()
{
return [
'general' => [
'title' => __('General', 'getwid'),
'sections' => [
'contact_from' => __('Contact Form Settings', 'getwid'),
]
],
'appearance' => [
'title' => __('Appearance', 'getwid'),
'sections' => [ ]
],
'blocks' => [
'title' => __('Blocks', 'getwid'),
'sections' => [ ]
],
'post_templates' => [
'title' => __('Post Templates', 'getwid'),
'sections' => [ ]
]
];
}
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',
[$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');
?>
$tab) :
$active_tab_class = $tab_id == $active_tab_id ? 'nav-tab-active' : '';
?>
renderPostTemplatesTab();
else :
?>
instagramTokenManager()->schedule_token_refresh_event();
$redirect_url = add_query_arg(
[
'getwid-instagram-success' => true
],
$this->getTabUrl('general')
);
} else {
$redirect_url = add_query_arg(
[
'instagram-error' => true
],
$this->getTabUrl('general')
);
}
wp_redirect( $redirect_url );
}
if (isset($_GET['getwid-instagram-success'])) {
add_action( 'admin_notices', [$this, 'getwid_instagram_notice_success'] );
}
if (isset($_GET['instagram-error'])) {
add_action( 'admin_notices', [$this, 'getwid_instagram_notice_error'] );
}
}
public function registerFields() {
/* #region Section Content Width */
add_settings_field( 'getwid_section_content_width', __( 'Section Content Width', 'getwid' ),
[ $this, 'renderSectionContentWidth' ], 'getwid_appearance', 'getwid_appearance' );
register_setting( 'getwid_appearance', 'getwid_section_content_width', [ 'type' => 'number', 'default' => '' ] );
/* #endregion */
/* #region Animation */
add_settings_field( 'getwid_animation', __( 'Animation', 'getwid' ),
[ $this, 'renderAnimation' ], 'getwid_appearance', 'getwid_appearance' );
register_setting( 'getwid_appearance', 'getwid_smooth_animation', [ 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean' ] );
/* #endregion */
/* #region AssetsOptimization */
add_settings_field( 'getwid_assets_optimization', __( 'Performance Optimization', 'getwid' ),
[ $this, 'renderAssetsOptimization'], 'getwid_general', 'getwid_general' );
register_setting( 'getwid_general', 'getwid_load_assets_on_demand', [ 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean' ] );
register_setting( 'getwid_general', 'getwid_move_css_to_head', [ 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean' ] );
/* #endregion */
/* #region Instagram Access Token */
add_settings_field( 'getwid_instagram_token', __( 'Instagram Access Token', 'getwid' ),
[ $this, 'renderInstagramToken' ], 'getwid_general', 'getwid_general' );
register_setting( 'getwid_general', 'getwid_instagram_token', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Instagram Cache Timeout */
add_settings_field( 'getwid_instagram_cache_timeout', __( 'Instagram Cache Timeout', 'getwid' ),
[ $this, 'renderInstagramCacheTimeout' ], 'getwid_general', 'getwid_general' );
register_setting( 'getwid_general', 'getwid_instagram_cache_timeout', [ 'type' => 'number', 'default' => 30 ] );
/* #endregion */
/* #region Google API Key */
add_settings_field( 'getwid_google_api_key', __( 'Google Maps API Key', 'getwid' ),
[ $this, 'renderGoogleApiKey' ], 'getwid_general', 'getwid_general' );
register_setting( 'getwid_general', 'getwid_google_api_key', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Recaptcha Site Key */
add_settings_field( 'getwid_contact_form_recipient_email', __( 'Recipient Email Address', 'getwid' ),
[ $this, 'renderContactFormRecipientEmail' ], 'getwid_general', 'getwid_contact_from' );
register_setting( 'getwid_general', 'getwid_contact_form_recipient_email', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Recaptcha Site Key */
add_settings_field( 'getwid_recaptcha_v2_site_key', __( 'Recaptcha Site Key', 'getwid' ),
[ $this, 'renderRecaptchaSiteKey' ], 'getwid_general', 'getwid_contact_from' );
register_setting( 'getwid_general', 'getwid_recaptcha_v2_site_key', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Recaptcha Secret Key */
add_settings_field( 'getwid_recaptcha_v2_secret_key', __( 'Recaptcha Secret Key', 'getwid' ),
[ $this, 'renderRecaptchaSecretKey' ], 'getwid_general', 'getwid_contact_from' );
register_setting( 'getwid_general', 'getwid_recaptcha_v2_secret_key', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Mailchimp Api Key */
add_settings_field( 'getwid_mailchimp_api_key', __( 'Mailchimp API Key', 'getwid' ),
[ $this, 'renderMailchimpApiKey' ], 'getwid_general', 'getwid_general' );
register_setting( 'getwid_general', 'getwid_mailchimp_api_key', [ 'type' => 'text', 'default' => '' ] );
/* #endregion */
/* #region Disabled Blocks */
add_settings_field( 'getwid_disabled_blocks', __( 'Disable Getwid Blocks', 'getwid' ),
[ $this, 'renderDisabledBlocks' ], 'getwid_blocks', 'getwid_blocks' );
$blocks = getwid()->blocksManager()->getBlocks();
foreach ($blocks as $name => $block) {
$option_name = $block->getDisabledOptionKey();
register_setting( 'getwid_blocks', $option_name, [ '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(
['nonce' => wp_create_nonce('getwid_nonce_save_instagram_token') ],
admin_url( 'options-general.php' )
);
$refreshURL = add_query_arg(
['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()->getBlocks();
$disabledBlocks = getwid()->blocksManager()->getDisabledBlocks();
ksort( $blocks );
?>
/
'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';
}
}