PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / addons / elementor / Elementor_Widget.php

Elementor_Widget.php in Post Grid Gutenberg Blocks – PostX 2.7.8, at addons/elementor/Elementor_Widget.php

109 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 class Gutenberg_Post_Blocks_Widget extends \Elementor\Widget_Base {
5
6 public function get_name() {
7 return 'gutenberg-post-blocks';
8 }
9
10 public function get_title() {
11 return __( 'PostX Template', 'ultimate-post' );
12 }
13
14 public function get_icon() {
15 return 'eicon-posts-grid';
16 }
17
18 public function get_categories() {
19 return [ 'general' ];
20 }
21
22 protected function _all_posts() {
23 $args = array(
24 'post_type' => 'ultp_templates',
25 'post_status' => 'publish',
26 'posts_per_page' => -1
27 );
28 $loop = new WP_Query( $args );
29 while ( $loop->have_posts() ) : $loop->the_post();
30 $data[get_the_ID()] = get_the_title();
31 endwhile;
32 wp_reset_postdata();
33 return $data;
34 }
35
36 protected function _register_controls() {
37 $this->start_controls_section(
38 'content_section',
39 [
40 'label' => __( 'Settings', 'ultimate-post' ),
41 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
42 ]
43 );
44 $this->add_control(
45 'saved_template',
46 [
47 'label' => __( 'Saved Template', 'plugin-domain' ),
48 'type' => \Elementor\Controls_Manager::SELECT,
49 'options' => $this->_all_posts(),
50 ]
51 );
52 $this->add_control(
53 'important_note',
54 [
55 'type' => \Elementor\Controls_Manager::RAW_HTML,
56 'raw' => '<a href="'.admin_url('edit.php?post_type=ultp_templates').'" class="ultp-elementor-settings" target="_blank">Edit Template with Gutenberg</a>',
57 ]
58 );
59 $this->end_controls_section();
60 }
61
62
63 protected function render() {
64 $settings = $this->get_settings_for_display();
65 $id = $settings['saved_template'];
66
67 if ($id) {
68 $this->set_inline_css($id);
69 echo '<div class="ultp-shortcode" data-postid="'.esc_attr($id).'">';
70 $args = array( 'p' => $id, 'post_type' => 'ultp_templates');
71 $the_query = new \WP_Query($args);
72 if ($the_query->have_posts()) {
73 while ($the_query->have_posts()) {
74 $the_query->the_post();
75 the_content();
76 }
77 wp_reset_postdata();
78 }
79 echo '</div>';
80 }else{
81 echo '<p>'.esc_html__('Please Select Your Saved Template.', 'ultimate-post').'</p>';
82 }
83 }
84
85 public function set_inline_css($id) {
86 if (isset($_GET['action']) || isset($_POST['action'])) {
87 $upload_dir_url = wp_get_upload_dir();
88 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
89 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$id}.css";
90 if (file_exists( $css_dir_path ) ) {
91 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
92 if (is_ssl()) {
93 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
94 }
95 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
96 echo ultimate_post()->set_inline(file_get_contents($css_url));
97 } else {
98 $css = get_post_meta($id, '_ultp_css', true);
99 if( $css ) {
100 echo ultimate_post()->set_inline(file_get_contents($css));
101 }
102 }
103 }else{
104 ultimate_post()->set_css_style($id);
105 }
106 }
107
108
109 }