Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
<?php
/**
 * Emails: Functions
 *
 * @package SimplePay\Core\Settings
 * @copyright Copyright (c) 2020, Sandhills Development, LLC
 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since 4.0.0
 */

namespace SimplePay\Pro\Emails;

use SimplePay\Core\Utils;
use SimplePay\Pro\Webhooks;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Retrieves a registered Email.
 *
 * @since 4.0.0
 *
 * @param string $email_id Registered email ID.
 * @return \SimplePay\Pro\Emails\Email|false
 */
function get( $email_id ) {
	$emails = Utils\get_collection( 'emails' );

	// Registered emails cannot be found, do nothing.
	if ( false === $emails ) {
		return false;
	}

	return $emails->get_item( $email_id );
}

/**
 * Returns the content type used to send HTML emails.
 *
 * @since 4.0.0
 *
 * @return string
 */
function html_content_type() {
	return 'text/html';
}

/**
 * Formats an email's message body for use in HTML.
 *
 * @since 4.0.0
 *
 * @param string $body HTML email body.
 * @return string
 */
function format_body( $body ) {
	$autop = true;

	/**
	 * Determines if an email's message body should have wpautop applied.
	 *
	 * @since 4.0.0
	 *
	 * @param bool $autop Determines if an email's message body should have
	 *                    wpautop applied.
	 */
	$autop = apply_filters( 'simpay_emails_autop', $autop );

	if ( true === $autop ) {
		$body = wpautop( $body );
	}

	return $body;
}

/**
 * Formats an email's subject based on the current Payment Mode.
 *
 * @since 4.0.0
 *
 * @param string $subject Email subject.
 * @param bool   $is_livemode If the Payment Mode is live mode or test mode.
 * @return string
 */
function format_subject_for_mode( $subject, $is_livemode ) {
	if ( true === $is_livemode ) {
		return $subject;
	}

	return sprintf(
		/* translators: %s Email subject */
		esc_html__( '[Test Mode] %s', 'simple-pay' ),
		$subject
	);
}

/**
 * Returns markup for settings note about webhooks being required to send emails.
 *
 * Only displays if:
 *
 *  - One or more emails are enabled
 *  - An event has not been recieved in 48 hours.
 *
 * @since 4.0.1
 *
 * @return string
 */
function get_webhook_requirement_note() {
	$event  = Webhooks\has_recent_event();
	$emails = Utils\get_collection( 'emails' );

	if (
		false !== $event ||
		false === $emails ||
		false === $emails->has_enabled_emails()
	) {
		return '';
	}

	$webhooks_url = simpay_docs_link(
		'',
		'webhooks',
		'global-settings',
		true
	);

	ob_start();
	?>

	<p class="description">
		<span class="dashicons dashicons-editor-help"></span>
		<strong>
		<?php esc_html_e(
			'No webhooks have been detected in two days.',
			'simple-pay'
		);
		?>
		</strong>

		<?php
		esc_html_e(
			'Webooks are required to deliver emails.',
			'simple-pay'
		);
		?>

		<a
			href="<?php echo esc_url( $webhooks_url ); ?>"
			target="_blank"
			rel="noopener noreferrer"
			class="simpay-external-link"
		>
			<?php
			esc_html_e(
				'View the webhook documentation',
				'simple-pay'
			);
			?>
			<?php echo Utils\get_external_link_markup(); ?>
		</a>
	</p>

	<?php
	return ob_get_clean();
}