-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwp-sendgrid.php
62 lines (50 loc) · 1.83 KB
/
wp-sendgrid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* Plugin Name: WP SendGrid
* Description: SendGrid integration for WordPress
* Version: 2.1.0
* Plugin URI: http://github.com/codeawhile/wp-sendgrid
* Author: Will Anderson
* Author URI: http://codeawhile.com/
* License: GPLv2
*/
class WP_SendGrid {
public static function start() {
WP_SendGrid::load_include( 'sendgrid-settings.php' );
$options = WP_SendGrid_Settings::get_settings();
if ( WP_SendGrid_Settings::API_REST == $options['api'] && !function_exists( 'wp_mail' ) ) {
self::load_include( 'wp-mail.php' );
} else {
add_action( 'phpmailer_init', array( __CLASS__, 'configure_smtp' ) );
}
add_action( 'plugin_action_links', array( __CLASS__, 'plugin_action_links' ), 10, 2 );
}
public static function plugin_action_links( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
$settings_link = '<a href="options-general.php?page=' . WP_SendGrid_Settings::SETTINGS_PAGE_SLUG . '">' . __( 'Settings', 'wp_mail_smtp' ) . '</a>';
array_unshift( $links, $settings_link );
}
return $links;
}
public static function configure_smtp( &$phpmailer ) {
$settings = WP_SendGrid_Settings::get_settings();
$phpmailer->Mailer = 'smtp';
$phpmailer->SMTPSecure = $settings['secure'] ? 'ssl' : 'none';
$phpmailer->Host = 'smtp.sendgrid.net';
$phpmailer->Port = $settings['secure'] ? 465 : 587;
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $settings['username'];
$phpmailer->Password = $settings['password'];
}
public static function load_include( $include ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/' . $include;
}
public static function load_view( $view, $vars = array() ) {
extract( $vars );
include plugin_dir_path( __FILE__ ) . 'views/' . $view;
}
public static function plugin_url( $path ) {
return plugins_url( $path, __FILE__ );
}
}
WP_SendGrid::start();