PHP code example of brain / occipital
1. Go to this page and download the library: Download brain/occipital library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brain / occipital example snippets php
Brain\Assets::addScript( 'my-script', 'front' )
->src( "//example.com/path/to/style.js" )
->deps( [ "jquery" ] )
->provide( "bootstrap-tooltip", "lightbox", "plugin-script" )
->ver( "20141007" )
->isFooter( TRUE )
->localizeData( [ 'name' => 'MyData', 'data' => [ 'foo' => 'bar' ] ] )
->condition( function( $query, $user ) {
return $query->is_front_page() && user_can( $user, 'edit_pages' );
});
js
{
"hp": ">=5.4",
"brain/occipital": "dev-master"
}
}
php
Brain\Assets::addStyle( 'foo' );
php
cipital::boot();
add_action( 'brain_loaded', function() {
// here go all the API methods
} );
php
addStyle( $handle, $args, $where )
php
Brain\Assets::addFrontScript( 'my-script' )
->src( "//example.com/path/to/script.js" )
->deps( [ "jquery" ] )
->provide( "bootstrap-tooltip", "lightbox", "plugin-script" )
->ver( "20141007" )
->footer( TRUE )
->localizeData( [ 'name' => 'MyData', 'data' => [ 'foo' => 'bar' ] ] )
->condition( function( $query, $user ) {
return $query->is_front_page() && user_can( $user, 'edit_pages' );
});
php
$args['condition'] = function( WP_Query $query, $user ) {
return $query->is_page( 'special_page' ) && user_can( $user, 'edit_pages')
}
php
$args['condition'] = function( WP_Screen $screen, WP_User $user ) {
return $screen->base === 'post' && user_can( $user, 'edit_pages')
}
php
Brain\Assets::addFrontStyle( 'mystyle' )
->src( '//cdn.example.com/path/to/mystyle.css' )
->provide([ 'open-sans', 'theme-style', 'plugin1-style', 'plugin2-style' ]);
php
wp_enqueue_style( 'plugin3-style', $url, array( 'plugin1-style', 'thickbox') );
php
Brain\Assets::addFrontScript( 'pluginscript' )
->src( $scripturl )
->provide([ 'jquery', 'jquery-ui-core' ]);
php
Brain\Assets::addFrontStyle( 'awesome_plugin_free_style' )
->src( $style_url );
Brain\Assets::addFrontScript( 'awesome_plugin_free_script' )
->src( $script_url );
php
Brain\Assets::addFrontStyle( 'awesome_plugin_premium_style' )
->src( $style_url )
->provide( [ 'awesome_plugin_free_style' ] );
Brain\Assets::addFrontScript( 'awesome_plugin_premium_script' )
->src( $script_url )
->provide( [ 'awesome_plugin_free_script' ] );
php
Brain\Assets::addAdminScript( 'awesome_script', [ 'src' => $script_url ] );
php
$script = Brain\Assets::getScript( 'awesome_script' );
$script->setSrc( str_replace( "example.com", "foo.com", $script->getSrc() ) )
->setCondition( function( WP_Query $query ) {
return ! $query->is_page( 'not-here' );
});
php
add_action( 'wp_print_scripts', function() {
wp_dequeue_script( 'awesome_script' );
if ( is_page('not-here') ) {
return;
}
global $wp_scripts;
$script = $wp_scripts->registered['awesome_script'];
$args = get_object_properties( $script );
$in_footer = isset( $args['extra']['group'] ) && $args['extra']['group'];
wp_deregister_script( 'awesome_script' );
wp_enqueue_script(
'awesome_script', $args['src'], $args['deps'], $args['ver'], $in_footer
);
}, 1 );
php
wp_register_script(
'foo',
'http://example.com/path/to/script.js',
array( 'jQuery' ),
'20141008',
TRUE
);
wp_localize_script(
'foo',
'FooData',
array( 'foo'=>'bar', 'bar'=>'baz' )
);
php
$script = new Brain\Occipital\Script;
$script->fillFromRegistered( 'foo' );
$data = $script->getLocalizeData();