Plugin Directory

Changeset 929995


Ignore:
Timestamp:
06/11/2014 12:47:06 AM (12 years ago)
Author:
dylanemoore
Message:

Adding version 1.01 of sendwithus plugin

Location:
sendwithus/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sendwithus/trunk/inc/helper_functions.php

    r927325 r929995  
    33 *  MISCELLANEOUS FUNCTIONS
    44 */
    5 global $default_wp_template_id;
    65
    76// Wrapper for the emails() function in the API
     
    1514}
    1615
    17 function set_template_global(){
     16function set_globals(){
    1817    $GLOBALS['templates'] = get_templates();
     18    $GLOBALS['api_key'] = get_api_key();
    1919}
    2020
    2121function create_default_template(){
    22     $current_user = wp_get_current_user();
    23 
     22    $active_templates = get_templates();
     23   
    2424    $api_key = get_option('api_key');
    2525    $api = new \sendwithus\API($api_key);
    2626    $response = $api->emails();
    2727
    28     $template_kvp_array = Array();
    29     $template_id_array = Array();
    30 
    3128    //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        }
    3737    }
    3838
    3939    //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 ) {
    4241        //Create a new template for default wordpress emails
    4342        $response = $api->create_email('Default Wordpress email',
    4443                    '{{default_email_subject}} ',
    4544                    '<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    }
    5851}
    5952
     
    7063    // Assign it to the default if no template is returned.
    7164    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');
    7366    }
    7467
     
    117110// Used to create an area to save plugin settings.
    118111function 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
    119117    // Save settings within wp_options table as 'sendwithus_settings'
    120118    register_setting( 'sendwithus_settings', 'api_key' );
    121     register_setting( 'sendwithus_settings', 'display_parameters' );
    122119
    123120    // Whether user is using multisite functionality or not.
    124121    register_setting( 'sendwithus_settings', 'multisite_enabled' );
    125122
    126     $default_template = get_user_option('default_wordpress_email_id', $current_user->ID);
    127 
    128123    foreach ( $GLOBALS['wp_notifications'] as $key => $value ) {
    129124        register_setting( 'sendwithus_settings', $key );
     
    131126        if ( get_option($key) == "" ) {
    132127            // Assign default template.
    133             update_option($key, $default_template);
     128            update_option($key, $default_id);
    134129        }
    135130    }
     
    140135        if ( get_option($key) == "" ) {
    141136            // 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    }
    148140}
    149141
  • sendwithus/trunk/inc/multisite_overrides.php

    r927325 r929995  
    1616    $options_site_url = esc_url(network_admin_url('settings.php'));
    1717    $remote_ip = wp_unslash( $_SERVER['REMOTE_ADDR'] );
    18 
     18    $default_email_subject = "New user ".$user->user_login." created at ".$site_name[1];
    1919    $response = $api->send(
    2020        get_option('ms_new_user_network_admin'),
     
    9090
    9191    //Subject line for default wordpress email
    92     $default_email_subject = "Welcome to".get_option('blogname');
     92    $default_email_subject = "Welcome to ".get_option('blogname');
    9393
    9494    $response = $api->send(
  • sendwithus/trunk/readme.txt

    r927347 r929995  
    5252== Changelog ==
    5353
     54= 1.01 =
     55* Bugfixes
     56
    5457= 1.0 =
    5558* Initial release
  • sendwithus/trunk/sendwithus.php

    r927325 r929995  
    2626}
    2727
    28 $GLOBALS['api_key'] = get_api_key();
     28set_globals();
    2929
    3030if ( $GLOBALS['api_key'] == '' || $GLOBALS['templates']->status == 'error' ) {
    3131    $GLOBALS['valid_key'] = false;
    32 }
    33 else{
     32} else {
    3433    // Establish whether an API key has been entered and that it is valid.
    3534    $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');
    3845}
    3946
     
    9198            do_settings_sections( 'sendwithus_settings' );
    9299            ?>
     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'); ?>" />
    93104
    94105            <!-- Only display if API key is populated -->
  • sendwithus/trunk/sendwithus_php/lib/API.php

    r927325 r929995  
    2121    private $API_CLIENT_STUB = "php-%s";
    2222
    23     private $DEBUG = true;
     23    private $DEBUG = false;
    2424
    2525    public function __construct($api_key, $options = array()) {
Note: See TracChangeset for help on using the changeset viewer.