| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcodes |
| 4 |
* |
| 5 |
* @package Yatra/Classes |
| 6 |
* @version 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Yatra Shortcodes class. |
| 13 |
*/ |
| 14 |
class Yatra_Shortcodes |
| 15 |
{ |
| 16 |
|
| 17 |
/** |
| 18 |
* Init shortcodes. |
| 19 |
*/ |
| 20 |
public static function init() |
| 21 |
{ |
| 22 |
$shortcodes = array( |
| 23 |
|
| 24 |
'yatra_checkout' => __CLASS__ . '::checkout', |
| 25 |
'yatra_cart' => __CLASS__ . '::cart', |
| 26 |
'yatra_my_account' => __CLASS__ . '::my_account', |
| 27 |
'yatra_activity' => __CLASS__ . '::activity', |
| 28 |
'yatra_destination' => __CLASS__ . '::destination', |
| 29 |
'yatra_discount_and_deals' => __CLASS__ . '::discount_deals', |
| 30 |
'yatra_tour' => __CLASS__ . '::tour', |
| 31 |
); |
| 32 |
|
| 33 |
foreach ($shortcodes as $shortcode => $function) { |
| 34 |
add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Shortcode Wrapper. |
| 42 |
* |
| 43 |
* @param string[] $function Callback function. |
| 44 |
* @param array $atts Attributes. Default to empty array. |
| 45 |
* @param array $wrapper Customer wrapper data. |
| 46 |
* |
| 47 |
* @return string |
| 48 |
*/ |
| 49 |
public static function shortcode_wrapper( |
| 50 |
$function, |
| 51 |
$atts = array(), |
| 52 |
$wrapper = array( |
| 53 |
'class' => 'yatra-shortcode-wrapper', |
| 54 |
'before' => null, |
| 55 |
'after' => null, |
| 56 |
) |
| 57 |
) |
| 58 |
{ |
| 59 |
ob_start(); |
| 60 |
|
| 61 |
// @codingStandardsIgnoreStart |
| 62 |
echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before']; |
| 63 |
call_user_func($function, $atts); |
| 64 |
echo empty($wrapper['after']) ? '</div>' : $wrapper['after']; |
| 65 |
// @codingStandardsIgnoreEnd |
| 66 |
|
| 67 |
return ob_get_clean(); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Checkout page shortcode. |
| 72 |
* |
| 73 |
* @param array $atts Attributes. |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public static function checkout($atts) |
| 77 |
{ |
| 78 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Checkout', 'output'), $atts); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* Cart page shortcode. |
| 84 |
* |
| 85 |
* @param array $atts Attributes. |
| 86 |
* @return string |
| 87 |
*/ |
| 88 |
public static function cart($atts) |
| 89 |
{ |
| 90 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Cart', 'output'), $atts); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
* my account page shortcode. |
| 96 |
* |
| 97 |
* @param array $atts Attributes. |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public static function my_account($atts) |
| 101 |
{ |
| 102 |
return self::shortcode_wrapper(array('Yatra_Shortcode_My_Account', 'output'), $atts); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* activity listing page shortcode. |
| 107 |
* |
| 108 |
* @param array $atts Attributes. |
| 109 |
* @return string |
| 110 |
*/ |
| 111 |
public static function activity($atts) |
| 112 |
{ |
| 113 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Activity', 'output'), $atts); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* destination listing page shortcode. |
| 118 |
* |
| 119 |
* @param array $atts Attributes. |
| 120 |
* @return string |
| 121 |
*/ |
| 122 |
public static function destination($atts) |
| 123 |
{ |
| 124 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Destination', 'output'), $atts); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
/** |
| 129 |
* discount_deals page shortcode. |
| 130 |
* |
| 131 |
* @param array $atts Attributes. |
| 132 |
* @return string |
| 133 |
*/ |
| 134 |
public static function discount_deals($atts) |
| 135 |
{ |
| 136 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Discount_And_Deals', 'output'), $atts); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* tour list page shortcode. |
| 141 |
* |
| 142 |
* @param array $atts Attributes. |
| 143 |
* @return string |
| 144 |
*/ |
| 145 |
public static function tour($atts) |
| 146 |
{ |
| 147 |
return self::shortcode_wrapper(array('Yatra_Shortcode_Tour', 'output'), $atts); |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
|