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
Merge requests
!19
activation aware builder
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
activation aware builder
feature/new-requirements
into
master
Overview
0
Commits
1
Pipelines
1
Changes
8
Merged
Krzysztof Dyszczyk
requested to merge
feature/new-requirements
into
master
6 years ago
Overview
0
Commits
1
Pipelines
1
Changes
8
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
7823c89d
1 commit,
6 years ago
8 files
+
136
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
src/Builder/InfoActivationBuilder.php
0 → 100644
+
82
−
0
View file @ 7823c89d
Edit in single-file editor
Open in Web IDE
<?php
namespace
WPDesk\PluginBuilder\Builder
;
use
WPDesk\PluginBuilder\Plugin\AbstractPlugin
;
use
WPDesk\PluginBuilder\Plugin\ActivationAware
;
use
WPDesk\PluginBuilder\Storage\PluginStorage
;
/**
* Builder that have info about activations
*
* Warning: We can't extend InfoBuilder.php as some old plugins(without wp-flow) will load the old version od InfoBuilder class that have private plugin property.
*
* @package WPDesk\PluginBuilder\Builder
*/
class
InfoActivationBuilder
extends
AbstractBuilder
{
const
FILTER_PLUGIN_CLASS
=
'wp_builder_plugin_class'
;
const
HOOK_BEFORE_PLUGIN_INIT
=
'wp_builder_before_plugin_init'
;
const
HOOK_AFTER_PLUGIN_INIT
=
'wp_builder_before_init'
;
/** @var AbstractPlugin */
private
$plugin
;
/** @var \WPDesk_Buildable */
private
$info
;
/** @var string */
protected
$storage_id
;
/**
* @var bool
*/
private
$is_active
;
/**
* @param \WPDesk_Buildable $info
* @param bool $is_active
*/
public
function
__construct
(
\WPDesk_Buildable
$info
,
$is_active
)
{
$this
->
info
=
$info
;
$this
->
storage_id
=
$info
->
get_class_name
();
$this
->
is_active
=
$is_active
;
}
/**
* Builds instance of plugin
*/
public
function
build_plugin
()
{
$class_name
=
apply_filters
(
self
::
FILTER_PLUGIN_CLASS
,
$this
->
info
->
get_class_name
());
/** @var AbstractPlugin $plugin */
$this
->
plugin
=
new
$class_name
(
$this
->
info
);
if
(
$this
->
plugin
instanceof
ActivationAware
&&
$this
->
is_active
)
{
$this
->
plugin
->
set_active
();
}
return
$this
->
plugin
;
}
public
function
store_plugin
(
PluginStorage
$storage
)
{
$storage
->
add_to_storage
(
$this
->
storage_id
,
$this
->
plugin
);
}
public
function
init_plugin
()
{
do_action
(
self
::
HOOK_BEFORE_PLUGIN_INIT
,
$this
->
plugin
);
$this
->
plugin
->
init
();
do_action
(
self
::
HOOK_AFTER_PLUGIN_INIT
,
$this
->
plugin
);
}
/**
* @return AbstractPlugin
*/
public
function
get_plugin
()
{
return
$this
->
plugin
;
}
}
\ No newline at end of file
Loading