| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
class PostX_Bricks_Integration extends \Bricks\Element { |
| 8 |
// Element properties |
| 9 |
public $category = 'general'; |
| 10 |
public $name = 'postx-addon'; |
| 11 |
public $icon = 'ti-layout-grid2'; |
| 12 |
|
| 13 |
// Return localised element label |
| 14 |
public function get_label() { |
| 15 |
return esc_html__( 'PostX Template', 'ultimate-post' ); |
| 16 |
} |
| 17 |
|
| 18 |
// Set builder controls |
| 19 |
public function set_controls() { |
| 20 |
$this->controls['template'] = array( |
| 21 |
'type' => 'select', |
| 22 |
'label' => esc_html__( 'Select Template', 'ultimate-post' ), |
| 23 |
'options' => ultimate_post()->get_all_lists( 'ultp_templates' ), |
| 24 |
'clearable' => false, |
| 25 |
'default' => '', |
| 26 |
'pasteStyles' => true, |
| 27 |
'inline' => true, |
| 28 |
); |
| 29 |
$this->controls['separator'] = array( |
| 30 |
'type' => 'separator', |
| 31 |
); |
| 32 |
$this->controls['help'] = array( |
| 33 |
'type' => 'info', |
| 34 |
'content' => 'Pick a Template from your saved ones. Or create a template from: <strong><i>Dashboard > PostX > Saved Templates</i></strong>', |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
// Render element HTML |
| 39 |
public function render() { |
| 40 |
$id = $this->settings['template']; |
| 41 |
$root_classes[] = 'bricks-postx-wrapper'; |
| 42 |
$this->set_attribute( '_root', 'class', $root_classes ); |
| 43 |
|
| 44 |
$current_url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url( $_SERVER['REQUEST_URI'] ) : ''; //phpcs:ignore |
| 45 |
|
| 46 |
// Render element HTML |
| 47 |
echo "<div {$this->render_attributes( '_root' )}>"; //phpcs:ignore |
| 48 |
if ( $id ) { |
| 49 |
echo ultimate_post()->build_css_for_inline_print( $id, true ); |
| 50 |
echo '<div class="ultp-shortcode" data-postid="' . esc_attr( $id ) . '">'; |
| 51 |
$args = array( |
| 52 |
'p' => $id, |
| 53 |
'post_type' => 'ultp_templates', |
| 54 |
); |
| 55 |
$the_query = new \WP_Query( $args ); |
| 56 |
if ( $the_query->have_posts() ) { |
| 57 |
while ( $the_query->have_posts() ) { |
| 58 |
$the_query->the_post(); |
| 59 |
the_content(); |
| 60 |
} |
| 61 |
wp_reset_postdata(); |
| 62 |
} |
| 63 |
echo '</div>'; |
| 64 |
} elseif ( strpos( 'bricks=run', $current_url ) !== false || strpos( $current_url, 'bricks/v1/render_element' ) !== false ) { |
| 65 |
echo '<p style="text-align:center; font-size: 20px;">' . 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>'; |
| 66 |
} |
| 67 |
echo '</div>'; |
| 68 |
} |
| 69 |
} |
| 70 |
|