Skip to content

Commit

Permalink
Merge pull request #82 from soup-bowl/soup-bowl/issue65
Browse files Browse the repository at this point in the history
Added CLI email viewer.
  • Loading branch information
soup-bowl committed Jan 18, 2022
2 parents ecf01a0 + 253a769 commit 643e21b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Yes! [Please see our GitHub repository here](https://github.com/soup-bowl/wp-sim

== Changelog ==
= Edge =
* Added: Read logged emails via WP-CLI.
* Added: Status message from testing emails ([#81](https://github.com/soup-bowl/wp-simple-smtp/issues/81)).
* Change: Quick config settings now contained within plugin ([#78](https://github.com/soup-bowl/wp-simple-smtp/issues/78)).
* Change: Tightened permissions to the log viewer ([#74](https://github.com/soup-bowl/wp-simple-smtp/issues/74)).
Expand Down
26 changes: 25 additions & 1 deletion src/cli/class-emaillog.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,37 @@ public function load_log( $args, $assoc_args ) {
}
}

/**
* Displays the contents of an email.
*
* <ID>
* : ID of the email you wish to load up.
*
* @when before_wp_load
*
* @param array $args Command-line arguments.
* @param array $assoc_args Associated arguments.
*/
public function view_email( $args, $assoc_args ) {
$email = $this->log_service->get_log_entry_by_id( (int) $args[0] );
if ( ! empty( $email ) ) {
WP_CLI::line( 'Recipient(s): ' . implode( ', ', $email->get_recipients() ) );
WP_CLI::line( 'Subject: ' . $email->get_subject() );
WP_CLI::line( 'Headers: ' . implode( ', ', $email->get_headers() ) );
WP_CLI::line( 'Contents:' );
WP_CLI::line( $email->get_body() );
} else {
WP_CLI::error( __( 'Email not found.', 'simple-smtp' ) );
}
}

/**
* Generates a CLI output list of entries derrived from the input.
*
* @param Log[] $entries Log entry collection.
* @return void Prints the log to the page.
*/
public function list( $entries ) {
private function list( $entries ) {
$list_format = [];
foreach ( $entries as $entry ) {
$list_format[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/log/class-logservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function delete_all_logs_to_email( $email ) {
* @return Log
*/
private function wp_to_obj( $post ) {
if ( empty( $post ) ) {
if ( empty( $post ) || $this->post_type !== $post->post_type ) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions wp-simple-smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function() {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'email-test', [ new wpsimplesmtp\cli\EmailTest(), 'test_email' ] );
WP_CLI::add_command( 'email-log', [ new wpsimplesmtp\cli\EmailLog(), 'load_log' ] );
WP_CLI::add_command( 'email-view', [ new wpsimplesmtp\cli\EmailLog(), 'view_email' ] );
}

if ( is_admin() ) {
Expand Down

0 comments on commit 643e21b

Please sign in to comment.