[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Customizer implementation for email. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 2.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Initialize the Customizer for emails. 15 * 16 * @since 2.5.0 17 * 18 * @param WP_Customize_Manager $wp_customize The Customizer object. 19 */ 20 function bp_email_init_customizer( WP_Customize_Manager $wp_customize ) { 21 if ( ! bp_is_email_customizer() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { 22 return; 23 } 24 25 $wp_customize->add_panel( 'bp_mailtpl', array( 26 'description' => __( 'Customize the appearance of emails sent by BuddyPress.', 'buddypress' ), 27 'title' => _x( 'BuddyPress Emails', 'screen heading', 'buddypress' ), 28 ) ); 29 30 $sections = bp_email_get_customizer_sections(); 31 foreach( $sections as $section_id => $args ) { 32 $wp_customize->add_section( $section_id, $args ); 33 } 34 35 $settings = bp_email_get_customizer_settings(); 36 foreach( $settings as $setting_id => $args ) { 37 $wp_customize->add_setting( $setting_id, $args ); 38 } 39 40 /** 41 * Fires to let plugins register extra Customizer controls for emails. 42 * 43 * @since 2.5.0 44 * 45 * @param WP_Customize_Manager $wp_customize The Customizer object. 46 */ 47 do_action( 'bp_email_customizer_register_sections', $wp_customize ); 48 49 $controls = bp_email_get_customizer_controls(); 50 foreach ( $controls as $control_id => $args ) { 51 $wp_customize->add_control( new $args['class']( $wp_customize, $control_id, $args ) ); 52 } 53 54 /* 55 * Hook actions/filters for further configuration. 56 */ 57 58 add_filter( 'customize_section_active', 'bp_email_customizer_hide_sections', 12, 2 ); 59 60 if ( is_customize_preview() ) { 61 /* 62 * Enqueue scripts/styles for the Customizer's preview window. 63 * 64 * Scripts can't be registered in bp_core_register_common_styles() etc because 65 * the Customizer loads very, very early. 66 */ 67 $bp = buddypress(); 68 $min = bp_core_get_minified_asset_suffix(); 69 70 wp_enqueue_script( 71 'bp-customizer-receiver-emails', 72 "{$bp->plugin_url}bp-core/admin/js/customizer-receiver-emails{$min}.js", 73 array( 'customize-preview' ), 74 bp_get_version(), 75 true 76 ); 77 78 // Include the preview loading style. 79 add_action( 'wp_footer', array( $wp_customize, 'customize_preview_loading_style' ) ); 80 } 81 } 82 add_action( 'bp_customize_register', 'bp_email_init_customizer' ); 83 84 /** 85 * Are we looking at the email customizer? 86 * 87 * @since 2.5.0 88 * 89 * @return bool 90 */ 91 function bp_is_email_customizer() { 92 return isset( $_GET['bp_customizer'] ) && $_GET['bp_customizer'] === 'email'; 93 } 94 95 /** 96 * Only show email sections in the Customizer. 97 * 98 * @since 2.5.0 99 * 100 * @param bool $active Whether the Customizer section is active. 101 * @param WP_Customize_Section $section {@see WP_Customize_Section} instance. 102 * @return bool 103 */ 104 function bp_email_customizer_hide_sections( $active, $section ) { 105 if ( ! bp_is_email_customizer() ) { 106 return $active; 107 } 108 109 return in_array( $section->id, array_keys( bp_email_get_customizer_sections() ), true ); 110 } 111 112 /** 113 * Get Customizer sections for emails. 114 * 115 * @since 2.5.0 116 * 117 * @return array 118 */ 119 function bp_email_get_customizer_sections() { 120 121 /** 122 * Filter Customizer sections for emails. 123 * 124 * @since 2.5.0 125 * 126 * @param array $sections Email Customizer sections to add. 127 */ 128 return apply_filters( 'bp_email_get_customizer_sections', array( 129 'section_bp_mailtpl_header' => array( 130 'capability' => 'bp_moderate', 131 'panel' => 'bp_mailtpl', 132 'title' => _x( 'Header', 'email', 'buddypress' ), 133 ), 134 'section_bp_mailtpl_body' => array( 135 'capability' => 'bp_moderate', 136 'panel' => 'bp_mailtpl', 137 'title' => _x( 'Body', 'email', 'buddypress' ), 138 ), 139 'section_bp_mailtpl_footer' => array( 140 'capability' => 'bp_moderate', 141 'panel' => 'bp_mailtpl', 142 'title' => _x( 'Footer', 'email', 'buddypress' ), 143 ), 144 ) ); 145 } 146 147 /** 148 * Get Customizer settings for emails. 149 * 150 * @since 2.5.0 151 * 152 * @return array 153 */ 154 function bp_email_get_customizer_settings() { 155 $defaults = bp_email_get_appearance_settings(); 156 157 /** 158 * Filter Customizer settings for emails. 159 * 160 * @since 2.5.0 161 * 162 * @param array $settings Email Customizer settings to add. 163 */ 164 return apply_filters( 'bp_email_get_customizer_settings', array( 165 'bp_email_options[email_bg]' => array( 166 'capability' => 'bp_moderate', 167 'default' => $defaults['email_bg'], 168 'sanitize_callback' => 'sanitize_hex_color', 169 'transport' => 'postMessage', 170 'type' => 'option', 171 ), 172 'bp_email_options[header_bg]' => array( 173 'capability' => 'bp_moderate', 174 'default' => $defaults['header_bg'], 175 'sanitize_callback' => 'sanitize_hex_color', 176 'transport' => 'postMessage', 177 'type' => 'option', 178 ), 179 'bp_email_options[header_text_size]' => array( 180 'capability' => 'bp_moderate', 181 'default' => $defaults['header_text_size'], 182 'sanitize_callback' => 'absint', 183 'transport' => 'postMessage', 184 'type' => 'option', 185 ), 186 'bp_email_options[header_text_color]' => array( 187 'capability' => 'bp_moderate', 188 'default' => $defaults['header_text_color'], 189 'sanitize_callback' => 'sanitize_hex_color', 190 'transport' => 'postMessage', 191 'type' => 'option', 192 ), 193 'bp_email_options[highlight_color]' => array( 194 'capability' => 'bp_moderate', 195 'default' => $defaults['highlight_color'], 196 'sanitize_callback' => 'sanitize_hex_color', 197 'transport' => 'postMessage', 198 'type' => 'option', 199 ), 200 'bp_email_options[body_bg]' => array( 201 'capability' => 'bp_moderate', 202 'default' => $defaults['body_bg'], 203 'sanitize_callback' => 'sanitize_hex_color', 204 'transport' => 'postMessage', 205 'type' => 'option', 206 ), 207 'bp_email_options[body_text_size]' => array( 208 'capability' => 'bp_moderate', 209 'default' => $defaults['body_text_size'], 210 'sanitize_callback' => 'absint', 211 'transport' => 'postMessage', 212 'type' => 'option', 213 ), 214 'bp_email_options[body_text_color]' => array( 215 'capability' => 'bp_moderate', 216 'default' => $defaults['body_text_color'], 217 'sanitize_callback' => 'sanitize_hex_color', 218 'transport' => 'postMessage', 219 'type' => 'option', 220 ), 221 'bp_email_options[footer_text]' => array( 222 'capability' => 'bp_moderate', 223 'default' => $defaults['footer_text'], 224 'sanitize_callback' => 'wp_filter_post_kses', 225 'transport' => 'postMessage', 226 'type' => 'option', 227 ), 228 'bp_email_options[footer_bg]' => array( 229 'capability' => 'bp_moderate', 230 'default' => $defaults['footer_bg'], 231 'sanitize_callback' => 'sanitize_hex_color', 232 'transport' => 'postMessage', 233 'type' => 'option', 234 ), 235 'bp_email_options[footer_text_size]' => array( 236 'capability' => 'bp_moderate', 237 'default' => $defaults['footer_text_size'], 238 'sanitize_callback' => 'absint', 239 'transport' => 'postMessage', 240 'type' => 'option', 241 ), 242 'bp_email_options[footer_text_color]' => array( 243 'capability' => 'bp_moderate', 244 'default' => $defaults['footer_text_color'], 245 'sanitize_callback' => 'sanitize_hex_color', 246 'transport' => 'postMessage', 247 'type' => 'option', 248 ), 249 ) ); 250 } 251 252 /** 253 * Get Customizer controls for emails. 254 * 255 * @since 2.5.0 256 * 257 * @return array 258 */ 259 function bp_email_get_customizer_controls() { 260 261 /** 262 * Filter Customizer controls for emails. 263 * 264 * @since 2.5.0 265 * 266 * @param array $controls Email Customizer controls to add. 267 */ 268 return apply_filters( 'bp_email_get_customizer_controls', array( 269 'bp_mailtpl_email_bg' => array( 270 'class' => 'WP_Customize_Color_Control', 271 'label' => __( 'Email background color', 'buddypress' ), 272 'section' => 'section_bp_mailtpl_header', 273 'settings' => 'bp_email_options[email_bg]', 274 ), 275 276 'bp_mailtpl_header_bg' => array( 277 'class' => 'WP_Customize_Color_Control', 278 'label' => __( 'Header background color', 'buddypress' ), 279 'section' => 'section_bp_mailtpl_header', 280 'settings' => 'bp_email_options[header_bg]', 281 ), 282 283 'bp_mailtpl_highlight_color' => array( 284 'class' => 'WP_Customize_Color_Control', 285 'description' => __( 'Applied to links and other decorative areas.', 'buddypress' ), 286 'label' => __( 'Highlight color', 'buddypress' ), 287 'section' => 'section_bp_mailtpl_header', 288 'settings' => 'bp_email_options[highlight_color]', 289 ), 290 291 'bp_mailtpl_header_text_color' => array( 292 'class' => 'WP_Customize_Color_Control', 293 'label' => __( 'Text color', 'buddypress' ), 294 'section' => 'section_bp_mailtpl_header', 295 'settings' => 'bp_email_options[header_text_color]', 296 ), 297 298 'bp_mailtpl_header_text_size' => array( 299 'class' => 'BP_Customizer_Control_Range', 300 'label' => __( 'Text size', 'buddypress' ), 301 'section' => 'section_bp_mailtpl_header', 302 'settings' => 'bp_email_options[header_text_size]', 303 304 'input_attrs' => array( 305 'max' => 100, 306 'min' => 1, 307 'step' => 1, 308 ), 309 ), 310 311 312 'bp_mailtpl_body_bg' => array( 313 'class' => 'WP_Customize_Color_Control', 314 'label' => __( 'Background color', 'buddypress' ), 315 'section' => 'section_bp_mailtpl_body', 316 'settings' => 'bp_email_options[body_bg]', 317 ), 318 319 320 'bp_mailtpl_body_text_color' => array( 321 'class' => 'WP_Customize_Color_Control', 322 'label' => __( 'Text color', 'buddypress' ), 323 'section' => 'section_bp_mailtpl_body', 324 'settings' => 'bp_email_options[body_text_color]', 325 ), 326 327 'bp_mailtpl_body_text_size' => array( 328 'class' => 'BP_Customizer_Control_Range', 329 'label' => __( 'Text size', 'buddypress' ), 330 'section' => 'section_bp_mailtpl_body', 331 'settings' => 'bp_email_options[body_text_size]', 332 333 'input_attrs' => array( 334 'max' => 24, 335 'min' => 8, 336 'step' => 1, 337 ), 338 ), 339 340 341 'bp_mailtpl_footer_text' => array( 342 'class' => 'WP_Customize_Control', 343 'description' => __('Change the email footer here', 'buddypress' ), 344 'label' => __( 'Footer text', 'buddypress' ), 345 'section' => 'section_bp_mailtpl_footer', 346 'settings' => 'bp_email_options[footer_text]', 347 'type' => 'textarea', 348 ), 349 350 'bp_mailtpl_footer_bg' => array( 351 'class' => 'WP_Customize_Color_Control', 352 'label' => __( 'Background color', 'buddypress' ), 353 'section' => 'section_bp_mailtpl_footer', 354 'settings' => 'bp_email_options[footer_bg]', 355 ), 356 357 'bp_mailtpl_footer_text_color' => array( 358 'class' => 'WP_Customize_Color_Control', 359 'label' => __( 'Text color', 'buddypress' ), 360 'section' => 'section_bp_mailtpl_footer', 361 'settings' => 'bp_email_options[footer_text_color]', 362 ), 363 364 'bp_mailtpl_footer_text_size' => array( 365 'class' => 'BP_Customizer_Control_Range', 366 'label' => __( 'Text size', 'buddypress' ), 367 'section' => 'section_bp_mailtpl_footer', 368 'settings' => 'bp_email_options[footer_text_size]', 369 370 'input_attrs' => array( 371 'max' => 24, 372 'min' => 8, 373 'step' => 1, 374 ), 375 ), 376 ) ); 377 } 378 379 /** 380 * Implements a JS redirect to the Customizer, previewing a randomly selected email. 381 * 382 * @since 2.5.0 383 */ 384 function bp_email_redirect_to_customizer() { 385 $switched = false; 386 387 // Switch to the root blog, where the email posts live. 388 if ( ! bp_is_root_blog() ) { 389 switch_to_blog( bp_get_root_blog_id() ); 390 $switched = true; 391 } 392 393 $email = get_posts( array( 394 'fields' => 'ids', 395 'orderby' => 'rand', 396 'post_status' => 'publish', 397 'post_type' => bp_get_email_post_type(), 398 'posts_per_page' => 1, 399 'suppress_filters' => false, 400 ) ); 401 402 $preview_url = admin_url(); 403 404 if ( $email ) { 405 $preview_url = get_post_permalink( $email[0] ) . '&bp_customizer=email'; 406 } 407 408 $redirect_url = add_query_arg( 409 array( 410 'autofocus[panel]' => 'bp_mailtpl', 411 'bp_customizer' => 'email', 412 'return' => rawurlencode( admin_url() ), 413 'url' => rawurlencode( $preview_url ), 414 ), 415 admin_url( 'customize.php' ) 416 ); 417 418 if ( $switched ) { 419 restore_current_blog(); 420 } 421 422 printf( 423 '<script type="text/javascript">window.location = "%s";</script>', 424 esc_url_raw( $redirect_url ) 425 ); 426 427 exit; 428 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |