| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! class_exists( 'PostX_WPBakery_Widget' ) ) { |
| 4 |
|
| 5 |
class PostX_WPBakery_Widget { |
| 6 |
|
| 7 |
/** |
| 8 |
* Main constructor |
| 9 |
*/ |
| 10 |
public function __construct() { |
| 11 |
add_shortcode( 'postx_wpbakery_widget', __CLASS__ . '::output' ); |
| 12 |
if ( function_exists( 'vc_lean_map' ) ) { |
| 13 |
vc_lean_map( 'postx_wpbakery_widget', __CLASS__ . '::map' ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Shortcode output |
| 19 |
*/ |
| 20 |
public static function output( $atts, $content = null ) { |
| 21 |
$output = ''; |
| 22 |
$atts = vc_map_get_attributes( 'postx_wpbakery_widget', $atts ); |
| 23 |
$templates = $atts['saved_template']; |
| 24 |
|
| 25 |
if ( $templates && $templates != 'empty' ) { |
| 26 |
if (isset($_GET['vc_editable'])) { // @codingStandardsIgnoreLine |
| 27 |
$output .= ultimate_post()->build_css_for_inline_print( $templates, true ); |
| 28 |
} |
| 29 |
|
| 30 |
$args = array( |
| 31 |
'p' => $templates, |
| 32 |
'post_type' => 'ultp_templates', |
| 33 |
); |
| 34 |
$the_query = new \WP_Query( $args ); |
| 35 |
|
| 36 |
if ( $the_query->have_posts() ) { |
| 37 |
while ( $the_query->have_posts() ) { |
| 38 |
$the_query->the_post(); |
| 39 |
ob_start(); |
| 40 |
the_content(); |
| 41 |
$output .= ob_get_clean(); |
| 42 |
} |
| 43 |
wp_reset_postdata(); |
| 44 |
} |
| 45 |
} elseif ( isset( $_GET['vc_editable'] ) ) { |
| 46 |
// @codingStandardsIgnoreLine |
| 47 |
$output .= '<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>'; |
| 48 |
} |
| 49 |
|
| 50 |
return $output; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static function map() { |
| 57 |
return array( |
| 58 |
'name' => esc_html__( 'PostX Template', 'ultimate-post' ), |
| 59 |
'description' => esc_html__( 'PostX Templates for WPBakery.', 'ultimate-post' ), |
| 60 |
'base' => 'postx_wpbakery_widget', |
| 61 |
'icon' => ULTP_URL . '/addons/wpbakery/wpbakery.png', |
| 62 |
'params' => array( |
| 63 |
array( |
| 64 |
'type' => 'dropdown', |
| 65 |
'heading' => esc_html__( 'Select Your Template', 'ultimate-post' ), |
| 66 |
'param_name' => 'saved_template', |
| 67 |
'value' => array_flip( ultimate_post()->get_all_lists( 'ultp_templates', 'empty' ) ), |
| 68 |
'description' => esc_html__( 'Pick a Template from your saved ones. Or create a template from: "Dashboard > PostX > Saved Templates"', 'ultimate-post' ), |
| 69 |
), |
| 70 |
), |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
new PostX_WPBakery_Widget(); |
| 78 |
|