Skip to content

Commit 0af8fb4

Browse files
committed
Network admin support! Set argument 'database' to network and data will be saved site-wide. Also two new arguments: network_admin & network_admin for where to show the panel.
1 parent 605c1c7 commit 0af8fb4

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ Send me an email at [email protected] so I can add you to our user sp
7474

7575
### Master ###
7676

77+
= 3.2.8.21 =
78+
* Added: Network admin support! Set argument 'database' to network and data will be saved site-wide. Also two new
79+
arguments: network_admin & network_admin for where to show the panel.
80+
7781
= 3.2.8.20 =
7882
* Fixed: Redux now ignores any directories that begin with `.` in the extension folder. See #1213.
7983

ReduxCore/framework.php

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
4+
35
/**
46
* Redux Framework is free software: you can redistribute it and/or modify
57
* it under the terms of the GNU General Public License as published by
@@ -66,7 +68,7 @@ class ReduxFramework {
6668
// ATTENTION DEVS
6769
// Please update the build number with each push, no matter how small.
6870
// This will make for easier support when we ask users what version they are using.
69-
public static $_version = '3.2.8.20';
71+
public static $_version = '3.2.8.21';
7072
public static $_dir;
7173
public static $_url;
7274
public static $_upload_dir;
@@ -138,7 +140,7 @@ static function init() {
138140
'admin_bar' => true, // Show the panel pages on the admin bar
139141
'help_tabs' => array(),
140142
'help_sidebar' => '', // __( '', 'redux-framework' );
141-
'database' => '', // possible: options, theme_mods, theme_mods_expanded, transient
143+
'database' => '', // possible: options, theme_mods, theme_mods_expanded, transient, network
142144
'customizer' => false, // setting to true forces get_theme_mod_expanded
143145
'global_variable' => '', // Changes global variable from $GLOBALS['YOUR_OPT_NAME'] to whatever you set here. false disables the global variable
144146
'output' => true, // Dynamically generate CSS
@@ -150,6 +152,8 @@ static function init() {
150152
'update_notice' => true, // Recieve an update notice of new commits when in dev mode
151153
'disable_save_warn' => false, // Disable the save warn
152154
'open_expanded' => false, // Start the panel fully expanded to start with
155+
'network_admin' => false, // Enable network admin when using network database mode
156+
'network_sites' => true, // Enable sites as well as admin when using network database mode
153157
'hints' => array(
154158
'icon' => 'icon-question-sign',
155159
'icon_position' => 'right',
@@ -349,6 +353,11 @@ public function __construct( $sections = array(), $args = array(), $extra_tabs =
349353
// Options page
350354
add_action( 'admin_menu', array( $this, '_options_page' ) );
351355

356+
// Add a network menu
357+
if ( $this->args['database'] == "network" && $this->args['network_admin'] ) {
358+
add_action( 'network_admin_menu', array( $this, '_options_page' ) );
359+
}
360+
352361
// Admin Bar menu
353362
add_action( 'admin_bar_menu', array( $this, '_admin_bar_menu' ) , 999 );
354363

@@ -385,6 +394,13 @@ public function __construct( $sections = array(), $args = array(), $extra_tabs =
385394
require_once(self::$_dir . 'inc/fields/import_export/import_export.php');
386395
$this->import_export = new Redux_import_export($this);
387396

397+
if ( $this->args['database'] == "network" && $this->args['network_admin'] ) {
398+
add_action('network_admin_edit_redux_' . $this->args['opt_name'], array( $this, 'save_network_page' ), 10, 0);
399+
add_action( 'admin_bar_menu', array( $this, 'network_admin_bar'), 999 );
400+
401+
402+
}
403+
388404
// mod_rewrite check
389405
//Redux_Functions::modRewriteCheck();
390406
}
@@ -399,8 +415,46 @@ public function __construct( $sections = array(), $args = array(), $extra_tabs =
399415

400416
} // __construct()
401417

418+
419+
public function network_admin_bar( $wp_admin_bar ) {
420+
421+
$args = array(
422+
'id' => $this->args['opt_name'].'_network_admin',
423+
'title' => $this->args['menu_title'],
424+
'parent'=> 'network-admin',
425+
'href' => network_admin_url('settings.php').'?page='.$this->args['page_slug'],
426+
'meta' => array( 'class' => 'redux-network-admin' )
427+
);
428+
$wp_admin_bar->add_node( $args );
429+
430+
}
431+
432+
public function stripslashes_deep( $value ) {
433+
$value = is_array($value) ?
434+
array_map('stripslashes_deep', $value) :
435+
stripslashes($value);
436+
437+
return $value;
438+
}
439+
440+
public function save_network_page() {
441+
442+
$data = $this->_validate_options( $_POST[$this->args['opt_name']] );
443+
444+
if (!empty($data)) {
445+
$this->set_options( $data );
446+
}
447+
448+
wp_redirect(add_query_arg(array('page' => $this->args['page_slug'], 'updated' => 'true'), network_admin_url('settings.php')));
449+
exit();
450+
}
451+
402452
public function _update_check() {
403-
Redux_Functions::updateCheck(self::$_version);
453+
// Only one notice per instance please
454+
if ( !isset( $this->update_checked ) ) {
455+
Redux_Functions::updateCheck(self::$_version);
456+
$this->update_checked = 1;
457+
}
404458
}
405459

406460
public function _admin_notices() {
@@ -551,6 +605,10 @@ function set_options( $value = '' ) {
551605
foreach ( $value as $k=>$v ) {
552606
set_theme_mod( $k, $v );
553607
}
608+
} else if ( $this->args['database'] === 'network' ) {
609+
// Strip those slashes!
610+
$value = json_decode( stripslashes( json_encode( $value ) ), true);
611+
update_site_option( $this->args['opt_name'], $value );
554612
} else {
555613
update_option( $this->args['opt_name'], $value );
556614
}
@@ -599,6 +657,9 @@ function get_options() {
599657
$result = get_theme_mod( $this->args['opt_name'] . '-mods' );
600658
} else if ( $this->args['database'] === 'theme_mods_expanded' ) {
601659
$result = get_theme_mods();
660+
} else if ( $this->args['database'] === 'network' ) {
661+
$result = get_site_option( $this->args['opt_name'], array() );
662+
$result = json_decode(stripslashes(json_encode($result)), true);
602663
} else {
603664
$result = get_option( $this->args['opt_name'], array() );
604665
}
@@ -2483,7 +2544,7 @@ public function _validate_options( $plugin_options ) {
24832544
$_COOKIE['redux_current_tab'] = 1;
24842545

24852546
unset( $plugin_options['defaults'], $plugin_options['compiler'], $plugin_options['import'], $plugin_options['import_code'] );
2486-
if ( $this->args['database'] == 'transient' || $this->args['database'] == 'theme_mods' || $this->args['database'] == 'theme_mods_expanded' ) {
2547+
if ( $this->args['database'] == 'transient' || $this->args['database'] == 'theme_mods' || $this->args['database'] == 'theme_mods_expanded' || $this->args['database'] == 'network' ) {
24872548
$this->set_options( $plugin_options );
24882549
return;
24892550
}
@@ -2916,7 +2977,13 @@ public function _options_page_html() {
29162977
$expanded = ($this->args['open_expanded']) ? ' fully-expanded' : '';
29172978

29182979
echo '<div class="redux-container' . $expanded . ( !empty( $this->args['class'] ) ? ' ' . $this->args['class'] : '' ) . '">';
2919-
echo '<form method="post" action="' . './options.php" enctype="multipart/form-data" id="redux-form-wrapper">';
2980+
$url = './options.php';
2981+
if ( $this->args['database'] == "network" && $this->args['network_admin'] ) {
2982+
if ( is_network_admin() ) {
2983+
$url = './edit.php?action=redux_' . $this->args['opt_name'];
2984+
}
2985+
}
2986+
echo '<form method="post" action="' . $url . '" enctype="multipart/form-data" id="redux-form-wrapper">';
29202987
echo '<input type="hidden" id="redux-compiler-hook" name="' . $this->args['opt_name'] . '[compiler]" value="" />';
29212988
echo '<input type="hidden" id="currentSection" name="' . $this->args['opt_name'] . '[redux-section]" value="" />';
29222989

redux-framework.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Description: Redux is a simple, truly extensible options framework for WordPress themes and plugins.
1313
* Author: Team Redux
1414
* Author URI: http://reduxframework.com
15-
* Version: 3.2.8.20
15+
* Version: 3.2.8.21
1616
* Text Domain: redux-framework
1717
* License: GPL3+
1818
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt

0 commit comments

Comments
 (0)