Repository URL to install this package:
|
Version:
4.1.3 ▾
|
<?php
/**
* Emails: Settings
*
* @package SimplePay\Pro\Emails
* @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\Settings;
use SimplePay\Core\Utils;
use SimplePay\Core\Settings;
use SimplePay\Core\i18n;
use function SimplePay\Pro\Emails\get_webhook_requirement_note;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers settings section.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Section_Collection $sections Section collection.
*/
function register_sections( $sections ) {
$sections->add(
new Settings\Section(
array(
'id' => 'emails',
'label' => esc_html_x(
'Emails',
'settings subsection label',
'simple-pay'
),
'priority' => 60,
)
)
);
}
add_action( 'simpay_register_settings_sections', __NAMESPACE__ . '\\register_sections' );
/**
* Registers settings subsections.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Subsections_Collection $subsections Subsections collection.
*/
function register_subsections( $subsections ) {
// General.
$subsections->add(
new Settings\Subsection(
array(
'id' => 'general',
'section' => 'emails',
'label' => esc_html_x(
'General',
'settings subsection label',
'simple-pay'
),
'priority' => 10,
)
)
);
// Active emails.
$emails = Utils\get_collection( 'emails' );
if ( false === $emails ) {
return;
}
$priority = 20;
/* @var $emails \SimplePay\Pro\Emails\Email[] */
foreach ( $emails->get_items() as $email ) {
if ( false === $email->is_active() ) {
continue;
}
$subsections->add(
new Settings\Subsection(
array(
'id' => $email->id,
'section' => 'emails',
'label' => $email->label,
'priority' => $priority,
)
)
);
$priority = $priority + 10;
}
}
add_action( 'simpay_register_settings_subsections', __NAMESPACE__ . '\\register_subsections' );
/**
* Registers email settings.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Setting_Collection $settings Settings collection.
*/
function register_settings( $settings ) {
register_general_settings( $settings );
register_email_settings( $settings );
}
add_action( 'simpay_register_settings', __NAMESPACE__ . '\\register_settings' );
/**
* Registers the general settings for emails.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Setting_Collection $settings Settings collection.
*/
function register_general_settings( $settings ) {
// Setup.
$settings->add(
new Settings\Setting(
array(
'id' => 'email_setup',
'section' => 'emails',
'subsection' => 'general',
'label' => esc_html_x(
'Setup',
'setting label',
'simple-pay'
),
'output' => function() {
echo wpautop(
wp_kses(
sprintf(
/* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */
__( 'Have questions about managing emails? %1$sView the email documentation%2$s', 'simple-pay' ),
'<a href="' . simpay_docs_link( '', 'emails', 'global-settings', true ) . '" target="_blank" rel="noopener noreferrer" class="simpay-external-link">',
Utils\get_external_link_markup() . '</a>'
),
array(
'a' => array(
'href' => true,
'class' => true,
'target' => true,
'rel' => true,
),
'span' => array(
'class' => 'screen-reader-text',
),
)
)
);
echo get_webhook_requirement_note(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
},
'priority' => 10,
)
)
);
// From name.
$settings->add(
new Settings\Setting_Input(
array(
'id' => 'email_from_name',
'section' => 'emails',
'subsection' => 'general',
'label' => esc_html_x(
'From Name',
'setting label',
'simple-pay'
),
'value' => simpay_get_setting(
'email_from_name',
get_site_option( 'blogname' )
),
'description' => wpautop(
esc_html__(
'The name that emails come from. This is usually your site name.',
'simple-pay'
)
),
'classes' => array(
'regular-text',
),
'priority' => 20,
)
)
);
// From email.
$settings->add(
new Settings\Setting_Input(
array(
'id' => 'email_from_address',
'section' => 'emails',
'subsection' => 'general',
'label' => esc_html_x(
'From Address',
'setting label',
'simple-pay'
),
'value' => simpay_get_setting(
'email_from_address',
get_site_option( 'admin_email' )
),
'description' => wpautop(
esc_html__(
'The email address to send emails from. This will act as the "from" and "reply-to" address.',
'simple-pay'
)
),
'classes' => array(
'regular-text',
),
'priority' => 30,
)
)
);
}
/**
* Registers the settings for active emails.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Setting_Collection $settings Settings collection.
*/
function register_email_settings( $settings ) {
$emails = Utils\get_collection( 'emails' );
if ( false === $emails ) {
return;
}
/* @var $emails \SimplePay\Pro\Emails\Email[] */
foreach ( $emails->get_items() as $email ) {
if ( false === $email->is_active() ) {
continue;
}
$email->register_settings( $settings );
}
}
/**
* Sanitizes Email settings.
*
* @since 4.0.0
*
* @param array $settings Settings to save.
* @return array $settings Setttings to save.
*/
function sanitize_settings( $settings ) {
// Ensure a valid "From Address".
if ( isset( $settings['email_from_address'] ) ) {
if ( ! is_email( $settings['email_from_address'] ) ) {
$settings['email_from_address'] = get_bloginfo( 'admin_email' );
}
} else {
$settings['email_from_address'] = get_bloginfo( 'admin_email' );
}
return $settings;
}
add_filter( 'simpay_update_settings', __NAMESPACE__ . '\\sanitize_settings' );