| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Elementor smart post show free shortcode Widget. |
| 5 |
* |
| 6 |
* @since 2.4.1 |
| 7 |
*/ |
| 8 |
class Shortcode_Widget extends \Elementor\Widget_Base { |
| 9 |
/** |
| 10 |
* Get widget name. |
| 11 |
* |
| 12 |
* @since 2.4.1 |
| 13 |
* @access public |
| 14 |
* |
| 15 |
* @return string Widget name. |
| 16 |
*/ |
| 17 |
public function get_name() { |
| 18 |
return 'smart_post_show_free_shortcode'; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get widget title. |
| 23 |
* |
| 24 |
* @since 2.4.1 |
| 25 |
* @access public |
| 26 |
* |
| 27 |
* @return string Widget title. |
| 28 |
*/ |
| 29 |
public function get_title() { |
| 30 |
return __( 'Smart Post Show', 'post-carousel' ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get widget icon. |
| 35 |
* |
| 36 |
* @since 2.2.5 |
| 37 |
* @access public |
| 38 |
* |
| 39 |
* @return string Widget icon. |
| 40 |
*/ |
| 41 |
public function get_icon() { |
| 42 |
return 'icon-sps-icon'; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get widget categories. |
| 47 |
* |
| 48 |
* @since 2.2.5 |
| 49 |
* @access public |
| 50 |
* |
| 51 |
* @return array Widget categories. |
| 52 |
*/ |
| 53 |
public function get_categories() { |
| 54 |
return array( 'basic' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get all post list. |
| 59 |
* |
| 60 |
* @since 2.2.5 |
| 61 |
* @return array |
| 62 |
*/ |
| 63 |
public function sp_pcp_post_list() { |
| 64 |
$post_list = array(); |
| 65 |
$sp_pcp_posts = new \WP_Query( |
| 66 |
array( |
| 67 |
'post_type' => 'sp_post_carousel', |
| 68 |
'post_status' => 'publish', |
| 69 |
'posts_per_page' => 10000, |
| 70 |
) |
| 71 |
); |
| 72 |
$posts = $sp_pcp_posts->posts; |
| 73 |
foreach ( $posts as $post ) { |
| 74 |
$post_list[ $post->ID ] = $post->post_title; |
| 75 |
} |
| 76 |
krsort( $post_list ); |
| 77 |
return $post_list; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Controls register. |
| 82 |
* |
| 83 |
* @return void |
| 84 |
*/ |
| 85 |
protected function _register_controls() { |
| 86 |
$this->start_controls_section( |
| 87 |
'content_section', |
| 88 |
array( |
| 89 |
'label' => __( 'Content', 'post-carousel' ), |
| 90 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 91 |
) |
| 92 |
); |
| 93 |
|
| 94 |
$this->add_control( |
| 95 |
'sp_smart_post_show_free_shortcode', |
| 96 |
array( |
| 97 |
'label' => __( 'Smart Post Show Shortcode(s)', 'post-carousel' ), |
| 98 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 99 |
'label_block' => true, |
| 100 |
'default' => '', |
| 101 |
'options' => $this->sp_pcp_post_list(), |
| 102 |
) |
| 103 |
); |
| 104 |
|
| 105 |
$this->end_controls_section(); |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Render smart post show free shortcode widget output on the frontend. |
| 111 |
* |
| 112 |
* @since 2.4.1 |
| 113 |
* @access protected |
| 114 |
*/ |
| 115 |
protected function render() { |
| 116 |
|
| 117 |
$settings = $this->get_settings_for_display(); |
| 118 |
$sp_pcp_shortcode = $settings['sp_smart_post_show_free_shortcode']; |
| 119 |
|
| 120 |
if ( '' === $sp_pcp_shortcode ) { |
| 121 |
echo '<div style="text-align: center; margin-top: 0; padding: 10px" class="elementor-add-section-drag-title">Select a shortcode</div>'; |
| 122 |
return; |
| 123 |
} |
| 124 |
|
| 125 |
$generator_id = $sp_pcp_shortcode; |
| 126 |
|
| 127 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 128 |
$pcp_gl_id = $generator_id; // Smart Post Show global ID for Shortcode metaboxes. |
| 129 |
|
| 130 |
// Preset Layouts. |
| 131 |
$layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true ); |
| 132 |
|
| 133 |
// All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc. |
| 134 |
$view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true ); |
| 135 |
$section_title = get_the_title( $pcp_gl_id ); |
| 136 |
|
| 137 |
SP_PC_Output::pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title ); |
| 138 |
?> |
| 139 |
<script src="<?php echo esc_url( SP_PC_URL . 'public/assets/js/scripts.min.js' ); ?>" ></script> |
| 140 |
<?php |
| 141 |
} else { |
| 142 |
echo do_shortcode( '[smart_post_show id="' . $generator_id . '"]' ); |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
|