Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-builder
Commits
57f32a5f
Commit
57f32a5f
authored
7 years ago
by
Grzegorz Rola
Browse files
Options
Downloads
Patches
Plain Diff
Added ActivationTracker class and HookableParent trait.
parent
fa8a1499
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!12
Feature/plugin activation
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/ActivationTracker.php
+77
-0
77 additions, 0 deletions
src/Plugin/ActivationTracker.php
src/Plugin/HookableParetn.php
+37
-0
37 additions, 0 deletions
src/Plugin/HookableParetn.php
with
114 additions
and
0 deletions
src/Plugin/ActivationTracker.php
0 → 100644
+
77
−
0
View file @
57f32a5f
<?php
/**
* Created by PhpStorm.
* User: grola
* Date: 25.07.18
* Time: 16:55
*/
namespace
WPDesk\PluginBuilder\Plugin
;
class
ActivationTracker
{
/**
* Namespace.
*
* @var string
*/
private
$namespace
;
/**
* ActivationTracker constructor.
*
* @param string $namespace Namespace for settings.
*/
public
function
__construct
(
$namespace
)
{
$this
->
namespace
=
$namespace
;
}
/**
* Option name for date storage
*
* @return string
*/
private
function
get_option_name_activation_date
()
{
return
$this
->
namespace
.
'_activation'
;
}
/**
* Returns activation date and sets it if were not set before
*
* @return int unix timestamp for activation datetime
*/
public
function
get_activation_date
()
{
$activation_date
=
get_option
(
$this
->
get_option_name_activation_date
()
);
if
(
empty
(
$activation_date
)
)
{
return
$this
->
touch_activation_date
();
}
return
intval
(
$activation_date
);
}
/**
* Was activation more than two weeks before today
*
* @return bool
*/
public
function
is_activated_more_than_two_weeks
()
{
$two_weeks
=
60
*
60
*
24
*
7
*
2
;
return
$this
->
get_activation_date
()
+
$two_weeks
<
time
();
}
/**
* Sets activatiion date for today
*
* @return int unit timestamp for now
*/
public
function
touch_activation_date
()
{
$now
=
time
();
update_option
(
$this
->
get_option_name_activation_date
(),
$now
);
return
$now
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Plugin/HookableParetn.php
0 → 100644
+
37
−
0
View file @
57f32a5f
<?php
namespace
WPDesk\PluginBuilder\Plugin
;
trait
HookableParent
{
/**
* Hookable objects.
*
* @var array[Hookable]
*/
private
$hookable_objects
=
array
();
/**
* Add hookable object.
*
* @param Hookable|HookablePluginDependant $hookable_object Hookable object.
*/
public
function
add_hookable
(
$hookable_object
)
{
if
(
$hookable_object
instanceof
HookablePluginDependant
)
{
$hookable_object
->
set_plugin
(
$this
);
}
$this
->
hookable_objects
[]
=
$hookable_object
;
}
/**
* Run hooks method on all hookable objects.
*/
protected
function
hooks_no_hookable_objects
()
{
/** @var Hookable $hookable_object $hookable_object */
foreach
(
$this
->
hookable_objects
as
$hookable_object
)
{
$hookable_object
->
hooks
();
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment