Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. $value = apply_filters( "pre_update_option_{$option}", $new_value, $old_value );
  2.  
  3. $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
  4.  
  5. <?php
  6. /** Plugin Name: (#16621) Send mail after Option Value changed */
  7.  
  8. add_action( 'plugins_loaded', '166221reactMail' );
  9. function 166221reactMail()
  10. {
  11. // @TODO Add you option names (valid triggers) here:
  12. $valid = [
  13. 'your',
  14. 'option',
  15. 'names',
  16. 'here',
  17. ];
  18.  
  19. // Attach each filter: Precise targetting option names
  20. foreach ( $valid as $name )
  21. {
  22. add_filter( "pre_update_option_{$name}", function( $new, $old )
  23. {
  24. # @TODO Adjust check/validity of mail trigger here
  25. if ( $new !== $old )
  26. {
  27. # @TODO uncomment the following line - see note below
  28. // add_filter( 'wp_mail_from', '166221reactMailFrom' );
  29.  
  30. # @TODO Adjust values for wp_mail()
  31. wp_mail(
  32. 'To@example.com',
  33. sprintf( 'Change notification from %s', get_option( 'blogname' ) ),
  34. sprintf( 'Value changed from %s to %s', $old, $new )
  35. );
  36. }
  37.  
  38. return $new;
  39. }
  40. }
  41. }
  42.  
  43. // @TODO Change "from" Name to make creating inbox rules easier
  44. function 166221reactMailFrom( $from )
  45. {
  46. remove_filter( current_filter(), __FUNCTION__ );
  47. return "foo@bar.com";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement