• Resolved Nicolas Lemoine

    (@nlemoine)


    Hi,

    I’m using a static cache plugin (cache enabler but same could apply to any caching plugin) and need to clear the cache when a translation is updated.

    I browsed the code for do_action but found nothing that could help, could you an action somewhere when a translation is created/updated? Possibly including details about the language.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tim W

    (@timwhitlock)

    That’s an interesting question. I can certainly add a hook in the next version.

    In the mean time you could hook into the save action….

    All Ajax actions including “save” fire loco_ajax_init when the code starts up. This gives you a controller instance as argument. For a save action you can test this for instanceof Loco_ajax_SaveController. The actual save operation won’t have occurred yet, but probably a good enough signal to do a purge unless you really want to keep purges to a minimum.

    If you want to be sure the file is written before you purge, that might be tricker. You could hook into loco_admin_shutdown which fires after the process completes. Then you might want to fish the file path out of the postdata and check it’s timestamp has incremented. Probably overkill. Up to you.

    Thread Starter Nicolas Lemoine

    (@nlemoine)

    Thanks a lot for the fast feedback and the workaround! I’ll test this and will keep an eye on LocoTranslate updates.

    Plugin Author Tim W

    (@timwhitlock)

    I forgot to add this in yesterday’s release, but I’ve added a new loco_file_written hook into the development branch.

    The next release will be 2.4.2 and will probably go live as soon as WP 5.5 is live.

    Use the hook like this:

    add_action('loco_file_written',function($path){
      if( 'mo' === pathinfo($path,PATHINFO_EXTENSION) ) {
        // Invalidate page caches
      }
    },10,1);

    This will fire for ALL file writes, so you should check the $path is relevant to what you’re doing. Note that the path may not always be an absolute path on your file system. If you are writing over FTP for example – this will be a virtual path.

    Thread Starter Nicolas Lemoine

    (@nlemoine)

    Hi Tim,

    Thanks for considering my request!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add an action when a translation is saved’ is closed to new replies.