reduxframework / redux-framework

Redux is a simple, truly extensible options framework for WordPress themes and plugins!

Home Page:http://redux.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Section filter for import/export not rendering

brasofilo opened this issue · comments

Site Health Report

Issue detected on a Vanilla installation on localhost and also tested on a live site (report below).

### redux-framework ###

version: 4.3.26
installation: plugin
data directory: /home2/user/public_html/wp-content/plugins/redux-framework/redux-core/
browser: 
    Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0
    Browser: Firefox
    Version: 110.0
    Platform: Linux

### redux-instance-b5f_admin_tweaks ###

opt_name: b5f_admin_tweaks
global_variable: b5f_admin_tweaks
dev_mode: true
ajax_save: false
page_slug: admintweaks
page_permissions: manage_options
menu_type: submenu
page_parent: options-general.php
compiler: true
output: true
output_tag: true
templates_path: undefined
extensions: 
    Accordion: 1.0.1
    Custom Fonts: 2.0.0
    Customizer: 4.0.0
    Datetime: 2.0.0
    Google Maps: 2.0.0
    Import Export: 4.0.0
    Js Button: 2.0.0
    Metaboxes: 4.0.0
    Multi Media: 4.3.15
    Options Object: 4.0.0
    Repeater: 4.3.7
    Search: 3.4.5
    Shortcodes: 4.3.5
    Social Profiles: 4.3.17
    Widget Areas: 1.0.0

Steps to reproduce

On the config file, show import/export:
'show_import_export' => true,

Add the following filter when instantiating my plugin:

    public static function init() {
        global $adt_option;

        add_filter(
            'redux/options/' . $adt_option . '/section/import/export', 
            [__CLASS__, 'modify_backup_section']
        );

        /* This hook works as expected */
        add_action( 'redux/page/' . $adt_option . '/enqueue', [__CLASS__, 'add_panel_css'] );
    }
 
    public static function modify_backup_section($section) {
        $section['title'] = 'Backups';
        $section['icon']  = 'dashicons dashicons-backup';
        return $section;
    }

Expected Behavior

If I modify the file /redux-core/inc/extensions/import_export/class-redux-extension-import-export.php directly it renders as I want it.

Actual Behavior

The filter is not rendered.
Inspecting the file class-redux-options-constructor.php#L294 I can see that the filter is applied.

But inspecting the $sections on the file /redux-core/inc/classes/class-redux-page-render.php shows the original section unmodified by the filter.

Any Error Details (PHP/JavaScript)

This issue doesn't generates any error...

Is that any reason this wouldn't work?

Redux::set_section(
	$opt_name,
	array(
		'id'               => 'import-export-options',
		'customizer_width' => '500px',
		'title'            => esc_html__( 'Backups', 'theme-name' ),
		'subtitle'         => esc_html__( 'Import and Export your theme options settings from file, text or URL.', 'theme-name' ),
		'icon'             => 'dashicons dashicons-backup',
		'fields'           => array(
			array(
				'id'       => 'opt-import-export',
				'type'     => 'import_export',
				'title'    => esc_html__( 'Backups', 'theme-name' ),
				'subtitle' => esc_html__( 'Save and restore your Redux options', 'theme-name' ),
			),
		),
	)
);

Also, you'll need to set 'show_import_export' => false,

There's really no need to reinvent the wheel.

Hi Kevin, thanks for your reply.

No, indeed not, there's no reason why that shouldn't work.

I'll do it like that but can't help but wonder what use case that filter has...

Most of those filters were from Redux 2, which was written by someone else pre-2013. I never went through them all to test each after Dovy added the Redux API, which loads things differently from the second version. I vaguely remember having an issue with the field hook when working on one of my themes. It runs in the same function as the section hook, and it wasn't working as it did way back in the day. The hook indeed changes the section/field data, but it still renders with the old data. I never figured out why because the enqueue hook worked, and I stuck with that. I suspect that's going to be a deep dive into the guts of this thing. Unfortunately, I only have so many hours a day to devote to it.

Oh, I see, it's practically arcane code by now, lol

Thanks a lot for your support!, it's an amazing tool