| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit Shortcodes class. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Registers shortcodes defined in the `convertkit_shortcodes` filter as WordPress Shortcodes. |
| 11 |
* |
| 12 |
* @package ConvertKit |
| 13 |
* @author ConvertKit |
| 14 |
*/ |
| 15 |
class ConvertKit_Shortcodes { |
| 16 |
|
| 17 |
/** |
| 18 |
* Constructor |
| 19 |
* |
| 20 |
* @since 1.9.6 |
| 21 |
*/ |
| 22 |
public function __construct() { |
| 23 |
|
| 24 |
add_action( 'init', array( $this, 'init' ), 10, 1 ); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register ConvertKit shortcodes. |
| 30 |
* |
| 31 |
* @since 1.9.6 |
| 32 |
*/ |
| 33 |
public function init() { |
| 34 |
|
| 35 |
// Get shortcodes. |
| 36 |
$shortcodes = convertkit_get_shortcodes(); |
| 37 |
|
| 38 |
// Bail if no shortcodes are available. |
| 39 |
if ( ! count( $shortcodes ) ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
// Iterate through shortcodes, registering them as shortcodes. |
| 44 |
foreach ( $shortcodes as $shortcode => $properties ) { |
| 45 |
// Register shortcode. |
| 46 |
add_shortcode( |
| 47 |
'convertkit_' . $shortcode, |
| 48 |
array( |
| 49 |
$properties['render_callback'][0], |
| 50 |
$properties['render_callback'][1], |
| 51 |
) |
| 52 |
); |
| 53 |
|
| 54 |
// For the Form shortcode, register the [convertkit] shortcode for backward compatibility. |
| 55 |
if ( $shortcode === 'form' ) { |
| 56 |
add_shortcode( |
| 57 |
'convertkit', |
| 58 |
array( |
| 59 |
$properties['render_callback'][0], |
| 60 |
$properties['render_callback'][1], |
| 61 |
) |
| 62 |
); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|