wpr-conditions-manager.php
5 days ago
wpr-editor-hooks.php
5 days ago
wpr-render-templates.php
5 days ago
wpr-templates-actions.php
5 days ago
wpr-templates-category-filter.php
5 days ago
wpr-templates-library.php
5 days ago
wpr-templates-loop.php
5 days ago
wpr-templates-modal-popups.php
5 days ago
wpr-templates-shortcode.php
5 days ago
wpr-templates-shortcode.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WprAddons\Admin\Includes; |
| 4 | |
| 5 | use Elementor; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly. |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * WPR_Templates_Shortcode setup |
| 13 | * |
| 14 | * @since 1.0 |
| 15 | */ |
| 16 | class WPR_Templates_Shortcode { |
| 17 | |
| 18 | public function __construct() { |
| 19 | add_shortcode( 'wpr-template', [ $this, 'shortcode' ] ); |
| 20 | |
| 21 | add_action('elementor/element/after_section_start', [ $this, 'extend_shortcode' ], 10, 3 ); |
| 22 | } |
| 23 | |
| 24 | public function shortcode( $attributes = [] ) { |
| 25 | if ( empty( $attributes['id'] ) ) { |
| 26 | return ''; |
| 27 | } else { |
| 28 | $id = intval($attributes['id']); |
| 29 | } |
| 30 | |
| 31 | // Ensure only publicly published posts can be accessed |
| 32 | $post = get_post($id); |
| 33 | |
| 34 | if (!$post || $post->post_status !== 'publish' || in_array($post->post_status, ['draft', 'private', 'future'])) { |
| 35 | return 'You do not have permission to view this post.'; |
| 36 | } |
| 37 | |
| 38 | // Optionally check if the post is password protected |
| 39 | if (post_password_required($post)) { |
| 40 | return 'This post is password protected.'; |
| 41 | } |
| 42 | |
| 43 | // WPML language handling |
| 44 | if (defined('ICL_LANGUAGE_CODE')) { |
| 45 | $default_language_code = apply_filters('wpml_default_language', null); |
| 46 | |
| 47 | if ( ICL_LANGUAGE_CODE !== $default_language_code ) { |
| 48 | $id = icl_object_id($id, 'elementor_library', false, ICL_LANGUAGE_CODE); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | $edit_link = '<span class="wpr-template-edit-btn" data-permalink="'. esc_url(get_permalink($id)) .'">Edit Template</span>'; |
| 53 | |
| 54 | $type = get_post_meta(get_the_ID(), '_wpr_template_type', true) || get_post_meta($id, '_elementor_template_type', true); |
| 55 | $has_css = 'internal' === get_option( 'elementor_css_print_method' ) || '' !== $type; |
| 56 | |
| 57 | return Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $id, $has_css ) . $edit_link; |
| 58 | } |
| 59 | |
| 60 | public function extend_shortcode( $section, $section_id, $args ) { |
| 61 | if ( $section->get_name() == 'shortcode' && $section_id == 'section_shortcode' ) { |
| 62 | $section->add_control( |
| 63 | 'select_template' , |
| 64 | [ |
| 65 | 'label' => esc_html__( 'Select Template', 'wpr-addons' ), |
| 66 | 'type' => 'wpr-ajax-select2', |
| 67 | 'options' => 'ajaxselect2/get_elementor_templates', |
| 68 | 'label_block' => true, |
| 69 | ] |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |