[wp-trac] [WordPress Trac] #34470: Wrong action name in set_transient()

WordPress Trac noreply at wordpress.org
Tue Oct 27 21:33:28 UTC 2015


#34470: Wrong action name in set_transient()
--------------------------------+-----------------------------
 Reporter:  GregLone            |      Owner:
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:  3.0
 Severity:  normal              |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 Here a small preview of `set_transient()`, I kept only the relevant parts:
 {{{#!php
 <?php
 function set_transient( $transient, $value, $expiration = 0 ) {
         // ...
         if ( wp_using_ext_object_cache() ) {
                 $result = wp_cache_set( $transient, $value, 'transient',
 $expiration );
         } else {
                 // ...
                 $transient = '_transient_' . $transient;
                 if ( false === get_option( $transient ) ) {
                         // ...
                 }
         }

         if ( $result ) {
                 // ...
                 do_action( 'set_transient_' . $transient, $value,
 $expiration, $transient );
                 // ...
                 do_action( 'setted_transient', $transient, $value,
 $expiration );
         }
         return $result;
 }
 }}}
 Note the line `$transient = '_transient_' . $transient;`, this is where
 the problem is: we change the value of `$transient`, which is used later
 in the `do_action()`s.

 In other `***_transient()` functions, this part is handled differently:
 {{{#!php
 <?php
 $option = '_site_transient_' . $transient;
 if ( false === get_site_option( $option ) ) {
 }}}

 Even annoying, if `wp_using_ext_object_cache()` is true then `$transient`
 does not change, so we won't have the same action name.
 As an example:
 {{{#!php
 <?php
 set_transient( 'foo', 'bar' );
 }}}
 Will trigger `set_transient_foo` if `wp_using_ext_object_cache()` is true
 and `set_transient__transient_foo` if not.

 As WP 4.4 adds the `$transient` parameter to the first `do_action()`, it
 might be a good time to fix this problem before going further.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34470>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list