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 EnqueuePublicAssets |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function handle() |
15
|
|
|
{ |
16
|
|
|
$this->enqueueAssets(); |
17
|
|
|
$this->enqueueRecaptchaScript(); |
18
|
|
|
$this->localizeAssets(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function enqueueAssets() |
25
|
|
|
{ |
26
|
|
|
if( apply_filters( 'site-reviews/assets/css', true )) { |
27
|
|
|
wp_enqueue_style( |
28
|
|
|
Application::ID, |
29
|
|
|
$this->getStylesheet(), |
30
|
|
|
[], |
31
|
|
|
glsr()->version |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
if( apply_filters( 'site-reviews/assets/js', true )) { |
35
|
|
|
wp_enqueue_script( |
36
|
|
|
Application::ID, |
37
|
|
|
glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
38
|
|
|
[],//glsr( Html::class )->getDependencies(), |
|
|
|
|
39
|
|
|
glsr()->version, |
40
|
|
|
true |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function enqueueRecaptchaScript() |
49
|
|
|
{ |
50
|
|
|
if( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.integration' ) != 'custom' )return; |
51
|
|
|
wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg([ |
52
|
|
|
'hl' => apply_filters( 'site-reviews/recaptcha/language', get_locale() ), |
53
|
|
|
'onload' => 'glsr_render_recaptcha', |
54
|
|
|
'render' => 'explicit', |
55
|
|
|
], 'https://www.google.com/recaptcha/api.js' )); |
56
|
|
|
$inlineScript = file_get_contents( glsr()->path( 'assets/scripts/recaptcha.js' )); |
57
|
|
|
wp_add_inline_script( Application::ID.'/google-recaptcha', $inlineScript, 'before' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function localizeAssets() |
64
|
|
|
{ |
65
|
|
|
$variables = [ |
66
|
|
|
'action' => Application::PREFIX.'action', |
67
|
|
|
'ajaxnonce' => wp_create_nonce( Application::ID.'-ajax-nonce' ), |
68
|
|
|
'ajaxpagination' => ['#wpadminbar','.site-navigation-fixed'], |
69
|
|
|
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
70
|
|
|
]; |
71
|
|
|
$variables = apply_filters( 'site-reviews/enqueue/localize', $variables ); |
72
|
|
|
wp_localize_script( Application::ID, 'site_reviews', $variables ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function getStylesheet() |
79
|
|
|
{ |
80
|
|
|
$currentTheme = sanitize_title( wp_get_theme()->get( 'Name' )); |
|
|
|
|
81
|
|
|
return file_exists( glsr()->path.'assets/styles/'.$currentTheme.'.css' ) |
82
|
|
|
? glsr()->url( 'assets/styles/'.$currentTheme.'.css' ) |
83
|
|
|
: glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.