';
}
public function get_expired_actions_json( $settings ) {
$actions = [];
$allowed_html = [
'a' => [
'href' => [],
'title' => [],
'target' => [],
],
'h1' => [],
'h2' => [],
'h3' => [],
'h4' => [],
'h5' => [],
'h6' => [],
'b' => [],
'strong' => [],
'i' => [],
'em' => [],
'p' => [],
'br' => [],
'ul' => [],
'ol' => [],
'li' => [],
'span' => [],
'div' => [
'class' => [],
],
'img' => [
'src' => [],
'alt' => [],
'width' => [],
'height' => [],
],
// Add more allowed tags and attributes as needed
];
if ( ! empty( $settings['timer_actions'] ) ) {
foreach( $settings['timer_actions'] as $key => $value ) {
switch ( $value ) {
case 'hide-timer':
$actions['hide-timer'] = '';
break;
case 'hide-element':
$actions['hide-element'] = $settings['hide_element_selector'];
break;
case 'message':
// $actions['message'] = $this->sanitize_no_js(wp_kses($settings['display_message_text'], $allowed_html));
$actions['message'] = wp_kses_post($settings['display_message_text'], $allowed_html);
break;
case 'redirect':
$actions['redirect'] = esc_url($settings['redirect_url']) ? esc_url($settings['redirect_url']) : '#';
break;
case 'load-template':
$actions['load-template'] = $settings['load_template'];
break;
}
}
}
return json_encode( $actions );
}
public function render_countdown_item( $settings, $item ) {
$html = '';
$html .= '';
if ( 'yes' === $settings['show_labels'] ) {
if ( 'seconds' !== $item ) {
$labels = [
'singular' => $settings['labels_'. $item .'_singular'],
'plural' => $settings['labels_'. $item .'_plural']
];
$html .= ''. esc_html($settings['labels_'. $item .'_plural']) .'';
} else {
$html .= ''. esc_html($settings['labels_'. $item .'_plural']) .'';
}
}
$html .= '
';
if ( $settings['show_separator'] ) {
$html .= '';
}
echo ''. $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
public function render_countdown_items( $settings ) {
// Days
if ( $settings['show_days'] ) {
$this->render_countdown_item( $settings, 'days' );
}
// Hours
if ( $settings['show_hours'] ) {
$this->render_countdown_item( $settings, 'hours' );
}
// Minutes
if ( $settings['show_minutes'] ) {
$this->render_countdown_item( $settings, 'minutes' );
}
// Seconds
if ( $settings['show_seconds'] ) {
$this->render_countdown_item( $settings, 'seconds' );
}
}
public function load_elementor_template( $settings ) {
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
return;
}
if ( ! empty( $settings['timer_actions'] ) && ! in_array( 'redirect', $settings['timer_actions'] ) ) {
if ( in_array( 'load-template', $settings['timer_actions'] ) ) {
// Load Elementor Template
echo \Elementor\Plugin::instance()->frontend->get_builder_content( $settings['load_template'], false ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
function format_date_to_standard($date_string) {
// Check if the date string is already in the desired format
$desired_format = 'Y-m-d H:i';
$date_in_desired_format = \DateTime::createFromFormat($desired_format, $date_string);
if ($date_in_desired_format && $date_in_desired_format->format($desired_format) === $date_string) {
return $date_string;
}
// Define the format that matches the input date string
$format = 'd/m/Y h:i a';
// Create a DateTime object from the input date string using the specified format
$date = \DateTime::createFromFormat($format, $date_string);
// Check if the date was created successfully
if ($date) {
// Format the date to 'Y-m-d H:i'
return $date->format('Y-m-d H:i');
} else {
// Handle the case where the date string is invalid
return 'Invalid date';
}
}
protected function render() {
// Get Settings
$settings = $this->get_settings_for_display();
// Render
echo 'get_countdown_attributes( $settings ) .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$this->render_countdown_items( $settings );
echo '
';
// Load Template
$this->load_elementor_template( $settings );
}
}