Support » Developing with WordPress » How to reload environment within wp shell

  • Resolved Leon Stafford

    (@leonstafford)


    When running wp shell and as an example, I call get_option(), I get value A, as expected. When I then modify the site via browser and set that option via dashboard to B, wp shell environment still reports value as A. If I relaunch the shell by exiting and running wp shell again, value is now B.

    Is there a way to reinit the whole WP app state within wp shell without having to exit?

Viewing 2 replies - 1 through 2 (of 2 total)
  • It is not so much reloading, but get_option() calls a cached option ( t ostop a process hammering the db )

    So you would need to clear the option cache

    wp_cache_get does have a ‘force’ parameter

    https://developer.wordpress.org/reference/functions/wp_cache_get/

    I haven’t tested this but calling wp_cache_get(‘myoption’, ‘options’, true )
    will probably clear the cache for that myoption

    Thread Starter Leon Stafford

    (@leonstafford)

    Many thanks for explaining it and giving me ideas, @alanfuller!

    A quick wp_cache_flush() between calls meets my needs for now. It’s a small dev environment, so doesn’t hurt to blow away all cache, but your suggested wp_cache_get() sounds much safer for anyone else looking to solve the same problem.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to reload environment within wp shell’ is closed to new replies.