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