bp_email_redirect_to_customizer

Implements a JS redirect to the Customizer, previewing a randomly selected email.

Description

bp_email_redirect_to_customizer(); 

Usage

  1. if ( !function_exists( 'bp_email_redirect_to_customizer' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-customizer-email.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_email_redirect_to_customizer(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-customizer-email.php  
  1. function bp_email_redirect_to_customizer() { 
  2. $switched = false; 
  3.  
  4. // Switch to the root blog, where the email posts live. 
  5. if ( ! bp_is_root_blog() ) { 
  6. $switched = true; 
  7.  
  8. $email = get_posts( array( 
  9. 'fields' => 'ids',  
  10. 'orderby' => 'rand',  
  11. 'post_status' => 'publish',  
  12. 'post_type' => bp_get_email_post_type(),  
  13. 'posts_per_page' => 1,  
  14. 'suppress_filters' => false,  
  15. ) ); 
  16.  
  17. $preview_url = admin_url(); 
  18.  
  19. if ( $email ) { 
  20. $preview_url = get_post_permalink( $email[0] ) . '&bp_customizer=email'; 
  21.  
  22. $redirect_url = add_query_arg
  23. array( 
  24. 'autofocus[panel]' => 'bp_mailtpl',  
  25. 'bp_customizer' => 'email',  
  26. 'return' => rawurlencode( admin_url() ),  
  27. 'url' => rawurlencode( $preview_url ),  
  28. ),  
  29. admin_url( 'customize.php' ) 
  30. ); 
  31.  
  32. if ( $switched ) { 
  33.  
  34. printf( 
  35. '<script type="text/javascript">window.location = "%s";</script>',  
  36. esc_url_raw( $redirect_url ) 
  37. ); 
  38.  
  39. exit;