%PDF- %PDF-
Direktori : /var/www/knwn/wp-content/plugins/wpsynchro/includes/Utilities/Actions/ |
Current File : //var/www/knwn/wp-content/plugins/wpsynchro/includes/Utilities/Actions/EmailOnSyncFailure.php |
<?php namespace WPSynchro\Utilities\Actions; use WPSynchro\Utilities\Actions\Action; use WPSynchro\InstallationFactory; use WPSynchro\Job; /** * Action: Send sync error email * @since 1.6.0 */ class EmailOnSyncFailure implements Action { /** * Initialize * @since 1.6.0 */ public function init() { static $added = null; if ($added !== true) { add_action("wpsynchro_synchronization_failure", function () { (new self())->doAction(func_get_args()); }, 10, 2); } $added = true; } /** * Execute action * @since 1.6.0 */ public function doAction($params) { $installation_id = $params[0]; $job_id = $params[1]; // Get installation $inst_factory = new InstallationFactory(); $installation = $inst_factory->retrieveInstallation($installation_id); if (!$installation) { return; } // Get job $job = new Job(); $job_load_result = $job->load($installation_id, $job_id); if (!$job_load_result) { return; } // Get emails to send to, and send $emails = $installation->getFailureEmailList(); if (count($emails) > 0) { $subject = $this->getSubject($installation->site_url); $content = $this->getContent($installation->site_url); $headers = ['Content-Type: text/plain; charset=UTF-8']; foreach ($emails as $email) { wp_mail($email, $subject, $content, $headers); } } } /** * Get subject * @since 1.6.0 */ public function getSubject($to) { return sprintf(__("[Synchronization failed] - Sync to %s failed", "wpsynchro"), $to); } /** * Get email content * @since 1.6.0 */ public function getContent($to) { $current_url = get_home_url(); return sprintf( __( "Hi, \r\n We just want to notify you that a synchronization has failed. The synchronization is to %s \r\n Synchronization is running on %s \r\n This is an automated email generated by WP Synchro plugin.", "wpsynchro" ), $to, $current_url ); } }