Completed
Push — master ( 23a8aa...afc025 )
by Bui Quang
7s
created

WPDFI::install()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * Plugin Name: WP Default Feature Image.
4
 * Description: Help you choose your default thumbnail for 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: GNUv3
9
 * Text Domain: wpdfi
10
 */
11
define('WPDFI_PLUGIN', __FILE__ );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
12
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...
13
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...
14
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...
15
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...
16
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...
17
18
require_once WPDFI_DIR_BASE . '/vendor/autoload.php';
19
20
use WPDFI\Traits\HasModule;
21
use WPDFI\Traits\Singleton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Singleton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
use WPDFI\PostType;
23
use WPDFI\Taxonomy;
24
use WPDFI\Term;
25
use WPDFI\Ajax;
26
use WPDFI\Admin;
27
use WPDFI\Image;
28
use WPDFI\Layout;
29
use WPDFI\Admin\Notice;
30
31
final class WPDFI
32
{
33
	use HasModule;
34
	use Singleton;
35
	
36
	/**
37
	 * @traitDoc
38
	 */
39
	public function initializes() 
40
	{
41
		$this->loadModules();
42
43
		Ajax::instance();
44
	}
45
46
	/**
47
	 * All WordPress hooks come here
48
	 * 
49
	 * @since 1.0.0
50
	 * @return void
51
	 */
52
	public function hooks() 
53
	{
54
55
		add_action( 'init', [$this, 'init']);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
56
57
		/* Load all module hooks */
58
		$this->moduleHooks();
59
60
	}
61
62
	/**
63
	 * All Install and default settings stuff for this plugin come here.
64
	 *
65
	 * @since 1.0.0
66
	 * @return void
67
	 */
68
	public function install() {
69
70
		$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...
71
		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...
72
			$options['options']['status_for_update'] = 'publish';
73
			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...
74
		}
75
76
	}
77
	
78
	/**
79
	 * init actions
80
	 * 
81
	 * @since 1.0.0
82
	 * @return void
83
	 */
84
	public function init() 
85
	{
86
		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...
87
	}
88
	
89
	/**
90
	 * @traitDoc
91
	 */
92
	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...
93
		$modules = [
94
			'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...
95
			'post_type' => PostType::instance(),
96
			'taxonomy'	=> Taxonomy::instance(),
97
			'term'		=> Term::instance(),
98
			'image'		=> Image::instance(),
99
			'layout'	=> Layout::instance(),
100
			'admin_notice' => Notice::instance(),
101
			'admin'		=> Admin::instance()
102
		];
103
			
104
		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...
105
			$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...
106
		}
107
		
108
		return $this;
109
	}
110
	
111
}
112
/**
113
 * Return singleton of WPDFI
114
 *
115
 * @since  1.0.0
116
 * @return WPDFI  Singleton instance of plugin class.
117
 */
118
function wpdfi() {
119
    return WPDFI::instance();
120
}
121
122
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...
123
124
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...