[wp-trac] [WordPress Trac] #22369: get_transient() do not call delete_transient() when deleting one

WordPress Trac noreply at wordpress.org
Wed Jul 2 16:57:36 UTC 2025


#22369: get_transient() do not call delete_transient() when deleting one
--------------------------+----------------------
 Reporter:  juliobox      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  General       |     Version:  2.8
 Severity:  normal        |  Resolution:  invalid
 Keywords:  has-patch     |     Focuses:
--------------------------+----------------------
Changes (by desrosj):

 * keywords:  close has-patch => has-patch
 * status:  reopened => closed
 * resolution:   => invalid


Comment:

 Hi @juliobox,

 Is there any reason why the `delete_option`, `delete_option_${option}`, or
 `deleted_option` hooks cant be used to accomplish this?

 The first one, `delete_option`, is called before any deletion occurs. So
 something like this would accomplish the same:

 {{{
 add_action( 'delete_option', function( $key ) {
         if ( ! str_contains( $key, '_transient_timeout' ) ) {
                 return;
         }

         $timeout = get_option( $key );

         if ( ! empty( $timeout ) && $timeout < time() ) {
                 // The transient has expired. Do whatever you need.
         }
 });
 }}}

 If you need to know what the value is, you can just target the actual
 transient will be deleted first (`( str_contains( $key,
 '_transient_timeout' ) || ~ str_contains( $key, '_transient_' )`)

 That said, adding a new filter is a distinctly different request than what
 this ticket originally proposed (calling `delete_transient()` within
 `get_transient()` when an expired transient is deleted. If you're
 interested in pursuing this further, could you please create a new ticket
 for that feature request?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/22369#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list