WPDFI   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initializes() 0 6 1
A hooks() 0 9 1
A install() 0 9 2
A init() 0 4 1
A loadModules() 0 18 2
1
<?php
2
/**
3
 * Plugin Name: WP Default Feature Image.
4
 * Description: Help you to choose default feature images for any post types, categories, tags,...
5
 * Version: 1.0.0
6
 * Author: Duc Bui Quang <[email protected]>
7
 * Author URI: https://www.ducbuiquang.com
8
 * License: GPLv2+
9
 * Text Domain: wpdfi
10
 *
11
12
WP Default Feature Image is free software: you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation, either version 2 of the License, or
15
any later version.
16
 
17
WP Default Feature Image is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
21
 
22
You should have received a copy of the GNU General Public License
23
along with WP Default Feature Image. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
24
25
*/
26
27
28
define('WPDFI_PLUGIN', __FILE__ );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
29
define('WPDFI_PLUGIN_BASENAME', plugin_basename( WPDFI_PLUGIN ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
30
define('WPDFI_URL_BASE', plugin_dir_url( WPDFI_PLUGIN) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
31
define('WPDFI_DIR_BASE', plugin_dir_path( WPDFI_PLUGIN ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
32
define('WPDFI_ASSETS', WPDFI_URL_BASE . '/assets/' );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
33
define('WPDFI_TEMPLATES_PATH', WPDFI_DIR_BASE.  '/templates/');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
34
35
require_once WPDFI_DIR_BASE . '/vendor/autoload.php';
36
37
use WPDFI\Traits\HasModule;
38
use WPDFI\Traits\Singleton;
39
use WPDFI\PostType;
40
use WPDFI\Taxonomy;
41
use WPDFI\Term;
42
use WPDFI\Ajax;
43
use WPDFI\Admin;
44
use WPDFI\Image;
45
use WPDFI\Layout;
46
use WPDFI\Admin\Notice;
47
48
final class WPDFI
49
{
50
	use HasModule;
51
	use Singleton;
52
	
53
	/**
54
	 * @traitDoc
55
	 */
56
	public function initializes() 
57
	{
58
		$this->loadModules();
59
60
		Ajax::instance();
61
	}
62
63
	/**
64
	 * All WordPress hooks come here
65
	 * 
66
	 * @since 1.0.0
67
	 * @return void
68
	 */
69
	public function hooks() 
70
	{
71
72
		add_action( 'init', [$this, 'init']);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
73
74
		/* Load all module hooks */
75
		$this->moduleHooks();
76
77
	}
78
79
	/**
80
	 * All Install and default settings stuff for this plugin come here.
81
	 *
82
	 * @since 1.0.0
83
	 * @return void
84
	 */
85
	public function install() {
86
87
		$options = get_option('wpdfi-settings');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
88
		if(!$options['options']['status_for_update']) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
89
			$options['options']['status_for_update'] = 'publish';
90
			update_option('wpdfi-settings', $options);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
91
		}
92
93
	}
94
	
95
	/**
96
	 * init actions
97
	 * 
98
	 * @since 1.0.0
99
	 * @return void
100
	 */
101
	public function init() 
102
	{
103
		load_plugin_textdomain('wpdfi', false, WPDFI_DIR_BASE . '/lang/');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
104
	}
105
	
106
	/**
107
	 * @traitDoc
108
	 */
109
	public function loadModules() {
0 ignored issues
show
Coding Style introduced by
The function name loadModules is in camel caps, but expected load_modules instead as per the coding standard.
Loading history...
110
		$modules = [
111
			'templater'	=> new VA\Templater(WPDFI_TEMPLATES_PATH, 'blade'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
112
			'post_type' => PostType::instance(),
113
			'taxonomy'	=> Taxonomy::instance(),
114
			'term'		=> Term::instance(),
115
			'image'		=> Image::instance(),
116
			'layout'	=> Layout::instance(),
117
			'admin_notice' => Notice::instance(),
118
			'admin'		=> Admin::instance()
119
		];
120
			
121
		foreach($modules as $moduleName => $moduleHandle) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
122
			$this->module($moduleName, $moduleHandle);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
123
		}
124
		
125
		return $this;
126
	}
127
	
128
}
129
/**
130
 * Return singleton of WPDFI
131
 *
132
 * @since  1.0.0
133
 * @return WPDFI  Singleton instance of plugin class.
134
 */
135
function wpdfi() {
136
    return WPDFI::instance();
137
}
138
139
add_action('plugins_loaded', [wpdfi(), 'hooks']);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
140
141
register_activation_hook(WPDFI_PLUGIN, [wpdfi(), 'install']);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...