PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / trunk
Shortcoder — Create Shortcodes for Anything vtrunk
6.5.4 trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / settings.php
shortcoder / admin Last commit date
css 4 weeks ago font 4 weeks ago images 4 weeks ago js 4 weeks ago admin.php 4 weeks ago edit.php 4 weeks ago form.php 4 weeks ago insert.php 4 weeks ago manage.php 4 weeks ago settings.php 4 weeks ago tools.php 4 weeks ago
settings.php
154 lines
1 <?php
2
3 class SC_Admin_Settings{
4
5 public static function init(){
6
7 add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
8
9 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
10
11 }
12
13 public static function admin_menu(){
14
15 add_submenu_page( 'edit.php?post_type=shortcoder', 'Shortcoder - Settings', 'Settings', 'manage_options', 'settings', array( __CLASS__, 'page' ) );
16
17 }
18
19 public static function enqueue_scripts( $hook ){
20
21 if( $hook != 'shortcoder_page_settings' ){
22 return false;
23 }
24
25 wp_enqueue_style( 'sc-admin-settings-css', SC_ADMIN_URL . 'css/style-settings.css', array(), SC_VERSION );
26
27 wp_enqueue_code_editor( array( 'type' => 'text/html' ) );
28
29 wp_enqueue_script( 'jquery' );
30 wp_enqueue_script( 'sc-admin-settings-js', SC_ADMIN_URL . 'js/script-settings.js', array( 'jquery' ), SC_VERSION );
31
32 }
33
34 public static function page(){
35
36 self::save_settings();
37
38 echo '<div class="wrap">';
39 echo '<div class="head_wrap">';
40 echo '<h1>Shortcoder - General Settings</h1>';
41 echo '</div>';
42
43 $settings = Shortcoder::get_settings();
44
45 echo '<div id="main">';
46
47 $fields = array(
48
49 array( __( 'Default editor', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
50 'value' => $settings[ 'default_editor' ],
51 'name' => 'sc_default_editor',
52 'list' => array(
53 'text' => __( 'Text editor', 'shortcoder' ),
54 'visual' => __( 'Visual editor', 'shortcoder' ),
55 'code' => __( 'Code editor', 'shortcoder' )
56 ),
57 'helper' => __( 'The default editor mode when creating new shortcodes', 'shortcoder' )
58 ))),
59
60 array( __( 'Default shortcode content', 'shortcoder' ), SC_Admin_Form::field( 'textarea', array(
61 'value' => $settings[ 'default_content' ],
62 'id' => 'sc_default_content',
63 'name' => 'sc_default_content',
64 'class' => 'widefat',
65 'helper' => __( 'The default shortcode content when creating new shortcodes', 'shortcoder' )
66 ))),
67
68 array( __( 'Show content in "All shortcodes" page', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
69 'value' => $settings[ 'list_content' ],
70 'name' => 'sc_list_content',
71 'list' => array(
72 'no' => __( 'Hidden', 'shortcoder' ),
73 '100' => __( '100 characters', 'shortcoder' ),
74 '200' => __( '200 characters', 'shortcoder' )
75 ),
76 'helper' => __( 'List the shortcode content in "All shortcodes" page.', 'shortcoder' )
77 ))),
78
79 array( __( 'Sanitize custom parameter value', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
80 'value' => $settings[ 'sanitize_custom_parameters' ],
81 'name' => 'sc_sanitize_custom_parameters',
82 'list' => array(
83 'no' => __( 'No', 'shortcoder' ),
84 'yes' => __( 'Yes', 'shortcoder' )
85 ),
86 'helper' => __( 'Sanitize shortcode parameter values before replacing them in shortcode content.', 'shortcoder' )
87 ))),
88
89 array( __( 'Sanitize custom field value', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
90 'value' => $settings[ 'sanitize_custom_fields' ],
91 'name' => 'sc_sanitize_custom_fields',
92 'list' => array(
93 'no' => __( 'No', 'shortcoder' ),
94 'yes' => __( 'Yes', 'shortcoder' )
95 ),
96 'helper' => __( 'Sanitize custom field values before replacing them in shortcode content.', 'shortcoder' )
97 ))),
98
99 );
100
101 echo '<form method="post">';
102
103 echo SC_Admin_Form::table($fields);
104
105 wp_nonce_field( 'sc_settings_nonce' );
106 echo '<p><button type="submit" class="button button-primary">' . esc_html__( 'Save settings', 'shortcoder' ) . '</button></p>';
107 echo '</form>';
108
109 echo '</div>';
110
111 echo '</div>';
112
113 }
114
115 public static function save_settings(){
116
117 if( $_POST && check_admin_referer( 'sc_settings_nonce' ) ){
118
119 $defaults = Shortcoder::default_settings();
120 $p = Shortcoder::set_defaults( SC_Admin::clean_post(), $defaults );
121
122 $values = array();
123
124 foreach( $defaults as $field => $default ){
125 $form_field = 'sc_' . $field;
126 $value = isset( $p[ $form_field ] ) ? $p[ $form_field ] : $default;
127
128 if( in_array( $field, array( 'default_content' ) ) ){
129 $values[ $field ] = current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( $value );
130 }else{
131 $values[ $field ] = sanitize_text_field( $value );
132 }
133 }
134
135 update_option( 'sc_settings', $values );
136 self::print_notice( 'Successfully saved the changes !' );
137
138 }
139
140 }
141
142 public static function print_notice( $msg = '', $type = 'success' ){
143
144 if( $msg != '' ){
145 echo '<div class="notice notice-' . esc_attr( $type ) . ' is-dismissible"><p>' . wp_kses_post( $msg ) . '</p></div>';
146 }
147
148 }
149
150 }
151
152 SC_Admin_Settings::init();
153
154 ?>