1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Handlers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
6
|
|
|
use GeminiLabs\SiteReviews\Commands\EnqueueAssets as Command; |
|
|
|
|
7
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
8
|
|
|
|
9
|
|
|
class EnqueueAssets |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $dependencies; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function handle( Command $command ) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$this->dependencies = glsr( 'Html' )->getDependencies(); |
22
|
|
|
$ajaxNonce = wp_create_nonce( Application::ID.'-ajax-nonce' ); |
23
|
|
|
$variables = [ |
24
|
|
|
'action' => glsr()->prefix . '_action', |
25
|
|
|
'ajaxurl' => add_query_arg( '_nonce', $ajaxNonce, admin_url( 'admin-ajax.php' )), |
26
|
|
|
'ajaxnonce' => $ajaxNonce, |
27
|
|
|
'ajaxpagination' => ['#wpadminbar','.site-navigation-fixed'], |
28
|
|
|
]; |
29
|
|
|
$this->enqueueAssets(); |
30
|
|
|
|
31
|
|
|
wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables )); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function enqueueAssets() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$currentTheme = sanitize_title( wp_get_theme()->get( 'Name' )); |
|
|
|
|
40
|
|
|
$stylesheet = file_exists( glsr()->path.'assets/css/'.$currentTheme.'.css' ) |
41
|
|
|
? glsr()->url.'assets/css/'.$currentTheme.'.css' |
42
|
|
|
: glsr()->url.'assets/css/'.Application::ID.'.css'; |
43
|
|
|
if( apply_filters( 'site-reviews/assets/css', true )) { |
44
|
|
|
wp_enqueue_style( |
45
|
|
|
Application::ID, |
46
|
|
|
$stylesheet, |
47
|
|
|
[], |
48
|
|
|
glsr()->version |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
if( apply_filters( 'site-reviews/assets/js', true )) { |
52
|
|
|
wp_enqueue_script( |
53
|
|
|
Application::ID, |
54
|
|
|
glsr()->url.'assets/js/'.Application::ID.'.js', |
55
|
|
|
['jquery'], |
56
|
|
|
glsr()->version, |
57
|
|
|
true |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
if( glsr( OptionManager::class )->get( 'settings.reviews-form.recaptcha.integration' ) == 'custom' ) { |
61
|
|
|
$this->enqueueRecaptchaScript(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function enqueueRecaptchaScript() |
69
|
|
|
{ |
70
|
|
|
wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg([ |
71
|
|
|
'hl' => apply_filters( 'site-reviews/recaptcha/language', get_locale() ), |
72
|
|
|
'onload' => 'glsr_render_recaptcha', |
73
|
|
|
'render' => 'explicit', |
74
|
|
|
], 'https://www.google.com/recaptcha/api.js' )); |
75
|
|
|
$inlineScript = file_get_contents( glsr()->path.'js/recaptcha.js' ); |
76
|
|
|
wp_add_inline_script( Application::ID.'/google-recaptcha', $inlineScript, 'before' ); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths