PluginProbe
Code Snippets / 2.10.1
Code Snippets v2.10.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.10.1, at php/admin-menus/class-settings-menu.php

91 lines 2.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 function load() {
25 parent::load();
26
27 if ( is_network_admin() ) {
28
29 if ( code_snippets_unified_settings() ) {
30 $this->update_network_options();
31 } else {
32 wp_redirect( code_snippets()->get_menu_url( 'settings', 'admin' ) );
33 exit;
34 }
35 }
36 }
37
38 /**
39 * Render the admin screen
40 */
41 function render() {
42 $update_url = is_network_admin() ? add_query_arg( 'update_site_option', true ) : admin_url( 'options.php' );
43
44 ?>
45 <div class="wrap">
46 <h1><?php esc_html_e( 'Settings', 'code-snippets' ); ?></h1>
47
48 <?php settings_errors( 'code-snippets-settings-notices' ); ?>
49
50 <form action="<?php echo esc_url( $update_url ); ?>" method="post">
51 <?php
52
53 settings_fields( 'code-snippets' );
54 do_settings_sections( 'code-snippets' );
55 submit_button();
56
57 ?>
58 </form>
59 </div>
60 <?php
61 }
62
63 /**
64 * Fill in for the Settings API in the Network Admin
65 */
66 function update_network_options() {
67
68 /* Ensure the settings have been saved */
69 if ( ! isset( $_GET['update_site_option'], $_POST['code_snippets_settings'] ) || ! $_GET['update_site_option'] ) {
70 return;
71 }
72
73 check_admin_referer( 'code-snippets-options' );
74
75 /* Retrieve the saved options and save them to the database */
76 $value = wp_unslash( $_POST['code_snippets_settings'] );
77 update_site_option( 'code_snippets_settings', $value );
78
79 /* Add an updated notice */
80 if ( ! count( get_settings_errors() ) ) {
81 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
82 }
83 set_transient( 'settings_errors', get_settings_errors(), 30 );
84
85 /* Redirect back to the settings menu */
86 $goback = add_query_arg( 'settings-updated', 'true', remove_query_arg( 'update_site_option', wp_get_referer() ) );
87 wp_redirect( $goback );
88 exit;
89 }
90 }
91