[wp-trac] [WordPress Trac] #33146: Add optional $name variable to theme_mod_$name Filter.

WordPress Trac noreply at wordpress.org
Mon Jul 27 20:20:46 UTC 2015


#33146: Add optional $name variable to theme_mod_$name Filter.
--------------------------+------------------------------
 Reporter:  clintstegman  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  4.2.3
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  template
--------------------------+------------------------------

Comment (by clintstegman):

 Thanks obenland!

 Replying to [comment:1 obenland]:
 > You need to know the name of the theme mod to use that filter, hat keeps
 you from using that same name within the callback?

 This is true, however, I would like to do it with 1 callback function. The
 way it currently exists, I have to create a unique function for each.

 If I could get the name as a variable I could do this.

 example:
 {{{
 function my_function($value, $name){
  //stuff
 }

 add_filter("theme_mod_X", "my_function", 10, 2);
 add_filter("theme_mod_Y", "my_function", 10, 2);
 add_filter("theme_mod_Z", "my_function", 10, 2);
 }}}

 Currently I'm doing it like this


 {{{
 function my_function($value, $name){
  //stuff
 }

 $callback = create_function("$value", 'my_function("$value", "X");');
 add_filter("theme_mod_X", $callback);
 $callback = create_function("$value", 'my_function("$value", "Y");');
 add_filter("theme_mod_Y", $callback);
 $callback = create_function("$value", 'my_function("$value", "Z");');
 add_filter("theme_mod_Z", $callback);
 }}}

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


More information about the wp-trac mailing list