| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPSpeedo_Team; |
| 4 |
|
| 5 |
if ( ! defined('ABSPATH') ) exit; |
| 6 |
|
| 7 |
class Shortcode { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_shortcode( 'wpspeedo-team', [ $this, 'shortcode'] ); |
| 11 |
} |
| 12 |
|
| 13 |
public function load_settings( $sc_id ) { |
| 14 |
$settings = plugin()->api->fetch_shortcode( $sc_id ); |
| 15 |
if ( empty($settings) ) return []; |
| 16 |
return $settings['settings']; |
| 17 |
} |
| 18 |
|
| 19 |
public function shortcode( $args ) { |
| 20 |
|
| 21 |
if ( empty($args['id']) ) return sprintf( '<h3>%s</h3>', esc_html__( 'Please provide a valid Team Shortcode ID.', 'wps-team' ) ); |
| 22 |
|
| 23 |
global $wps_team_id; |
| 24 |
|
| 25 |
$wps_team_id = $args['id']; |
| 26 |
|
| 27 |
$settings = (array) $this->load_settings( $args['id'] ); |
| 28 |
|
| 29 |
if ( empty( $settings ) ) { |
| 30 |
return sprintf( '<h3>%s</h3>', sprintf( |
| 31 |
/* translators: %s: shortcode ID */ |
| 32 |
__( 'Team Shortcode <strong>%s</strong> not found', 'wps-team' ), |
| 33 |
esc_html( $args['id'] ) |
| 34 |
)); |
| 35 |
} |
| 36 |
|
| 37 |
ob_start(); |
| 38 |
|
| 39 |
global $shortcode_loader; |
| 40 |
|
| 41 |
global $wps_team_is_builder; |
| 42 |
|
| 43 |
$mode = 'public'; |
| 44 |
|
| 45 |
if ( $wps_team_is_builder ) { |
| 46 |
$mode = 'builder'; |
| 47 |
} |
| 48 |
|
| 49 |
$shortcode_loader = new Shortcode_Loader([ |
| 50 |
'id' => $args['id'], |
| 51 |
'settings' => $settings, |
| 52 |
'mode' => $mode |
| 53 |
]); |
| 54 |
|
| 55 |
$shortcode_loader->load_template(); |
| 56 |
|
| 57 |
unset( $wps_team_id ); |
| 58 |
|
| 59 |
return ob_get_clean(); |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
} |