chetmac / airpress

27 stars 9 forks source link

"Undefined index: sort_direction" error in Admin view #6

Open theecrit opened 4 years ago

theecrit commented 4 years ago

Not sure if this is the best place for this, but I'm getting a couple of php errors when viewing the Virtual Posts configuration page (this is a local install):

Error 1: ( ! ) Notice: Undefined index: sort_direction in /Users/jBook/Sites/michaelsand.dev.cc/wp-content/plugins/airpress/lib/chetmac/AirpressVirtualPostsAdmin.php on line 375

Viewing this in the actual AirpressVirtualPostsAdmin.php file:

function airpress_admin_vp_render_element_select__direction($args) {
    $options = $args[0];
    $option_name = $args[1];
    $field_name = $args[2];
    $directions = array(["value" => "asc","label" => "Ascending (A-Z)"],["value" => "desc","label" => "Descending (Z-A)"]);

    echo '<select id="' . $field_name . '" name="' . $option_name . '[' . $field_name . ']">';

    foreach ( $directions as $d ) {
        $selected = ($options[$field_name] == $d["value"])? " selected" : "";
        $option = '<option value="' . $d["value"] . '"'.$selected.'>';
        $option .= $d["label"];
        $option .= '</option>';
        echo $option;
    }
    echo '</select>';
}

And then if I scroll up in that same file, I also see:

################################
    $field_name = "sort";
    $field_title = "Sort results";
    add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_vp_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );

    ################################
    $field_name = "sort_direction";
    $field_title = "Sort direction";
    add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_vp_render_element_select__direction', $option_name, $section_name, array($options,$option_name,$field_name) );

    ################################

And I notice 'airpress_admin_vp_render_element_select__direction' has an extra underscore. If I remove that, error 1 resolves (but the drop-down menu disappears altogether on the config page in my WP admin dashboard). I still see error 2, below.

Error 2: Notice: Undefined index: sort_direction in /Users/jBook/Sites/michaelsand.dev.cc/wp-content/plugins/airpress/lib/chetmac/AirpressVirtualPostsAdmin.php on line 375

I'm pretty sure this is basically trying to get the Sort Direction drop-down to populate with the sort options; error 1 corresponds to the "Ascending (A-Z)" option, while error 2 corresponds to the "Descending (Z-A)" option.

I'm pretty awful with php, so none of my futzing has worked. Any chance you might know what's going on here? Thanks so much!

(Edited to add: the ReadMe suggests this an older release of AirPress; I'm using the latest 1.1.62 with WP v5.4, so not sure if this is part of the issue.)