PluginProbe
Code Snippets / 2.13.1
Code Snippets v2.13.1
4.0.0-beta.2 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 All 65 releases
code-snippets / php / admin-menus / class-settings-menu.php

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

149 lines 4.0 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( 'code-snippets-settings-notices', 'settings_reset',
36 __( 'All settings have been reset to their defaults.', 'code-snippets' ), 'updated' );
37 set_transient( 'settings_errors', get_settings_errors(), 30 );
38
39 wp_redirect( esc_url_raw( add_query_arg( 'settings-updated', true, remove_query_arg( 'reset_settings' ) ) ) );
40 exit;
41 }
42
43 if ( is_network_admin() ) {
44
45 if ( code_snippets_unified_settings() ) {
46 $this->update_network_options();
47 } else {
48 wp_redirect( code_snippets()->get_menu_url( 'settings', 'admin' ) );
49 exit;
50 }
51 }
52 }
53
54 /**
55 * Enqueue the stylesheet for the settings menu
56 */
57 public function enqueue_assets() {
58 $plugin = code_snippets();
59
60 wp_enqueue_style(
61 'code-snippets-edit',
62 plugins_url( 'css/min/settings.css', $plugin->file ),
63 array(), $plugin->version
64 );
65
66 code_snippets_editor_settings_preview_assets();
67 }
68
69 /**
70 * Render the admin screen
71 */
72 public function render() {
73 $update_url = is_network_admin() ? add_query_arg( 'update_site_option', true ) : admin_url( 'options.php' );
74
75 ?>
76 <div class="wrap">
77 <h1><?php esc_html_e( 'Settings', 'code-snippets' );
78
79 if ( code_snippets()->admin->is_compact_menu() ) {
80
81 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
82 esc_html_x( 'Manage', 'snippets', 'code-snippets' ),
83 code_snippets()->get_menu_url()
84 );
85
86 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
87 esc_html_x( 'Add New', 'snippet', 'code-snippets' ),
88 code_snippets()->get_menu_url( 'add' )
89 );
90
91 printf( '<a href="%2$s" class="page-title-action">%1$s</a>',
92 esc_html_x( 'Import', 'snippets', 'code-snippets' ),
93 code_snippets()->get_menu_url( 'import' )
94 );
95 }
96
97 ?></h1>
98
99 <?php settings_errors( 'code-snippets-settings-notices' ); ?>
100
101 <form action="<?php echo esc_url( $update_url ); ?>" method="post">
102 <?php
103
104 settings_fields( 'code-snippets' );
105 do_settings_sections( 'code-snippets' );
106
107 ?>
108 <p class="submit" style="max-width: 1020px;">
109 <?php submit_button( null, 'primary', 'submit', false ); ?>
110
111 <a class="button button-secondary" style="float: right;"
112 href="<?php echo esc_url( add_query_arg( 'reset_settings', true ) ); ?>">
113 <?php esc_html_e( 'Reset to Default', 'code-snippets' ); ?>
114 </a>
115 </p>
116 </form>
117 </div>
118 <?php
119 }
120
121 /**
122 * Fill in for the Settings API in the Network Admin
123 */
124 function update_network_options() {
125
126 /* Ensure the settings have been saved */
127 if ( ! isset( $_GET['update_site_option'], $_POST['code_snippets_settings'] ) || ! $_GET['update_site_option'] ) {
128 return;
129 }
130
131 check_admin_referer( 'code-snippets-options' );
132
133 /* Retrieve the saved options and save them to the database */
134 $value = wp_unslash( $_POST['code_snippets_settings'] );
135 update_site_option( 'code_snippets_settings', $value );
136
137 /* Add an updated notice */
138 if ( ! count( get_settings_errors() ) ) {
139 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'code-snippets' ), 'updated' );
140 }
141 set_transient( 'settings_errors', get_settings_errors(), 30 );
142
143 /* Redirect back to the settings menu */
144 $goback = add_query_arg( 'settings-updated', 'true', remove_query_arg( 'update_site_option', wp_get_referer() ) );
145 wp_redirect( $goback );
146 exit;
147 }
148 }
149