Changeset 929995
- Timestamp:
- 06/11/2014 12:47:06 AM (12 years ago)
- Location:
- sendwithus/trunk
- Files:
-
- 5 edited
-
inc/helper_functions.php (modified) (6 diffs)
-
inc/multisite_overrides.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
sendwithus.php (modified) (2 diffs)
-
sendwithus_php/lib/API.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sendwithus/trunk/inc/helper_functions.php
r927325 r929995 3 3 * MISCELLANEOUS FUNCTIONS 4 4 */ 5 global $default_wp_template_id;6 5 7 6 // Wrapper for the emails() function in the API … … 15 14 } 16 15 17 function set_ template_global(){16 function set_globals(){ 18 17 $GLOBALS['templates'] = get_templates(); 18 $GLOBALS['api_key'] = get_api_key(); 19 19 } 20 20 21 21 function create_default_template(){ 22 $ current_user = wp_get_current_user();23 22 $active_templates = get_templates(); 23 24 24 $api_key = get_option('api_key'); 25 25 $api = new \sendwithus\API($api_key); 26 26 $response = $api->emails(); 27 27 28 $template_kvp_array = Array();29 $template_id_array = Array();30 31 28 //Get the default wordpress email template ID 32 $default_id = get_user_option('default_wordpress_email_id', $current_user->ID); 33 34 //Create an array of template id's 35 foreach($response as $template){ 36 array_push($template_id_array, $template->id); 29 $default_id = get_option('default_wordpress_email_id'); 30 $default_deleted = true; 31 32 // Ensure that the default template hasn't been deleted. 33 foreach ( $active_templates as $current ) { 34 if ( $current->id == $default_id && $default_id != "" ) { 35 $default_deleted = false; 36 } 37 37 } 38 38 39 39 //If the default wordpress template id isn't in the array 40 if(!in_array($default_id, $template_id_array)){ 41 40 if( $default_id == "" || $default_deleted ) { 42 41 //Create a new template for default wordpress emails 43 42 $response = $api->create_email('Default Wordpress email', 44 43 '{{default_email_subject}} ', 45 44 '<html><head></head><body>{{default_message}}</body></html>'); 46 $response = $api->emails(); 47 //Create a KVP array of the template name => id 48 foreach($response as $template){ 49 $template_kvp_array[$template->name] = $template->id; 50 } 51 52 $default_wordpress_id = $template_kvp_array['Default Wordpress email']; 53 $success = update_user_option($current_user->ID, 'default_wordpress_email_id',$default_wordpress_id); 54 } 55 56 $default_wp_template_id = get_user_option('default_wordpress_email_id', $current_user->ID); 57 45 46 // Only save if the response is good. 47 if ( is_object($response) ) { 48 update_option('default_wordpress_email_id', $response->id); 49 } 50 } 58 51 } 59 52 … … 70 63 // Assign it to the default if no template is returned. 71 64 if($current_template == "") { 72 $current_template = get_ user_option('default_wordpress_email_id', $current_user->ID);65 $current_template = get_option('default_wordpress_email_id'); 73 66 } 74 67 … … 117 110 // Used to create an area to save plugin settings. 118 111 function sendwithus_register_settings() { 112 // Make sure the default template ID doesn't get overwritten! 113 $default_id = get_option('default_wordpress_email_id'); 114 register_setting( 'sendwithus_settings', 'default_wordpress_email_id'); 115 update_option('default_wordpress_email_id', $default_id); 116 119 117 // Save settings within wp_options table as 'sendwithus_settings' 120 118 register_setting( 'sendwithus_settings', 'api_key' ); 121 register_setting( 'sendwithus_settings', 'display_parameters' );122 119 123 120 // Whether user is using multisite functionality or not. 124 121 register_setting( 'sendwithus_settings', 'multisite_enabled' ); 125 122 126 $default_template = get_user_option('default_wordpress_email_id', $current_user->ID);127 128 123 foreach ( $GLOBALS['wp_notifications'] as $key => $value ) { 129 124 register_setting( 'sendwithus_settings', $key ); … … 131 126 if ( get_option($key) == "" ) { 132 127 // Assign default template. 133 update_option($key, $default_ template);128 update_option($key, $default_id); 134 129 } 135 130 } … … 140 135 if ( get_option($key) == "" ) { 141 136 // Assign default template. 142 update_option($key, $default_template); 143 } 144 } 145 146 $GLOBALS['templates'] = get_templates(); 147 137 update_option($key, $default_id); 138 } 139 } 148 140 } 149 141 -
sendwithus/trunk/inc/multisite_overrides.php
r927325 r929995 16 16 $options_site_url = esc_url(network_admin_url('settings.php')); 17 17 $remote_ip = wp_unslash( $_SERVER['REMOTE_ADDR'] ); 18 18 $default_email_subject = "New user ".$user->user_login." created at ".$site_name[1]; 19 19 $response = $api->send( 20 20 get_option('ms_new_user_network_admin'), … … 90 90 91 91 //Subject line for default wordpress email 92 $default_email_subject = "Welcome to ".get_option('blogname');92 $default_email_subject = "Welcome to ".get_option('blogname'); 93 93 94 94 $response = $api->send( -
sendwithus/trunk/readme.txt
r927347 r929995 52 52 == Changelog == 53 53 54 = 1.01 = 55 * Bugfixes 56 54 57 = 1.0 = 55 58 * Initial release -
sendwithus/trunk/sendwithus.php
r927325 r929995 26 26 } 27 27 28 $GLOBALS['api_key'] = get_api_key();28 set_globals(); 29 29 30 30 if ( $GLOBALS['api_key'] == '' || $GLOBALS['templates']->status == 'error' ) { 31 31 $GLOBALS['valid_key'] = false; 32 } 33 else{ 32 } else { 34 33 // Establish whether an API key has been entered and that it is valid. 35 34 $GLOBALS['valid_key'] = true; 36 add_action( 'plugins_loaded', 'create_default_template'); 37 add_action( 'plugins_loaded', 'set_template_global'); 35 36 add_action( 'init', 'create_default_template'); 37 38 // Some sites don't work with muplugins_loaded for some reason. 39 // This will make default be created. 40 if ( did_action('create_default_template') == 0 ) { 41 add_action( 'plugins_loaded', 'create_default_template'); 42 } 43 44 add_action( 'plugins_loaded', 'set_globals'); 38 45 } 39 46 … … 91 98 do_settings_sections( 'sendwithus_settings' ); 92 99 ?> 100 101 <!-- Hidden input containing default template ID --> 102 <input id="default_wordpress_email_id" name="default_wordpress_email_id" 103 style="display: none;" value="<?php echo get_option('default_wordpress_email_id'); ?>" /> 93 104 94 105 <!-- Only display if API key is populated --> -
sendwithus/trunk/sendwithus_php/lib/API.php
r927325 r929995 21 21 private $API_CLIENT_STUB = "php-%s"; 22 22 23 private $DEBUG = true;23 private $DEBUG = false; 24 24 25 25 public function __construct($api_key, $options = array()) {
Note: See TracChangeset
for help on using the changeset viewer.