Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WP Mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
Library
WP Mail
Merge requests
!2
Devel
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Devel
devel
into
main
Overview
44
Commits
35
Pipelines
34
Changes
1
Merged
Piotr Potrebka
requested to merge
devel
into
main
2 years ago
Overview
44
Commits
35
Pipelines
34
Changes
1
0
0
Merge request reports
Viewing commit
0991e54c
Prev
Next
Show latest version
1 file
+
2
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
0991e54c
feat: email abstract
· 0991e54c
Piotr Potrebka
authored
2 years ago
src/EmailSender.php deleted
100644 → 0
+
0
−
101
View file @ 53209129
<?php
namespace
WPDesk\Library\WPEmail\Emails
;
use
WPDesk\Library\WPEmail\Abstracts\EmailInterface
;
class
EmailSender
{
/**
* @var EmailInterface[]
*/
private
$emails
=
[];
/**
* @var string
*/
private
$from
;
/**
* @var string
*/
private
$from_name
;
/**
* @param $from
* @param $from_name
*/
public
function
__construct
(
$from
=
''
,
$from_name
=
''
)
{
$this
->
from
=
$from
;
$this
->
from_name
=
$from_name
;
}
public
function
add_email
(
EmailInterface
$email
)
{
$this
->
emails
[
$email
->
get_id
()
]
=
$email
;
}
public
function
get_emails
():
array
{
return
$this
->
emails
;
}
/**
* WordPress callback for setting the from email
*
* @param string $email
*
* @return string
*/
public
function
from
(
$email
)
{
if
(
!
empty
(
$this
->
from
)
&&
is_email
(
$this
->
from
)
)
{
$email
=
$this
->
from
;
}
return
$email
;
}
/**
* WordPress callback for setting the from name
*
* @param string $name
*
* @return string
*/
public
function
from_name
(
$name
)
{
if
(
!
empty
(
$this
->
from_name
)
)
{
$name
=
html_entity_decode
(
sanitize_text_field
(
$this
->
from_name
)
);
}
return
$name
;
}
/**
* Add filters before fire wp_mail.
*
* @return void
*/
private
function
before_wp_mail
()
{
add_filter
(
'wp_mail_from'
,
array
(
$this
,
'from'
)
);
add_filter
(
'wp_mail_from_name'
,
array
(
$this
,
'from_name'
)
);
}
public
function
send
()
{
foreach
(
$this
->
get_emails
()
as
$email
)
{
$this
->
before_wp_mail
();
wp_mail
(
$email
->
get_recipients
(),
$email
->
get_subject
(),
$email
->
render
(),
$email
->
get_headers
(),
$email
->
get_attachments
()
);
$this
->
after_wp_mail
();
}
}
/**
* Remove filters after fire wp_mail.
*
* @return void
*/
private
function
after_wp_mail
()
{
remove_filter
(
'wp_mail_from'
,
array
(
$this
,
'from'
)
);
remove_filter
(
'wp_mail_from_name'
,
array
(
$this
,
'from_name'
)
);
}
}
Loading