|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Handlers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Html; |
|
8
|
|
|
|
|
9
|
|
|
class EnqueueAssets |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $dependencies; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @return void |
|
18
|
|
|
*/ |
|
19
|
|
|
public function handle() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->dependencies = glsr( Html::class )->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->enqueue(); |
|
30
|
|
|
wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables )); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function enqueue() |
|
37
|
|
|
{ |
|
38
|
|
|
$currentTheme = sanitize_title( wp_get_theme()->get( 'Name' )); |
|
|
|
|
|
|
39
|
|
|
$stylesheet = file_exists( glsr()->path.'assets/css/'.$currentTheme.'.css' ) |
|
40
|
|
|
? glsr()->url.'assets/css/'.$currentTheme.'.css' |
|
41
|
|
|
: glsr()->url.'assets/css/'.Application::ID.'.css'; |
|
42
|
|
|
if( apply_filters( 'site-reviews/assets/css', true )) { |
|
43
|
|
|
wp_enqueue_style( |
|
44
|
|
|
Application::ID, |
|
45
|
|
|
$stylesheet, |
|
46
|
|
|
[], |
|
47
|
|
|
glsr()->version |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
if( apply_filters( 'site-reviews/assets/js', true )) { |
|
51
|
|
|
wp_enqueue_script( |
|
52
|
|
|
Application::ID, |
|
53
|
|
|
glsr()->url.'assets/js/'.Application::ID.'.js', |
|
54
|
|
|
['jquery'], |
|
55
|
|
|
glsr()->version, |
|
56
|
|
|
true |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
if( glsr( OptionManager::class )->get( 'settings.reviews-form.recaptcha.integration' ) == 'custom' ) { |
|
60
|
|
|
$this->enqueueRecaptchaScript(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function enqueueRecaptchaScript() |
|
68
|
|
|
{ |
|
69
|
|
|
wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg([ |
|
70
|
|
|
'hl' => apply_filters( 'site-reviews/recaptcha/language', get_locale() ), |
|
71
|
|
|
'onload' => 'glsr_render_recaptcha', |
|
72
|
|
|
'render' => 'explicit', |
|
73
|
|
|
], 'https://www.google.com/recaptcha/api.js' )); |
|
74
|
|
|
$inlineScript = file_get_contents( glsr()->path.'js/recaptcha.js' ); |
|
75
|
|
|
wp_add_inline_script( Application::ID.'/google-recaptcha', $inlineScript, 'before' ); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|