start_controls_section(
'content_section',
array(
'label' => __( 'Content', 'post-carousel' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
)
);
$this->add_control(
'sp_smart_post_show_pro_template',
array(
'label' => __( 'Smart Post Templates', 'post-carousel' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'label_block' => true,
'default' => '0',
'options' => Helper::get_save_template_list(),
)
);
$this->end_controls_section();
}
/**
* Render the template content by querying the sp_post_template post
* and applying the_content filter so Gutenberg blocks render properly.
*
* @since 2.4.1
* @param int $template_id Template post ID.
* @return void
*/
protected function render_template_content( $template_id ) {
$args = array(
'p' => $template_id,
'post_type' => 'sp_post_template',
'post_status' => 'publish',
'posts_per_page' => 1,
);
$the_query = new \WP_Query( $args );
$dynamic_css = get_post_meta( $template_id, '_sp_smart_css', true ); // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_post_meta_param2
if ( $the_query->have_posts() ) {
echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo apply_filters( 'the_content', get_the_content() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo '
';
wp_reset_postdata();
} else {
echo ''
. esc_html__( 'Template not found.', 'post-carousel' )
. '
';
}
}
/**
* Render smart post show pro shortcode widget output on the frontend.
*
* @since 2.4.1
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
$sp_pcp_template = $settings['sp_smart_post_show_pro_template'] ?? '';
$template_id = (int) $sp_pcp_template;
if ( empty( $template_id ) ) {
echo '
Please select a Smart Post Saved Templates
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
if ( $template_id ) {
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
$upload_dir = wp_upload_dir();
$css_file = $upload_dir['basedir'] . '/smart-post-show/static/sp-post-' . $template_id . '.css';
$css_url = $upload_dir['baseurl'] . '/smart-post-show/static/sp-post-' . $template_id . '.css';
if ( file_exists( $css_file ) ) {
echo ''; // phpcs:ignore
}
$dynamic_css = get_post_meta( $template_id, '_sp_smart_css', true ); // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_post_meta_param2
echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo do_shortcode( '[smart_post id="' . $template_id . '"]' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
';
echo do_shortcode( '[smart_post id="' . $template_id . '"]' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '';
}
}
}
}