• Resolved sajjad

    (@sajjad203)


    Hi,
    fist Thanks a lot for the awesome plugin.
    I am using the latest version of redux as separated plugin. v4.1.20

    I have used select type field with the data=callback.
    My code:

    array(
                'id'       => 'my_id',
                'type'     => 'select',
                'title'    => 'my title',
                'data'  => 'callback',
                'args' => 'my_func_name',
            ),

    My function return an array and the field in option panel works correct.
    But there is a warning:

    Notice: Undefined offset: 0 in C:\xampp\htdocs\kianpanel\wp-content\plugins\redux-framework\redux-core\inc\classes\class-redux-wordpress-data.php on line 470

    Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in C:\xampp\htdocs\kianpanel\wp-content\plugins\redux-framework\redux-core\inc\classes\class-redux-wordpress-data.php on line 470

    I think there is a problem in redux. I have checked the $args by var_dump. It return twice. Once empty array and another one with an array included my function_name.

    Can you check it?
    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Dōvy Paukstys

    (@dovyp)

    Definitely looks like our bug. Let me take a look.

    Plugin Contributor Dōvy Paukstys

    (@dovyp)

    I stand corrected, it seems to work find. Here’s some example code:

    Field:

    array(
    	'id'               => 'opt-select-callback',
    	'type'             => 'select',
    	'data'             => 'callback',
    	'args'             => 'redux_demo_select_data_callback',
    	'title'            => esc_html__( 'Custom callback with WordPress data', 'your-textdomain-here' ),
    	'subtitle'         => esc_html__( 'You can customize data using your own function here.', 'your-textdomain-here' ),
    	'desc'             => esc_html__( 'This is the description field, again good for additional info.', 'your-textdomain-here' ),
    ),

    Callback function

    function redux_demo_select_data_callback() {
    	return array(
    		'here' => 'Here I am',
    		'rocking' => 'Rocking like a hurricane',
    	);
    }
    

    Seems to work fine for me. Here’s the docs outlining the same thing.

    https://docs.redux.io/configuration/fields/data.html#using-a-custom-callback

    Have a great day!

    Thread Starter sajjad

    (@sajjad203)

    WOW, Fast support ??

    Thank you for the response but please check it again ??
    In the first time there is no warning but when you select an option and save the settings and refresh the page, you can see it.

    Plugin Contributor Dōvy Paukstys

    (@dovyp)

    Ahh, those are details I needed! Then I’ll take a look.

    Plugin Contributor Dōvy Paukstys

    (@dovyp)

    This has been resolved in Redux 4.1.21. ??

    Thread Starter sajjad

    (@sajjad203)

    I updated redux to this version but i see the warnings yet ??

    Plugin Contributor Dōvy Paukstys

    (@dovyp)

    Can you try it with 4.1.22?

    Thread Starter sajjad

    (@sajjad203)

    I updated to 4.1.23 and it’s not resolved.
    Also i reset all options and test it again but the warning appeared again.

    Screen shot:
    https://img.techpowerup.org/201025/opera-snapshot-2020-10-25-122127-localhost.png

    Plugin Contributor Dōvy Paukstys

    (@dovyp)

    So this worked for me and I think you might be experiencing a race condition. Make sure your function is defined around the same time as you define your options.

    I added new code to support running a class method instead of just a function and that’s in the repo, but here’s the test code I used. It worked without an issue.

    
    Redux::set_section(
    	$opt_name,
    	array(
    		'title'      => esc_html__( 'Select', 'your-textdomain-here' ),
    		'id'         => 'select-select-callback',
    		'desc'       => esc_html__( 'For full documentation on this field, visit: ', 'your-textdomain-here' ) . '<a href="//docs.redux.io/core/fields/select/" target="_blank">docs.redux.io/core/fields/select/</a>',
    		'subsection' => true,
    		'fields'     => array(
    			array(
    				'id'       => 'opt-select-elusive-callback',
    				'type'     => 'select',
    				'data'  => 'callback',
    				//'args'=> 'my_callback_function',
    				'args' => array('Foo', 'data'),
    				'title'    => esc_html__( 'Select Callback', 'your-textdomain-here' ),
    				'subtitle' => esc_html__( 'No validation can be done on this field type', 'your-textdomain-here' ),
    				'desc'     => esc_html__( 'Here\'s a list of all the elusive icons by name and icon.', 'your-textdomain-here' ),
    			)
    		),
    	)
    );
    
    class Foo {
    
    	function data() {
    		return array(
    			'here' => 'Here I am2',
    			'rocking' => 'Rocking like a hurricane2',
    		);
    	}
    }
    
    function my_callback_function() {
    	return array(
    		'here' => 'Here I am',
    		'rocking' => 'Rocking like a hurricane',
    	);
    }
    

    Best of luck!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Warning on type select and data callback’ is closed to new replies.