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