• Resolved hshah

    (@hshah)


    I am renaming attachments for 2 different CPTs, so just to avoid any confusion with the code, I have 2 separate functions which invoke mfrh_rename when a post is created or updated.

    Both CPTs can be updated via the front end, but for one of them, users see “There has been a critical error on your website.”

    The error is:
    Uncaught Error: Call to undefined function mfrh_rename()

    If I go and edit that CPT from wp-admin, it works fine. The other CPT works fine from both the frontend and backend.

    Do I need to do something specific to load the mfrh plugin?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter hshah

    (@hshah)

    @tigroumeow

    What do you make of this?

    Plugin Author Jordy Meow

    (@tigroumeow)

    Hi @hshah,

    In fact, I am not sure why this happens. This function is not called by Media File Renamer itself. But Media File Renamer makes this function available.

    What plugin is using this function? It seems they don’t do it well, or too early (before the plugins are actually loaded).

    Of course, you should make sure the plugin is actually enabled too.

    Thread Starter hshah

    (@hshah)

    @tigroumeow

    I’m a little confused by your reply. I’m calling mfrh_rename in my own function to rename attachments added to posts.

    I’m carrying on with what we spoke about in this thread:
    https://wordpress.org/support/topic/rename-on-upload-but-after-post-save/

    When trying to use mfrh_rename in a post transition hook I get the mentioned error. The function I’m calling (my own one to do the renames) is the same one as I did with post save/update hooks. The post transition hook gives me that error but the post save/update one doesn’t.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Unfortunately, that will be a bit tricky then 🙁 The function is accessible as soon as the ‘plugins_loaded’ action has been run by WordPress. before that, the plugins are not initialized, and Media File Renamer neither.

    Before calling the function, you should check if it exists (function_exists) first to avoid errors, and log it if there is, to check where it was called exactly (and when).

    You should also check the action/filter you are currently being hooked to, and at what time it is called by WordPress. There is probably an official page somewhere about this, meanwhile I found this one: http://rachievee.com/the-wordpress-hooks-firing-sequence/

    Thread Starter hshah

    (@hshah)

    @tigroumeow

    If the function doesn’t exist, how do I call it?

    Plugin Author Jordy Meow

    (@tigroumeow)

    But can’t 🙂 I am just trying to give you pointers. You need to find a way to do this. Unfortunately, you will not be able to call any other functions from other plugins as well, it’s not an issue related to Media File Renamer, it’s an issue related to what you do and when in the hooks order.

    Thread Starter hshah

    (@hshah)

    @tigroumeow

    So mfrh_rename isn’t actually available globally?

    I can use it with post save and update but not post transition hooks, so that implies it’s not a global function.

    I’ve tried checking if the function exists and it doesn’t… I just need to know how to actually load the plugin in that scenario.

    Plugin Author Jordy Meow

    (@tigroumeow)

    It is available globally.

    You should also check the action/filter you are currently being hooked to, and at what time it is called by WordPress. There is probably an official page somewhere about this, meanwhile, I found this one: http://rachievee.com/the-wordpress-hooks-firing-sequence/

    I am sorry to say, but you should just check all this in detail. Have a look in the code of the plugin, the function is there, declared as global, and actually many other plugins use it as well. It’s just a matter of when it’s called, but as a developer implementing WordPress hooks, you need to understand the hook you are using and when they are fired (not only it’s important for calling my function, but also everything else you might be doing at that moment).

    Also, you shouldn’t load the plugin by yourself, as the plugin is also using hooks and other functions in WP). The plugin is loaded by WordPress, and the events are then fired. You should hook on an event which is fired after the plugins are loaded 🙂 It’s as simple as that, but it will require you to find the best hook depending on your scenario.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Call to undefined function mfrh_rename()’ is closed to new replies.