| @@ -2,111 +2,82 @@ | ||
| 2 | 2 | defined( 'ABSPATH' ) || exit; |
| 3 | 3 | |
| 4 | 4 | class Gutenberg_Post_Blocks_Widget extends \Elementor\Widget_Base { |
| 5 | 5 | |
| 6 | - public function get_name() { | |
| 7 | - return 'gutenberg-post-blocks'; | |
| 8 | - } | |
| 6 | + public function get_name() { | |
| 7 | + return 'gutenberg-post-blocks'; | |
| 8 | + } | |
| 9 | 9 | |
| 10 | - public function get_title() { | |
| 11 | - return __( 'Gutenberg Post Blocks', 'ultimate-post' ); | |
| 12 | - } | |
| 10 | + public function get_title() { | |
| 11 | + return __( 'PostX Template', 'ultimate-post' ); | |
| 12 | + } | |
| 13 | 13 | |
| 14 | - public function get_icon() { | |
| 15 | - return 'fa fa-code'; | |
| 16 | - } | |
| 14 | + public function get_icon() { | |
| 15 | + return 'eicon-posts-grid'; | |
| 16 | + } | |
| 17 | 17 | |
| 18 | - public function get_categories() { | |
| 19 | - return [ 'general' ]; | |
| 20 | - } | |
| 18 | + public function get_categories() { | |
| 19 | + return array( 'general' ); | |
| 20 | + } | |
| 21 | 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( | |
| 22 | + protected function register_controls() { | |
| 23 | + $this->start_controls_section( | |
| 24 | + 'content_section', | |
| 25 | + array( | |
| 26 | + 'label' => __( 'Settings', 'ultimate-post' ), | |
| 27 | + 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, | |
| 28 | + ) | |
| 29 | + ); | |
| 30 | + $this->add_control( | |
| 45 | 31 | 'saved_template', |
| 46 | - [ | |
| 47 | - 'label' => __( 'Saved Template', 'plugin-domain' ), | |
| 48 | - 'type' => \Elementor\Controls_Manager::SELECT, | |
| 49 | - 'options' => $this->_all_posts(), | |
| 50 | - ] | |
| 32 | + array( | |
| 33 | + 'label' => __( 'Saved Template', 'ultimate-post' ), | |
| 34 | + 'type' => \Elementor\Controls_Manager::SELECT, | |
| 35 | + 'options' => ultimate_post()->get_all_lists( 'ultp_templates' ), | |
| 36 | + ) | |
| 51 | 37 | ); |
| 52 | - $this->add_control( | |
| 53 | - 'important_note', | |
| 54 | - [ | |
| 38 | + $this->add_control( | |
| 39 | + 'edit_template', | |
| 40 | + array( | |
| 55 | 41 | '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 | - ] | |
| 42 | + 'raw' => '<a href="' . admin_url( 'edit.php?post_type=ultp_templates' ) . '" style="color:#fff; background-color:#0c0d0e; padding:10px 20px; border-radius:4px; display:inline-block;" target="_blank"><span style="color:#fff; font-size:12px; width:12px; height:12px;" class="dashicons dashicons-edit"></span> ' . __( 'Edit This Template', 'ultimate-post' ) . '</a>', | |
| 43 | + ) | |
| 58 | 44 | ); |
| 59 | - $this->end_controls_section(); | |
| 60 | - } | |
| 45 | + $this->add_control( | |
| 46 | + 'add_new_template', | |
| 47 | + array( | |
| 48 | + 'type' => \Elementor\Controls_Manager::RAW_HTML, | |
| 49 | + 'raw' => '<a href="' . admin_url( 'post-new.php?post_type=ultp_templates' ) . '" style="color:#fff; background-color:#0c0d0e; padding:10px 20px; border-radius:4px; display:inline-block;" target="_blank"><span style="color:#fff; font-size:12px; width:12px; height:12px;" class="dashicons dashicons-plus-alt2"></span> ' . __( 'Add New Template', 'ultimate-post' ) . '</a>', | |
| 50 | + ) | |
| 51 | + ); | |
| 52 | + $this->end_controls_section(); | |
| 53 | + } | |
| 61 | 54 | |
| 62 | 55 | |
| 63 | - protected function render() { | |
| 64 | - $settings = $this->get_settings_for_display(); | |
| 65 | - $id = $settings['saved_template']; | |
| 66 | - ob_start(); | |
| 56 | + protected function render() { | |
| 57 | + $settings = $this->get_settings_for_display(); | |
| 58 | + $id = $settings['saved_template']; | |
| 67 | 59 | |
| 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 | -} | |
| 60 | + if ( $id ) { | |
| 61 | + if ( isset( $_GET['action'] ) || isset( $_POST['action'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended | |
| 62 | + echo ultimate_post()->build_css_for_inline_print( $id, true ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 63 | + } | |
| 64 | + echo '<div class="ultp-shortcode" data-postid="' . esc_attr( $id ) . '">'; | |
| 65 | + $args = array( | |
| 66 | + 'p' => $id, | |
| 67 | + 'post_type' => 'ultp_templates', | |
| 68 | + ); | |
| 69 | + $the_query = new \WP_Query( $args ); | |
| 70 | + if ( $the_query->have_posts() ) { | |
| 71 | + while ( $the_query->have_posts() ) { | |
| 72 | + $the_query->the_post(); | |
| 73 | + the_content(); | |
| 74 | + } | |
| 75 | + wp_reset_postdata(); | |
| 76 | + } | |
| 77 | + echo '</div>'; | |
| 78 | + } elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'elementor' ) { | |
| 79 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended | |
| 80 | + echo '<p style="text-align:center;">' . sprintf( esc_html__( 'Pick a Template from your saved ones. Or create a template from: %s.', 'ultimate-post' ) . ' ', '<strong><i>' . esc_html__( 'Dashboard > PostX > Saved Templates', 'ultimate-post' ) . '</i></strong>' ) . '</p>'; | |
| 81 | + } | |
| 82 | + } | |
| 83 | +} | |