• Resolved Gal Baras

    (@galbaras)


    The action mfrh_url_renamed is called twice in a row in call_hooks_rename_url() with different arguments and no indication to the action function that there’s a difference.

    I think that the action hooks should be renamed, combined, or passed some argument that tells the respective functions what’s going on. Personally, I’d combine them into a single call with all of the parameters:

    do_action( 'mfrh_url_renamed', $post, $orig_image_url, $new_image_url, $this->clean_url( $orig_image_url ), $this->clean_url( $new_image_url ) );

    Of course, developers should be warned about this change in a advance.

    ALSO, call_hooks_rename_url() is called by call_post_actions() for the full-size image, and then for each thumbnail, triggering the mfrh_url_renamed action (twice) for each thumbnail, without passing any argument to indicate that this is a thumbnail, or which thumbnail it is.

    I suggest passing a $size argument to call_hooks_rename_url(), which will then also be passed by do_action() to the mfrh_url_renamed action functions.

    For context, I’m updating meta data in the image’s parent post, which only needs to be done once for the full-size image, and my action function has to figure out that it’s being called with absolute URLs with no thumbnail size in the file name before it decides to continue processing.

    Side comment: the variable $post and names like call_post_actions() are confusing, because in actual fact, they’re dealing with attachments. The global $post variable is an object, but in this context, it may be an array, which means that downstream functions, like those triggered by action, have to figure this out before proceeding correctly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    The action mfrh_url_renamed is called twice in a row in call_hooks_rename_url() with different arguments and no indication to the action function that there’s a difference.

    I did this for a reason a while ago, but in fact, I don’t think it’s needed anymore, and the second call is good enough. I will comment this out and try it on my test installs. You can expect the first call to be removed, that will also make things much faster.

    I suggest passing a $size argument to call_hooks_rename_url(), which will then also be passed by do_action() to the mfrh_url_renamed action functions.

    That’s a very good idea. I will implement this right now! While looking at this, I noticed that I can optimize the code, and avoid repeating the same SQL requests.

    For context, I’m updating meta data in the image’s parent post, which only needs to be done once for the full-size image, and my action function has to figure out that it’s being called with absolute URLs with no thumbnail size in the file name before it decides to continue processing.

    You know your install perfectly apparently, and of course, that’s much better, especially if you want to optimize things ?? It makes sense to disable the Side Updates I have included; you can simply use yours, that will be faster.

    If you are interesting in trying the new version, you know where to contact me ?? I can send you the new version today.

    Thread Starter Gal Baras

    (@galbaras)

    Jordy, in my case, the absolute URLs are preferred, and that’s the first do_action(). If you only leave the second, I’ll have to figure out even more than I do now :0

    Perhaps you can post here what you intend to do and we can discuss before testing? Other people may want to contribute.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘mfrh_url_renamed action called twice with different URLs’ is closed to new replies.