FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
wordpress-plugin/src/Plugin.php at main · simpleanalytics/wordpress-plugin · GitHub
simpleanalytics
/
wordpress-plugin
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
4
Code
Issues
2
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
wordpress-plugin
/
src
/
Plugin.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (68 loc) · 2.54 KB
Breadcrumbs
wordpress-plugin
/
src
/
Plugin.php
Copy path
File metadata and controls
83 lines (68 loc) · 2.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace
SimpleAnalytics
;
use
SimpleAnalytics
\
Actions
\
AddInactiveComment
;
use
SimpleAnalytics
\
Actions
\
AddNoScriptTag
;
use
SimpleAnalytics
\
Actions
\
AddPluginSettingsLink
;
use
SimpleAnalytics
\
Scripts
\
AnalyticsScript
;
use
SimpleAnalytics
\
Scripts
\
AutomatedEventsScript
;
use
SimpleAnalytics
\
Scripts
\
InactiveScript
;
use
SimpleAnalytics
\
Settings
\
AdminPage
;
final
class
Plugin
{
protected
$
hooks
;
protected
$
settings
;
protected
$
trackingRules
;
protected
$
scripts
;
protected
$
adminPage
;
public
function
__construct
(
WordPressHooks
$
hooks
,
WordPressSettings
$
settings
,
TrackingRules
$
trackingRules
,
ScriptRegistry
$
scripts
,
AdminPage
$
adminPage
) {
$
this
->
hooks
=
$
hooks
;
$
this
->
settings
=
$
settings
;
$
this
->
trackingRules
=
$
trackingRules
;
$
this
->
scripts
=
$
scripts
;
$
this
->
adminPage
=
$
adminPage
;
}
public
function
boot
():
void
{
$
this
->
hooks
->
addAction
(
'
init
'
, \Closure::
fromCallable
([
$
this
,
'
onInit
'
]));
$
this
->
hooks
->
onActivation
(\Closure::
fromCallable
([
$
this
,
'
onActivation
'
]));
if
(
$
this
->
hooks
->
isAdmin
()) {
$
this
->
adminPage
->
register
();
AddPluginSettingsLink::
register
();
}
}
public
function
onInit
():
void
{
$
hasExcludedIp
=
$
this
->
trackingRules
->
hasExcludedIp
();
$
hasExcludedUserRole
=
$
this
->
trackingRules
->
hasExcludedUserRole
();
$
tracking
= !
$
hasExcludedIp
&& !
$
hasExcludedUserRole
;
if
(
$
tracking
) {
$
this
->
scripts
->
push
(
new
AnalyticsScript
);
}
else
{
$
this
->
scripts
->
push
(
new
InactiveScript
);
$
reason
=
$
hasExcludedIp
?
'
Exclude IP Address
'
:
'
Exclude User Role
'
;
AddInactiveComment::
register
(
$
reason
);
}
if
(
$
tracking
&&
$
this
->
settings
->
get
(SettingName::
NOSCRIPT
)) {
AddNoScriptTag::
register
();
}
if
(
$
this
->
settings
->
boolean
(SettingName::
AUTOMATED_EVENTS
)) {
$
this
->
scripts
->
push
(
new
AutomatedEventsScript
);
}
$
this
->
scripts
->
register
();
}
public
function
onActivation
():
void
{
$
this
->
settings
->
register
(SettingName::
ENABLED
,
true
);
foreach
(
array_diff
(SettingName::
cases
(), [SettingName::
ENABLED
])
as
$
name
) {
$
this
->
settings
->
register
(
$
name
);
}
// Legacy. Update the option introduced in a previous release to use autoloading.
$
this
->
settings
->
update
(SettingName::
CUSTOM_DOMAIN
,
$
this
->
settings
->
get
(SettingName::
CUSTOM_DOMAIN
),
true
);
}
}
Back
|
FazBrowse Home
|
New Git URL