Skip to content

Commit

Permalink
If multisite use network wide option
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemolter committed Aug 6, 2016
1 parent a1b8cd0 commit 9a67361
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
54 changes: 41 additions & 13 deletions postmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,41 @@ function init() {


function load_settings() {
$settings = get_option( 'postmark_settings' );

// If on a multisite instance, get the network wide option
if ( is_multisite() ){
$settings = get_site_option( 'postmark_settings' );
}
else {
$settings = get_option( 'postmark_settings' );
}



if ( false === $settings ) {
$settings = array(
'enabled' => get_option( 'postmark_enabled', 0 ),
'api_key' => get_option( 'postmark_api_key', '' ),
'sender_address' => get_option( 'postmark_sender_address', '' ),
'force_html' => get_option( 'postmark_force_html', 0 ),
'track_opens' => get_option( 'postmark_trackopens', 0 )
);

update_option( 'postmark_settings', json_encode( $settings ) );


// If on a multisite instance, update the network wide option
if ( is_multisite() ){
$settings = array(
'enabled' => get_site_option( 'postmark_enabled', 0 ),
'api_key' => get_site_option( 'postmark_api_key', '' ),
'sender_address' => get_site_option( 'postmark_sender_address', '' ),
'force_html' => get_site_option( 'postmark_force_html', 0 ),
'track_opens' => get_site_option( 'postmark_trackopens', 0 )
);
update_site_option( 'postmark_settings', json_encode( $settings ) );
}
else {
$settings = array(
'enabled' => get_option( 'postmark_enabled', 0 ),
'api_key' => get_option( 'postmark_api_key', '' ),
'sender_address' => get_option( 'postmark_sender_address', '' ),
'force_html' => get_option( 'postmark_force_html', 0 ),
'track_opens' => get_option( 'postmark_trackopens', 0 )
);
update_option( 'postmark_settings', json_encode( $settings ) );
}

return $settings;
}

Expand Down Expand Up @@ -197,8 +219,14 @@ function save_settings() {
else {
$settings['track_opens'] = 0;
}

update_option( 'postmark_settings', json_encode($settings) );

// If on a multisite instance, get the network wide option
if ( is_multisite() ){
update_site_option( 'postmark_settings', json_encode($settings) );
}
else {
update_option( 'postmark_settings', json_encode($settings) );
}

wp_die('Settings saved');
}
Expand Down
8 changes: 7 additions & 1 deletion wp-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
// Compact the input, apply the filters, and extract them back out
extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );

$settings = json_decode( get_option( 'postmark_settings' ), true );
if (is_multisite()){
$settings = json_decode( get_site_option( 'postmark_settings' ), true );
}
else {
$settings = json_decode( get_option( 'postmark_settings' ), true );
}


if ( ! is_array( $attachments ) ) {
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
Expand Down

0 comments on commit 9a67361

Please sign in to comment.