| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Rules; |
| 4 |
|
| 5 |
use Depicter\Rules\Condition\Conditions; |
| 6 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 7 |
|
| 8 |
class ServiceProvider implements ServiceProviderInterface |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* {@inheritDoc} |
| 13 |
*/ |
| 14 |
public function register( $container ) { |
| 15 |
$app = $container[ WPEMERGE_APPLICATION_KEY ]; |
| 16 |
|
| 17 |
// register conditions manager |
| 18 |
$container[ 'depicter.displayRules.conditions' ] = function () { |
| 19 |
return new Conditions(); |
| 20 |
}; |
| 21 |
|
| 22 |
$app->alias( 'conditions', 'depicter.displayRules.conditions' ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* {@inheritDoc} |
| 27 |
*/ |
| 28 |
public function bootstrap($container) |
| 29 |
{ |
| 30 |
add_action( 'wp_head', function(){ |
| 31 |
$documentIDs = \Depicter::document()->getConditionalDocumentIDs(); |
| 32 |
|
| 33 |
foreach( $documentIDs as $documentID ) { |
| 34 |
if ( !empty( $_GET['dp-disable-popups'] ) ) { |
| 35 |
try{ |
| 36 |
$documentType = \Depicter::documentRepository()->findOne( $documentID )->getProperty('type'); |
| 37 |
if ( in_array( $documentType, ['popup', 'banner-bar'] ) ) { |
| 38 |
continue; |
| 39 |
} |
| 40 |
}catch( \Exception $e ){ |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
if ( \Depicter::document()->displayRules( $documentID )->displayConditions()->areMet() ) { |
| 45 |
\Depicter::front()->assets()->enqueueStyles(); |
| 46 |
\Depicter::front()->assets()->enqueueScripts(); |
| 47 |
|
| 48 |
\Depicter::document()->cacheCustomStyles( $documentID ); |
| 49 |
\Depicter::front()->assets()->enqueueCustomAssets( $documentID ); |
| 50 |
\Depicter::front()->assets()->enqueuePreloadTags( $documentID ); |
| 51 |
|
| 52 |
add_action( 'wp_footer', function() use ( $documentID ) { |
| 53 |
echo \Depicter::front()->render()->document( $documentID ); |
| 54 |
}); |
| 55 |
} |
| 56 |
} |
| 57 |
}); |
| 58 |
} |
| 59 |
} |
| 60 |
|