reduxframework / redux-framework

Redux is a simple, truly extensible options framework for WordPress themes and plugins!
http://redux.io
Other
1.74k stars 583 forks source link

Class Redux_Network not being loaded by core, save without Ajax fails #3941

Closed brasofilo closed 1 year ago

brasofilo commented 1 year ago

Site Health Report

### wp-core ###

version: 6.2
site_language: en_US
user_language: en_US
timezone: +00:00
permalink: /%year%/%monthnum%/%day%/%postname%/
https_status: false
multisite: true
user_registration: false
blog_public: 1
default_comment_status: open
environment_type: local
site_count: 3
network_count: 1
user_count: 2
dotorg_communication: true

### wp-active-theme ###

name: Twenty Twenty-Three (twentytwentythree)
version: 1.1
author: the WordPress team
author_website: https://wordpress.org
parent_theme: none
theme_features: core-block-patterns, post-thumbnails, responsive-embeds, editor-styles, html5, automatic-feed-links, block-templates, widgets-block-editor
theme_path: /app/public/wp-content/themes/twentytwentythree
auto_update: Disabled

### wp-plugins-active (1) ###

Redux Multisite: version: 1.0, author: Rodolfo Buaiz, Auto-updates disabled

### wp-media ###

image_editor: WP_Image_Editor_GD
imagick_module_version: Not available
imagemagick_version: Not available
imagick_version: Not available
file_uploads: File uploads is turned off
post_max_size: 1000M
upload_max_filesize: 300M
max_effective_size: 300 MB
max_file_uploads: 20
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, WebP, BMP, XPM
ghostscript_version: 9.55.0

### wp-server ###

server_architecture: Linux 5.19.0-38-generic x86_64
httpd_software: nginx/1.16.0
php_version: 8.1.9 64bit
php_sapi: fpm-fcgi
max_input_variables: 4000
time_limit: 1200
memory_limit: 256M
max_input_time: 600
upload_max_filesize: 300M
php_post_max_size: 1000M
curl_version: 7.68.0 OpenSSL/1.1.1f
suhosin: false
imagick_availability: false
pretty_permalinks: true

### wp-database ###

extension: mysqli
server_version: 8.0.16
client_version: mysqlnd 8.1.9
max_allowed_packet: 16777216
max_connections: 151

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /app/public/wp-content
WP_PLUGIN_DIR: /app/public/wp-content/plugins
WP_MEMORY_LIMIT: 64M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: true
WP_DEBUG_DISPLAY: false
WP_DEBUG_LOG: false
SCRIPT_DEBUG: false
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: local
DB_CHARSET: utf8
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable

Steps to reproduce

I tested with a vanilla plugin just loading Redux config file. The plugin is Network Enabled on an empty WP installation in my computer.

The init method loads the config and that's about it: add_action( 'plugins_loaded', [__CLASS__, 'init'] );

I'm using the barebone-config.php and these are the relevant arguments:

$args = array(
    'opt_name'         => $opt_name,
    'menu_type'        => 'menu',
    'ajax_save'        => false,
    'dev_mode'         => true,
    'page_parent'      => '',
    'page_permissions' => 'manage_options',
    'page_slug'        => 'my_options',
    'database'         => 'network',
    'network_admin'    => true,
);

I'm not using AJAX to save, and when we save our options the plugin redirects to WordPress Dashboard: /wp-admin/network/index.php . Navigating back to the plugin page (/wp-admin/network/admin.php?page=my_options) shows that the options were not saved.

If I change ajax_save to true, the options are saved correctly.

Expected Behavior

The plugin should save the options and go back to the plugin page: admin.php?page=my_options

Actual Behavior

The hook that saves multisite options is network_admin_edit_{$_GET['action']}.

I found it inside the file /redux-core/inc/classes/class-redux-network.php that defines the Redux_Network class. The class is not used anywhere inside redux-core.

I instantiated the network class inside redux-core/framework.php constructor and the Save action started working (see error below *``**).

new Redux_AJAX_Save( $this );
new Redux_AJAX_Typography( $this );
new Redux_AJAX_Select2( $this );
new Redux_Health( $this );
new Redux_Network( $this ); // <------ added this

Any Error Details (PHP/JavaScript)

*``** It works but there is the following error:

PHP Fatal error: Uncaught TypeError: Redux_Options_Constructor::validate_options(): Argument #1 ($plugin_options) must be of type array, string given, called in /redux-multisite/redux-core/inc/classes/class-redux-network.php on line 75 and defined in /redux-multisite/redux-core/inc/classes/class-redux-options-constructor.php:710

The error is being caused by the function sanitize_text_field in line 69 of class-redux-network.php.

If we remove it, the Multisite Save Options without AJAX finally works ok; I'm not sure how to fix this one though...

$opt_name = sanitize_text_field( wp_unslash( $_POST[ $core->args['opt_name'] ] ) ); // <--- error
$opt_name =  wp_unslash( $_POST[ $core->args['opt_name'] ] ); // <---- works
kprovance commented 1 year ago

The reason the class doesn't load is that the network admin panel feature was never finished. We couldn't make it work properly. The code was left in with the idea it may be revisited. It never happened. You're free to keep trying, but it's unlikely we'll finish that feature. The demand isn't there to justify the time.

brasofilo commented 1 year ago

Ok, gotcha, thanks for the feedback!