PluginProbe
Code Snippets / 2.14.6
Code Snippets v2.14.6
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / admin-menus / class-settings-menu.php

class-settings-menu.php in Code Snippets 2.14.6, at php/admin-menus/class-settings-menu.php

157 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This class handles the settings admin menu
5 * @since 2.4.0
6 * @package Code_Snippets
7 */
8 class Code_Snippets_Settings_Menu extends Code_Snippets_Admin_Menu {
9
10 /**
11 * Constructor
12 */
13 public function __construct() {
14
15 parent::__construct( 'settings',
16 _x( 'Settings', 'menu label', 'code-snippets' ),
17 __( 'Snippets Settings', 'code-snippets' )
18 );
19 }
20
21 /**
22 * Executed when the admin page is loaded
23 */
24 public function load() {
25 parent::load();
26
27 if ( isset( $_GET['reset_settings'] ) && $_GET['reset_settings'] ) {
28
29 if ( code_snippets_unified_settings() ) {
30 delete_site_option( 'code_snippets_settings' );
31 } else {
32 delete_option( 'code_snippets_settings' );
33 }
34
35 add_settings_error(
36 'code-snippets-settings-notices',
37 'settings_reset',
38 __( 'All settings have been reset to their defaults.', 'code-snippets' ),
39 'updated'
40 );
41
42 set_transient( 'settings_errors', get_settings_errors(), 30 );
43
44 wp_redirect( esc_url_raw( add_query_arg( 'settings-updated', true, remove_query_arg( 'reset_settings' ) ) ) );
45 exit;
46 }
47
48 if ( is_network_admin() ) {
49
50 if ( code_snippets_unified_settings() ) {
51 $this->update_network_options();
52 } else {
53 wp_redirect( code_snippets()->get_menu_url( 'settings', 'admin' ) );
54 exit;
55 }
56 }
57 }
58
59 /**
60 * Enqueue the stylesheet for the settings menu
61 */
62 public function enqueue_assets() {
63 $plugin = code_snippets();
64
65 wp_enqueue_style(
66 'code-snippets-edit',
67 plugins_url( 'css/min/settings.css', $plugin->file ),
68 array(),
69 $plugin->version
70 );
71
72 code_snippets_editor_settings_preview_assets();
73 }
74
75 /**
76 * Render the admin screen
77 */
78 public function render() {
79 $update_url = is_network_admin() ? add_query_arg( 'update_site_option', true ) : admin_url( 'options.php' );
80
81 ?>
82 <div class="wrap">
83 <h1>
84 <?php esc_html_e( 'Settings', 'code-snippets' );
85
86 if ( code_snippets()->admin->is_compact_menu() ) {
87
88 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
89 esc_html_x( 'Manage', 'snippets', 'code-snippets' ),
90 esc_url( code_snippets()->get_menu_url() )
91 );
92
93 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
94 esc_html_x( 'Add New', 'snippet', 'code-snippets' ),
95 esc_url( code_snippets()->get_menu_url( 'add' ) )
96 );
97
98 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
99 esc_html_x( 'Import', 'snippets', 'code-snippets' ),
100 esc_url( code_snippets()->get_menu_url( 'import' ) )
101 );
102 }
103
104 ?>
105 </h1>
106
107 <?php settings_errors( 'code-snippets-settings-notices' ); ?>
108
109 <form action="<?php echo esc_url( $update_url ); ?>" method="post">
110 <?php
111
112 settings_fields( 'code-snippets' );
113 do_settings_sections( 'code-snippets' );
114
115 ?>
116 <p class="submit" style="max-width: 1020px;">
117 <?php submit_button( null, 'primary', 'submit', false ); ?>
118
119 <a class="button button-secondary" style="float: right;"
120 href="<?php echo esc_url( add_query_arg( 'reset_settings', true ) ); ?>">
121 <?php esc_html_e( 'Reset to Default', 'code-snippets' ); ?>
122 </a>
123 </p>
124 </form>
125 </div>
126 <?php
127 }
128
129 /**
130 * Fill in for the Settings API in the Network Admin
131 */
132 public function update_network_options() {
133
134 /* Ensure the settings have been saved */
135 if ( ! isset( $_GET['update_site_option'], $_POST['code_snippets_settings'] ) || ! $_GET['update_site_option'] ) {
136 return;
137 }
138
139 check_admin_referer( 'code-snippets-options' );
140
141 /* Retrieve the saved options and save them to the database */
142 $value = map_deep( wp_unslash( $_POST['code_snippets_settings'] ), 'sanitize_key' );
143 update_site_option( 'code_snippets_settings', $value );
144
145 /* Add an updated notice */
146 if ( ! count( get_settings_errors() ) ) {
147 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'code-snippets' ), 'updated' );
148 }
149 set_transient( 'settings_errors', get_settings_errors(), 30 );
150
151 /* Redirect back to the settings menu */
152 $goback = add_query_arg( 'settings-updated', 'true', remove_query_arg( 'update_site_option', wp_get_referer() ) );
153 wp_redirect( $goback );
154 exit;
155 }
156 }
157