Version Description
- Add new debugging configuration option
- Fix bug that resulted from WP 3.2's update to a new phpmailer
- Fix bug with checking 'Use GMail?' did not auto-reset settings accordingly (jQuery bug regarding .attr() vs .prop() introduced in jQ 1.6 in WP 3.2)
- Fix to call add_filter() instead of add_action() for 'wp_mail_from' (props Callum Macdonald)
- Fix to call add_filter() instead of add_action() for 'wp_mail_from_name'
- Store error messages for later display rather than immediately outputting (too early)
- Save a static version of itself in class variable $instance
- Deprecate use of global variable $c2c_configure_smtp to store instance
- Add explicit empty() checks in a couple places
- Delete plugin settings on uninstallation
- Add __construct(), activation(), and uninstall()
- Add more FAQ questions
- Regenerate .pot
- Update plugin framework to version 023
- Note compatibility through WP 3.2+
- Drop compatibility with versions of WP older than 3.0
- Explicitly declare all functions as public and class variables as private
- Minor code formatting changes (spacing)
- Update copyright date (2011)
- Add plugin homepage and author links in description in readme.txt
Download this release
Release Info
Developer | coffee2code |
Plugin | Configure SMTP |
Version | 3.1 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.1
- c2c-plugin.php +111 -66
- configure-smtp.php +90 -39
- readme.txt +42 -4
c2c-plugin.php
CHANGED
@@ -2,12 +2,12 @@
|
|
2 |
/**
|
3 |
* @package C2C_Plugins
|
4 |
* @author Scott Reilly
|
5 |
-
* @version
|
6 |
*/
|
7 |
/*
|
8 |
Basis for other plugins
|
9 |
|
10 |
-
Compatible with WordPress
|
11 |
|
12 |
=>> Read the accompanying readme.txt file for more information. Also, visit the plugin's homepage
|
13 |
=>> for more information and the latest updates
|
@@ -17,7 +17,7 @@ Installation:
|
|
17 |
*/
|
18 |
|
19 |
/*
|
20 |
-
Copyright (c) 2010 by Scott Reilly (aka coffee2code)
|
21 |
|
22 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
23 |
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
@@ -32,15 +32,15 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRA
|
|
32 |
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
33 |
*/
|
34 |
|
35 |
-
if ( !class_exists( '
|
36 |
|
37 |
-
class
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
/**
|
46 |
* Handles installation tasks, such as ensuring plugin options are instantiated and saved to options table.
|
@@ -52,7 +52,7 @@ class C2C_Plugin_017 {
|
|
52 |
* @param array $plugin_options (optional) Array specifying further customization of plugin configuration.
|
53 |
* @return void
|
54 |
*/
|
55 |
-
function
|
56 |
global $pagenow;
|
57 |
$id_base = sanitize_title( $id_base );
|
58 |
if ( !file_exists( $file ) )
|
@@ -81,7 +81,7 @@ class C2C_Plugin_017 {
|
|
81 |
$this->$key = $settings[$key];
|
82 |
|
83 |
$this->author_prefix = $author_prefix;
|
84 |
-
$this->id_base
|
85 |
$this->options_page = ''; // This will be set when the options is created
|
86 |
$this->plugin_basename = plugin_basename( $file );
|
87 |
$this->plugin_file = $file;
|
@@ -89,16 +89,15 @@ class C2C_Plugin_017 {
|
|
89 |
$this->u_id_base = $u_id_base; // Underscored version of id_base
|
90 |
$this->version = $version;
|
91 |
|
92 |
-
add_action( 'init',
|
93 |
$plugin_file = implode( '/', array_slice( explode( '/', $this->plugin_basename ), -2 ) );
|
94 |
-
add_action( 'activate_' . $plugin_file,
|
95 |
-
add_action( 'deactivate_' . $plugin_file,
|
96 |
-
register_uninstall_hook( $this->plugin_file, array( &$this, 'uninstall' ) );
|
97 |
|
98 |
-
add_action( 'admin_init',
|
99 |
|
100 |
if ( basename( $pagenow, '.php' ) == $this->settings_page )
|
101 |
-
add_action( 'admin_head',
|
102 |
}
|
103 |
|
104 |
/**
|
@@ -108,22 +107,11 @@ class C2C_Plugin_017 {
|
|
108 |
*
|
109 |
* @return void
|
110 |
*/
|
111 |
-
function install() {
|
112 |
$this->options = $this->get_options();
|
113 |
update_option( $this->admin_options_name, $this->options );
|
114 |
}
|
115 |
|
116 |
-
/**
|
117 |
-
* Handles uninstallation tasks, such as deleting plugin options.
|
118 |
-
*
|
119 |
-
* This can be overridden.
|
120 |
-
*
|
121 |
-
* @return void
|
122 |
-
*/
|
123 |
-
function uninstall() {
|
124 |
-
delete_option( $this->admin_options_name );
|
125 |
-
}
|
126 |
-
|
127 |
/**
|
128 |
* Handles deactivation tasks
|
129 |
*
|
@@ -131,14 +119,14 @@ class C2C_Plugin_017 {
|
|
131 |
*
|
132 |
* @return void
|
133 |
*/
|
134 |
-
function deactivate() { }
|
135 |
|
136 |
/**
|
137 |
* Handles actions to be hooked to 'init' action, such as loading text domain and loading plugin config data array.
|
138 |
*
|
139 |
* @return void
|
140 |
*/
|
141 |
-
function init() {
|
142 |
global $c2c_plugin_max_css_version;
|
143 |
if ( !isset( $c2c_plugin_max_css_version ) || ( $c2c_plugin_max_css_version < $this->plugin_css_version ) )
|
144 |
$c2c_plugin_max_css_version = $this->plugin_css_version;
|
@@ -161,6 +149,55 @@ class C2C_Plugin_017 {
|
|
161 |
$this->register_filters();
|
162 |
}
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
/**
|
165 |
* Prevents this plugin from being included when WordPress phones home
|
166 |
* to check for plugin updates.
|
@@ -169,7 +206,7 @@ class C2C_Plugin_017 {
|
|
169 |
* @param string $url URL for the update check
|
170 |
* @return array The response array with this plugin removed, if present
|
171 |
*/
|
172 |
-
function disable_update_check( $r, $url ) {
|
173 |
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
|
174 |
return $r; // Not a plugin update request. Bail immediately.
|
175 |
$plugins = unserialize( $r['body']['plugins'] );
|
@@ -184,7 +221,7 @@ class C2C_Plugin_017 {
|
|
184 |
*
|
185 |
* @return void
|
186 |
*/
|
187 |
-
function init_options() {
|
188 |
register_setting( $this->admin_options_name, $this->admin_options_name, array( &$this, 'sanitize_inputs' ) );
|
189 |
add_settings_section( 'default', '', array( &$this, 'draw_default_section' ), $this->plugin_file );
|
190 |
add_filter( 'whitelist_options', array( &$this, 'whitelist_options' ) );
|
@@ -198,7 +235,7 @@ class C2C_Plugin_017 {
|
|
198 |
* @param array $options Array of options
|
199 |
* @return array The whitelist-amended $options array
|
200 |
*/
|
201 |
-
function whitelist_options( $options ) {
|
202 |
$added = array( $this->admin_options_name => array( $this->admin_options_name ) );
|
203 |
$options = add_option_whitelist( $added, $options );
|
204 |
return $options;
|
@@ -209,7 +246,7 @@ class C2C_Plugin_017 {
|
|
209 |
*
|
210 |
* @return void
|
211 |
*/
|
212 |
-
function draw_default_section() { }
|
213 |
|
214 |
/**
|
215 |
* Gets the label for a given option
|
@@ -217,7 +254,7 @@ class C2C_Plugin_017 {
|
|
217 |
* @param string $opt The option
|
218 |
* @return string The label for the option
|
219 |
*/
|
220 |
-
function get_option_label( $opt ) {
|
221 |
return isset( $this->config[$opt]['label'] ) ? $this->config[$opt]['label'] : '';
|
222 |
}
|
223 |
|
@@ -226,7 +263,7 @@ class C2C_Plugin_017 {
|
|
226 |
*
|
227 |
* @return array
|
228 |
*/
|
229 |
-
function reset_options() {
|
230 |
$options = $this->get_options( false );
|
231 |
return $options;
|
232 |
}
|
@@ -234,7 +271,7 @@ class C2C_Plugin_017 {
|
|
234 |
/**
|
235 |
* Sanitize user inputs prior to saving
|
236 |
*/
|
237 |
-
function sanitize_inputs( $inputs ) {
|
238 |
do_action( $this->get_hook( 'before_save_options' ), $this );
|
239 |
if ( isset( $_POST['Reset'] ) ) {
|
240 |
$options = $this->reset_options();
|
@@ -274,13 +311,15 @@ class C2C_Plugin_017 {
|
|
274 |
case 'array':
|
275 |
if ( empty( $val ) )
|
276 |
$val = array();
|
|
|
|
|
277 |
elseif ( $input == 'text' )
|
278 |
$val = explode( ',', str_replace( array( ', ', ' ', ',' ), ',', $val ) );
|
279 |
else
|
280 |
$val = array_map( 'trim', explode( "\n", trim( $val ) ) );
|
281 |
break;
|
282 |
case 'hash':
|
283 |
-
if ( !empty( $val ) && $input != 'select' ) {
|
284 |
$new_values = array();
|
285 |
foreach ( explode( "\n", $val ) AS $line ) {
|
286 |
list( $shortcut, $text ) = array_map( 'trim', explode( "=>", $line, 2 ) );
|
@@ -299,6 +338,7 @@ class C2C_Plugin_017 {
|
|
299 |
}
|
300 |
$options = apply_filters( $this->get_hook( 'before_update_option' ), $options, $this );
|
301 |
}
|
|
|
302 |
return $options;
|
303 |
}
|
304 |
|
@@ -307,16 +347,14 @@ class C2C_Plugin_017 {
|
|
307 |
*
|
308 |
* @return void
|
309 |
*/
|
310 |
-
function load_config()
|
311 |
-
die( 'Function load_config() must be overridden in sub-class.' );
|
312 |
-
}
|
313 |
|
314 |
/**
|
315 |
* Verify that the necessary configuration files were set in the inheriting class.
|
316 |
*
|
317 |
* @return void
|
318 |
*/
|
319 |
-
function verify_config() {
|
320 |
// Ensure required configuration options have been configured via the sub-class. Die if any aren't.
|
321 |
foreach ( $this->required_config as $config ) {
|
322 |
if ( empty( $this->$config ) )
|
@@ -328,7 +366,7 @@ class C2C_Plugin_017 {
|
|
328 |
else {
|
329 |
// Initialize any option attributes that weren't specified by the plugin
|
330 |
foreach ( $this->get_option_names( true ) as $opt ) {
|
331 |
-
foreach ( array( 'datatype', 'default', 'help', 'input', 'input_attributes', 'label', 'no_wrap', 'options', 'output' ) as $attrib ) {
|
332 |
if ( !isset( $this->config[$opt][$attrib] ) )
|
333 |
$this->config[$opt][$attrib] = '';
|
334 |
}
|
@@ -343,7 +381,7 @@ class C2C_Plugin_017 {
|
|
343 |
*
|
344 |
* @return void
|
345 |
*/
|
346 |
-
function load_textdomain() {
|
347 |
$subdir = empty( $this->textdomain_subdir ) ? '' : '/'.$this->textdomain_subdir;
|
348 |
load_plugin_textdomain( $this->textdomain, false, basename( dirname( $this->plugin_file ) ) . $subdir );
|
349 |
}
|
@@ -354,7 +392,7 @@ class C2C_Plugin_017 {
|
|
354 |
*
|
355 |
* @return void
|
356 |
*/
|
357 |
-
function register_filters() {
|
358 |
// This should be overridden in order to define filters.
|
359 |
}
|
360 |
|
@@ -370,7 +408,7 @@ class C2C_Plugin_017 {
|
|
370 |
* @param object $screen The screen object (only supplied in WP 3.0)
|
371 |
* @return void (Text is echoed)
|
372 |
*/
|
373 |
-
function contextual_help( $contextual_help, $screen_id, $screen = null ) {
|
374 |
if ( $screen_id != $this->options_page )
|
375 |
return $contextual_help;
|
376 |
|
@@ -389,7 +427,7 @@ class C2C_Plugin_017 {
|
|
389 |
*
|
390 |
* @return void
|
391 |
*/
|
392 |
-
function add_c2c_admin_css() {
|
393 |
global $c2c_plugin_max_css_version, $c2c_plugin_css_was_output;
|
394 |
if ( ( $c2c_plugin_max_css_version != $this->plugin_css_version ) || ( isset( $c2c_plugin_css_was_output ) && $c2c_plugin_css_was_output ) )
|
395 |
return;
|
@@ -432,7 +470,7 @@ class C2C_Plugin_017 {
|
|
432 |
.c2c-fieldset {border:1px solid #ccc; padding:2px 8px;}
|
433 |
.c2c-textarea, .c2c-inline_textarea {width:95%;font-family:"Courier New", Courier, mono;}
|
434 |
.c2c-nowrap {
|
435 |
-
white-space:nowrap;overflow:
|
436 |
}
|
437 |
.see-help {font-size:x-small;font-style:italic;}
|
438 |
.more-help {display:block;margin-top:8px;}
|
@@ -446,7 +484,7 @@ CSS;
|
|
446 |
*
|
447 |
* @return void
|
448 |
*/
|
449 |
-
function admin_menu() {
|
450 |
add_filter( 'plugin_action_links_' . $this->plugin_basename, array( &$this, 'plugin_action_links' ) );
|
451 |
switch ( $this->settings_page ) {
|
452 |
case 'options-general' :
|
@@ -469,7 +507,7 @@ CSS;
|
|
469 |
* @param int $limit The default limit value for the current posts query.
|
470 |
* @return array Links associated with a plugin on the admin Plugins page
|
471 |
*/
|
472 |
-
function plugin_action_links( $action_links ) {
|
473 |
$settings_link = '<a href="' . $this->settings_page . '.php?page='.$this->plugin_basename.'">' . __( 'Settings', $this->textdomain ) . '</a>';
|
474 |
array_unshift( $action_links, $settings_link );
|
475 |
return $action_links;
|
@@ -483,7 +521,7 @@ CSS;
|
|
483 |
* @param string $opt The option name
|
484 |
* @return bool If the option is valid for this version of WP
|
485 |
*/
|
486 |
-
function is_option_valid( $opt ) {
|
487 |
global $wp_version;
|
488 |
$valid = true;
|
489 |
$ver_operators = array( 'wpgt' => '>', 'wpgte' => '>=', 'wplt' => '<', 'wplte' => '<=' );
|
@@ -504,7 +542,7 @@ CSS;
|
|
504 |
* @param bool $include_non_options (optional) Should non-options be included? Default is false.
|
505 |
* @return array Array of option names.
|
506 |
*/
|
507 |
-
function get_option_names( $include_non_options = false ) {
|
508 |
if ( !$include_non_options && !empty( $this->option_names ) )
|
509 |
return $this->option_names;
|
510 |
if ( $include_non_options )
|
@@ -524,7 +562,7 @@ CSS;
|
|
524 |
* @param bool $with_current_values (optional) Should the currently saved values be returned? If false, then the plugin's defaults are returned. Default is true.
|
525 |
* @return array The options array for the plugin (which is also stored in $this->options if !$with_options).
|
526 |
*/
|
527 |
-
function get_options( $with_current_values = true ) {
|
528 |
if ( $with_current_values && !empty( $this->options ) )
|
529 |
return $this->options;
|
530 |
// Derive options from the config
|
@@ -535,6 +573,10 @@ CSS;
|
|
535 |
if ( !$with_current_values )
|
536 |
return $options;
|
537 |
$this->options = wp_parse_args( get_option( $this->admin_options_name ), $options );
|
|
|
|
|
|
|
|
|
538 |
// Un-escape fields
|
539 |
foreach ( $option_names as $opt ) {
|
540 |
if ( $this->config[$opt]['allow_html'] == true ) {
|
@@ -560,7 +602,7 @@ CSS;
|
|
560 |
* @param string $prefix A prefix string, unique to the form
|
561 |
* @return string The name
|
562 |
*/
|
563 |
-
function get_form_submit_name( $prefix ) {
|
564 |
return $prefix . '_' . $this->u_id_base;
|
565 |
}
|
566 |
|
@@ -569,7 +611,7 @@ CSS;
|
|
569 |
*
|
570 |
* @return string The action URL
|
571 |
*/
|
572 |
-
function form_action_url() {
|
573 |
return $_SERVER['PHP_SELF'] . '?page=' . $this->plugin_basename;
|
574 |
}
|
575 |
|
@@ -579,7 +621,7 @@ CSS;
|
|
579 |
* @param string $prefix The prefix for the form's unique submit hidden input field
|
580 |
* @return bool True if the plugin's settings have been submitted for saving, else false.
|
581 |
*/
|
582 |
-
function is_submitting_form( $prefix ) {
|
583 |
return ( isset( $_POST['option_page'] ) && ( $_POST['option_page'] == $this->admin_options_name ) );
|
584 |
}
|
585 |
|
@@ -588,7 +630,7 @@ CSS;
|
|
588 |
*
|
589 |
* @return bool True if on the plugin's settings page, else false.
|
590 |
*/
|
591 |
-
function is_plugin_admin_page() {
|
592 |
global $pagenow;
|
593 |
return ( basename( $pagenow, '.php' ) == $this->settings_page && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == $this->plugin_basename );
|
594 |
}
|
@@ -599,7 +641,7 @@ CSS;
|
|
599 |
* @param string $opt The name/key of the option.
|
600 |
* @return void
|
601 |
*/
|
602 |
-
function display_option( $opt ) {
|
603 |
do_action( $this->get_hook( 'pre_display_option' ), $opt );
|
604 |
|
605 |
$options = $this->get_options();
|
@@ -694,7 +736,7 @@ CSS;
|
|
694 |
* @param string $localized_heading_text (optional) Localized page heading text.
|
695 |
* @return void
|
696 |
*/
|
697 |
-
function options_page_description( $localized_heading_text = '' ) {
|
698 |
if ( empty( $localized_heading_text ) )
|
699 |
$localized_heading_text = $this->name;
|
700 |
if ( $localized_heading_text )
|
@@ -709,13 +751,16 @@ CSS;
|
|
709 |
*
|
710 |
* @return void
|
711 |
*/
|
712 |
-
function options_page() {
|
713 |
$options = $this->get_options();
|
714 |
|
|
|
|
|
|
|
715 |
if ( $this->saved_settings )
|
716 |
echo "<div id='message' class='updated fade'><p><strong>" . $this->saved_settings_msg . '</strong></p></div>';
|
717 |
|
718 |
-
$logo = plugins_url(
|
719 |
|
720 |
echo "<div class='wrap'>\n";
|
721 |
echo "<div class='icon32' style='width:44px;'><img src='$logo' alt='" . esc_attr__( 'A plugin by coffee2code', $this->textdomain ) . "' /><br /></div>\n";
|
@@ -749,7 +794,7 @@ CSS;
|
|
749 |
* @param string $hook The name of a hook, to be made plugin-specific.
|
750 |
* @return string The plugin-specific version of the hook name.
|
751 |
*/
|
752 |
-
function get_hook( $hook ) {
|
753 |
return $this->hook_prefix . '_' . $hook;
|
754 |
}
|
755 |
|
@@ -760,7 +805,7 @@ CSS;
|
|
760 |
*
|
761 |
* @return string The URL
|
762 |
*/
|
763 |
-
function readme_url() {
|
764 |
return 'http://wordpress.org/extend/plugins/' . $this->id_base . '/tags/' . $this->version . '/readme.txt';
|
765 |
}
|
766 |
} // end class
|
2 |
/**
|
3 |
* @package C2C_Plugins
|
4 |
* @author Scott Reilly
|
5 |
+
* @version 023
|
6 |
*/
|
7 |
/*
|
8 |
Basis for other plugins
|
9 |
|
10 |
+
Compatible with WordPress 3.0+, 3.1+, 3.2+.
|
11 |
|
12 |
=>> Read the accompanying readme.txt file for more information. Also, visit the plugin's homepage
|
13 |
=>> for more information and the latest updates
|
17 |
*/
|
18 |
|
19 |
/*
|
20 |
+
Copyright (c) 2010-2011 by Scott Reilly (aka coffee2code)
|
21 |
|
22 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
23 |
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
32 |
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
33 |
*/
|
34 |
|
35 |
+
if ( !class_exists( 'C2C_Plugin_023' ) ) :
|
36 |
|
37 |
+
abstract class C2C_Plugin_023 {
|
38 |
+
protected $plugin_css_version = '007';
|
39 |
+
protected $options = array();
|
40 |
+
protected $option_names = array();
|
41 |
+
protected $required_config = array( 'menu_name', 'name' );
|
42 |
+
protected $saved_settings = false;
|
43 |
+
protected $saved_settings_msg = '';
|
44 |
|
45 |
/**
|
46 |
* Handles installation tasks, such as ensuring plugin options are instantiated and saved to options table.
|
52 |
* @param array $plugin_options (optional) Array specifying further customization of plugin configuration.
|
53 |
* @return void
|
54 |
*/
|
55 |
+
public function C2C_Plugin_023( $version, $id_base, $author_prefix, $file, $plugin_options = array() ) {
|
56 |
global $pagenow;
|
57 |
$id_base = sanitize_title( $id_base );
|
58 |
if ( !file_exists( $file ) )
|
81 |
$this->$key = $settings[$key];
|
82 |
|
83 |
$this->author_prefix = $author_prefix;
|
84 |
+
$this->id_base = $id_base;
|
85 |
$this->options_page = ''; // This will be set when the options is created
|
86 |
$this->plugin_basename = plugin_basename( $file );
|
87 |
$this->plugin_file = $file;
|
89 |
$this->u_id_base = $u_id_base; // Underscored version of id_base
|
90 |
$this->version = $version;
|
91 |
|
92 |
+
add_action( 'init', array( &$this, 'init' ) );
|
93 |
$plugin_file = implode( '/', array_slice( explode( '/', $this->plugin_basename ), -2 ) );
|
94 |
+
add_action( 'activate_' . $plugin_file, array( &$this, 'install' ) );
|
95 |
+
add_action( 'deactivate_' . $plugin_file, array( &$this, 'deactivate' ) );
|
|
|
96 |
|
97 |
+
add_action( 'admin_init', array( &$this, 'init_options' ) );
|
98 |
|
99 |
if ( basename( $pagenow, '.php' ) == $this->settings_page )
|
100 |
+
add_action( 'admin_head', array( &$this, 'add_c2c_admin_css' ) );
|
101 |
}
|
102 |
|
103 |
/**
|
107 |
*
|
108 |
* @return void
|
109 |
*/
|
110 |
+
public function install() {
|
111 |
$this->options = $this->get_options();
|
112 |
update_option( $this->admin_options_name, $this->options );
|
113 |
}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
/**
|
116 |
* Handles deactivation tasks
|
117 |
*
|
119 |
*
|
120 |
* @return void
|
121 |
*/
|
122 |
+
public function deactivate() { }
|
123 |
|
124 |
/**
|
125 |
* Handles actions to be hooked to 'init' action, such as loading text domain and loading plugin config data array.
|
126 |
*
|
127 |
* @return void
|
128 |
*/
|
129 |
+
public function init() {
|
130 |
global $c2c_plugin_max_css_version;
|
131 |
if ( !isset( $c2c_plugin_max_css_version ) || ( $c2c_plugin_max_css_version < $this->plugin_css_version ) )
|
132 |
$c2c_plugin_max_css_version = $this->plugin_css_version;
|
149 |
$this->register_filters();
|
150 |
}
|
151 |
|
152 |
+
/**
|
153 |
+
* Checks to see if the plugin has been upgraded from an earlier version.
|
154 |
+
*
|
155 |
+
* Calls handle_plugin_update() if an upgrade was detected. Override that
|
156 |
+
* to do whatever needs done to bring older settings, etc up-to-date.
|
157 |
+
*
|
158 |
+
* @since 021
|
159 |
+
*/
|
160 |
+
function check_if_plugin_was_upgraded() {
|
161 |
+
$_version = isset( $this->options['_version'] ) ? $this->options['_version'] : '0.0';
|
162 |
+
if ( $_version != $this->version ) {
|
163 |
+
// Save the original options into another option in case something goes wrong.
|
164 |
+
// TODO: Currently just saves one version back... should it save more?
|
165 |
+
update_option( 'bkup_' . $this->admin_options_name, $this->options );
|
166 |
+
|
167 |
+
$this->options['_version'] = $this->version;
|
168 |
+
$options = $this->handle_plugin_upgrade( $_version, $this->options );
|
169 |
+
update_option( $this->admin_options_name, $options );
|
170 |
+
$this->options = $options;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Handle plugin updates. (To be implemented by inheriting class, if
|
176 |
+
* necessary.)
|
177 |
+
*
|
178 |
+
* Intended to be used for updating plugin options, etc.
|
179 |
+
*
|
180 |
+
* This is only called if the version stored in the db doesn't match the
|
181 |
+
* plugin's current version. At the very least the settings will get
|
182 |
+
* re-saved so that the new current version can be recorded.
|
183 |
+
*
|
184 |
+
* @since 021
|
185 |
+
* @param string $old_version The version number of the old version of
|
186 |
+
* the plugin. '0.0' indicates no version previously stored
|
187 |
+
* @param array $options Array of all plugin options
|
188 |
+
*/
|
189 |
+
protected function handle_plugin_upgrade( $old_version, $options ) {
|
190 |
+
/* Example:
|
191 |
+
if ( version_compare( '1.2', $old_version ) > 0 ) {
|
192 |
+
// Plugin got upgraded from a version earlier than 1.2
|
193 |
+
// Which (for this example) is when a minimum value got raised
|
194 |
+
if ( $options['min_value'] < 5 )
|
195 |
+
$options['min_value'] = 5;
|
196 |
+
}
|
197 |
+
*/
|
198 |
+
return $options; // Important!
|
199 |
+
}
|
200 |
+
|
201 |
/**
|
202 |
* Prevents this plugin from being included when WordPress phones home
|
203 |
* to check for plugin updates.
|
206 |
* @param string $url URL for the update check
|
207 |
* @return array The response array with this plugin removed, if present
|
208 |
*/
|
209 |
+
public function disable_update_check( $r, $url ) {
|
210 |
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
|
211 |
return $r; // Not a plugin update request. Bail immediately.
|
212 |
$plugins = unserialize( $r['body']['plugins'] );
|
221 |
*
|
222 |
* @return void
|
223 |
*/
|
224 |
+
public function init_options() {
|
225 |
register_setting( $this->admin_options_name, $this->admin_options_name, array( &$this, 'sanitize_inputs' ) );
|
226 |
add_settings_section( 'default', '', array( &$this, 'draw_default_section' ), $this->plugin_file );
|
227 |
add_filter( 'whitelist_options', array( &$this, 'whitelist_options' ) );
|
235 |
* @param array $options Array of options
|
236 |
* @return array The whitelist-amended $options array
|
237 |
*/
|
238 |
+
public function whitelist_options( $options ) {
|
239 |
$added = array( $this->admin_options_name => array( $this->admin_options_name ) );
|
240 |
$options = add_option_whitelist( $added, $options );
|
241 |
return $options;
|
246 |
*
|
247 |
* @return void
|
248 |
*/
|
249 |
+
public function draw_default_section() { }
|
250 |
|
251 |
/**
|
252 |
* Gets the label for a given option
|
254 |
* @param string $opt The option
|
255 |
* @return string The label for the option
|
256 |
*/
|
257 |
+
public function get_option_label( $opt ) {
|
258 |
return isset( $this->config[$opt]['label'] ) ? $this->config[$opt]['label'] : '';
|
259 |
}
|
260 |
|
263 |
*
|
264 |
* @return array
|
265 |
*/
|
266 |
+
public function reset_options() {
|
267 |
$options = $this->get_options( false );
|
268 |
return $options;
|
269 |
}
|
271 |
/**
|
272 |
* Sanitize user inputs prior to saving
|
273 |
*/
|
274 |
+
public function sanitize_inputs( $inputs ) {
|
275 |
do_action( $this->get_hook( 'before_save_options' ), $this );
|
276 |
if ( isset( $_POST['Reset'] ) ) {
|
277 |
$options = $this->reset_options();
|
311 |
case 'array':
|
312 |
if ( empty( $val ) )
|
313 |
$val = array();
|
314 |
+
elseif ( is_array( $val ) )
|
315 |
+
$val = array_map( 'trim', $val );
|
316 |
elseif ( $input == 'text' )
|
317 |
$val = explode( ',', str_replace( array( ', ', ' ', ',' ), ',', $val ) );
|
318 |
else
|
319 |
$val = array_map( 'trim', explode( "\n", trim( $val ) ) );
|
320 |
break;
|
321 |
case 'hash':
|
322 |
+
if ( !empty( $val ) && $input != 'select' && !is_array( $val ) ) {
|
323 |
$new_values = array();
|
324 |
foreach ( explode( "\n", $val ) AS $line ) {
|
325 |
list( $shortcut, $text ) = array_map( 'trim', explode( "=>", $line, 2 ) );
|
338 |
}
|
339 |
$options = apply_filters( $this->get_hook( 'before_update_option' ), $options, $this );
|
340 |
}
|
341 |
+
$options['_version'] = $this->version;
|
342 |
return $options;
|
343 |
}
|
344 |
|
347 |
*
|
348 |
* @return void
|
349 |
*/
|
350 |
+
abstract protected function load_config();
|
|
|
|
|
351 |
|
352 |
/**
|
353 |
* Verify that the necessary configuration files were set in the inheriting class.
|
354 |
*
|
355 |
* @return void
|
356 |
*/
|
357 |
+
protected function verify_config() {
|
358 |
// Ensure required configuration options have been configured via the sub-class. Die if any aren't.
|
359 |
foreach ( $this->required_config as $config ) {
|
360 |
if ( empty( $this->$config ) )
|
366 |
else {
|
367 |
// Initialize any option attributes that weren't specified by the plugin
|
368 |
foreach ( $this->get_option_names( true ) as $opt ) {
|
369 |
+
foreach ( array( 'datatype', 'default', 'help', 'input', 'input_attributes', 'label', 'no_wrap', 'options', 'output', 'required' ) as $attrib ) {
|
370 |
if ( !isset( $this->config[$opt][$attrib] ) )
|
371 |
$this->config[$opt][$attrib] = '';
|
372 |
}
|
381 |
*
|
382 |
* @return void
|
383 |
*/
|
384 |
+
protected function load_textdomain() {
|
385 |
$subdir = empty( $this->textdomain_subdir ) ? '' : '/'.$this->textdomain_subdir;
|
386 |
load_plugin_textdomain( $this->textdomain, false, basename( dirname( $this->plugin_file ) ) . $subdir );
|
387 |
}
|
392 |
*
|
393 |
* @return void
|
394 |
*/
|
395 |
+
public function register_filters() {
|
396 |
// This should be overridden in order to define filters.
|
397 |
}
|
398 |
|
408 |
* @param object $screen The screen object (only supplied in WP 3.0)
|
409 |
* @return void (Text is echoed)
|
410 |
*/
|
411 |
+
public function contextual_help( $contextual_help, $screen_id, $screen = null ) {
|
412 |
if ( $screen_id != $this->options_page )
|
413 |
return $contextual_help;
|
414 |
|
427 |
*
|
428 |
* @return void
|
429 |
*/
|
430 |
+
public function add_c2c_admin_css() {
|
431 |
global $c2c_plugin_max_css_version, $c2c_plugin_css_was_output;
|
432 |
if ( ( $c2c_plugin_max_css_version != $this->plugin_css_version ) || ( isset( $c2c_plugin_css_was_output ) && $c2c_plugin_css_was_output ) )
|
433 |
return;
|
470 |
.c2c-fieldset {border:1px solid #ccc; padding:2px 8px;}
|
471 |
.c2c-textarea, .c2c-inline_textarea {width:95%;font-family:"Courier New", Courier, mono;}
|
472 |
.c2c-nowrap {
|
473 |
+
white-space:nowrap;overflow:auto;
|
474 |
}
|
475 |
.see-help {font-size:x-small;font-style:italic;}
|
476 |
.more-help {display:block;margin-top:8px;}
|
484 |
*
|
485 |
* @return void
|
486 |
*/
|
487 |
+
public function admin_menu() {
|
488 |
add_filter( 'plugin_action_links_' . $this->plugin_basename, array( &$this, 'plugin_action_links' ) );
|
489 |
switch ( $this->settings_page ) {
|
490 |
case 'options-general' :
|
507 |
* @param int $limit The default limit value for the current posts query.
|
508 |
* @return array Links associated with a plugin on the admin Plugins page
|
509 |
*/
|
510 |
+
public function plugin_action_links( $action_links ) {
|
511 |
$settings_link = '<a href="' . $this->settings_page . '.php?page='.$this->plugin_basename.'">' . __( 'Settings', $this->textdomain ) . '</a>';
|
512 |
array_unshift( $action_links, $settings_link );
|
513 |
return $action_links;
|
521 |
* @param string $opt The option name
|
522 |
* @return bool If the option is valid for this version of WP
|
523 |
*/
|
524 |
+
protected function is_option_valid( $opt ) {
|
525 |
global $wp_version;
|
526 |
$valid = true;
|
527 |
$ver_operators = array( 'wpgt' => '>', 'wpgte' => '>=', 'wplt' => '<', 'wplte' => '<=' );
|
542 |
* @param bool $include_non_options (optional) Should non-options be included? Default is false.
|
543 |
* @return array Array of option names.
|
544 |
*/
|
545 |
+
protected function get_option_names( $include_non_options = false ) {
|
546 |
if ( !$include_non_options && !empty( $this->option_names ) )
|
547 |
return $this->option_names;
|
548 |
if ( $include_non_options )
|
562 |
* @param bool $with_current_values (optional) Should the currently saved values be returned? If false, then the plugin's defaults are returned. Default is true.
|
563 |
* @return array The options array for the plugin (which is also stored in $this->options if !$with_options).
|
564 |
*/
|
565 |
+
protected function get_options( $with_current_values = true ) {
|
566 |
if ( $with_current_values && !empty( $this->options ) )
|
567 |
return $this->options;
|
568 |
// Derive options from the config
|
573 |
if ( !$with_current_values )
|
574 |
return $options;
|
575 |
$this->options = wp_parse_args( get_option( $this->admin_options_name ), $options );
|
576 |
+
|
577 |
+
// Check to see if the plugin has been updated
|
578 |
+
$this->check_if_plugin_was_upgraded();
|
579 |
+
|
580 |
// Un-escape fields
|
581 |
foreach ( $option_names as $opt ) {
|
582 |
if ( $this->config[$opt]['allow_html'] == true ) {
|
602 |
* @param string $prefix A prefix string, unique to the form
|
603 |
* @return string The name
|
604 |
*/
|
605 |
+
protected function get_form_submit_name( $prefix ) {
|
606 |
return $prefix . '_' . $this->u_id_base;
|
607 |
}
|
608 |
|
611 |
*
|
612 |
* @return string The action URL
|
613 |
*/
|
614 |
+
protected function form_action_url() {
|
615 |
return $_SERVER['PHP_SELF'] . '?page=' . $this->plugin_basename;
|
616 |
}
|
617 |
|
621 |
* @param string $prefix The prefix for the form's unique submit hidden input field
|
622 |
* @return bool True if the plugin's settings have been submitted for saving, else false.
|
623 |
*/
|
624 |
+
protected function is_submitting_form( $prefix ) {
|
625 |
return ( isset( $_POST['option_page'] ) && ( $_POST['option_page'] == $this->admin_options_name ) );
|
626 |
}
|
627 |
|
630 |
*
|
631 |
* @return bool True if on the plugin's settings page, else false.
|
632 |
*/
|
633 |
+
protected function is_plugin_admin_page() {
|
634 |
global $pagenow;
|
635 |
return ( basename( $pagenow, '.php' ) == $this->settings_page && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == $this->plugin_basename );
|
636 |
}
|
641 |
* @param string $opt The name/key of the option.
|
642 |
* @return void
|
643 |
*/
|
644 |
+
public function display_option( $opt ) {
|
645 |
do_action( $this->get_hook( 'pre_display_option' ), $opt );
|
646 |
|
647 |
$options = $this->get_options();
|
736 |
* @param string $localized_heading_text (optional) Localized page heading text.
|
737 |
* @return void
|
738 |
*/
|
739 |
+
protected function options_page_description( $localized_heading_text = '' ) {
|
740 |
if ( empty( $localized_heading_text ) )
|
741 |
$localized_heading_text = $this->name;
|
742 |
if ( $localized_heading_text )
|
751 |
*
|
752 |
* @return void
|
753 |
*/
|
754 |
+
public function options_page() {
|
755 |
$options = $this->get_options();
|
756 |
|
757 |
+
if ( function_exists( 'settings_errors' ) ) // Check for pre-3.0 compatibility
|
758 |
+
settings_errors();
|
759 |
+
|
760 |
if ( $this->saved_settings )
|
761 |
echo "<div id='message' class='updated fade'><p><strong>" . $this->saved_settings_msg . '</strong></p></div>';
|
762 |
|
763 |
+
$logo = plugins_url( 'c2c_minilogo.png', $this->plugin_file );
|
764 |
|
765 |
echo "<div class='wrap'>\n";
|
766 |
echo "<div class='icon32' style='width:44px;'><img src='$logo' alt='" . esc_attr__( 'A plugin by coffee2code', $this->textdomain ) . "' /><br /></div>\n";
|
794 |
* @param string $hook The name of a hook, to be made plugin-specific.
|
795 |
* @return string The plugin-specific version of the hook name.
|
796 |
*/
|
797 |
+
protected function get_hook( $hook ) {
|
798 |
return $this->hook_prefix . '_' . $hook;
|
799 |
}
|
800 |
|
805 |
*
|
806 |
* @return string The URL
|
807 |
*/
|
808 |
+
public function readme_url() {
|
809 |
return 'http://wordpress.org/extend/plugins/' . $this->id_base . '/tags/' . $this->version . '/readme.txt';
|
810 |
}
|
811 |
} // end class
|
configure-smtp.php
CHANGED
@@ -2,27 +2,30 @@
|
|
2 |
/**
|
3 |
* @package Configure_SMTP
|
4 |
* @author Scott Reilly
|
5 |
-
* @version 3.
|
6 |
*/
|
7 |
/*
|
8 |
Plugin Name: Configure SMTP
|
9 |
-
Version: 3.
|
10 |
Plugin URI: http://coffee2code.com/wp-plugins/configure-smtp/
|
11 |
Author: Scott Reilly
|
12 |
Author URI: http://coffee2code.com
|
13 |
Text Domain: configure-smtp
|
14 |
Description: Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
|
15 |
|
16 |
-
Compatible with WordPress
|
17 |
|
18 |
=>> Read the accompanying readme.txt file for instructions and documentation.
|
19 |
=>> Also, visit the plugin's homepage for additional information and updates.
|
20 |
=>> Or visit: http://wordpress.org/extend/plugins/configure-smtp/
|
21 |
|
|
|
|
|
|
|
22 |
*/
|
23 |
|
24 |
/*
|
25 |
-
Copyright (c) 2004-
|
26 |
|
27 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
28 |
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
@@ -37,26 +40,61 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRA
|
|
37 |
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
38 |
*/
|
39 |
|
40 |
-
if ( !class_exists( 'c2c_ConfigureSMTP' ) ) :
|
41 |
|
42 |
require_once( 'c2c-plugin.php' );
|
43 |
|
44 |
-
class c2c_ConfigureSMTP extends
|
45 |
|
46 |
-
|
|
|
|
|
47 |
'host' => 'smtp.gmail.com',
|
48 |
'port' => '465',
|
49 |
'smtp_auth' => true,
|
50 |
'smtp_secure' => 'ssl'
|
51 |
);
|
|
|
52 |
|
53 |
/**
|
54 |
* Constructor
|
55 |
*
|
56 |
* @return void
|
57 |
*/
|
58 |
-
function
|
59 |
-
$this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
/**
|
@@ -64,8 +102,8 @@ class c2c_ConfigureSMTP extends C2C_Plugin_017 {
|
|
64 |
*
|
65 |
* @return void
|
66 |
*/
|
67 |
-
function load_config() {
|
68 |
-
$this->name
|
69 |
$this->menu_name = __( 'SMTP', $this->textdomain );
|
70 |
|
71 |
$this->config = array(
|
@@ -95,6 +133,9 @@ class c2c_ConfigureSMTP extends C2C_Plugin_017 {
|
|
95 |
'wordwrap' => array( 'input' => 'short_text', 'default' => '',
|
96 |
'label' => __( 'Wordwrap length', $this->textdomain ),
|
97 |
'help' => __( 'Sets word wrapping on the body of the message to a given number of characters.', $this->textdomain ) ),
|
|
|
|
|
|
|
98 |
'hr' => array(),
|
99 |
'from_email' => array( 'input' => 'text', 'default' => '',
|
100 |
'label' => __( 'Sender e-mail', $this->textdomain ),
|
@@ -110,15 +151,15 @@ class c2c_ConfigureSMTP extends C2C_Plugin_017 {
|
|
110 |
*
|
111 |
* @return void
|
112 |
*/
|
113 |
-
function register_filters() {
|
114 |
global $pagenow;
|
115 |
if ( 'options-general.php' == $pagenow )
|
116 |
-
add_action( 'admin_print_footer_scripts',
|
117 |
-
add_action( 'admin_init',
|
118 |
-
add_action( 'phpmailer_init',
|
119 |
-
|
120 |
-
|
121 |
-
add_action( $this->get_hook( 'after_settings_form' ),
|
122 |
add_filter( $this->get_hook( 'before_update_option' ), array( &$this, 'maybe_gmail_override' ) );
|
123 |
}
|
124 |
|
@@ -127,9 +168,11 @@ class c2c_ConfigureSMTP extends C2C_Plugin_017 {
|
|
127 |
*
|
128 |
* @return void (Text will be echoed.)
|
129 |
*/
|
130 |
-
function options_page_description() {
|
131 |
$options = $this->get_options();
|
132 |
parent::options_page_description( __( 'Configure SMTP Settings', $this->textdomain ) );
|
|
|
|
|
133 |
$str = '<a href="#test">' . __( 'test', $this->textdomain ) . '</a>';
|
134 |
if ( empty( $options['host'] ) )
|
135 |
echo '<div class="error"><p>' . __( 'SMTP mailing is currently <strong>NOT ENABLED</strong> because no SMTP host has been specified.' ) . '</p></div>';
|
@@ -141,15 +184,20 @@ class c2c_ConfigureSMTP extends C2C_Plugin_017 {
|
|
141 |
*
|
142 |
* @return void (Text is echoed.)
|
143 |
*/
|
144 |
-
function add_js() {
|
145 |
-
$alert = __( 'Be sure to specify your GMail email address (
|
|
|
146 |
echo <<<JS
|
147 |
<script type="text/javascript">
|
148 |
function configure_gmail() {
|
149 |
-
|
|
|
150 |
jQuery('#host').val('{$this->gmail_config['host']}');
|
151 |
jQuery('#port').val('{$this->gmail_config['port']}');
|
152 |
-
jQuery('#
|
|
|
|
|
|
|
153 |
jQuery('#smtp_secure').val('{$this->gmail_config['smtp_secure']}');
|
154 |
if (!jQuery('#smtp_user').val().match(/.+@gmail.com$/) ) {
|
155 |
jQuery('#smtp_user').val('USERNAME@gmail.com').focus().get(0).setSelectionRange(0,8);
|
@@ -169,7 +217,7 @@ JS;
|
|
169 |
* @param array $options The options array prior to saving
|
170 |
* @return array The options array with GMail settings taking precedence, if relevant
|
171 |
*/
|
172 |
-
function maybe_gmail_override( $options ) {
|
173 |
// If GMail is to be used, those settings take precendence
|
174 |
if ( $options['use_gmail'] )
|
175 |
$options = wp_parse_args( $this->gmail_config, $options );
|
@@ -180,7 +228,7 @@ JS;
|
|
180 |
* Sends test e-mail if form was submitted requesting to do so.
|
181 |
*
|
182 |
*/
|
183 |
-
function maybe_send_test() {
|
184 |
if ( isset( $_POST[$this->get_form_submit_name( 'submit_test_email' )] ) ) {
|
185 |
check_admin_referer( $this->nonce_field );
|
186 |
$user = wp_get_current_user();
|
@@ -196,15 +244,14 @@ JS;
|
|
196 |
// Check success
|
197 |
global $phpmailer;
|
198 |
if ( $phpmailer->ErrorInfo != "" ) {
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
echo '</div>';
|
205 |
} else {
|
206 |
-
|
207 |
-
|
208 |
}
|
209 |
}
|
210 |
}
|
@@ -214,7 +261,7 @@ JS;
|
|
214 |
*
|
215 |
* @return void (Text will be echoed.)
|
216 |
*/
|
217 |
-
function send_test_form() {
|
218 |
$user = wp_get_current_user();
|
219 |
$email = $user->user_email;
|
220 |
$action_url = $this->form_action_url();
|
@@ -235,7 +282,7 @@ JS;
|
|
235 |
* @param object $phpmailer PHPMailer object
|
236 |
* @return void
|
237 |
*/
|
238 |
-
function phpmailer_init( $phpmailer ) {
|
239 |
$options = $this->get_options();
|
240 |
// Don't configure for SMTP if no host is provided.
|
241 |
if ( empty( $options['host'] ) )
|
@@ -252,6 +299,8 @@ JS;
|
|
252 |
$phpmailer->SMTPSecure = $options['smtp_secure'];
|
253 |
if ( $options['wordwrap'] > 0 )
|
254 |
$phpmailer->WordWrap = $options['wordwrap'];
|
|
|
|
|
255 |
}
|
256 |
|
257 |
/**
|
@@ -260,9 +309,9 @@ JS;
|
|
260 |
* @param string $from The "from" e-mail address used by WordPress by default
|
261 |
* @return string The potentially new "from" e-mail address, if overridden via the plugin's settings.
|
262 |
*/
|
263 |
-
function wp_mail_from( $from ) {
|
264 |
$options = $this->get_options();
|
265 |
-
if ( $options['from_email'] )
|
266 |
$from = $options['from_email'];
|
267 |
return $from;
|
268 |
}
|
@@ -273,15 +322,17 @@ JS;
|
|
273 |
* @param string $from The "from" name used by WordPress by default
|
274 |
* @return string The potentially new "from" name, if overridden via the plugin's settings.
|
275 |
*/
|
276 |
-
function wp_mail_from_name( $from_name ) {
|
277 |
$options = $this->get_options();
|
278 |
-
if ( $options['from_name'] )
|
279 |
$from_name = wp_specialchars_decode( $options['from_name'], ENT_QUOTES );
|
280 |
return $from_name;
|
281 |
}
|
282 |
|
283 |
} // end c2c_ConfigureSMTP
|
284 |
|
|
|
|
|
285 |
$GLOBALS['c2c_configure_smtp'] = new c2c_ConfigureSMTP();
|
286 |
|
287 |
endif; // end if !class_exists()
|
2 |
/**
|
3 |
* @package Configure_SMTP
|
4 |
* @author Scott Reilly
|
5 |
+
* @version 3.1
|
6 |
*/
|
7 |
/*
|
8 |
Plugin Name: Configure SMTP
|
9 |
+
Version: 3.1
|
10 |
Plugin URI: http://coffee2code.com/wp-plugins/configure-smtp/
|
11 |
Author: Scott Reilly
|
12 |
Author URI: http://coffee2code.com
|
13 |
Text Domain: configure-smtp
|
14 |
Description: Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
|
15 |
|
16 |
+
Compatible with WordPress 3.0+, 3.1+, 3.2+.
|
17 |
|
18 |
=>> Read the accompanying readme.txt file for instructions and documentation.
|
19 |
=>> Also, visit the plugin's homepage for additional information and updates.
|
20 |
=>> Or visit: http://wordpress.org/extend/plugins/configure-smtp/
|
21 |
|
22 |
+
TODO:
|
23 |
+
* Update screenshots for WP 3.2
|
24 |
+
* Add ability to configure plugin via defines in wp-config.php
|
25 |
*/
|
26 |
|
27 |
/*
|
28 |
+
Copyright (c) 2004-2011 by Scott Reilly (aka coffee2code)
|
29 |
|
30 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
31 |
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
40 |
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
41 |
*/
|
42 |
|
43 |
+
if ( ! class_exists( 'c2c_ConfigureSMTP' ) ) :
|
44 |
|
45 |
require_once( 'c2c-plugin.php' );
|
46 |
|
47 |
+
class c2c_ConfigureSMTP extends C2C_Plugin_023 {
|
48 |
|
49 |
+
public static $instance;
|
50 |
+
|
51 |
+
private $gmail_config = array(
|
52 |
'host' => 'smtp.gmail.com',
|
53 |
'port' => '465',
|
54 |
'smtp_auth' => true,
|
55 |
'smtp_secure' => 'ssl'
|
56 |
);
|
57 |
+
private $error_msg = '';
|
58 |
|
59 |
/**
|
60 |
* Constructor
|
61 |
*
|
62 |
* @return void
|
63 |
*/
|
64 |
+
public function __construct() {
|
65 |
+
$this->c2c_ConfigureSMTP();
|
66 |
+
}
|
67 |
+
|
68 |
+
public function c2c_ConfigureSMTP() {
|
69 |
+
// Be a singleton
|
70 |
+
if ( ! is_null( self::$instance ) )
|
71 |
+
return;
|
72 |
+
|
73 |
+
$this->C2C_Plugin_023( '3.1', 'configure-smtp', 'c2c', __FILE__, array() );
|
74 |
+
register_activation_hook( __FILE__, array( __CLASS__, 'activation' ) );
|
75 |
+
self::$instance = $this;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Handles activation tasks, such as registering the uninstall hook.
|
80 |
+
*
|
81 |
+
* @since 3.1
|
82 |
+
*
|
83 |
+
* @return void
|
84 |
+
*/
|
85 |
+
public function activation() {
|
86 |
+
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Handles uninstallation tasks, such as deleting plugin options.
|
91 |
+
*
|
92 |
+
* @since 3.1
|
93 |
+
*
|
94 |
+
* @return void
|
95 |
+
*/
|
96 |
+
public function uninstall() {
|
97 |
+
delete_option( 'c2c_configure_smtp' );
|
98 |
}
|
99 |
|
100 |
/**
|
102 |
*
|
103 |
* @return void
|
104 |
*/
|
105 |
+
public function load_config() {
|
106 |
+
$this->name = __( 'Configure SMTP', $this->textdomain );
|
107 |
$this->menu_name = __( 'SMTP', $this->textdomain );
|
108 |
|
109 |
$this->config = array(
|
133 |
'wordwrap' => array( 'input' => 'short_text', 'default' => '',
|
134 |
'label' => __( 'Wordwrap length', $this->textdomain ),
|
135 |
'help' => __( 'Sets word wrapping on the body of the message to a given number of characters.', $this->textdomain ) ),
|
136 |
+
'debug' => array( 'input' => 'checkbox', 'default' => false,
|
137 |
+
'label' => __( 'Enable debugging?', $this->textdomain ),
|
138 |
+
'help' => __( 'Only check this if you are experiencing problems and would like more error reporting to occur. <em>Uncheck this once you have finished debugging.</em>', $this->textdomain ) ),
|
139 |
'hr' => array(),
|
140 |
'from_email' => array( 'input' => 'text', 'default' => '',
|
141 |
'label' => __( 'Sender e-mail', $this->textdomain ),
|
151 |
*
|
152 |
* @return void
|
153 |
*/
|
154 |
+
public function register_filters() {
|
155 |
global $pagenow;
|
156 |
if ( 'options-general.php' == $pagenow )
|
157 |
+
add_action( 'admin_print_footer_scripts', array( &$this, 'add_js' ) );
|
158 |
+
add_action( 'admin_init', array( &$this, 'maybe_send_test' ) );
|
159 |
+
add_action( 'phpmailer_init', array( &$this, 'phpmailer_init' ) );
|
160 |
+
add_filter( 'wp_mail_from', array( &$this, 'wp_mail_from' ) );
|
161 |
+
add_filter( 'wp_mail_from_name', array( &$this, 'wp_mail_from_name' ) );
|
162 |
+
add_action( $this->get_hook( 'after_settings_form' ), array( &$this, 'send_test_form' ) );
|
163 |
add_filter( $this->get_hook( 'before_update_option' ), array( &$this, 'maybe_gmail_override' ) );
|
164 |
}
|
165 |
|
168 |
*
|
169 |
* @return void (Text will be echoed.)
|
170 |
*/
|
171 |
+
public function options_page_description() {
|
172 |
$options = $this->get_options();
|
173 |
parent::options_page_description( __( 'Configure SMTP Settings', $this->textdomain ) );
|
174 |
+
if ( ! empty( $this->error_msg ) )
|
175 |
+
echo $this->error_msg;
|
176 |
$str = '<a href="#test">' . __( 'test', $this->textdomain ) . '</a>';
|
177 |
if ( empty( $options['host'] ) )
|
178 |
echo '<div class="error"><p>' . __( 'SMTP mailing is currently <strong>NOT ENABLED</strong> because no SMTP host has been specified.' ) . '</p></div>';
|
184 |
*
|
185 |
* @return void (Text is echoed.)
|
186 |
*/
|
187 |
+
public function add_js() {
|
188 |
+
$alert = __( 'Be sure to specify your full GMail email address (including the "@gmail.com") as the SMTP username, and your GMail password as the SMTP password.', $this->textdomain );
|
189 |
+
$checked = $this->gmail_config['smtp_auth'] ? '1' : '';
|
190 |
echo <<<JS
|
191 |
<script type="text/javascript">
|
192 |
function configure_gmail() {
|
193 |
+
// The .attr('checked') == true is only for pre-WP3.2
|
194 |
+
if (jQuery('#use_gmail').attr('checked') == 'checked' || jQuery('#use_gmail').attr('checked') == true) {
|
195 |
jQuery('#host').val('{$this->gmail_config['host']}');
|
196 |
jQuery('#port').val('{$this->gmail_config['port']}');
|
197 |
+
if (jQuery('#use_gmail').attr('checked') == 'checked')
|
198 |
+
jQuery('#smtp_auth').prop('checked', $checked);
|
199 |
+
else // pre WP-3.2 only
|
200 |
+
jQuery('#smtp_auth').attr('checked', {$this->gmail_config['smtp_auth']});
|
201 |
jQuery('#smtp_secure').val('{$this->gmail_config['smtp_secure']}');
|
202 |
if (!jQuery('#smtp_user').val().match(/.+@gmail.com$/) ) {
|
203 |
jQuery('#smtp_user').val('USERNAME@gmail.com').focus().get(0).setSelectionRange(0,8);
|
217 |
* @param array $options The options array prior to saving
|
218 |
* @return array The options array with GMail settings taking precedence, if relevant
|
219 |
*/
|
220 |
+
public function maybe_gmail_override( $options ) {
|
221 |
// If GMail is to be used, those settings take precendence
|
222 |
if ( $options['use_gmail'] )
|
223 |
$options = wp_parse_args( $this->gmail_config, $options );
|
228 |
* Sends test e-mail if form was submitted requesting to do so.
|
229 |
*
|
230 |
*/
|
231 |
+
public function maybe_send_test() {
|
232 |
if ( isset( $_POST[$this->get_form_submit_name( 'submit_test_email' )] ) ) {
|
233 |
check_admin_referer( $this->nonce_field );
|
234 |
$user = wp_get_current_user();
|
244 |
// Check success
|
245 |
global $phpmailer;
|
246 |
if ( $phpmailer->ErrorInfo != "" ) {
|
247 |
+
$this->error_msg = '<div class="error"><p>' . __( 'An error was encountered while trying to send the test e-mail.', $this->textdomain ) . '</p>';
|
248 |
+
$this->error_msg .= '<blockquote style="font-weight:bold;">';
|
249 |
+
$this->error_msg .= '<p>' . $phpmailer->ErrorInfo . '</p>';
|
250 |
+
$this->error_msg .= '</p></blockquote>';
|
251 |
+
$this->error_msg .= '</div>';
|
|
|
252 |
} else {
|
253 |
+
$this->error_msg = '<div class="updated"><p>' . __( 'Test e-mail sent.', $this->textdomain ) . '</p>';
|
254 |
+
$this->error_msg .= '<p>' . sprintf( __( 'The body of the e-mail includes this time-stamp: %s.', $this->textdomain ), $timestamp ) . '</p></div>';
|
255 |
}
|
256 |
}
|
257 |
}
|
261 |
*
|
262 |
* @return void (Text will be echoed.)
|
263 |
*/
|
264 |
+
public function send_test_form() {
|
265 |
$user = wp_get_current_user();
|
266 |
$email = $user->user_email;
|
267 |
$action_url = $this->form_action_url();
|
282 |
* @param object $phpmailer PHPMailer object
|
283 |
* @return void
|
284 |
*/
|
285 |
+
public function phpmailer_init( $phpmailer ) {
|
286 |
$options = $this->get_options();
|
287 |
// Don't configure for SMTP if no host is provided.
|
288 |
if ( empty( $options['host'] ) )
|
299 |
$phpmailer->SMTPSecure = $options['smtp_secure'];
|
300 |
if ( $options['wordwrap'] > 0 )
|
301 |
$phpmailer->WordWrap = $options['wordwrap'];
|
302 |
+
if ( $options['debug'] )
|
303 |
+
$phpmailer->SMTPDebug = true;
|
304 |
}
|
305 |
|
306 |
/**
|
309 |
* @param string $from The "from" e-mail address used by WordPress by default
|
310 |
* @return string The potentially new "from" e-mail address, if overridden via the plugin's settings.
|
311 |
*/
|
312 |
+
public function wp_mail_from( $from ) {
|
313 |
$options = $this->get_options();
|
314 |
+
if ( ! empty( $options['from_email'] ) )
|
315 |
$from = $options['from_email'];
|
316 |
return $from;
|
317 |
}
|
322 |
* @param string $from The "from" name used by WordPress by default
|
323 |
* @return string The potentially new "from" name, if overridden via the plugin's settings.
|
324 |
*/
|
325 |
+
public function wp_mail_from_name( $from_name ) {
|
326 |
$options = $this->get_options();
|
327 |
+
if ( ! empty( $options['from_name'] ) )
|
328 |
$from_name = wp_specialchars_decode( $options['from_name'], ENT_QUOTES );
|
329 |
return $from_name;
|
330 |
}
|
331 |
|
332 |
} // end c2c_ConfigureSMTP
|
333 |
|
334 |
+
// NOTICE: The 'c2c_configure_smtp' global is deprecated and will be removed in the plugin's version 3.0.
|
335 |
+
// Instead, use: c2c_ConfigureSMTP::$instance
|
336 |
$GLOBALS['c2c_configure_smtp'] = new c2c_ConfigureSMTP();
|
337 |
|
338 |
endif; // end if !class_exists()
|
readme.txt
CHANGED
@@ -2,10 +2,10 @@
|
|
2 |
Contributors: coffee2code
|
3 |
Donate link: http://coffee2code.com/donate
|
4 |
Tags: email, smtp, gmail, sendmail, wp_mail, phpmailer, outgoing mail, tls, ssl, security, privacy, wp-phpmailer, coffee2code
|
5 |
-
Requires at least:
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 3.
|
8 |
-
Version: 3.
|
9 |
|
10 |
Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
|
11 |
|
@@ -31,6 +31,8 @@ Regardless of whether SMTP is enabled, the plugin provides you the ability to de
|
|
31 |
|
32 |
A simple test button is also available that allows you to send a test e-mail to yourself to check if sending e-mail has been properly configured for your blog.
|
33 |
|
|
|
|
|
34 |
|
35 |
== Installation ==
|
36 |
|
@@ -54,6 +56,17 @@ Check out the settings for your local e-mail program. More than likely that is
|
|
54 |
|
55 |
If your settings worked, you should receive the test e-mail at the e-mail address associated with your WordPress blog user account. That e-mail contains a time-stamp which was reported to you by the plugin when the e-mail was sent. If you are trying out various setting values, be sure to record what your settings were and what the time-stamp was when sending with those settings.
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
== Screenshots ==
|
59 |
|
@@ -62,6 +75,28 @@ If your settings worked, you should receive the test e-mail at the e-mail addres
|
|
62 |
|
63 |
== Changelog ==
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
= 3.0.1 =
|
66 |
* Update plugin framework to 017 to use password input field instead of text field for SMTP password
|
67 |
|
@@ -134,6 +169,9 @@ If your settings worked, you should receive the test e-mail at the e-mail addres
|
|
134 |
|
135 |
== Upgrade Notice ==
|
136 |
|
|
|
|
|
|
|
137 |
= 3.0.1 =
|
138 |
Minor update. Use password input field for SMTP password instead of regular text input field.
|
139 |
|
2 |
Contributors: coffee2code
|
3 |
Donate link: http://coffee2code.com/donate
|
4 |
Tags: email, smtp, gmail, sendmail, wp_mail, phpmailer, outgoing mail, tls, ssl, security, privacy, wp-phpmailer, coffee2code
|
5 |
+
Requires at least: 3.0
|
6 |
+
Tested up to: 3.2
|
7 |
+
Stable tag: 3.1
|
8 |
+
Version: 3.1
|
9 |
|
10 |
Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
|
11 |
|
31 |
|
32 |
A simple test button is also available that allows you to send a test e-mail to yourself to check if sending e-mail has been properly configured for your blog.
|
33 |
|
34 |
+
Links: [Plugin Homepage](http://coffee2code.com/wp-plugins/configure-smtp/) | [Author Homepage](http://coffee2code.com)
|
35 |
+
|
36 |
|
37 |
== Installation ==
|
38 |
|
56 |
|
57 |
If your settings worked, you should receive the test e-mail at the e-mail address associated with your WordPress blog user account. That e-mail contains a time-stamp which was reported to you by the plugin when the e-mail was sent. If you are trying out various setting values, be sure to record what your settings were and what the time-stamp was when sending with those settings.
|
58 |
|
59 |
+
= Why am I getting this error when attempting to send a test message: `SMTP Error: Could not connect to SMTP host.`? =
|
60 |
+
|
61 |
+
There are a number of reasons you could be getting this error:
|
62 |
+
# Your server (or a router to which it is connected) may be blocking all outgoing SMTP traffic.
|
63 |
+
# Your mail server may be configured to allow SMTP connections only from certain servers.
|
64 |
+
# You have supplied incorrect server settings (hostname, port number, secure protocol type).
|
65 |
+
|
66 |
+
= What am I getting this error: `SMTP Error: Could not authenticate.`? =
|
67 |
+
|
68 |
+
The connection to the SMTP server was successful, but the credentials you provided (username and/or password) are not correct.
|
69 |
+
|
70 |
|
71 |
== Screenshots ==
|
72 |
|
75 |
|
76 |
== Changelog ==
|
77 |
|
78 |
+
= 3.1 =
|
79 |
+
* Add new debugging configuration option
|
80 |
+
* Fix bug that resulted from WP 3.2's update to a new phpmailer
|
81 |
+
* Fix bug with checking 'Use GMail?' did not auto-reset settings accordingly (jQuery bug regarding .attr() vs .prop() introduced in jQ 1.6 in WP 3.2)
|
82 |
+
* Fix to call add_filter() instead of add_action() for 'wp_mail_from' (props Callum Macdonald)
|
83 |
+
* Fix to call add_filter() instead of add_action() for 'wp_mail_from_name'
|
84 |
+
* Store error messages for later display rather than immediately outputting (too early)
|
85 |
+
* Save a static version of itself in class variable $instance
|
86 |
+
* Deprecate use of global variable $c2c_configure_smtp to store instance
|
87 |
+
* Add explicit empty() checks in a couple places
|
88 |
+
* Delete plugin settings on uninstallation
|
89 |
+
* Add __construct(), activation(), and uninstall()
|
90 |
+
* Add more FAQ questions
|
91 |
+
* Regenerate .pot
|
92 |
+
* Update plugin framework to version 023
|
93 |
+
* Note compatibility through WP 3.2+
|
94 |
+
* Drop compatibility with versions of WP older than 3.0
|
95 |
+
* Explicitly declare all functions as public and class variables as private
|
96 |
+
* Minor code formatting changes (spacing)
|
97 |
+
* Update copyright date (2011)
|
98 |
+
* Add plugin homepage and author links in description in readme.txt
|
99 |
+
|
100 |
= 3.0.1 =
|
101 |
* Update plugin framework to 017 to use password input field instead of text field for SMTP password
|
102 |
|
169 |
|
170 |
== Upgrade Notice ==
|
171 |
|
172 |
+
= 3.1 =
|
173 |
+
Recommended update. Highlights: fixed numerous bugs; added a debug mode; updated compatibility through WP 3.2; dropped compatibility with version of WP older than 3.0; updated plugin framework.
|
174 |
+
|
175 |
= 3.0.1 =
|
176 |
Minor update. Use password input field for SMTP password instead of regular text input field.
|
177 |
|