wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

It is not possible to extend class methods

Open marko-stimac opened this issue 6 years ago • 1 comments

Extending class is not possible anymore, I get errors when trying to redefine some things in start_el:

  Fatal error: Uncaught Error: Call to private method WP_Bootstrap_Navwalker::get_linkmod_type() 
  Error: Call to private method WP_Bootstrap_Navwalker::get_linkmod_type() 

In previous versions I has something like this, small code where I only changed a bits of code I needed in a single method. Currently only way to redefine it is to copy whole class?

class My_Bootstrap_Navwalker extends WP_Bootstrap_Navwalker {

    public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
         ...
    }

}

marko-stimac avatar Dec 03 '18 08:12 marko-stimac

Hmmm yes I see the issue here. The method is intended to only ever be referenced from inside the class so thus it was made private - perhaps protected was the better choice here? Maybe even just going to public?

A change like this would be considered a breaking change and require a major version bump to be pushed out. I do plan to work on the next major version in the coming weeks so I'm tagging this issue for that and will cycle back to this with a viable solution soon I hope.

Thanks for highlighting this.

pattonwebz avatar Dec 04 '18 23:12 pattonwebz