1

Can anyone help me to determine what function/statement in this file causes the fatal error after upgrading to php 7.0? On php 5.6 everything works fine.

Error: "Declaration of theme_navigation::update() should be compatible with WP_Widget::update($new_instance, $old_instance)" on line 0

Code:

class theme_navigation extends WP_Widget {
public function __construct() {
    parent::__construct(
        'theme_navigation', // Base ID
        'Child Page Navigation', // Name
        array('description' => '') // Args
    );
}

function form($instance){
    $instance['tiutle'] = apply_filters( 'widget_title', $instance['title'] ); ?>
  <p>Title: <input name="cpn_title" id="cpn_title" type="text" <?php if(isset($instance['title']) && $instance['title'] != "") echo 'value="'.$instance['title'].'"'; ?> /></p>
  <p>Sort by Sort Order? <input name="cpn_sort" id="cpn_sort" type="checkbox" <?php if(isset($instance['sort']) && $instance['sort']) echo 'checked="checked"'; ?> value="1" /></p>
<?php }

function update(){
    if(!isset($_POST['cpn_sort']))
        $_POST['cpn_sort'] = 0;

    foreach($_POST as $field => $val){
        if(substr($field,0,4) != "cpn_")
            continue;

        $opts[substr($field,4)] = attribute_escape($_POST[$field]);
        unset($_POST[$field]);
    }

    return $opts;
}

function widget($args,$instance){
    global $post;
    $instance['title'] = apply_filters( 'widget_title', $instance['title'] );

    $page_arr = array('child_of' => $post->ID, 'parent' => $post->ID);

    if($instance['sort'])
        $page_arr['sort_column'] = 'menu_order';

    $pages = get_pages($page_arr);

    if($post->post_parent && !count($pages))
        $page_arr['child_of'] = $page_arr['parent'] = $post->post_parent;
        $pages = get_pages($page_arr);

    if(!count($pages))
        return;

    echo $args['before_widget'];

    if(isset($instance['title']) && $instance['title'] != "")
        echo $args['before_title'].$instance['title'].$args['after_title'];

    echo "<ul>";

    foreach($pages as $page){
        echo "<li><a href='".get_permalink($page->ID)."'>".get_the_title($page->ID)."</a></li>";
    }

    echo "</ul>".$args['after_widget'];
}
}
add_action( 'widgets_init', create_function( '', 'register_widget( "theme_navigation" );' ) );
1
  • 4
    The error message says it all. update() needs to be update($new, $old) (aka have 2 arguments)
    – kero
    Commented Aug 29, 2017 at 15:21

1 Answer 1

6

You must have the same function arguments in functions on class inheritance.

So replace function update() with update($new_instance, $old_instance) in your code

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.