Skip to content

Instantly share code, notes, and snippets.

@tannerm
Forked from trepmal/wpmandrill-ms.php
Last active August 29, 2015 14:24
Show Gist options
  • Save tannerm/b6d06e3d784f7c12bdd5 to your computer and use it in GitHub Desktop.
Save tannerm/b6d06e3d784f7c12bdd5 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: wpMandrill MS
* Plugin URI: https://gist.github.com/tannerm/b6d06e3d784f7c12bdd5
* Description: Network-wide settings for wpMandrill.
* Version: 2015.07.07
* Author: Kailey Lampert, Tanner Moushey
* Author URI: kaileylampert.com
* License: GPLv2 or later
* TextDomain: wpmandrill-ms
* DomainPath:
* Network: true
*/
$wpmandrill_ms = new WPMandrill_MS();
class WPMandrill_MS {
function __construct() {
add_action( 'admin_menu', array( &$this, 'admin_menu' ), 11 );
add_action( 'network_admin_menu', array( &$this, 'network_admin_menu' ) );
add_filter( 'default_option_wpmandrill', array( &$this, 'pre_option_wpmandrill' ) );
}
function admin_menu() {
remove_submenu_page( 'options-general.php', 'wpmandrill' );
}
function network_admin_menu() {
add_submenu_page( 'settings.php', __( 'Mandrill', 'wpmandrill-ms' ), __( 'wpMandrill MS', 'wpmandrill-ms' ), 'edit_posts', __CLASS__, array(
&$this,
'network_page'
) );
}
function network_page() { ?>
<div class="wrap">
<h2><?php _e( 'wpMandrill MS', 'wpmandrill-ms' ); ?></h2>
<?php
if ( isset( $_POST['save_wpmandrill_ms'] ) ) {
if ( wp_verify_nonce( $_POST['save_wpmandrill_ms'], 'save_wpmandrill_ms' ) ) {
$options = array_map( 'strip_tags', $_POST['wpmandrill_ms'] );
update_site_option( 'wpmandrill_ms', $options );
echo '<div class="updated"><p>Saved.</p></div>';
} else {
echo '<div class="updated"><p>Failed nonce check.</p></div>';
}
}
$d = array(
'api_key' => '',
'from_name' => '',
'from_username' => '',
'from_domain' => '',
'reply_to' => '',
'tags' => ''
);
$options = get_site_option( 'wpmandrill_ms', $d );
?>
<form method="post">
<table class="form-table">
<tbody>
<tr>
<td colspan="2"><h3>API Settings</h3></td>
</tr>
<tr>
<td>API Key:</td>
<td>
<input type="text" name="wpmandrill_ms[api_key]" value="<?php echo esc_attr( $options['api_key'] ); ?>" size="45" />
</td>
</tr>
<tr>
<td colspan="2"><h3>Sender Settings</h3></td>
</tr>
<tr>
<td>FROM Name:</td>
<td>
<input type="text" name="wpmandrill_ms[from_name]" value="<?php echo esc_attr( $options['from_name'] ); ?>" />
<p class="description">Name the recipients will see in their email clients.</p>
</td>
</tr>
<tr>
<td>FROM Email:</td>
<td>
<input type="text" name="wpmandrill_ms[from_username]" value="<?php echo esc_attr( $options['from_username'] ); ?>" />
<p class="description">This address will be used as the sender of the outgoing emails.</p>
</td>
</tr>
<tr>
<td>Reply-To Email:</td>
<td>
<input type="text" name="wpmandrill_ms[reply_to]" value="<?php echo esc_attr( $options['reply_to'] ); ?>" />
<p class="description">Leave blank to use the FROM Email. If you want to override this setting, you must use the mandrill_payload WordPress filter.</p>
</td>
</tr>
<tr>
<td>Content</td>
<td>
<label><input type="checkbox" name="wpmandrill_ms[nl2br]" value="1" <?php checked( isset( $options['nl2br'] ) ); ?> /> <?php echo esc_html( 'Replace all line feeds ("\n") by <br/> in the message body?' ); ?>
</label>
<p class="description">If you are sending HTML emails already keep this setting deactivated.
<br />
But if you are sending text only emails (WordPress default) this option might help your emails look better.
<br />
You can change the value of this setting on the fly by using the wpmandrill_nl2br filter.
</p>
</td>
</tr>
<tr>
<td>General Tags:</td>
<td>
<textarea name="wpmandrill_ms[tags]"><?php echo esc_textarea( $options['tags'] ); ?></textarea>
<p class="description">If there are tags that you want appended to every call, list them here, one per line.
<br />
Also keep in mind that you can add or remove tags using the mandrill_payload WordPress filter.
</p>
</td>
</tr>
</tbody>
</table>
<?php
wp_nonce_field( 'save_wpmandrill_ms', 'save_wpmandrill_ms' );
submit_button();
?>
</form>
</div><?php
}
function pre_option_wpmandrill( $return ) {
return get_site_option( 'wpmandrill_ms' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment