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