PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.5.3
Shortcoder — Create Shortcodes for Anything v6.5.3
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 1 month ago font 1 month ago images 1 month ago js 1 month ago admin.php 1 month ago edit.php 1 month ago form.php 1 month ago insert.php 1 month ago manage.php 1 month ago settings.php 1 month ago tools.php 1 month ago
settings.php
144 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 field value', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
80 'value' => $settings[ 'sanitize_custom_fields' ],
81 'name' => 'sc_sanitize_custom_fields',
82 'list' => array(
83 'no' => __( 'No', 'shortcoder' ),
84 'yes' => __( 'Yes', 'shortcoder' )
85 ),
86 'helper' => __( 'Sanitize custom field values before replacing them in shortcode content.', 'shortcoder' )
87 ))),
88
89 );
90
91 echo '<form method="post">';
92
93 echo SC_Admin_Form::table($fields);
94
95 wp_nonce_field( 'sc_settings_nonce' );
96 echo '<p><button type="submit" class="button button-primary">' . esc_html__( 'Save settings', 'shortcoder' ) . '</button></p>';
97 echo '</form>';
98
99 echo '</div>';
100
101 echo '</div>';
102
103 }
104
105 public static function save_settings(){
106
107 if( $_POST && check_admin_referer( 'sc_settings_nonce' ) ){
108
109 $defaults = Shortcoder::default_settings();
110 $p = Shortcoder::set_defaults( SC_Admin::clean_post(), $defaults );
111
112 $values = array();
113
114 foreach( $defaults as $field => $default ){
115 $form_field = 'sc_' . $field;
116 $value = isset( $p[ $form_field ] ) ? $p[ $form_field ] : $default;
117
118 if( in_array( $field, array( 'default_content' ) ) ){
119 $values[ $field ] = current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( $value );
120 }else{
121 $values[ $field ] = sanitize_text_field( $value );
122 }
123 }
124
125 update_option( 'sc_settings', $values );
126 self::print_notice( 'Successfully saved the changes !' );
127
128 }
129
130 }
131
132 public static function print_notice( $msg = '', $type = 'success' ){
133
134 if( $msg != '' ){
135 echo '<div class="notice notice-' . esc_attr( $type ) . ' is-dismissible"><p>' . wp_kses_post( $msg ) . '</p></div>';
136 }
137
138 }
139
140 }
141
142 SC_Admin_Settings::init();
143
144 ?>