/**
* Astra Theme Customizer Configuration Builder.
*
* @package astra-builder
* @author Astra
* @copyright Copyright (c) 2020, Astra
* @link https://wpastra.com/
* @since 3.0.0
*/
// No direct access, please.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Register Builder Customizer Configurations.
*
* @since 3.0.0
*/
class Astra_Button_Component_Configs {
/**
* Register Builder Customizer Configurations.
*
* @param array $configurations Configurations.
* @param string $builder_type Builder Type.
* @param string $section Section.
*
* @since 3.0.0
* @return array $configurations Astra Customizer Configurations with updated configurations.
*/
public static function register_configuration( $configurations, $builder_type = 'header', $section = 'section-hb-button-' ) {
if ( 'footer' === $builder_type ) {
$class_obj = Astra_Builder_Footer::get_instance();
$number_of_button = Astra_Builder_Helper::$num_of_footer_button;
$component_limit = defined( 'ASTRA_EXT_VER' ) ? Astra_Builder_Helper::$component_limit : Astra_Builder_Helper::$num_of_footer_button;
} else {
$class_obj = Astra_Builder_Header::get_instance();
$number_of_button = Astra_Builder_Helper::$num_of_header_button;
$component_limit = defined( 'ASTRA_EXT_VER' ) ? Astra_Builder_Helper::$component_limit : Astra_Builder_Helper::$num_of_header_button;
}
$button_config = array();
for ( $index = 1; $index <= $component_limit; $index++ ) {
$_section = $section . $index;
$_prefix = 'button' . $index;
/**
* These options are related to Header Section - Button.
* Prefix hs represents - Header Section.
*/
$button_config[] = array(
/*
* Header Builder section - Button Component Configs.
*/
array(
'name' => $_section,
'type' => 'section',
'priority' => 50,
/* translators: %s Index */
'title' => ( 1 === $number_of_button ) ? __( 'Button', 'astra' ) : sprintf( __( 'Button %s', 'astra' ), $index ),
'panel' => 'panel-' . $builder_type . '-builder-group',
'clone_index' => $index,
'clone_type' => $builder_type . '-button',
),
/**
* Option: Header Builder Tabs
*/
array(
'name' => $_section . '-ast-context-tabs',
'section' => $_section,
'type' => 'control',
'control' => 'ast-builder-header-control',
'priority' => 0,
'description' => '',
),
/**
* Option: Button Text
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-text' ),
'type' => 'control',
'control' => 'text',
'section' => $_section,
'priority' => 20,
'title' => __( 'Text', 'astra' ),
'transport' => 'postMessage',
'partial' => array(
'selector' => '.ast-' . $builder_type . '-button-' . $index,
'container_inclusive' => false,
'render_callback' => array( $class_obj, 'button_' . $index ),
'fallback_refresh' => false,
),
'context' => Astra_Builder_Helper::$general_tab,
),
/**
* Option: Button Link
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-link-option]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-link-option' ),
'type' => 'control',
'control' => 'ast-link',
'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_link' ),
'section' => $_section,
'priority' => 30,
'title' => __( 'Link', 'astra' ),
'transport' => 'postMessage',
'partial' => array(
'selector' => '.ast-' . $builder_type . '-button-' . $index,
'container_inclusive' => false,
'render_callback' => array( $class_obj, 'button_' . $index ),
),
'context' => Astra_Builder_Helper::$general_tab,
'divider' => array( 'ast_class' => 'ast-top-section-divider' ),
),
/**
* Group: Primary Header Button Colors Group
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-color-group]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-color-group' ),
'type' => 'control',
'control' => 'ast-color-group',
'title' => __( 'Text Color', 'astra' ),
'section' => $_section,
'transport' => 'postMessage',
'priority' => 70,
'context' => Astra_Builder_Helper::$design_tab,
'responsive' => true,
'divider' => array( 'ast_class' => 'ast-section-spacing' ),
),
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-background-color-group]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-color-group' ),
'type' => 'control',
'control' => 'ast-color-group',
'title' => __( 'Background Color', 'astra' ),
'section' => $_section,
'transport' => 'postMessage',
'priority' => 70,
'context' => Astra_Builder_Helper::$design_tab,
'responsive' => true,
),
/**
* Option: Button Text Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-text-color',
'transport' => 'postMessage',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-text-color' ),
'type' => 'sub-control',
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-color-group]',
'section' => $_section,
'tab' => __( 'Normal', 'astra' ),
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 9,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Normal', 'astra' ),
),
/**
* Option: Button Text Hover Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-text-h-color',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-text-h-color' ),
'transport' => 'postMessage',
'type' => 'sub-control',
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-color-group]',
'section' => $_section,
'tab' => __( 'Hover', 'astra' ),
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 9,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Hover', 'astra' ),
),
/**
* Option: Button Background Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-back-color',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-back-color' ),
'transport' => 'postMessage',
'type' => 'sub-control',
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-background-color-group]',
'section' => $_section,
'tab' => __( 'Normal', 'astra' ),
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 10,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Normal', 'astra' ),
),
/**
* Option: Button Button Hover Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-back-h-color',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-back-h-color' ),
'transport' => 'postMessage',
'type' => 'sub-control',
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-background-color-group]',
'section' => $_section,
'tab' => __( 'Hover', 'astra' ),
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 10,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Hover', 'astra' ),
),
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-builder-button-border-colors-group]',
'type' => 'control',
'control' => 'ast-color-group',
'title' => __( 'Border Color', 'astra' ),
'section' => $_section,
'priority' => 70,
'transport' => 'postMessage',
'context' => Astra_Builder_Helper::$design_tab,
'responsive' => true,
'divider' => array( 'ast_class' => 'ast-bottom-divider' ),
),
/**
* Option: Button Border Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-border-color',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-border-color' ),
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-builder-button-border-colors-group]',
'transport' => 'postMessage',
'type' => 'sub-control',
'section' => $_section,
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 70,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Normal', 'astra' ),
),
/**
* Option: Button Border Hover Color
*/
array(
'name' => $builder_type . '-' . $_prefix . '-border-h-color',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-border-h-color' ),
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-builder-button-border-colors-group]',
'transport' => 'postMessage',
'type' => 'sub-control',
'section' => $_section,
'control' => 'ast-responsive-color',
'responsive' => true,
'rgba' => true,
'priority' => 70,
'context' => Astra_Builder_Helper::$design_tab,
'title' => __( 'Hover', 'astra' ),
),
/**
* Option: Button Border Size
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-border-size]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-border-size' ),
'type' => 'control',
'section' => $_section,
'control' => 'ast-border',
'transport' => 'postMessage',
'linked_choices' => true,
'priority' => 99,
'title' => __( 'Border Width', 'astra' ),
'context' => Astra_Builder_Helper::$design_tab,
'choices' => array(
'top' => __( 'Top', 'astra' ),
'right' => __( 'Right', 'astra' ),
'bottom' => __( 'Bottom', 'astra' ),
'left' => __( 'Left', 'astra' ),
),
'divider' => array( 'ast_class' => 'ast-top-section-divider' ),
),
/**
* Option: Button Radius Fields
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-border-radius-fields]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-border-radius-fields' ),
'type' => 'control',
'control' => 'ast-responsive-spacing',
'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_responsive_spacing' ),
'section' => $_section,
'title' => __( 'Border Radius', 'astra' ),
'linked_choices' => true,
'transport' => 'postMessage',
'unit_choices' => array( 'px', 'em', '%' ),
'choices' => array(
'top' => __( 'Top', 'astra' ),
'right' => __( 'Right', 'astra' ),
'bottom' => __( 'Bottom', 'astra' ),
'left' => __( 'Left', 'astra' ),
),
'priority' => 99,
'context' => Astra_Builder_Helper::$design_tab,
'connected' => false,
'divider' => array( 'ast_class' => 'ast-top-section-divider' ),
),
/**
* Option: Primary Header Button Typography
*/
array(
'name' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-typography]',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-text-typography' ),
'type' => 'control',
'control' => 'ast-settings-group',
'title' => __( 'Font', 'astra' ),
'section' => $_section,
'transport' => 'postMessage',
'context' => Astra_Builder_Helper::$design_tab,
'priority' => 90,
),
/**
* Option: Primary Header Button Font Family
*/
array(
'name' => $builder_type . '-' . $_prefix . '-font-family',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-font-family' ),
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-typography]',
'type' => 'sub-control',
'section' => $_section,
'control' => 'ast-font',
'font_type' => 'ast-font-family',
'title' => __( 'Font Family', 'astra' ),
'context' => Astra_Builder_Helper::$general_tab,
'connect' => $builder_type . '-' . $_prefix . '-font-weight',
'priority' => 1,
'divider' => array( 'ast_class' => 'ast-sub-bottom-dotted-divider' ),
),
/**
* Option: Primary Footer Button Font Weight
*/
array(
'name' => $builder_type . '-' . $_prefix . '-font-weight',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-font-weight' ),
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-typography]',
'type' => 'sub-control',
'section' => $_section,
'control' => 'ast-font',
'font_type' => 'ast-font-weight',
'title' => __( 'Font Weight', 'astra' ),
'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_font_weight' ),
'connect' => $builder_type . '-' . $_prefix . '-font-family',
'priority' => 2,
'context' => Astra_Builder_Helper::$general_tab,
'divider' => array( 'ast_class' => 'ast-sub-bottom-dotted-divider' ),
),
/**
* Option: Primary Header Button Font Size
*/
array(
'name' => $builder_type . '-' . $_prefix . '-font-size',
'default' => astra_get_option( $builder_type . '-' . $_prefix . '-font-size' ),
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-typography]',
'transport' => 'postMessage',
'title' => __( 'Font Size', 'astra' ),
'type' => 'sub-control',
'section' => $_section,
'control' => 'ast-responsive-slider',
'priority' => 3,
'context' => Astra_Builder_Helper::$general_tab,
'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_responsive_slider' ),
'suffix' => array( 'px', 'em', 'vw', 'rem' ),
'input_attrs' => array(
'px' => array(
'min' => 0,
'step' => 1,
'max' => 200,
),
'em' => array(
'min' => 0,
'step' => 0.01,
'max' => 20,
),
'vw' => array(
'min' => 0,
'step' => 0.1,
'max' => 25,
),
'rem' => array(
'min' => 0,
'step' => 0.1,
'max' => 20,
),
),
),
/**
* Option: Primary Footer Button Font Extras
*/
array(
'name' => $builder_type . '-' . $_prefix . '-font-extras',
'parent' => ASTRA_THEME_SETTINGS . '[' . $builder_type . '-' . $_prefix . '-text-typography]',
'section' => $_section,
'type' => 'sub-control',
'control' => 'ast-font-extras',
'priority' => 5,
'default' => astra_get_option( 'breadcrumb-font-extras' ),
'context' => Astra_Builder_Helper::$general_tab,
'title' => __( 'Font Extras', 'astra' ),
),
);
if ( 'footer' === $builder_type ) {
$button_config[] = array(
array(
'name' => ASTRA_THEME_SETTINGS . '[footer-button-' . $index . '-alignment]',
'default' => astra_get_option( 'footer-button-' . $index . '-alignment' ),
'type' => 'control',
'control' => 'ast-selector',
'section' => $_section,
'priority' => 35,
'title' => __( 'Alignment', 'astra' ),
'context' => Astra_Builder_Helper::$general_tab,
'transport' => 'postMessage',
'choices' => array(
'flex-start' => 'align-left',
'center' => 'align-center',
'flex-end' => 'align-right',
),
'divider' => array( 'ast_class' => 'ast-top-section-divider' ),
),
);
}
$button_config[] = Astra_Builder_Base_Configuration::prepare_visibility_tab( $_section, $builder_type );
$button_config[] = Astra_Extended_Base_Configuration::prepare_advanced_tab( $_section );
}
$button_config = call_user_func_array( 'array_merge', $button_config + array( array() ) );
$configurations = array_merge( $configurations, $button_config );
return $configurations;
}
}
/**
* Kicking this off by creating object of this class.
*/
new Astra_Button_Component_Configs(); Writing
*
* @package WordPress
*/
/** Make sure that the WordPress bootstrap has run before continuing. */
require __DIR__ . '/wp-load.php';
/** This filter is documented in wp-admin/options.php */
if ( ! apply_filters( 'enable_post_by_email_configuration', true ) ) {
wp_die( __( 'This action has been disabled by the administrator.' ), 403 );
}
$mailserver_url = get_option( 'mailserver_url' );
if ( 'mail.example.com' === $mailserver_url || empty( $mailserver_url ) ) {
wp_die( __( 'This action has been disabled by the administrator.' ), 403 );
}
/**
* Fires to allow a plugin to do a complete takeover of Post by Email.
*
* @since 2.9.0
*/
do_action( 'wp-mail.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** Get the POP3 class with which to access the mailbox. */
require_once ABSPATH . WPINC . '/class-pop3.php';
/** Only check at this interval for new messages. */
if ( ! defined( 'WP_MAIL_INTERVAL' ) ) {
define( 'WP_MAIL_INTERVAL', 5 * MINUTE_IN_SECONDS );
}
$last_checked = get_transient( 'mailserver_last_checked' );
if ( $last_checked ) {
wp_die(
sprintf(
// translators: %s human readable rate limit.
__( 'Email checks are rate limited to once every %s.' ),
human_time_diff( time() - WP_MAIL_INTERVAL, time() )
),
__( 'Slow down, no need to check for new mails so often!' ),
429
);
}
set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL );
$time_difference = (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
$phone_delim = '::';
$pop3 = new POP3();
if ( ! $pop3->connect( get_option( 'mailserver_url' ), get_option( 'mailserver_port' ) ) || ! $pop3->user( get_option( 'mailserver_login' ) ) ) {
wp_die( esc_html( $pop3->ERROR ) );
}
$count = $pop3->pass( get_option( 'mailserver_pass' ) );
if ( false === $count ) {
wp_die( esc_html( $pop3->ERROR ) );
}
if ( 0 === $count ) {
$pop3->quit();
wp_die( __( 'There does not seem to be any new mail.' ) );
}
// Always run as an unauthenticated user.
wp_set_current_user( 0 );
for ( $i = 1; $i <= $count; $i++ ) {
$message = $pop3->get( $i );
$bodysignal = false;
$boundary = '';
$charset = '';
$content = '';
$content_type = '';
$content_transfer_encoding = '';
$post_author = 1;
$author_found = false;
$post_date = null;
$post_date_gmt = null;
foreach ( $message as $line ) {
// Body signal.
if ( strlen( $line ) < 3 ) {
$bodysignal = true;
}
if ( $bodysignal ) {
$content .= $line;
} else {
if ( preg_match( '/Content-Type: /i', $line ) ) {
$content_type = trim( $line );
$content_type = substr( $content_type, 14, strlen( $content_type ) - 14 );
$content_type = explode( ';', $content_type );
if ( ! empty( $content_type[1] ) ) {
$charset = explode( '=', $content_type[1] );
$charset = ( ! empty( $charset[1] ) ) ? trim( $charset[1] ) : '';
}
$content_type = $content_type[0];
}
if ( preg_match( '/Content-Transfer-Encoding: /i', $line ) ) {
$content_transfer_encoding = trim( $line );
$content_transfer_encoding = substr( $content_transfer_encoding, 27, strlen( $content_transfer_encoding ) - 27 );
$content_transfer_encoding = explode( ';', $content_transfer_encoding );
$content_transfer_encoding = $content_transfer_encoding[0];
}
if ( 'multipart/alternative' === $content_type && str_contains( $line, 'boundary="' ) && '' === $boundary ) {
$boundary = trim( $line );
$boundary = explode( '"', $boundary );
$boundary = $boundary[1];
}
if ( preg_match( '/Subject: /i', $line ) ) {
$subject = trim( $line );
$subject = substr( $subject, 9, strlen( $subject ) - 9 );
// Captures any text in the subject before $phone_delim as the subject.
if ( function_exists( 'iconv_mime_decode' ) ) {
$subject = iconv_mime_decode( $subject, 2, get_option( 'blog_charset' ) );
} else {
$subject = wp_iso_descrambler( $subject );
}
$subject = explode( $phone_delim, $subject );
$subject = $subject[0];
}
/*
* Set the author using the email address (From or Reply-To, the last used)
* otherwise use the site admin.
*/
if ( ! $author_found && preg_match( '/^(From|Reply-To): /', $line ) ) {
if ( preg_match( '|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches ) ) {
$author = $matches[0];
} else {
$author = trim( $line );
}
$author = sanitize_email( $author );
if ( is_email( $author ) ) {
$userdata = get_user_by( 'email', $author );
if ( ! empty( $userdata ) ) {
$post_author = $userdata->ID;
$author_found = true;
}
}
}
if ( preg_match( '/Date: /i', $line ) ) { // Of the form '20 Mar 2002 20:32:37 +0100'.
$ddate = str_replace( 'Date: ', '', trim( $line ) );
// Remove parenthesized timezone string if it exists, as this confuses strtotime().
$ddate = preg_replace( '!\s*\(.+\)\s*$!', '', $ddate );
$ddate_timestamp = strtotime( $ddate );
$post_date = gmdate( 'Y-m-d H:i:s', $ddate_timestamp + $time_difference );
$post_date_gmt = gmdate( 'Y-m-d H:i:s', $ddate_timestamp );
}
}
}
// Set $post_status based on $author_found and on author's publish_posts capability.
if ( $author_found ) {
$user = new WP_User( $post_author );
$post_status = ( $user->has_cap( 'publish_posts' ) ) ? 'publish' : 'pending';
} else {
// Author not found in DB, set status to pending. Author already set to admin.
$post_status = 'pending';
}
$subject = trim( $subject );
if ( 'multipart/alternative' === $content_type ) {
$content = explode( '--' . $boundary, $content );
$content = $content[2];
// Match case-insensitive Content-Transfer-Encoding.
if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) {
$content = explode( $delim[0], $content );
$content = $content[1];
}
$content = strip_tags( $content, '
" . __( 'Author:' ) . ' ' . esc_html( $post_author ) . ' " . __( 'Posted title:' ) . ' ' . esc_html( $post_title ) . ' ' . sprintf(
/* translators: %s: POP3 error. */
__( 'Oops: %s' ),
esc_html( $pop3->ERROR )
) . ' ' . sprintf(
/* translators: %s: The message ID. */
__( 'Mission complete. Message %s deleted.' ),
'' . $i . ''
) . '