| 1 |
<?php |
| 2 |
namespace Depicter\WordPress; |
| 3 |
|
| 4 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 5 |
|
| 6 |
/** |
| 7 |
* Register shortcodes. |
| 8 |
*/ |
| 9 |
class ShortcodesServiceProvider implements ServiceProviderInterface { |
| 10 |
/** |
| 11 |
* {@inheritDoc} |
| 12 |
*/ |
| 13 |
public function register( $container ) { |
| 14 |
// Nothing to register. |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* {@inheritDoc} |
| 19 |
*/ |
| 20 |
public function bootstrap( $container ) { |
| 21 |
add_shortcode('depicter' , [ $this, 'process_shortcode' ]); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Shortcode callback |
| 26 |
* |
| 27 |
* @param array $attrs |
| 28 |
* @param null $content |
| 29 |
* |
| 30 |
* @return string |
| 31 |
* @throws \Exception |
| 32 |
*/ |
| 33 |
function process_shortcode( $attrs, $content = null ) { |
| 34 |
|
| 35 |
extract( shortcode_atts([ |
| 36 |
'id' => '', |
| 37 |
'alias' => '', |
| 38 |
'slug' => '' |
| 39 |
], |
| 40 |
$attrs, |
| 41 |
'depicter' |
| 42 |
)); |
| 43 |
|
| 44 |
$documentId = $id; |
| 45 |
|
| 46 |
if ( empty( $documentId ) ) { |
| 47 |
if( empty( $slug ) && ! empty( $alias ) ){ |
| 48 |
$slug = $alias; |
| 49 |
} |
| 50 |
$documentId = $slug; |
| 51 |
} |
| 52 |
|
| 53 |
return \Depicter::front()->render()->document( $documentId, [ 'echo' => false ] ); |
| 54 |
} |
| 55 |
} |
| 56 |
|