Code_Manager.php
4 years ago
Code_Manager_Dashboard.php
4 years ago
Code_Manager_Export.php
4 years ago
Code_Manager_Form.php
4 years ago
Code_Manager_Import.php
4 years ago
Code_Manager_Import_File.php
4 years ago
Code_Manager_List.php
4 years ago
Code_Manager_List_View.php
4 years ago
Code_Manager_Model.php
4 years ago
Code_Manager_Preview.php
4 years ago
Code_Manager_Settings.php
4 years ago
Code_Manager_Tabs.php
4 years ago
Message_Box.php
4 years ago
WP_List_Table.php
4 years ago
Code_Manager_Settings.php
236 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Code Manager plugin settings page |
| 4 | * |
| 5 | * @package Code_Manager |
| 6 | */ |
| 7 | |
| 8 | namespace Code_Manager { |
| 9 | |
| 10 | /** |
| 11 | * Class Code_Manager_Settings |
| 12 | * |
| 13 | * Handles plugin settings page |
| 14 | * |
| 15 | * @author Peter Schulz |
| 16 | * @since 1.0.0 |
| 17 | */ |
| 18 | class Code_Manager_Settings { |
| 19 | |
| 20 | /** |
| 21 | * Builds the settings page and stores the settings in WP options |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | public function show() { |
| 26 | if ( isset( $_REQUEST['action'] ) ) { |
| 27 | $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay. |
| 28 | |
| 29 | // Security check. |
| 30 | $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. |
| 31 | if ( ! wp_verify_nonce( $wp_nonce, 'code-manager-settings' . Code_manager::get_current_user_login() ) ) { |
| 32 | wp_die( __( 'ERROR: Not authorized', 'code-manager' ) ); |
| 33 | } |
| 34 | |
| 35 | if ( 'save' === $action ) { |
| 36 | // Save options. |
| 37 | update_option( |
| 38 | 'code_manager_plugin_navigation', |
| 39 | isset( $_REQUEST['plugin_navigation'] ) ? |
| 40 | sanitize_text_field( wp_unslash( $_REQUEST['plugin_navigation'] ) ) : 'dashboard' |
| 41 | ); // input var okay. |
| 42 | |
| 43 | update_option( |
| 44 | 'code_manager_plugin_hide_foreign_notices', |
| 45 | isset( $_REQUEST['plugin_hide_foreign_notices'] ) ? |
| 46 | sanitize_text_field( wp_unslash( $_REQUEST['plugin_hide_foreign_notices'] ) ) : 'off' |
| 47 | ); // input var okay. |
| 48 | |
| 49 | update_option( |
| 50 | 'code_manager_plugin_code_execution', |
| 51 | isset( $_REQUEST['plugin_code_execution'] ) ? |
| 52 | sanitize_text_field( wp_unslash( $_REQUEST['plugin_code_execution'] ) ) : 'off' |
| 53 | ); // input var okay. |
| 54 | |
| 55 | update_option( |
| 56 | 'code_manager_plugin_tables', |
| 57 | isset( $_REQUEST['plugin_tables'] ) ? |
| 58 | sanitize_text_field( wp_unslash( $_REQUEST['plugin_tables'] ) ) : 'off' |
| 59 | ); // input var okay. |
| 60 | |
| 61 | update_option( |
| 62 | 'code_manager_plugin_options', |
| 63 | isset( $_REQUEST['plugin_options'] ) ? |
| 64 | sanitize_text_field( wp_unslash( $_REQUEST['plugin_options'] ) ) : 'off' |
| 65 | ); // input var okay. |
| 66 | } elseif ( 'setdefaults' === $action ) { |
| 67 | // Set all plugin settings back to their defaults. |
| 68 | delete_option( 'code_manager_plugin_navigation' ); |
| 69 | delete_option( 'code_manager_plugin_hide_foreign_notices' ); |
| 70 | delete_option( 'code_manager_plugin_code_execution' ); |
| 71 | delete_option( 'code_manager_plugin_tables' ); |
| 72 | delete_option( 'code_manager_plugin_options' ); |
| 73 | } |
| 74 | |
| 75 | $msg = new Message_Box( |
| 76 | array( |
| 77 | 'message_text' => __( 'Settings saved', 'code-manager' ), |
| 78 | ) |
| 79 | ); |
| 80 | $msg->box(); |
| 81 | } |
| 82 | |
| 83 | // Get options. |
| 84 | $plugin_navigation = get_option( 'code_manager_plugin_navigation' ); |
| 85 | if ( false === $plugin_navigation ) { |
| 86 | $plugin_navigation = 'dashboard'; |
| 87 | } |
| 88 | |
| 89 | $plugin_hide_foreign_notices = get_option( 'code_manager_plugin_hide_foreign_notices' ); |
| 90 | if ( false === $plugin_hide_foreign_notices ) { |
| 91 | $plugin_hide_foreign_notices = 'on'; |
| 92 | } |
| 93 | |
| 94 | $plugin_code_execution = get_option( 'code_manager_plugin_code_execution' ); |
| 95 | if ( false === $plugin_code_execution ) { |
| 96 | $plugin_code_execution = 'on'; |
| 97 | } |
| 98 | |
| 99 | $plugin_tables = get_option( 'code_manager_plugin_tables' ); |
| 100 | if ( false === $plugin_tables ) { |
| 101 | $plugin_tables = 'off'; |
| 102 | } |
| 103 | |
| 104 | $plugin_options = get_option( 'code_manager_plugin_options' ); |
| 105 | if ( false === $plugin_options ) { |
| 106 | $plugin_options = 'on'; |
| 107 | } |
| 108 | ?> |
| 109 | <div class="wrap"> |
| 110 | <h1 class="wp-heading-inline"> |
| 111 | <span> |
| 112 | <span> |
| 113 | <?php echo CODE_MANAGER_SETTINGS_H1_TITLE; ?> |
| 114 | </span> |
| 115 | <?php |
| 116 | if ( ! Code_Manager_Dashboard::dashboard_enabled() ) { |
| 117 | ?> |
| 118 | <a href="<?php echo CODE_MANAGER_HELP_URL; ?>" target="_blank" |
| 119 | title="Plugin help - opens in a new tab or window"> |
| 120 | <span class="material-icons cm_menu_title">help_outline</span></a> |
| 121 | <?php |
| 122 | } |
| 123 | ?> |
| 124 | </span> |
| 125 | </h1> |
| 126 | <br/><br/> |
| 127 | <form id="code_manager_settings" method="post" action="?page=<?php echo CODE_MANAGER_SETTINGS_MENU_SLUG; ?>"> |
| 128 | <table class="code-manager-table-settings"> |
| 129 | |
| 130 | <tr> |
| 131 | <th><?php echo __( 'Plugin navigation', 'wp-data-access' ); ?></th> |
| 132 | <td> |
| 133 | <select name="plugin_navigation"> |
| 134 | <option value="both" <?php echo 'both' === $plugin_navigation ? 'selected' : ''; ?>>Show submenus and dashboard</option> |
| 135 | <option value="dashboard" <?php echo 'dashboard' === $plugin_navigation ? 'selected' : ''; ?>>Show dashboard only (hide submenus)</option> |
| 136 | <option value="menu" <?php echo 'menu' === $plugin_navigation ? 'selected' : ''; ?>>Show submenus only (hide dashboard)</option> |
| 137 | </select> |
| 138 | </td> |
| 139 | </tr> |
| 140 | <tr> |
| 141 | <th><?php echo __( 'Notices', 'wp-data-access' ); ?></th> |
| 142 | <td> |
| 143 | <label> |
| 144 | <input type="checkbox" name="plugin_hide_foreign_notices" <?php echo 'on' === $plugin_hide_foreign_notices ? 'checked' : ''; ?> /> |
| 145 | <?php echo __( 'Hide notices of other themes and plugins on Code Manager admin pages', 'wp-data-access' ); ?> |
| 146 | </label> |
| 147 | </td> |
| 148 | </tr> |
| 149 | |
| 150 | <tr> |
| 151 | <th> |
| 152 | <?php echo __( 'Code execution' ); ?> |
| 153 | </th> |
| 154 | <td> |
| 155 | <label for="plugin_code_execution"> |
| 156 | <input type="checkbox" |
| 157 | id="plugin_code_execution" |
| 158 | name="plugin_code_execution" |
| 159 | <?php echo 'on' === $plugin_code_execution ? 'checked' : ''; ?> |
| 160 | /> |
| 161 | <?php echo __( 'Enabled (uncheck to disable)' ); ?> |
| 162 | </label> |
| 163 | </td> |
| 164 | </tr> |
| 165 | <tr> |
| 166 | <th> |
| 167 | <?php echo __( 'On plugin uninstall' ); ?> |
| 168 | </th> |
| 169 | <td> |
| 170 | <label for="plugin_tables"> |
| 171 | <input type="checkbox" |
| 172 | id="plugin_tables" |
| 173 | name="plugin_tables" |
| 174 | <?php echo 'on' === $plugin_tables ? 'checked' : ''; ?> |
| 175 | /> |
| 176 | <?php echo __( 'Remove plugin tables (this will delete all your code)' ); ?> |
| 177 | </label> |
| 178 | <br/> |
| 179 | <label for="plugin_options"> |
| 180 | <input type="checkbox" |
| 181 | id="plugin_options" |
| 182 | name="plugin_options" |
| 183 | <?php echo 'on' === $plugin_options ? 'checked' : ''; ?> |
| 184 | /> |
| 185 | <?php echo __( 'Remove plugin options' ); ?> |
| 186 | </label> |
| 187 | </td> |
| 188 | </tr> |
| 189 | </table> |
| 190 | <div class="code-manager-table-settings-button"> |
| 191 | <input type="hidden" name="action" value="save"/> |
| 192 | <input type="submit" |
| 193 | value="<?php echo __( 'Save Code Manager settings', 'code-manager' ); ?>" |
| 194 | class="button button-primary"/> |
| 195 | <a href="javascript:void(0)" |
| 196 | onclick="return reset_defaults()" |
| 197 | class="button"> |
| 198 | <?php echo __( 'Reset Code Manager settings to defaults', 'code-manager' ); ?> |
| 199 | </a> |
| 200 | </div> |
| 201 | <?php wp_nonce_field( 'code-manager-settings' . Code_manager::get_current_user_login(), '_wpnonce', false ); ?> |
| 202 | </form> |
| 203 | </div> |
| 204 | <script type="text/javascript"> |
| 205 | jQuery(function() { |
| 206 | jQuery( '.cm_menu_title' ).tooltip(); |
| 207 | }); |
| 208 | function reset_defaults() { |
| 209 | html = '<div>Reset to defaults?</div>'; |
| 210 | var dialog = jQuery(html).dialog({ |
| 211 | dialogClass: "no-close", |
| 212 | buttons: { |
| 213 | 'Yes': function() { |
| 214 | dialog.dialog('destroy'); |
| 215 | jQuery('input[name="action"]').val('setdefaults'); |
| 216 | jQuery('#code_manager_settings').trigger('submit'); |
| 217 | }, |
| 218 | 'No': function() { |
| 219 | dialog.dialog('destroy'); |
| 220 | }, |
| 221 | 'Cancel': function() { |
| 222 | dialog.dialog('destroy'); |
| 223 | } |
| 224 | } |
| 225 | }); |
| 226 | jQuery(".ui-dialog-titlebar").hide(); |
| 227 | return false; |
| 228 | } |
| 229 | </script> |
| 230 | <?php |
| 231 | } |
| 232 | |
| 233 | } |
| 234 | |
| 235 | } |
| 236 |