-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Added dashboard widget with acorn mail configuration
- Loading branch information
1 parent
797ba56
commit effc4ca
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{!! $message !!} | ||
|
||
@if ($config && $config->isNotEmpty()) | ||
<table class="widefat striped"> | ||
<tbody> | ||
@foreach ($config as $key => $value) | ||
<tr> | ||
<th><strong>{{ $key }}</strong></th> | ||
<td>{{ $value }}</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Roots\AcornMail; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Str; | ||
use Roots\Acorn\Application; | ||
|
||
class Widget | ||
{ | ||
/** | ||
* The mail configuration. | ||
*/ | ||
protected Collection $config; | ||
|
||
/** | ||
* The AcornMail instance. | ||
*/ | ||
private AcornMail $acornMail; | ||
|
||
/** | ||
* Instantiate the Acorn Mail Widget. | ||
*/ | ||
public function __construct(private Application $app) | ||
{ | ||
$this->acornMail = $this->app->make(AcornMail::class); | ||
$this->config = Collection::make($this->app->config->get('mail.mailers.smtp')) | ||
->merge($this->app->config->get('mail.from')); | ||
|
||
add_action('wp_dashboard_setup', [$this, 'add']); | ||
} | ||
|
||
/** | ||
* Make a new instance of Acorn Mail Widget. | ||
*/ | ||
public static function make(Application $app): self | ||
{ | ||
return new static($app); | ||
} | ||
|
||
/** | ||
* Add the Acorn Mail widget to the WordPress dashboard. | ||
*/ | ||
public function add() | ||
{ | ||
wp_add_dashboard_widget('acorn_mail_widget', 'Acorn Mail', [$this, 'content']); | ||
} | ||
|
||
/** | ||
* Render the Acorn Mail widget content. | ||
*/ | ||
public function content() | ||
{ | ||
if (! $this->acornMail->configured()) { | ||
|
||
echo view('AcornMail::widget', [ | ||
'message' => wpautop('Acorn mail is <strong>not</strong> configured and is mimicking out-of-the-box WordPress email delivery.'), | ||
'config' => null, | ||
]); | ||
|
||
return; | ||
} | ||
|
||
$config = collect($this->config) | ||
->map(fn ($value, $key) => $key === 'password' ? Str::mask($value, '*', 0) : $value) | ||
->mapWithKeys(fn ($value, $key) => [Str::title($key) => $value]) | ||
->filter(); | ||
|
||
echo view('AcornMail::widget', [ | ||
'message' => wpautop('Acorn mail is configured and will use SMTP for email delivery.'), | ||
'config' => $config, | ||
]); | ||
} | ||
} |