render_page('addons');
}
public function alphagf_help_page() {
$this->render_page('help');
}
public function alphagf_changelog_page() {
$this->render_page('changelog');
}
private function render_page($view) {
echo '
';
echo '
';
include_once ALPHAGF_PATH . '/includes/admin/views/header.php';
echo '
';
include_once ALPHAGF_PATH . '/includes/admin/views/' . $view . '.php';
echo '';
echo '
';
}
public function enqueue_admin_scripts() {
$current_screen = get_current_screen();
wp_enqueue_style('alphagf_icon', ALPHAGF_ASSETS . '/css/font_style.css', [], ALPHAGF_VERSION);
if ($current_screen && strpos($current_screen->base, 'alphagf_') !== false) {
wp_enqueue_style('alphagf_admin', ALPHAGF_ASSETS . '/css/alphagf_dashboard.css', [], ALPHAGF_VERSION);
wp_enqueue_script('alphagf_admin', ALPHAGF_ASSETS . '/js/alphagf_admin.js', ['jquery'], ALPHAGF_VERSION, true);
wp_localize_script(
'alphagf_admin',
'alphagf_admin',
[
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('alphagf_nonce'),
]
);
}
}
public function alphagf_save_addons() {
if (!check_ajax_referer('alphagf_nonce', 'nonce', false)) {
wp_send_json_error(['message' => esc_html__('Something went wrong.', 'alpha-addons-for-gravity-forms')]);
}
if (! current_user_can('manage_options')) {
wp_send_json_error(['message' => esc_html__('Sorry, you are not allowed to do that.', 'alpha-addons-for-gravity-forms')], 403);
}
$sanitized_addons = [];
if (isset($_POST['addons'])) {
$posted_addons = array_map('sanitize_text_field', (array) wp_unslash($_POST['addons']));
$known_addons = array_keys(ALPHAGF_utilities::get_dashboard_addons());
$sanitized_addons = array_values(array_intersect($posted_addons, $known_addons));
}
update_option('alphagf_addons', $sanitized_addons);
wp_send_json_success([
'message' => esc_html__('Your changes has been saved successfully.', 'alpha-addons-for-gravity-forms'),
]);
wp_die();
}
public static function instance() {
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
}