/** * Check for and handle form submission. * * @return bool Have settings been updated? * @since 3.0 * @static */ protected static function maybe_save() { // Fetch existing settings $settings = $existing_settings = DP_Welcome_Pack::get_settings(); $updated = false; // Has the Friend invitation feature been toggled on/off? if (!empty($_POST['dpw_friendstoggle'])) { if ('on' == $_POST['dpw_friendstoggle']) { $settings['dpw_friendstoggle'] = true; } else { $settings['dpw_friendstoggle'] = false; } } // Has the Group invitation feature been toggled on/off? if (!empty($_POST['dpw_groupstoggle'])) { if ('on' == $_POST['dpw_groupstoggle']) { $settings['dpw_groupstoggle'] = true; } else { $settings['dpw_groupstoggle'] = false; } } // Has the Start Page feature been toggled on/off? if (!empty($_POST['dpw_startpagetoggle'])) { if ('on' == $_POST['dpw_startpagetoggle']) { $settings['dpw_startpagetoggle'] = true; } else { $settings['dpw_startpagetoggle'] = false; } } // Has the Welcome Message feature been toggled on/off? if (!empty($_POST['dpw_welcomemsgtoggle'])) { if ('on' == $_POST['dpw_welcomemsgtoggle']) { $settings['dpw_welcomemsgtoggle'] = true; } else { $settings['dpw_welcomemsgtoggle'] = false; } } // Has the email customisation feature been toggled on/off? if (!empty($_POST['dpw_emailtoggle'])) { if ('on' == $_POST['dpw_emailtoggle']) { $settings['dpw_emailtoggle'] = true; } else { $settings['dpw_emailtoggle'] = false; } } // Has the list of friends (to send invites to) been updated? if (!empty($_POST['friends'])) { $settings['friends'] = array_map('absint', (array) $_POST['friends']); } // Has the list of groups (to send invites to) been updated? if (!empty($_POST['groups'])) { $settings['groups'] = array_map('absint', (array) $_POST['groups']); } // Has the Start Page URL been updated? if (!empty($_POST['startpage'])) { $settings['startpage'] = sanitize_text_field(wp_kses_data($_POST['startpage'])); } // Has the Welcome Message body text been updated? if (!empty($_POST['welcomemsg'])) { $settings['welcomemsg'] = stripslashes(wp_filter_kses($_POST['welcomemsg'])); } // Has the Welcome Message subject text been updated? if (!empty($_POST['welcomemsgsubject'])) { $settings['welcomemsgsubject'] = stripslashes(sanitize_text_field(wp_filter_kses($_POST['welcomemsgsubject']))); } // Has the Welcome Message sender (who the message is sent from) been updated? if (!empty($_POST['welcomemsgsender'])) { $settings['welcomemsgsender'] = absint($_POST['welcomemsgsender']); } // If the new settings are different from the existing settings, then they've been changed. Save them to the database! if ($settings != $existing_settings) { check_admin_referer('dpw-admin', 'dpw-admin-nonce'); bp_update_option('welcomepack', $settings); $updated = true; } return $updated; }
/** * Load the email from the database that has been associated with the email that's being sent * * @param string $subject Email subject * @global object $bp */ public function email_load_emails($subject) { global $bp; if (!isset($bp->welcome_pack)) { $bp->welcome_pack = array(); } // Triple-check that the email subject passed matches one of the hardcoded email types $email_types = DP_Welcome_Pack::email_get_types(); // This email hasn't been loaded from the database if (!empty($email_types[$subject]) && !isset($bp->welcome_pack[$subject])) { $bp->welcome_pack[$subject] = new stdClass(); $email = get_posts(array('meta_key' => 'welcomepack_type', 'meta_value' => (int) $email_types[$subject], 'numberposts' => 1, 'post_type' => 'dpw_email')); if (!$email || is_wp_error($email)) { return; } $email = array_shift($email); $post_content = apply_filters('the_content', $email->post_content); $post_title = apply_filters('the_title', $email->post_title, $email->ID); $bp->welcome_pack[$subject]->message = $post_content; $bp->welcome_pack[$subject]->subject = $post_title; $bp->welcome_pack[$subject]->template = get_post_meta($email->ID, 'welcomepack_template', true); } // Allow third-party plugins to modify the updated email text do_action('dpw_email_load_emails', $subject); }