-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathasset-manager.php
67 lines (60 loc) · 2.09 KB
/
asset-manager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Asset Manager Base Plugin File.
*
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
*
* @package AssetManager
*/
/**
* Filesystem path to AssetManager.
*/
defined( 'AM_BASE_DIR' ) || define( 'AM_BASE_DIR', __DIR__ );
// Load the Composer autoloader.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
} elseif ( ! class_exists( \Alley\WP\Asset_Manager\Asset_Manager::class ) ) {
add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error">
<p>
<?php
esc_html_e(
'Asset Manager is not installed. Please switch to a tagged release or track the `production-built` branch.',
'am'
);
?>
</p>
</div>
<?php
}
);
return;
}
// Setup the aliases to the legacy Asset Manager classes (pre-1.4.0).
class_alias( \Alley\WP\Asset_Manager\Scripts::class, 'Asset_Manager_Scripts' );
class_alias( \Alley\WP\Asset_Manager\Styles::class, 'Asset_Manager_Styles' );
class_alias( \Alley\WP\Asset_Manager\Preload::class, 'Asset_Manager_Preload' );
class_alias( \Alley\WP\Asset_Manager\SVG_Sprite::class, 'Asset_Manager_SVG_Sprite' );
/**
* Map plugin meta capabilities.
*
* @param string[] $caps Primitive capabilities required of the user.
* @param string $cap Capability being checked.
* @return string[] Updated primitive capabilities.
*/
function am_map_meta_caps( $caps, $cap ) {
// By default, require the 'manage_options' capability to view asset errors.
if ( 'am_view_asset_error' === $cap ) {
$caps = [ 'manage_options' ];
}
return $caps;
}
add_filter( 'map_meta_cap', 'am_map_meta_caps', 10, 2 );
// Setup the plugin's main classes after the theme has been setup.
add_action( 'after_setup_theme', [ \Alley\WP\Asset_Manager\Preload::class, 'instance' ], 10 );
add_action( 'after_setup_theme', [ \Alley\WP\Asset_Manager\Scripts::class, 'instance' ], 10 );
add_action( 'after_setup_theme', [ \Alley\WP\Asset_Manager\Styles::class, 'instance' ], 10 );
add_action( 'after_setup_theme', [ \Alley\WP\Asset_Manager\SVG_Sprite::class, 'instance' ], 10 );