PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.5.6
Post Grid Gutenberg Blocks – PostX v2.5.6
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.5.6, at addons/elementor/Elementor_Widget.php

112 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 ob_start();
67
68 if($id){
69 $this->set_inline_css($id);
70 echo '<div class="ultp-shortcode" data-postid="'.$id.'">';
71 $args = array( 'p' => $id, 'post_type' => 'ultp_templates');
72 $the_query = new \WP_Query($args);
73 if ($the_query->have_posts()) {
74 while ($the_query->have_posts()) {
75 $the_query->the_post();
76 the_content();
77 }
78 wp_reset_postdata();
79 }
80 echo '</div>';
81 }else{
82 echo '<p>'.__('Please Select Your Saved Template.', 'ultimate-post').'</p>';
83 }
84
85 echo ob_get_clean();
86 }
87
88 public function set_inline_css($id) {
89 if(isset($_GET['action']) || isset($_POST['action'])){
90 $upload_dir_url = wp_get_upload_dir();
91 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
92 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$id}.css";
93 if ( file_exists( $css_dir_path ) ) {
94 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
95 if (is_ssl()) {
96 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
97 }
98 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
99 echo '<style type="text/css">'.file_get_contents($css_url).'</style>';
100 } else {
101 $css = get_post_meta($id, '_ultp_css', true);
102 if( $css ) {
103 echo '<style type="text/css">'.$css.'</style>';
104 }
105 }
106 }else{
107 ultimate_post()->set_css_style($id);
108 }
109 }
110
111
112 }