options = get_option('ftu_jetpack_booster_options');
$this->options = ($this->options) ? $this->options : array();
$this->has_jetpack = false;
/* this assumes we do not want any empty options */
$this->options = FTU::cleanOptions($this->options);
$this->options = array_merge(
// Set Defaults
array(
'email_template' => _x( '
!!!EMAIL_SUBJECT!!!
!!!EMAIL_BODY!!!
', 'default email template' ),
),
// set options
$this->options
);
/* actions */
add_action( 'admin_head', array($this,'custom_post_type_icon'));
/* look for Jetpack, we can hook into it */
add_action( 'admin_init', array($this,'dependentplugin_activate'));
/* actions */
add_action( 'admin_head', array($this,'custom_post_type_icon'));
/* queue frontend scripts */
add_action('wp_enqueue_scripts', array($this,'script_init_42U'));
/* queue admin scripts */
add_action('admin_enqueue_scripts', array($this,'admin_script_init_42U'));
add_action('admin_menu', array($this,'register_42U_page'));
/* */
add_action( 'grunion_pre_message_sent', array($this, 'set_redirect'),100,3);
/* filters */
/* filter to make our mail from jetpack pretty */
add_filter('wp_mail', array($this,'wp_mail_hook'));
/* set up our redirect */
add_filter('grunion_contact_form_redirect_url', array($this, 'contact_form_redirect'));
}
public function set_redirect($post_id, $all_values, $extra_values) {
global $JETTPACKBOOSTER_REDIRECT;
foreach ( (array) $all_values as $all_key => $all_value ) {
$match = preg_match('/redirect/', $all_key);
if ($match === 1) {
$JETTPACKBOOSTER_REDIRECT = $all_value;
}
}
}
public function register_42U_page() {
/* set up this 42U plugin admin page*/
// queue backend scripts
add_action( 'admin_init', array($this,'script_init_42U') );
/* create nav and load page styles */
$page = add_submenu_page('42-Umbrellas', '42U Jetpack Booster Options','Jetpack Booster Options','administrator',__FILE__, array($this,'booster_opts_42U'));
/* register options */
register_setting('ftu_jetpack_booster_options','ftu_jetpack_booster_options'); // 3rd param = optional callback
add_settings_section('ftu_jetpack_booster_main_section','Jetpack Booster Settings',array($this,'ftu_jetpack_booster_main_section_cb'),__FILE__);
add_settings_field('disable_HTMLemail',"Disable HTML Templates in Jetpack, I'd rather use plain text",array($this,'disable_HTMLemail_setting'),__FILE__,'ftu_jetpack_booster_main_section');
/*
add_settings_field('disable_modernizr',"Skip Modernizr, I don't need it!",array($this,'disable_modernizr_setting'),__FILE__,'ftu_jetpack_booster_main_section');
*/
}
public function script_init_42U() {
/* Register our scripts. */
wp_register_style( 'JetpackBoosterStylesheet', plugins_url('css/jetpack-booster.css', __FILE__) );
wp_enqueue_style( 'JetpackBoosterStylesheet' );
wp_register_script( 'JetpackBooster', plugins_url('js/booster.js', __FILE__),array('jquery'),false,true);
wp_enqueue_script( 'JetpackBooster' );
}
public function admin_script_init_42U() {
wp_register_style( 'jetpack_boosterStylesheet', plugins_url('css/style.css', __FILE__) );
wp_enqueue_style( 'jetpack_boosterStylesheet' );
}
public function booster_opts_42U() {
?>
Jetpack Booster Options
Updated');
}
?>
The 42U Jetpack Booster adds redirect tags and HTML email templates to Jetpack
Setting A Redirect
To add a redirect to your Jetpack Contact Form, just add a text field named "redirect" to your form. It will be hidden on display.
From the HTML view, set the default value to the location where you would like the form to redirect after submission. Note: you must replace the default each time after editing the form with the Jetpack WYSIWYG editor. The value is not saved by Jetpack.
options['disable_HTMLemail'] == '1' ) ? 'checked' : '';
echo "";
}
public function dependentplugin_activate() {
/* check for jetpack on every admin page load */
$jetpack = new Theme_Plugin_Dependency( 'jetpack', 'http://wordpress.org/extend/plugins/jetpack/' );
if ( $jetpack->check_active() ) {
$this->has_jetpack = true;
}
if ( $_GET['page'] == '42u-jetpack-booster/42u-jetpack-booster.php' && current_user_can( 'install_plugins' ) ) {
if ( ! $jetpack->check_active() ) {
$jetpack_msg = "What, no Jetpack? Jetpack greatly enhances the display of user profiles and managing feedback, along with a host of other cool features. It's free, you should try it out. This plugin won't do much without it.";
if ( $jetpack->check() ) {
$jetpack_msg .= ' Click here to activate it!';
} else if ( $install_link = $jetpack->install_link() ) {
$jetpack_msg .= ' Click here to install it!';
}
$jetpack_obj = new FTU_Admin_Notices( 'jetpack', $jetpack_msg, 'updated', true);
}
}
}
public function custom_post_type_icon() {
FTU::set_post_type_icon($image_urls=array('plugin'=>'jetpack-booster',
'admin-image'=>'images/jetpack_booster_adminmenu16-sprite.png',
'posts-image'=>'images/jetpack_booster_adminpage32.png',
'admin-imageX2'=>'images/jetpack_booster_adminmenu16-sprite_2x.png',
'posts-imageX2'=>'images/jetpack_booster_adminpage32_2x.png',
'file' => __FILE__
));
}
public function mail_content_type() {
return "text/html";
}
public function contact_form_redirect() {
global $JETTPACKBOOSTER_REDIRECT;
if ($JETTPACKBOOSTER_REDIRECT) {
return $JETTPACKBOOSTER_REDIRECT;
}
}
public function wp_mail_hook($data) {
/* we only want to do this if JetPack is installed and we have contact form fields */
global $post;
global $JETTPACKBOOSTER_REDIRECT;
$jetpack = new Theme_Plugin_Dependency( 'jetpack', 'http://wordpress.org/extend/plugins/jetpack/' );
if ( $jetpack->check_active() ) {
$this->has_jetpack = true;
}
if( $this->has_jetpack && $JETTPACKBOOSTER_REDIRECT) {
if ($this->options['disable_HTMLemail']) {
$pattern = '/redirect:.*?\n/i';
$data["message"] = preg_replace($pattern, '', $data["message"]);
} else {
add_filter("wp_mail_content_type", array($this,'mail_content_type'));
$subject = $data["subject"];
$pattern = '/redirect:.*?\n/i';
$message = nl2br(preg_replace($pattern, '', $data["message"]));
$template = $this->options['email_template'];
$footer_links = "You have received this email because you are a contact at " . get_bloginfo('name') . ". Log in to change your preferences.";
$template = preg_replace('/!!!EMAIL_BODY!!!/',$message,$template);
$template = preg_replace('/!!!EMAIL_SUBJECT!!!/',$subject,$template);
$template = preg_replace('/!!!EMAIL_FOOTER_LINKS!!!/',$footer_links,$template);
$data["message"] = $template;
}
}
return $data;
}
}
$jetpack_booster = new _42UJETPACK_BOOSTER();