Mailer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A mailer() 0 13 2
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPFoundation\Configuration\Mailer;
13
14
/**
15
 * Class that configures the parameters used by "wp_mail".
16
 *
17
 * Define the following global variables in your "wp-config-custom.php" file:
18
 *
19
 *    MAILER_HOST: Url to the host.
20
 *    MAILER_PORT: The port used by SMTP.
21
 *    MAILER_USERNAME: The username used to send the email.
22
 *    MAILER_PASSWORD: The password required to send the email.
23
 *    MAILER_FROM: The email address that will be shown to the receiver.
24
 *    MAILER_FROM_NAME: The name that will be shown to the receiver.
25
 *
26
 * Remember to add this class to your theme constructor.
27
 *
28
 * @author Gorka Laucirica <[email protected]>
29
 * @author Jon Torrado <[email protected]>
30
 */
31
final class Mailer
32
{
33
    /**
34
     * Constructor.
35
     */
36
    public function __construct()
37
    {
38
        add_action('phpmailer_init', [$this, 'mailer']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
39
    }
40
41
    /**
42
     * Configures the mailer according to the parameters in "wp-config-custom.php".
43
     *
44
     * @param object $phpMailer The PhpMailer instance
45
     */
46
    public function mailer($phpMailer)
47
    {
48
        if (MAILER_SMTP) {
49
            $phpMailer->isSMTP();
50
            $phpMailer->SMTPAuth = true;
51
        }
52
        $phpMailer->Host = MAILER_HOST;
53
        $phpMailer->Port = MAILER_PORT;
54
        $phpMailer->Username = MAILER_USERNAME;
55
        $phpMailer->Password = MAILER_PASSWORD;
56
        $phpMailer->SMTPSecure = MAILER_TRANSPORT;
57
        $phpMailer->Sender = $phpMailer->From;
58
    }
59
}
60