PluginProbe
SurveyJS: Drag & Drop Form Builder / trunk
SurveyJS: Drag & Drop Form Builder vtrunk
trunk 2.5.2 2.5.3 2.5.4 2.5.5
surveyjs / views / settings.php

settings.php in SurveyJS: Drag & Drop Form Builder trunk, at views/settings.php

80 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 class SurveyJS_SettingsPage {
5
6 function __construct() {
7 $this->add_hooks();
8 }
9
10 private function add_hooks() {
11 add_action( "admin_init", array( $this, 'init' ) );
12 }
13
14 public static function get_license_key() {
15 $settings = (array) get_option( 'surveyjs-settings' );
16 if ( isset( $settings['license_key'] ) ) {
17 return $settings['license_key'];
18 }
19 return "";
20 }
21
22 public function init() {
23 register_setting( 'surveyjs-settings-group', 'surveyjs-settings', array(
24 'type' => 'array',
25 'sanitize_callback' => array( $this, 'sanitize_settings' ),
26 ) );
27
28 add_settings_section( 'sjs-license-key-section', esc_html__( 'Set License Key', 'surveyjs' ), array($this, 'sjs_license_key_section'), 'surveyjs-settings-page' );
29 add_settings_field( 'license_key', esc_html__( 'License Key', 'surveyjs' ), array($this, 'set_license_key_render'), 'surveyjs-settings-page', 'sjs-license-key-section' );
30 }
31
32 public function sanitize_settings( $input ) {
33 $sanitized = array();
34 if ( isset( $input['license_key'] ) ) {
35 $sanitized['license_key'] = sanitize_text_field( $input['license_key'] );
36 }
37 return $sanitized;
38 }
39
40 public function sjs_license_key_section() {
41 esc_html_e( 'setting your license key', 'surveyjs' );
42 if ( isset( $_GET["settings-updated"] ) && sanitize_text_field($_GET["settings-updated"]) ) {
43 flush_rewrite_rules( true );
44 echo "<div style='color: #179d82;'>" . esc_html__( 'Successfully updated!', 'surveyjs' ) . "</div>";
45 }
46 }
47
48 public function set_license_key_render() {
49 $settings = (array) get_option( 'surveyjs-settings' );
50
51 if (isset($settings['license_key']))
52 {
53 $license_key = esc_attr( $settings['license_key'] );
54 }
55 $value = '';
56 if ($license_key )
57 {
58 echo "<input type='text' placeholder='put the license key here...' name='surveyjs-settings[license_key]' id='surveyjs-settings[license_key]' value='" . esc_attr( $license_key ) . "' style='width: 350px;'/>";
59 } else {
60 echo "<input type='text' placeholder='put the license key here...' name='surveyjs-settings[license_key]' id='surveyjs-settings[license_key]' style='width: 350px;'/>";
61 }
62 }
63
64 public static function surveyjs_render_settings() {
65 ?>
66 <div class="wrap">
67 <h2><?php esc_html_e( 'SurveyJS Settings', 'surveyjs' ); ?></h2>
68 <form action="options.php" method="POST">
69 <?php settings_fields( 'surveyjs-settings-group' ); ?>
70 <?php do_settings_sections( 'surveyjs-settings-page' ); ?>
71 <?php submit_button(); ?>
72 </form>
73 </div>
74 <?php
75 }
76 }
77
78 $sjsSettingsPage = new SurveyJS_SettingsPage();
79 ?>
80