PluginProbe
Snippet Shortcodes / 5.2.1
Snippet Shortcodes v5.2.1
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / pages / page.settings.php

page.settings.php in Snippet Shortcodes 5.2.1, at includes/pages/page.settings.php

180 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die('Jog on!');
4
5 function sh_cd_settings_page_generic() {
6
7 if ( !current_user_can( 'manage_options' ) ) {
8 wp_die( __( 'You do not have sufficient permissions to access this page.' , SH_CD_SLUG ) );
9 }
10
11 $disable_if_not_premium_class = ( sh_cd_is_premium() ) ? '' : 'sh-cd-disabled';
12
13 ?>
14
15 <div id="icon-options-general" class="icon32"></div>
16
17 <div id="poststuff">
18
19 <div id="post-body" class="metabox-holder columns-3 yk-mt-settings">
20
21 <!-- main content -->
22 <div id="post-body-content">
23
24 <div class="meta-box-sortables ui-sortable">
25
26 <div class="postbox">
27 <h3 class="postbox-header">
28 <span>
29 <?php echo __( 'Settings', SH_CD_SLUG ); ?>
30 </span>
31 </h3>
32 <div class="inside">
33 <form method="post" action="options.php" class="sh-cd-settings">
34 <?php
35
36 settings_fields( 'sh-cd-options-group' );
37 do_settings_sections( 'sh-cd-options-group' );
38
39 ?>
40
41 <?php
42 if ( false === sh_cd_is_premium() ) {
43 sh_cd_display_pro_upgrade_notice();
44 }
45 ?>
46 <h3><?php echo __( 'User Experience' , SH_CD_SLUG); ?></h3>
47 <hr />
48 <table class="form-table">
49 <tr>
50 <th scope="row"><?php echo __( 'Default Editor' , SH_CD_SLUG); ?></th>
51 <?php $default_editor = sh_cd_default_editor_get(); ?>
52 <td>
53 <select id="sh-cd-option-default-editor" name="sh-cd-option-default-editor">
54 <?php
55 foreach ( sh_cd_editors_options( false ) as $editor => $label ) {
56 printf( '<option value="%s" %s>%s</option>', esc_attr( $editor ), selected( $editor, $default_editor ), esc_html( $label ) );
57 }
58 ?>
59 </select>
60 </td>
61 </tr>
62 <tr>
63 <th scope="row"><?php echo __( 'Tooltips enabled' , SH_CD_SLUG); ?></th>
64 <?php $is_enabled = sh_cd_tooltips_is_enabled(); ?>
65 <td>
66 <select id="sh-cd-option-tool-tips-enabled" name="sh-cd-option-tool-tips-enabled">
67 <option value="yes" <?php selected( $is_enabled, true ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option>
68 <option value="no" <?php selected( $is_enabled, false ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option>
69 </select>
70 </td>
71 </tr>
72 </table>
73 <h3><?php echo __( 'Permissions' , SH_CD_SLUG); ?></h3>
74 <hr />
75 <table class="form-table">
76 <tr class="<?php echo $disable_if_not_premium_class; ?>">
77 <th scope="row"><?php echo __( 'Who can view and modify snippet shortcodes?' , SH_CD_SLUG); ?></th>
78 <?php $edit_permissions = sh_cd_permission_role(); ?>
79 <td>
80 <select id="sh-cd-edit-permissions" name="sh-cd-edit-permissions" <?php disabled( sh_cd_is_premium(), false ); ?>>
81 <option value="manage_options" <?php selected( $edit_permissions, 'manage_options' ); ?>><?php echo __( 'Administrators Only', SH_CD_SLUG ); ?></option>
82 <option value="read_private_posts" <?php selected( $edit_permissions, 'read_private_posts' ); ?>><?php echo __( 'Editors and above', SH_CD_SLUG ); ?></option>
83 <option value="publish_posts" <?php selected( $edit_permissions, 'publish_posts' ); ?>><?php echo __( 'Authors and above', SH_CD_SLUG ); ?></option>
84 </select>
85 <p><?php echo __('Specify the minimum level of user role that can edit and view shortcodes.', SH_CD_SLUG)?></p>
86 </td>
87 </tr>
88 <tr class="<?php echo $disable_if_not_premium_class; ?>">
89 <th scope="row"><a href="https://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/database-values-by-id" target="_blank" rel="noopener">"db-value-by-id"</a> <?php echo __( 'shortcode enabled', SH_CD_SLUG ); ?>?</th>
90 <?php $is_enabled = sh_cd_is_shortcode_db_value_by_id_enabled(); ?>
91 <td>
92 <select id="sh-cd-shortcode-db-value-by-id-enabled" name="sh-cd-shortcode-db-value-by-id-enabled" <?php disabled( sh_cd_is_premium(), false ); ?>>
93 <option value="No" <?php selected( $is_enabled, false ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option>
94 <option value="Yes" <?php selected( $is_enabled, true ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option>
95 </select>
96 <p><?php echo __('Should the Premium shortcode, [sv slug="db-value-by-id"] be enabled?', SH_CD_SLUG)?></p>
97 </td>
98 </tr>
99 </table>
100 <h3><?php echo __( 'Utilities' , SH_CD_SLUG); ?></h3>
101 <hr />
102 <table class="form-table">
103 <tr class="<?php echo $disable_if_not_premium_class; ?>">
104 <th scope="row"><?php echo __( 'Render-count analytics enabled?', SH_CD_SLUG ); ?></th>
105 <?php $render_count_enabled = sh_cd_is_render_count_enabled(); ?>
106 <td>
107 <select id="sh-cd-option-render-count-enabled" name="sh-cd-option-render-count-enabled" <?php disabled( sh_cd_is_premium(), false ); ?>>
108 <option value="yes" <?php selected( $render_count_enabled, true ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option>
109 <option value="no" <?php selected( $render_count_enabled, false ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option>
110 </select>
111 <p><?php echo __( 'Track how many times each shortcode has been rendered, shown on its edit screen. Disable this on a high-traffic site to avoid the extra database write on every shortcode render.', SH_CD_SLUG ); ?></p>
112 </td>
113 </tr>
114 </table>
115 <?php submit_button(); ?>
116 </form>
117 </div>
118 </div>
119 </div>
120 </div>
121 </div>
122 <!-- #poststuff -->
123
124 </div> <!-- .wrap -->
125
126 <?php
127
128 }
129
130 /**
131 * Register fields to save
132 */
133 function sh_cd_register_settings(){
134
135 register_setting( 'sh-cd-options-group', 'sh-cd-edit-permissions', [ 'sanitize_callback' => 'sh_cd_sanitize_edit_permissions' ] );
136 register_setting( 'sh-cd-options-group', 'sh-cd-shortcode-db-value-by-id-enabled', [ 'sanitize_callback' => 'sh_cd_sanitize_yes_no' ] );
137 register_setting( 'sh-cd-options-group', 'sh-cd-option-tool-tips-enabled', [ 'sanitize_callback' => 'sh_cd_sanitize_tooltips_enabled' ] );
138 register_setting( 'sh-cd-options-group', 'sh-cd-option-default-editor', [ 'sanitize_callback' => 'sh_cd_sanitize_default_editor' ] );
139 register_setting( 'sh-cd-options-group', 'sh-cd-option-render-count-enabled', [ 'sanitize_callback' => 'sh_cd_sanitize_render_count_enabled' ] );
140 }
141
142 /**
143 * Sanitize the "who can view/edit shortcodes" permission role setting
144 */
145 function sh_cd_sanitize_edit_permissions( $value ) {
146
147 $allowed = [ 'manage_options', 'read_private_posts', 'publish_posts' ];
148
149 return ( true === in_array( $value, $allowed, true ) ) ? $value : 'manage_options';
150 }
151
152 /**
153 * Sanitize the "db-value-by-id" enabled setting
154 */
155 function sh_cd_sanitize_yes_no( $value ) {
156 return ( 'Yes' === $value ) ? 'Yes' : 'No';
157 }
158
159 /**
160 * Sanitize the tooltips enabled setting
161 */
162 function sh_cd_sanitize_tooltips_enabled( $value ) {
163 return ( 'yes' === $value ) ? 'yes' : 'no';
164 }
165
166 /**
167 * Sanitize the default editor setting
168 */
169 function sh_cd_sanitize_default_editor( $value ) {
170 return ( true === sh_cd_editors_is_valid( $value ) ) ? $value : 'tinymce';
171 }
172
173 /**
174 * Sanitize the render-count analytics enabled setting
175 */
176 function sh_cd_sanitize_render_count_enabled( $value ) {
177 return ( 'yes' === $value ) ? 'yes' : 'no';
178 }
179 add_action( 'admin_init', 'sh_cd_register_settings' );
180