• Resolved nosilver4u

    (@nosilver4u)


    In the EWWW Image Editor plugin, I’ve extended the GD, Imagick, and Gmagick classes for WP_Image_Editor with my own classes:
    EWWWIO_GD_Editor
    EWWWIO_Gmagick_Editor
    EWWWIO_Imagick_Editor

    The intent is to reuse as much of the existing methods as possible. As such, they each contain one and only one method: _save. This method is pretty much identical to the parent class, except it hooks in the optimizations for the plugin. My understanding was that WP and other themes/plugins should be able to fallback to the parent class automatically for methods not in my child classes.

    Is that correct, or should I have implemented every method available (as some sort of call to the parent class methods)?

    @dh-shredder – any chance you could take a look?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot override protected functions such as _save(). save() is public and fair game, _save() is not.

    (FYI, requesting the attention of particular members is frowned upon here. I get it (your desire), and have gotten it to (personal requests), frankly it is mildly annoying even if flattering. Just so you know.)

    Thread Starter nosilver4u

    (@nosilver4u)

    sorry about that, I wasn’t sure if it was ok or not. He’s one of the few people I’ve seen post online about actually extending wp_image_editor. Plenty of stuff about using it, very little on how to extend it.

    At any rate, I didn’t know you couldn’t override protected functions. Are you sure about that? Because it works… I can crop, rotate, scale, all that stuff, and when the save function is called, it most definitely uses my _save routine. From what I’ve read, private functions cannot be overwritten, but protected ones are fair game.

    I think I’ve found the answer to my original question as well on php.net:

    The extended or derived class has all variables and functions of the base class and what you add in the extended definition.

    Moderator bcworkz

    (@bcworkz)

    No I’m not sure. Protected, private similar but very different. Sorry for my confusion, I have trouble keeping similar terms straight. Glad you were able to answer your own question despite my confusion.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘extending wp image editor – am I doing it wrong?’ is closed to new replies.