Issues (206)

Plugin/Loader.php (2 issues)

1
<?php
2
namespace NirjharLo\Cgss;
3
4
if ( ! defined( 'ABSPATH' ) ) exit;
5
6
7
use \NirjharLo\Cgss\Lib\Script;
8
9
use \NirjharLo\Cgss\Lib\Action\Scan;
10
use \NirjharLo\Cgss\Lib\Action\Insight;
11
12
use \NirjharLo\Cgss\Models\Insight as InsightModel;
13
14
use \NirjharLo\Cgss\Src\Db;
15
use \NirjharLo\Cgss\Src\Install;
16
use \NirjharLo\Cgss\Src\Settings;
17
18
19
final class Loader {
20
21
	/**
22
	 * Plugin Instance.
23
	 *
24
	 * @var PLUGIN_BUILD the PLUGIN Instance
25
	 */
26
	protected static $instance;
27
28
29
	/**
30
	 * Main Plugin Instance.
31
	 *
32
	 * @return PLUGIN_BUILD
33
	 */
34
	public static function instance() {
35
36
		if ( is_null( self::$instance ) ) {
37
			self::$instance = new self();
38
			self::$instance->init();
39
		}
40
41
		return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance also could return the type NirjharLo\Cgss\Loader which is incompatible with the documented return type NirjharLo\Cgss\PLUGIN_BUILD.
Loading history...
42
	}
43
44
	public function installation() {
45
46
			$install = new Install();
47
			$install->textDomin = 'cgss';
48
			$install->phpVerAllowed = '5.4';
49
			$install->pluginPageLinks = array(
50
											array(
51
												'slug' => home_url().'/wp-admin/admin.php?page=seo-scan',
52
												'label' => __( 'Dashboard', 'cgss' )
53
											),
54
										);
55
			$install->execute();
56
	}
57
58
59
	public function db_install() {
60
61
			$db = new Db();
62
			$db->table = 'cgss_insight';
63
			$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT,
64
						item varchar(256) NOT NULL,
65
						remark varchar(512) NOT NULL,
66
						UNIQUE KEY ID (ID)";
67
			$db->build();
68
69
			$insert_data = $this->insert_prelim_data();
70
	}
71
72
73
	public function db_uninstall() {
74
75
		$tableName = 'cgss_insight';
76
77
		global $wpdb;
78
		$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$tableName" );
79
	}
80
81
82
        public function insert_prelim_data() {
83
84
                $model = new InsightModel();
85
86
                if ($model->count() === 0) {
87
88
                $init_insight = array(
89
                                __('Score','cgss'),
90
                                __('Snippet','cgss'),
91
                                __('Text','cgss'),
92
                                __('Links','cgss'),
93
                                __('Keywords','cgss'),
94
                                __('Images','cgss'),
95
                                __('Responsive','cgss'),
96
                                __('Speed','cgss'),
97
                                __('Social','cgss')
98
                        );
99
                $no_data = __( 'No scan reports are available yet', 'cgss' );
100
                foreach ($init_insight as $key => $value) {
101
                        $model->insert($value, $no_data, $key + 1);
102
                }
103
                }
104
        }
105
106
107
	//Include scripts
108
	public function scripts() {
109
110
		new Script();
111
	}
112
113
114
115
	//Include settings pages
116
	public function settings() {
117
118
		new Settings();
119
	}
120
121
122
123
	// Add custom insight action
124
	public function insight() {
125
126
		new Insight();
127
	}
128
129
130
131
	// Add custom insight action
132
	public function scan() {
133
134
		new Scan();
135
	}
136
137
138
	public function init() {
139
140
		register_activation_hook( CGSS_FILE, array( $this, 'db_install' ) );
141
		register_uninstall_hook( CGSS_FILE, array( 'BUILD', 'db_uninstall' ) ); //$this won't work here.
142
143
		add_action('init', array($this, 'installation'));
144
145
		$this->scripts();
146
		$this->settings();
147
148
		// Add custom actions, defined in settings
149
		add_action( 'cgss_scan', array( $this, 'scan' ) );
150
		add_action( 'cgss_fetch_insight', array( $this, 'insight' ) );
151
	}
152
} ?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
153