Home > OS >  Custom Class for a plugin options give error, Notice: Trying to access array offset on value of type
Custom Class for a plugin options give error, Notice: Trying to access array offset on value of type

Time:07-25

I have custom options for a plugin in wordpress, it work fine until I make the upgrade, I am using a custom class that find in github

 class RationalOptionPages {
/* ==========================================================================
   Vars
   ========================================================================== */
protected $attributes = array(
    'input'     => array(
        'autocomplete'  => false,
        'autofocus'     => false,
        'disabled'      => false,
        'list'          => false,
        'max'           => false,
        'maxlength'     => false,
        'min'           => false,
        'pattern'       => false,
        'readonly'      => false,
        'required'      => true,
        'size'          => false,
        'step'          => false,
    ), 

I made a another page for the options

   'section-three'  => array(
            'title'         => __( 'Block', 'sample-domain' ),
            'fields'        => array(
                'radio'         => array(
                    'uid' => 'asp_typing_option',
                    'title'         => __( 'Typing Block Option', 'sample-domain' ),
                    'type'          => 'radio',
                    'value'         => 'option-one',
                    'choices'       => array(
                        'option-one'    => __( 'Active', 'sample-domain' ),
                        'option-two'    => __( 'Deactivate', 'sample-domain' ),
                    ),
                ),
            ),
        ),  

The problem occur when I reset the website then output an error

 Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\wordpress\wp-content\plugins\redux-framework\init.php on line 3 theerror is for all the options, then i save and the error disappear

I call the options with this way

$opt_sectionas = get_option('sample-page')['asp_section_option'];
$opt_carousel = get_option('sample-page')['asp_carousel_option'];
$opt_animate = get_option('sample-page')['asp_animate_aos_option'];
$opt_columns = get_option('sample-page')['asp_advance_columns_option'];

CodePudding user response:

I solved the problem adding the next to the call options section this is old version

$opt_sectionas = get_option('sample-page')['asp_section_option'];
$opt_carousel = get_option('sample-page')['asp_carousel_option'];

this is new version

$opt_sectionas = get_option('sample-page')['asp_section_option'] ?? '';
$opt_carousel = get_option('sample-page')['asp_carousel_option'] ?? ''; 
  • Related