ENQUEUE ERROR:
' . $code . ' - ' . $error->get_error_message( $code ) . ' Bad asset:
' . print_r( $error->get_error_data( $code ), true ) . '
',
82 | [
83 | 'div' => [ 'class' ],
84 | 'strong' => [],
85 | 'em' => [],
86 | 'pre' => [],
87 | ]
88 | );
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/concerns/trait-conditions.php:
--------------------------------------------------------------------------------
1 | true,
42 | 'single' => is_single(),
43 | 'search' => is_search(),
44 | ]
45 | );
46 | }
47 |
48 | return static::$_conditions;
49 | }
50 |
51 | /**
52 | * Determine if an asset should be added (enqueued) or not.
53 | *
54 | * @param string $asset Type of asset.
55 | * @return bool|WP_Error
56 | */
57 | public function asset_should_add( $asset ) {
58 | /**
59 | * Filter function for preventing an asset from loading, regardless of conditions
60 | *
61 | * @since 0.0.1
62 | *
63 | * @param bool $add_asset Whether or not to forcefully prevent asset from loading
64 | * @param array $asset Asset to prevent from loading
65 | */
66 | if ( ! apply_filters( 'am_asset_should_add', true, $asset ) ) {
67 | return false;
68 | }
69 |
70 | // Already-added assets should not be added again.
71 | if ( empty( $asset['handle'] ) || in_array( $asset['handle'], $this->asset_handles, true ) ) {
72 | return false;
73 | }
74 |
75 | // If there's no condition, asset should load.
76 | if ( empty( $asset['condition'] ) ) {
77 | return true;
78 | }
79 |
80 | $conditions = static::get_conditions();
81 | $condition_result = true;
82 |
83 | // Default functionality of condition is 'include'.
84 | if ( ! empty( $asset['condition']['include'] ) ) {
85 | $condition_include = $asset['condition']['include'];
86 | } elseif ( ! empty( $asset['condition']['include_any'] ) ) {
87 | $condition_include_any = $asset['condition']['include_any'];
88 | } elseif ( empty( $asset['condition']['exclude'] ) ) {
89 | $condition_include = $asset['condition'];
90 | }
91 |
92 | // Check 'include' conditions (all must be true for asset to load)
93 | // There might only be an 'exclude' condition, so check empty() first.
94 | if ( ! empty( $condition_include ) ) {
95 | $condition_include = ! is_array( $condition_include ) ? [ $condition_include ] : $condition_include;
96 |
97 | foreach ( $condition_include as $condition_true ) {
98 | if ( ! empty( $conditions[ $condition_true ] ) ) {
99 | continue;
100 | } else {
101 | $condition_result = false;
102 | break;
103 | }
104 | }
105 | }
106 |
107 | // Check for 'include_any' to allow for matching of _any_ condition instead of all conditions.
108 | if ( ! empty( $condition_include_any ) ) {
109 | $condition_result = false;
110 | $condition_include_any = ! is_array( $condition_include_any ) ? [ $condition_include_any ] : $condition_include_any;
111 |
112 | foreach ( $condition_include_any as $condition_true ) {
113 | if ( $conditions[ $condition_true ] ) {
114 | $condition_result = true;
115 | }
116 | }
117 | }
118 |
119 | // Check 'exclude' conditions (all must be false for asset to load)
120 | // Verify $condition_result is true. If it's already false, we don't need to check excludes.
121 | if ( ! empty( $asset['condition']['exclude'] ) && $condition_result ) {
122 | $condition_exclude = ! is_array( $asset['condition']['exclude'] ) ? [ $asset['condition']['exclude'] ] : $asset['condition']['exclude'];
123 |
124 | foreach ( $condition_exclude as $condition_false ) {
125 | if ( ! $conditions[ $condition_false ] ) {
126 | continue;
127 | } else {
128 | $condition_result = false;
129 | break;
130 | }
131 | }
132 | }
133 |
134 | return $condition_result;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/concerns/trait-singleton.php:
--------------------------------------------------------------------------------
1 | |string|null $src URI to script or array of inline script data.
37 | * @param array