Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../src/Admin/Builder/Notifica.../Advanced
File: EmailTemplate.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Builder\Notifications\Advanced;
[2] Fix | Delete
[3] Fix | Delete
use WPForms_Builder_Panel_Settings;
[4] Fix | Delete
use WPForms\Emails\Helpers;
[5] Fix | Delete
use WPForms\Admin\Education\Helpers as EducationHelpers;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Email Template.
[9] Fix | Delete
* This class will register the Email Template field in the "Notification" → "Advanced" settings.
[10] Fix | Delete
* The Email Template field will allow users to override the default email template for a specific notification.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 1.8.5
[13] Fix | Delete
*/
[14] Fix | Delete
class EmailTemplate {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Initialize class.
[18] Fix | Delete
*
[19] Fix | Delete
* @since 1.8.5
[20] Fix | Delete
*/
[21] Fix | Delete
public function init() {
[22] Fix | Delete
[23] Fix | Delete
$this->hooks();
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Hooks.
[28] Fix | Delete
*
[29] Fix | Delete
* @since 1.8.5
[30] Fix | Delete
*/
[31] Fix | Delete
private function hooks() {
[32] Fix | Delete
[33] Fix | Delete
add_action( 'wpforms_builder_enqueues', [ $this, 'builder_assets' ] );
[34] Fix | Delete
add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'builder_footer_scripts' ] );
[35] Fix | Delete
add_filter( 'wpforms_lite_admin_education_builder_notifications_advanced_settings_content', [ $this, 'settings' ], 5, 3 );
[36] Fix | Delete
add_filter( 'wpforms_pro_admin_builder_notifications_advanced_settings_content', [ $this, 'settings' ], 5, 3 );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Enqueue assets for the builder.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 1.8.5
[43] Fix | Delete
*/
[44] Fix | Delete
public function builder_assets() {
[45] Fix | Delete
[46] Fix | Delete
$min = wpforms_get_min_suffix();
[47] Fix | Delete
[48] Fix | Delete
wp_enqueue_script(
[49] Fix | Delete
'wpforms-builder-email-template',
[50] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/admin/builder/email-template{$min}.js",
[51] Fix | Delete
[ 'jquery', 'jquery-confirm', 'wpforms-builder' ],
[52] Fix | Delete
WPFORMS_VERSION,
[53] Fix | Delete
true
[54] Fix | Delete
);
[55] Fix | Delete
[56] Fix | Delete
wp_localize_script(
[57] Fix | Delete
'wpforms-builder-email-template',
[58] Fix | Delete
'wpforms_builder_email_template',
[59] Fix | Delete
[
[60] Fix | Delete
'is_pro' => wpforms()->is_pro(),
[61] Fix | Delete
'templates' => Helpers::get_email_template_choices( false ),
[62] Fix | Delete
]
[63] Fix | Delete
);
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Output Email Template modal.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 1.8.5
[70] Fix | Delete
*/
[71] Fix | Delete
public function builder_footer_scripts() {
[72] Fix | Delete
[73] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[74] Fix | Delete
echo wpforms_render(
[75] Fix | Delete
'builder/notifications/email-template-modal',
[76] Fix | Delete
[
[77] Fix | Delete
'pro_badge' => ! wpforms()->is_pro() ? EducationHelpers::get_badge( 'Pro' ) : '',
[78] Fix | Delete
],
[79] Fix | Delete
true
[80] Fix | Delete
);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Add Email Template settings.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 1.8.5
[87] Fix | Delete
*
[88] Fix | Delete
* @param string $content Notification → Advanced content.
[89] Fix | Delete
* @param WPForms_Builder_Panel_Settings $settings Builder panel settings.
[90] Fix | Delete
* @param int $id Notification id.
[91] Fix | Delete
*
[92] Fix | Delete
* @return string
[93] Fix | Delete
*/
[94] Fix | Delete
public function settings( $content, $settings, $id ) {
[95] Fix | Delete
[96] Fix | Delete
// Retrieve email template choices and disabled choices.
[97] Fix | Delete
// A few of the email templates are only available in the Pro version and will be disabled for non-Pro users.
[98] Fix | Delete
// The disabled choices will be added to the select field with a "(Pro)" label appended to the name.
[99] Fix | Delete
list( $options, $disabled_options ) = $this->get_email_template_options();
[100] Fix | Delete
[101] Fix | Delete
// Add Email Template field.
[102] Fix | Delete
$content .= wpforms_panel_field(
[103] Fix | Delete
'select',
[104] Fix | Delete
'notifications',
[105] Fix | Delete
'template',
[106] Fix | Delete
$settings->form_data,
[107] Fix | Delete
esc_html__( 'Email Template', 'wpforms-lite' ),
[108] Fix | Delete
[
[109] Fix | Delete
'default' => '',
[110] Fix | Delete
'options' => $options,
[111] Fix | Delete
'disabled_options' => $disabled_options,
[112] Fix | Delete
'class' => 'wpforms-panel-field-email-template-wrap',
[113] Fix | Delete
'input_class' => 'wpforms-panel-field-email-template',
[114] Fix | Delete
'parent' => 'settings',
[115] Fix | Delete
'subsection' => $id,
[116] Fix | Delete
'after' => $this->get_template_modal_link_content(),
[117] Fix | Delete
'tooltip' => esc_html__( 'Override the default email template for this specific notification.', 'wpforms-lite' ),
[118] Fix | Delete
],
[119] Fix | Delete
false
[120] Fix | Delete
);
[121] Fix | Delete
[122] Fix | Delete
return $content;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Get Email template choices.
[127] Fix | Delete
*
[128] Fix | Delete
* This function will return an array of email template choices and an array of disabled choices.
[129] Fix | Delete
* The disabled choices are templates that are only available in the Pro version.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 1.8.5
[132] Fix | Delete
*
[133] Fix | Delete
* @return array
[134] Fix | Delete
*/
[135] Fix | Delete
private function get_email_template_options() {
[136] Fix | Delete
[137] Fix | Delete
// Retrieve the available email template choices.
[138] Fix | Delete
$choices = Helpers::get_email_template_choices( false );
[139] Fix | Delete
[140] Fix | Delete
// If there are no templates or the choices are not an array, return empty arrays.
[141] Fix | Delete
if ( empty( $choices ) || ! is_array( $choices ) ) {
[142] Fix | Delete
return [ [], [] ];
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
// Check if the Pro version is active.
[146] Fix | Delete
$is_pro = wpforms()->is_pro();
[147] Fix | Delete
[148] Fix | Delete
// Initialize arrays for options and disabled options.
[149] Fix | Delete
$options = [];
[150] Fix | Delete
$disabled_options = [];
[151] Fix | Delete
[152] Fix | Delete
// Iterate through the templates and build the $options array.
[153] Fix | Delete
foreach ( $choices as $key => $choice ) {
[154] Fix | Delete
$value = esc_attr( $key );
[155] Fix | Delete
$name = esc_html( $choice['name'] );
[156] Fix | Delete
$is_disabled = ! $is_pro && isset( $choice['is_pro'] ) && $choice['is_pro'];
[157] Fix | Delete
[158] Fix | Delete
// If the option is disabled for non-Pro users, add it to the disabled options array.
[159] Fix | Delete
if ( $is_disabled ) {
[160] Fix | Delete
$disabled_options[] = $value;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
// Build the $options array with appropriate labels.
[164] Fix | Delete
// Pro badge labels are not meant to be translated.
[165] Fix | Delete
$options[ $key ] = $is_disabled ? sprintf( '%s (Pro)', $name ) : $name;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
// Add an empty option to the beginning of the $options array.
[169] Fix | Delete
// This is a placeholder option that will be replaced with the default template name.
[170] Fix | Delete
$options = array_merge( [ '' => esc_html__( 'Default Template', 'wpforms-lite' ) ], $options );
[171] Fix | Delete
[172] Fix | Delete
// Return the options and disabled options arrays.
[173] Fix | Delete
return [ $options, $disabled_options ];
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Get Email template modal link content.
[178] Fix | Delete
*
[179] Fix | Delete
* @since 1.8.5
[180] Fix | Delete
*
[181] Fix | Delete
* @return string
[182] Fix | Delete
*/
[183] Fix | Delete
private function get_template_modal_link_content() {
[184] Fix | Delete
[185] Fix | Delete
return wpforms_render( 'builder/notifications/email-template-link' );
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function