Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WP Mail
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
Library
WP Mail
Commits
0ef316d0
Commit
0ef316d0
authored
2 years ago
by
Piotr Potrebka
Browse files
Options
Downloads
Patches
Plain Diff
feat: email styles
parent
b6190bdd
No related branches found
No related tags found
1 merge request
!2
Devel
Pipeline
#156492
passed with stages
in 1 minute and 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Mailer.php
+59
-22
59 additions, 22 deletions
src/Mailer.php
with
59 additions
and
22 deletions
src/Mailer.php
+
59
−
22
View file @
0ef316d0
...
@@ -26,17 +26,30 @@ class Mailer {
...
@@ -26,17 +26,30 @@ class Mailer {
/**
/**
* @var array
* @var array
*/
*/
private
$attributes
;
private
$template_attributes
;
/**
* @var string
*/
private
$from
;
/**
* @var string
*/
private
$from_name
;
/**
/**
* @param array $dirs
* @param array $dirs
* @param array $template_attributes
*/
*/
public
function
__construct
(
public
function
__construct
(
array
$dirs
=
[],
array
$dirs
=
[],
array
$attributes
=
[]
array
$
template_
attributes
=
[]
)
{
)
{
$this
->
attributes
=
$attributes
;
$this
->
template_
attributes
=
$
template_
attributes
;
$this
->
set_renderer
(
$this
->
init_renderer
(
$dirs
)
);
$this
->
set_renderer
(
$this
->
init_renderer
(
$dirs
)
);
$this
->
set_from
(
get_bloginfo
(
'admin_email'
)
);
$this
->
set_from_name
(
get_bloginfo
(
'name'
,
'display'
)
);
}
}
/**
/**
...
@@ -79,6 +92,38 @@ class Mailer {
...
@@ -79,6 +92,38 @@ class Mailer {
return
$this
->
emails
;
return
$this
->
emails
;
}
}
/**
* @param string $from
*
* @return void
*/
public
function
set_from
(
string
$from
)
{
$this
->
from
=
$from
;
}
/**
* @return string
*/
public
function
get_from
():
string
{
return
$this
->
from
;
}
/**
* @param string $from_name
*
* @return void
*/
public
function
set_from_name
(
string
$from_name
)
{
$this
->
from_name
=
$from_name
;
}
/**
* @return string
*/
public
function
get_from_name
():
string
{
return
$this
->
from_name
;
}
/** @return void */
/** @return void */
public
function
send
(
$include
=
[]
)
{
public
function
send
(
$include
=
[]
)
{
foreach
(
$this
->
get_emails
()
as
$email
)
{
foreach
(
$this
->
get_emails
()
as
$email
)
{
...
@@ -88,22 +133,14 @@ class Mailer {
...
@@ -88,22 +133,14 @@ class Mailer {
if
(
$email
->
get_is_enable
()
)
{
if
(
$email
->
get_is_enable
()
)
{
add_filter
(
add_filter
(
'wp_mail_from'
,
'wp_mail_from'
,
$from_cb
=
static
function
(
$from
)
use
(
$email
)
{
$from_cb
=
static
function
(
$from
)
{
if
(
!
empty
(
$email
->
get_from
()
)
)
{
return
$this
->
get_from
();
return
$email
->
get_from
();
}
return
$from
;
}
}
);
);
add_filter
(
add_filter
(
'wp_mail_from_name'
,
'wp_mail_from_name'
,
$from_name_cb
=
static
function
(
$from_name
)
use
(
$email
)
{
$from_name_cb
=
static
function
(
$from_name
)
{
if
(
!
empty
(
$email
->
get_from_name
()
)
)
{
return
$this
->
get_from_name
();
return
$email
->
get_from_name
();
}
return
$from_name
;
}
}
);
);
add_action
(
'wp_mail_failed'
,
[
$this
,
'catch_error'
]
);
add_action
(
'wp_mail_failed'
,
[
$this
,
'catch_error'
]
);
...
@@ -144,12 +181,12 @@ class Mailer {
...
@@ -144,12 +181,12 @@ class Mailer {
$output
=
$this
->
renderer
->
render
(
$output
=
$this
->
renderer
->
render
(
'html/email-header'
,
'html/email-header'
,
[
[
'heading'
=>
$this
->
attributes
[
'heading'
]
??
$email
->
get_heading
(),
'heading'
=>
$this
->
template_
attributes
[
'heading'
]
??
$email
->
get_heading
(),
'logo'
=>
$this
->
attributes
[
'logo'
]
'logo'
=>
$this
->
template_
attributes
[
'logo'
]
]
]
);
);
$output
.
=
$this
->
renderer
->
render
(
'html/'
.
$email
->
get_id
(),
[
'content'
=>
$email
->
get_content
()
]
);
$output
.
=
$this
->
renderer
->
render
(
'html/'
.
$email
->
get_id
(),
[
'content'
=>
$email
->
get_content
()
]
);
$output
.
=
$this
->
renderer
->
render
(
'html/email-footer'
,
[
'footer'
=>
$this
->
attributes
[
'footer'
]
]
);
$output
.
=
$this
->
renderer
->
render
(
'html/email-footer'
,
[
'footer'
=>
$this
->
template_
attributes
[
'footer'
]
]
);
return
$this
->
css_inline
(
$output
);
return
$this
->
css_inline
(
$output
);
}
}
...
@@ -163,10 +200,10 @@ class Mailer {
...
@@ -163,10 +200,10 @@ class Mailer {
$styles
=
$this
->
renderer
->
render
(
$styles
=
$this
->
renderer
->
render
(
'html/email-styles'
,
'html/email-styles'
,
[
[
'primary'
=>
$this
->
attributes
[
'primary'
]
??
'#d15291'
,
'primary'
=>
$this
->
template_
attributes
[
'primary'
]
??
'#d15291'
,
'text'
=>
$this
->
attributes
[
'text'
]
??
'#303030'
,
'text'
=>
$this
->
template_
attributes
[
'text'
]
??
'#303030'
,
'bg'
=>
$this
->
attributes
[
'bg'
]
??
'#f9f9f9'
,
'bg'
=>
$this
->
template_
attributes
[
'bg'
]
??
'#f9f9f9'
,
'body'
=>
$this
->
attributes
[
'body'
]
??
'#ffffff'
,
'body'
=>
$this
->
template_
attributes
[
'body'
]
??
'#ffffff'
,
]
]
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment