Completed
Push — develop ( c5ce4a...c74055 )
by David
02:32
created
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -11,99 +11,99 @@  discard block
 block discarded – undo
11 11
  */
12 12
 function wl_core_install_entity_type_data() {
13 13
 
14
-	Wordlift_Log_Service::get_instance()->debug('Installing Entity Type data...');
15
-
16
-	// Ensure the custom type and the taxonomy are registered.
17
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
18
-
19
-	wl_entity_type_taxonomy_register();
20
-
21
-	// Ensure the custom taxonomy for dbpedia topics is registered
22
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
23
-
24
-	// Set the taxonomy data.
25
-	// Note: parent types must be defined before child types.
26
-	$terms = array(
27
-		'thing'         => array(
28
-			'label'       => 'Thing',
29
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
30
-		),
31
-		'creative-work' => array(
32
-			'label'       => 'CreativeWork',
33
-			'description' => 'A creative work (or a Music Album).',
34
-		),
35
-		'event'         => array(
36
-			'label'       => 'Event',
37
-			'description' => 'An event.',
38
-		),
39
-		'organization'  => array(
40
-			'label'       => 'Organization',
41
-			'description' => 'An organization, including a government or a newspaper.',
42
-		),
43
-		'person'        => array(
44
-			'label'       => 'Person',
45
-			'description' => 'A person (or a music artist).',
46
-		),
47
-		'place'         => array(
48
-			'label'       => 'Place',
49
-			'description' => 'A place.',
50
-		),
51
-		'localbusiness' => array(
52
-			'label'       => 'LocalBusiness',
53
-			'description' => 'A local business.',
54
-		),
55
-	);
56
-
57
-	foreach ( $terms as $slug => $term ) {
58
-
59
-		// Create the term if it does not exist, then get its ID
60
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
61
-
62
-		if ( 0 == $term_id || is_null( $term_id ) ) {
63
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
64
-		} else {
65
-			$term_id = $term_id['term_id'];
66
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
67
-		}
68
-
69
-		// Check for errors.
70
-		if ( is_wp_error( $result ) ) {
71
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
72
-			continue;
73
-		}
74
-
75
-		// Check if 'parent' corresponds to an actual term and get its ID.
76
-		if ( ! isset( $term['parents'] ) ) {
77
-			$term['parents'] = array();
78
-		}
79
-
80
-		$parent_ids = array();
81
-		foreach ( $term['parents'] as $parent_slug ) {
82
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
83
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
84
-		}
85
-
86
-		// Define a parent in the WP taxonomy style (not important for WL)
87
-		if ( empty( $parent_ids ) ) {
88
-			// No parent
89
-			$parent_id = 0;
90
-		} else {
91
-			// Get first parent
92
-			$parent_id = $parent_ids[0];
93
-		}
94
-
95
-		// Update term with description, slug and parent
96
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
97
-			'name'        => $term['label'],
98
-			'slug'        => $slug,
99
-			'description' => $term['description'],
100
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
101
-			'parent'      => $parent_id,
102
-		) );
103
-
104
-	}
105
-
106
-	Wordlift_Log_Service::get_instance()->debug('Entity Type data installed.');
14
+    Wordlift_Log_Service::get_instance()->debug('Installing Entity Type data...');
15
+
16
+    // Ensure the custom type and the taxonomy are registered.
17
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
18
+
19
+    wl_entity_type_taxonomy_register();
20
+
21
+    // Ensure the custom taxonomy for dbpedia topics is registered
22
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
23
+
24
+    // Set the taxonomy data.
25
+    // Note: parent types must be defined before child types.
26
+    $terms = array(
27
+        'thing'         => array(
28
+            'label'       => 'Thing',
29
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
30
+        ),
31
+        'creative-work' => array(
32
+            'label'       => 'CreativeWork',
33
+            'description' => 'A creative work (or a Music Album).',
34
+        ),
35
+        'event'         => array(
36
+            'label'       => 'Event',
37
+            'description' => 'An event.',
38
+        ),
39
+        'organization'  => array(
40
+            'label'       => 'Organization',
41
+            'description' => 'An organization, including a government or a newspaper.',
42
+        ),
43
+        'person'        => array(
44
+            'label'       => 'Person',
45
+            'description' => 'A person (or a music artist).',
46
+        ),
47
+        'place'         => array(
48
+            'label'       => 'Place',
49
+            'description' => 'A place.',
50
+        ),
51
+        'localbusiness' => array(
52
+            'label'       => 'LocalBusiness',
53
+            'description' => 'A local business.',
54
+        ),
55
+    );
56
+
57
+    foreach ( $terms as $slug => $term ) {
58
+
59
+        // Create the term if it does not exist, then get its ID
60
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
61
+
62
+        if ( 0 == $term_id || is_null( $term_id ) ) {
63
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
64
+        } else {
65
+            $term_id = $term_id['term_id'];
66
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
67
+        }
68
+
69
+        // Check for errors.
70
+        if ( is_wp_error( $result ) ) {
71
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
72
+            continue;
73
+        }
74
+
75
+        // Check if 'parent' corresponds to an actual term and get its ID.
76
+        if ( ! isset( $term['parents'] ) ) {
77
+            $term['parents'] = array();
78
+        }
79
+
80
+        $parent_ids = array();
81
+        foreach ( $term['parents'] as $parent_slug ) {
82
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
83
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
84
+        }
85
+
86
+        // Define a parent in the WP taxonomy style (not important for WL)
87
+        if ( empty( $parent_ids ) ) {
88
+            // No parent
89
+            $parent_id = 0;
90
+        } else {
91
+            // Get first parent
92
+            $parent_id = $parent_ids[0];
93
+        }
94
+
95
+        // Update term with description, slug and parent
96
+        wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
97
+            'name'        => $term['label'],
98
+            'slug'        => $slug,
99
+            'description' => $term['description'],
100
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
101
+            'parent'      => $parent_id,
102
+        ) );
103
+
104
+    }
105
+
106
+    Wordlift_Log_Service::get_instance()->debug('Entity Type data installed.');
107 107
 
108 108
 }
109 109
 
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function wl_core_install_create_relation_instance_table() {
114 114
 
115
-	global $wpdb;
116
-	// global $wl_db_version;
117
-	$installed_version = get_option( 'wl_db_version' );
115
+    global $wpdb;
116
+    // global $wl_db_version;
117
+    $installed_version = get_option( 'wl_db_version' );
118 118
 
119
-	if ( WL_DB_VERSION != $installed_version ) {
120
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
121
-		$charset_collate = $wpdb->get_charset_collate();
119
+    if ( WL_DB_VERSION != $installed_version ) {
120
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
121
+        $charset_collate = $wpdb->get_charset_collate();
122 122
 
123
-		// Sql statement for the relation instances custom table
124
-		$sql = <<<EOF
123
+        // Sql statement for the relation instances custom table
124
+        $sql = <<<EOF
125 125
 			CREATE TABLE $table_name (
126 126
   				id int(11) NOT NULL AUTO_INCREMENT,
127 127
   				subject_id int(11) NOT NULL,
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
 			) $charset_collate;
134 134
 EOF;
135 135
 
136
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
137
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
138
-		$results = dbDelta( $sql );
136
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
137
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
138
+        $results = dbDelta( $sql );
139 139
 
140
-		wl_write_log( $results );
140
+        wl_write_log( $results );
141 141
 
142
-		update_option( 'wl_db_version', WL_DB_VERSION );
143
-	}
142
+        update_option( 'wl_db_version', WL_DB_VERSION );
143
+    }
144 144
 }
145 145
 
146 146
 /**
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function wl_core_upgrade_db_to_1_0() {
153 153
 
154
-	if ( ! get_option( 'wl_db_version' ) ) {
155
-		wl_core_install_create_relation_instance_table();
156
-	}
154
+    if ( ! get_option( 'wl_db_version' ) ) {
155
+        wl_core_install_create_relation_instance_table();
156
+    }
157 157
 
158 158
 }
159 159
 
@@ -166,31 +166,31 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function wl_core_upgrade_db_1_0_to_3_10() {
168 168
 
169
-	// If the DB version is less than 3.10, than flatten the txonomy.
170
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
169
+    // If the DB version is less than 3.10, than flatten the txonomy.
170
+    if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
171 171
 
172
-		$term_slugs = array(
173
-			'thing',
174
-			'creative-work',
175
-			'event',
176
-			'organization',
177
-			'person',
178
-			'place',
179
-			'localbusiness',
180
-		);
172
+        $term_slugs = array(
173
+            'thing',
174
+            'creative-work',
175
+            'event',
176
+            'organization',
177
+            'person',
178
+            'place',
179
+            'localbusiness',
180
+        );
181 181
 
182
-		foreach ( $term_slugs as $slug ) {
182
+        foreach ( $term_slugs as $slug ) {
183 183
 
184
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
184
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
185 185
 
186
-			// Set the term's parent to 0.
187
-			if ( $term ) {
188
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
189
-					'parent' => 0,
190
-				) );
191
-			}
192
-		}
193
-	}
186
+            // Set the term's parent to 0.
187
+            if ( $term ) {
188
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
189
+                    'parent' => 0,
190
+                ) );
191
+            }
192
+        }
193
+    }
194 194
 
195 195
 }
196 196
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
  * @since 3.12.0
204 204
  */
205 205
 function wl_core_upgrade_db_3_10_3_12() {
206
-	/*
206
+    /*
207 207
 	 * As this upgrade functionality runs on the init hook, and the AMP plugin
208 208
 	 * initialization does the same, avoid possible race conditions by
209 209
 	 * deferring the actual flush to a later hook.
210 210
 	 */
211
-	add_action( 'wp_loaded', function () {
212
-		flush_rewrite_rules();
213
-	} );
211
+    add_action( 'wp_loaded', function () {
212
+        flush_rewrite_rules();
213
+    } );
214 214
 }
215 215
 
216 216
 /**
@@ -221,51 +221,51 @@  discard block
 block discarded – undo
221 221
  * @since 3.14.0
222 222
  */
223 223
 function wl_core_upgrade_db_3_12_3_14() {
224
-	$result = wp_insert_term(
225
-		'Recipe',
226
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
227
-		array(
228
-			'slug'        => 'recipe',
229
-			'description' => 'A Recipe.',
230
-		)
231
-	);
232
-
233
-	// Assign capabilities to manipulate entities to admins.
234
-	$admins = get_role( 'administrator' );
235
-
236
-	$admins->add_cap( 'edit_wordlift_entity' );
237
-	$admins->add_cap( 'edit_wordlift_entities' );
238
-	$admins->add_cap( 'edit_others_wordlift_entities' );
239
-	$admins->add_cap( 'publish_wordlift_entities' );
240
-	$admins->add_cap( 'read_private_wordlift_entities' );
241
-	$admins->add_cap( 'delete_wordlift_entity' );
242
-
243
-	// Assign capabilities to manipulate entities to editors.
244
-	$editors = get_role( 'editor' );
245
-
246
-	$editors->add_cap( 'edit_wordlift_entity' );
247
-	$editors->add_cap( 'edit_wordlift_entities' );
248
-	$editors->add_cap( 'edit_others_wordlift_entities' );
249
-	$editors->add_cap( 'publish_wordlift_entities' );
250
-	$editors->add_cap( 'read_private_wordlift_entities' );
251
-	$editors->add_cap( 'delete_wordlift_entity' );
224
+    $result = wp_insert_term(
225
+        'Recipe',
226
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
227
+        array(
228
+            'slug'        => 'recipe',
229
+            'description' => 'A Recipe.',
230
+        )
231
+    );
232
+
233
+    // Assign capabilities to manipulate entities to admins.
234
+    $admins = get_role( 'administrator' );
235
+
236
+    $admins->add_cap( 'edit_wordlift_entity' );
237
+    $admins->add_cap( 'edit_wordlift_entities' );
238
+    $admins->add_cap( 'edit_others_wordlift_entities' );
239
+    $admins->add_cap( 'publish_wordlift_entities' );
240
+    $admins->add_cap( 'read_private_wordlift_entities' );
241
+    $admins->add_cap( 'delete_wordlift_entity' );
242
+
243
+    // Assign capabilities to manipulate entities to editors.
244
+    $editors = get_role( 'editor' );
245
+
246
+    $editors->add_cap( 'edit_wordlift_entity' );
247
+    $editors->add_cap( 'edit_wordlift_entities' );
248
+    $editors->add_cap( 'edit_others_wordlift_entities' );
249
+    $editors->add_cap( 'publish_wordlift_entities' );
250
+    $editors->add_cap( 'read_private_wordlift_entities' );
251
+    $editors->add_cap( 'delete_wordlift_entity' );
252 252
 
253 253
 }
254 254
 
255 255
 // Check db status on automated plugins updates
256 256
 function wl_core_update_db_check() {
257 257
 
258
-	wl_core_install_entity_type_data();
258
+    wl_core_install_entity_type_data();
259 259
 
260
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
260
+    if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
261 261
 
262
-		wl_core_upgrade_db_to_1_0();
263
-		wl_core_upgrade_db_1_0_to_3_10();
264
-		wl_core_upgrade_db_3_10_3_12();
265
-		wl_core_upgrade_db_3_12_3_14();
266
-		update_option( 'wl_db_version', WL_DB_VERSION );
262
+        wl_core_upgrade_db_to_1_0();
263
+        wl_core_upgrade_db_1_0_to_3_10();
264
+        wl_core_upgrade_db_3_10_3_12();
265
+        wl_core_upgrade_db_3_12_3_14();
266
+        update_option( 'wl_db_version', WL_DB_VERSION );
267 267
 
268
-	}
268
+    }
269 269
 
270 270
 }
271 271
 
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -54,37 +54,37 @@  discard block
 block discarded – undo
54 54
 		),
55 55
 	);
56 56
 
57
-	foreach ( $terms as $slug => $term ) {
57
+	foreach ($terms as $slug => $term) {
58 58
 
59 59
 		// Create the term if it does not exist, then get its ID
60
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
60
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
61 61
 
62
-		if ( 0 == $term_id || is_null( $term_id ) ) {
63
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
62
+		if (0 == $term_id || is_null($term_id)) {
63
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
64 64
 		} else {
65 65
 			$term_id = $term_id['term_id'];
66
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
66
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
67 67
 		}
68 68
 
69 69
 		// Check for errors.
70
-		if ( is_wp_error( $result ) ) {
71
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
70
+		if (is_wp_error($result)) {
71
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
72 72
 			continue;
73 73
 		}
74 74
 
75 75
 		// Check if 'parent' corresponds to an actual term and get its ID.
76
-		if ( ! isset( $term['parents'] ) ) {
76
+		if ( ! isset($term['parents'])) {
77 77
 			$term['parents'] = array();
78 78
 		}
79 79
 
80 80
 		$parent_ids = array();
81
-		foreach ( $term['parents'] as $parent_slug ) {
82
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
83
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
81
+		foreach ($term['parents'] as $parent_slug) {
82
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
83
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
84 84
 		}
85 85
 
86 86
 		// Define a parent in the WP taxonomy style (not important for WL)
87
-		if ( empty( $parent_ids ) ) {
87
+		if (empty($parent_ids)) {
88 88
 			// No parent
89 89
 			$parent_id = 0;
90 90
 		} else {
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 
95 95
 		// Update term with description, slug and parent
96
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
96
+		wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
97 97
 			'name'        => $term['label'],
98 98
 			'slug'        => $slug,
99 99
 			'description' => $term['description'],
100 100
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
101 101
 			'parent'      => $parent_id,
102
-		) );
102
+		));
103 103
 
104 104
 	}
105 105
 
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 
115 115
 	global $wpdb;
116 116
 	// global $wl_db_version;
117
-	$installed_version = get_option( 'wl_db_version' );
117
+	$installed_version = get_option('wl_db_version');
118 118
 
119
-	if ( WL_DB_VERSION != $installed_version ) {
120
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
119
+	if (WL_DB_VERSION != $installed_version) {
120
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
121 121
 		$charset_collate = $wpdb->get_charset_collate();
122 122
 
123 123
 		// Sql statement for the relation instances custom table
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 EOF;
135 135
 
136 136
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
137
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
138
-		$results = dbDelta( $sql );
137
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
138
+		$results = dbDelta($sql);
139 139
 
140
-		wl_write_log( $results );
140
+		wl_write_log($results);
141 141
 
142
-		update_option( 'wl_db_version', WL_DB_VERSION );
142
+		update_option('wl_db_version', WL_DB_VERSION);
143 143
 	}
144 144
 }
145 145
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function wl_core_upgrade_db_to_1_0() {
153 153
 
154
-	if ( ! get_option( 'wl_db_version' ) ) {
154
+	if ( ! get_option('wl_db_version')) {
155 155
 		wl_core_install_create_relation_instance_table();
156 156
 	}
157 157
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 function wl_core_upgrade_db_1_0_to_3_10() {
168 168
 
169 169
 	// If the DB version is less than 3.10, than flatten the txonomy.
170
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
170
+	if (version_compare(get_option('wl_db_version'), '3.9', '<=')) {
171 171
 
172 172
 		$term_slugs = array(
173 173
 			'thing',
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 			'localbusiness',
180 180
 		);
181 181
 
182
-		foreach ( $term_slugs as $slug ) {
182
+		foreach ($term_slugs as $slug) {
183 183
 
184
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
184
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
185 185
 
186 186
 			// Set the term's parent to 0.
187
-			if ( $term ) {
188
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
187
+			if ($term) {
188
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
189 189
 					'parent' => 0,
190
-				) );
190
+				));
191 191
 			}
192 192
 		}
193 193
 	}
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * initialization does the same, avoid possible race conditions by
209 209
 	 * deferring the actual flush to a later hook.
210 210
 	 */
211
-	add_action( 'wp_loaded', function () {
211
+	add_action('wp_loaded', function() {
212 212
 		flush_rewrite_rules();
213 213
 	} );
214 214
 }
@@ -231,24 +231,24 @@  discard block
 block discarded – undo
231 231
 	);
232 232
 
233 233
 	// Assign capabilities to manipulate entities to admins.
234
-	$admins = get_role( 'administrator' );
234
+	$admins = get_role('administrator');
235 235
 
236
-	$admins->add_cap( 'edit_wordlift_entity' );
237
-	$admins->add_cap( 'edit_wordlift_entities' );
238
-	$admins->add_cap( 'edit_others_wordlift_entities' );
239
-	$admins->add_cap( 'publish_wordlift_entities' );
240
-	$admins->add_cap( 'read_private_wordlift_entities' );
241
-	$admins->add_cap( 'delete_wordlift_entity' );
236
+	$admins->add_cap('edit_wordlift_entity');
237
+	$admins->add_cap('edit_wordlift_entities');
238
+	$admins->add_cap('edit_others_wordlift_entities');
239
+	$admins->add_cap('publish_wordlift_entities');
240
+	$admins->add_cap('read_private_wordlift_entities');
241
+	$admins->add_cap('delete_wordlift_entity');
242 242
 
243 243
 	// Assign capabilities to manipulate entities to editors.
244
-	$editors = get_role( 'editor' );
244
+	$editors = get_role('editor');
245 245
 
246
-	$editors->add_cap( 'edit_wordlift_entity' );
247
-	$editors->add_cap( 'edit_wordlift_entities' );
248
-	$editors->add_cap( 'edit_others_wordlift_entities' );
249
-	$editors->add_cap( 'publish_wordlift_entities' );
250
-	$editors->add_cap( 'read_private_wordlift_entities' );
251
-	$editors->add_cap( 'delete_wordlift_entity' );
246
+	$editors->add_cap('edit_wordlift_entity');
247
+	$editors->add_cap('edit_wordlift_entities');
248
+	$editors->add_cap('edit_others_wordlift_entities');
249
+	$editors->add_cap('publish_wordlift_entities');
250
+	$editors->add_cap('read_private_wordlift_entities');
251
+	$editors->add_cap('delete_wordlift_entity');
252 252
 
253 253
 }
254 254
 
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 
258 258
 	wl_core_install_entity_type_data();
259 259
 
260
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
260
+	if (get_option('wl_db_version') != WL_DB_VERSION) {
261 261
 
262 262
 		wl_core_upgrade_db_to_1_0();
263 263
 		wl_core_upgrade_db_1_0_to_3_10();
264 264
 		wl_core_upgrade_db_3_10_3_12();
265 265
 		wl_core_upgrade_db_3_12_3_14();
266
-		update_option( 'wl_db_version', WL_DB_VERSION );
266
+		update_option('wl_db_version', WL_DB_VERSION);
267 267
 
268 268
 	}
269 269
 
270 270
 }
271 271
 
272
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
272
+add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first
Please login to merge, or discard this patch.
src/admin/class-wordlift-entity-type-settings.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -30,208 +30,208 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class Wordlift_Admin_Entity_Type_Settings {
32 32
 
33
-	/**
34
-	 * A {@link Wordlift_Log_Service} instance.
35
-	 *
36
-	 * @since  3.14.0
37
-	 * @access private
38
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
39
-	 */
40
-	private $log;
41
-
42
-	/**
43
-	 * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance.
44
-	 *
45
-	 * @since 3.14.0
46
-	 */
47
-	public function __construct() {
48
-
49
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Handle menu registration.
55
-	 *
56
-	 * The registration is required, although we do not want to actually to add
57
-	 * an item to the menu, in order to "whitelist" the access to the settings page in
58
-	 * the admin.
59
-	 *
60
-	 * @since 3.11.0
61
-	 */
62
-	public function admin_menu() {
63
-
64
-		/*
33
+    /**
34
+     * A {@link Wordlift_Log_Service} instance.
35
+     *
36
+     * @since  3.14.0
37
+     * @access private
38
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
39
+     */
40
+    private $log;
41
+
42
+    /**
43
+     * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance.
44
+     *
45
+     * @since 3.14.0
46
+     */
47
+    public function __construct() {
48
+
49
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
50
+
51
+    }
52
+
53
+    /**
54
+     * Handle menu registration.
55
+     *
56
+     * The registration is required, although we do not want to actually to add
57
+     * an item to the menu, in order to "whitelist" the access to the settings page in
58
+     * the admin.
59
+     *
60
+     * @since 3.11.0
61
+     */
62
+    public function admin_menu() {
63
+
64
+        /*
65 65
 		 * Before anything else check if an settings form was submitted.
66 66
 		 * This has to be done before any output happens in order to be able to
67 67
 		 * display proper "die" error messages and redirect.
68 68
 		 */
69
-		if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
69
+        if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
70 70
 
71
-			// Validate inputs. Do not return on invalid parameters or capabilities.
72
-			$this->validate_proper_term();
71
+            // Validate inputs. Do not return on invalid parameters or capabilities.
72
+            $this->validate_proper_term();
73 73
 
74
-			// If proper form submission, handle it and redirect back to the settings page.
75
-			if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
76
-				$this->handle_form_submission();
77
-			}
74
+            // If proper form submission, handle it and redirect back to the settings page.
75
+            if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
76
+                $this->handle_form_submission();
77
+            }
78 78
 
79
-			// Register admin notices handler.
80
-			add_action( 'admin_notices', array( $this, 'admin_notice' ) );
79
+            // Register admin notices handler.
80
+            add_action( 'admin_notices', array( $this, 'admin_notice' ) );
81 81
 
82
-		}
82
+        }
83 83
 
84
-		/*
84
+        /*
85 85
 		 * Use a null parent slug to prevent the menu from actually appearing
86 86
 		 * in the admin menu.
87 87
 		 */
88
-		// @todo: use the new {@link Wordlift_Admin_Page}.
89
-		add_submenu_page(
90
-			null,
91
-			__( 'Edit Entity term', 'wordlift' ),
92
-			__( 'Edit Entity term', 'wordlift' ),
93
-			'manage_options',
94
-			'wl_entity_type_settings',
95
-			array( $this, 'render' )
96
-		);
97
-	}
98
-
99
-	/**
100
-	 * Output admin notices if needed, based on the message url parameter.
101
-	 * A value of 1 indicates that a successful save was done.
102
-	 *
103
-	 * @since 3.11.0
104
-	 */
105
-	function admin_notice() {
106
-		if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
107
-			?>
88
+        // @todo: use the new {@link Wordlift_Admin_Page}.
89
+        add_submenu_page(
90
+            null,
91
+            __( 'Edit Entity term', 'wordlift' ),
92
+            __( 'Edit Entity term', 'wordlift' ),
93
+            'manage_options',
94
+            'wl_entity_type_settings',
95
+            array( $this, 'render' )
96
+        );
97
+    }
98
+
99
+    /**
100
+     * Output admin notices if needed, based on the message url parameter.
101
+     * A value of 1 indicates that a successful save was done.
102
+     *
103
+     * @since 3.11.0
104
+     */
105
+    function admin_notice() {
106
+        if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
107
+            ?>
108 108
 			<div class="notice notice-success is-dismissible">
109 109
 				<p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p>
110 110
 			</div>
111 111
 			<?php
112
-		}
113
-	}
114
-
115
-	/**
116
-	 * Validate the existence of the entity type indicated by the tag_ID url
117
-	 * parameter before doing any processing. Done before any output to mimic
118
-	 * the way WordPress handles same situation with "normal" term editing screens.
119
-	 *
120
-	 * @since 3.11.0
121
-	 */
122
-	function validate_proper_term() {
123
-
124
-		// Validate capabilities.
125
-		if ( ! current_user_can( 'manage_options' ) ) {
126
-			wp_die(
127
-				'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
128
-				'<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
129
-				403
130
-			);
131
-		}
132
-
133
-		// Get the term id and the actual term.
134
-		$term_id = (int) $_REQUEST['tag_ID'];
135
-
136
-		if ( ! term_exists( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ) ) {
137
-			wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
138
-		}
139
-
140
-	}
141
-
142
-	/**
143
-	 * Handle the form submission of the settings form. On successful
144
-	 * handling redirect tp the setting edit page.
145
-	 *
146
-	 * @since 3.11.0
147
-	 */
148
-	function handle_form_submission() {
149
-
150
-		$term_id = (int) $_POST['tag_ID'];
151
-
152
-		// Check the nonce.
153
-		check_admin_referer( 'update-entity_type_term_' . $term_id );
154
-
155
-		$term = get_term( $term_id, 'wl_entity_type' );
156
-
157
-		$this->set_setting(
158
-			$term_id,
159
-			trim( wp_unslash( $_POST['title'] ) ),
160
-			wp_unslash( $_POST['description'] )
161
-		);
162
-
163
-		// Redirect back to the term settings page and indicate a save was done.
164
-		$url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
165
-
166
-		wp_redirect( $url );
167
-		exit;
168
-
169
-	}
170
-
171
-	/**
172
-	 * Render the settings page for the term.
173
-	 *
174
-	 * Access and parameter validity is assumed to be done earlier.
175
-	 *
176
-	 * @since 3.11.0
177
-	 */
178
-	function render() {
179
-
180
-		// Set variables used by the partial
181
-		$term_id  = absint( $_REQUEST['tag_ID'] );
182
-		$settings = $this->get_setting( $term_id );
183
-
184
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
185
-
186
-	}
187
-
188
-	/**
189
-	 * Store the entity type term settings in the DB
190
-	 *
191
-	 * @since 3.11.0
192
-	 *
193
-	 * @param    integer $term_id     The ID of the entity type term
194
-	 * @param    string  $title       The override for the terms title.
195
-	 * @param    string  $description The override for the terms description.
196
-	 *
197
-	 */
198
-	function set_setting( $term_id, $title, $description ) {
199
-
200
-		$settings             = get_option( 'wl_entity_type_settings', array() );
201
-		$settings[ $term_id ] = array(
202
-			'title'       => $title,
203
-			'description' => $description,
204
-		);
205
-		update_option( 'wl_entity_type_settings', $settings );
206
-
207
-	}
208
-
209
-	/**
210
-	 * Retrieve the entity type term settings from the DB
211
-	 *
212
-	 * @since 3.11.0
213
-	 *
214
-	 * @param    integer $term_id The ID of the entity type term
215
-	 *
216
-	 * @return    null|array {
217
-	 *                null is returned when there are no settings otherwise
218
-	 *                an array is returned with following fields
219
-	 *
220
-	 * @type    string    title    The overriding title for the term
221
-	 * @type    string    description    The overriding description for the term
222
-	 *            }
223
-	 */
224
-	function get_setting( $term_id ) {
225
-
226
-		$settings = get_option( 'wl_entity_type_settings', array() );
227
-
228
-		if ( isset( $settings[ $term_id ] ) ) {
229
-			return $settings[ $term_id ];
230
-		}
231
-
232
-		$this->log->warn( "No settings found for term id $term_id." );
233
-
234
-		return null;
235
-	}
112
+        }
113
+    }
114
+
115
+    /**
116
+     * Validate the existence of the entity type indicated by the tag_ID url
117
+     * parameter before doing any processing. Done before any output to mimic
118
+     * the way WordPress handles same situation with "normal" term editing screens.
119
+     *
120
+     * @since 3.11.0
121
+     */
122
+    function validate_proper_term() {
123
+
124
+        // Validate capabilities.
125
+        if ( ! current_user_can( 'manage_options' ) ) {
126
+            wp_die(
127
+                '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
128
+                '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
129
+                403
130
+            );
131
+        }
132
+
133
+        // Get the term id and the actual term.
134
+        $term_id = (int) $_REQUEST['tag_ID'];
135
+
136
+        if ( ! term_exists( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ) ) {
137
+            wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
138
+        }
139
+
140
+    }
141
+
142
+    /**
143
+     * Handle the form submission of the settings form. On successful
144
+     * handling redirect tp the setting edit page.
145
+     *
146
+     * @since 3.11.0
147
+     */
148
+    function handle_form_submission() {
149
+
150
+        $term_id = (int) $_POST['tag_ID'];
151
+
152
+        // Check the nonce.
153
+        check_admin_referer( 'update-entity_type_term_' . $term_id );
154
+
155
+        $term = get_term( $term_id, 'wl_entity_type' );
156
+
157
+        $this->set_setting(
158
+            $term_id,
159
+            trim( wp_unslash( $_POST['title'] ) ),
160
+            wp_unslash( $_POST['description'] )
161
+        );
162
+
163
+        // Redirect back to the term settings page and indicate a save was done.
164
+        $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
165
+
166
+        wp_redirect( $url );
167
+        exit;
168
+
169
+    }
170
+
171
+    /**
172
+     * Render the settings page for the term.
173
+     *
174
+     * Access and parameter validity is assumed to be done earlier.
175
+     *
176
+     * @since 3.11.0
177
+     */
178
+    function render() {
179
+
180
+        // Set variables used by the partial
181
+        $term_id  = absint( $_REQUEST['tag_ID'] );
182
+        $settings = $this->get_setting( $term_id );
183
+
184
+        include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
185
+
186
+    }
187
+
188
+    /**
189
+     * Store the entity type term settings in the DB
190
+     *
191
+     * @since 3.11.0
192
+     *
193
+     * @param    integer $term_id     The ID of the entity type term
194
+     * @param    string  $title       The override for the terms title.
195
+     * @param    string  $description The override for the terms description.
196
+     *
197
+     */
198
+    function set_setting( $term_id, $title, $description ) {
199
+
200
+        $settings             = get_option( 'wl_entity_type_settings', array() );
201
+        $settings[ $term_id ] = array(
202
+            'title'       => $title,
203
+            'description' => $description,
204
+        );
205
+        update_option( 'wl_entity_type_settings', $settings );
206
+
207
+    }
208
+
209
+    /**
210
+     * Retrieve the entity type term settings from the DB
211
+     *
212
+     * @since 3.11.0
213
+     *
214
+     * @param    integer $term_id The ID of the entity type term
215
+     *
216
+     * @return    null|array {
217
+     *                null is returned when there are no settings otherwise
218
+     *                an array is returned with following fields
219
+     *
220
+     * @type    string    title    The overriding title for the term
221
+     * @type    string    description    The overriding description for the term
222
+     *            }
223
+     */
224
+    function get_setting( $term_id ) {
225
+
226
+        $settings = get_option( 'wl_entity_type_settings', array() );
227
+
228
+        if ( isset( $settings[ $term_id ] ) ) {
229
+            return $settings[ $term_id ];
230
+        }
231
+
232
+        $this->log->warn( "No settings found for term id $term_id." );
233
+
234
+        return null;
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since      3.11.0
13 13
  */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function __construct() {
48 48
 
49
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
49
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Admin_Entity_Type_Settings');
50 50
 
51 51
 	}
52 52
 
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
 		 * This has to be done before any output happens in order to be able to
67 67
 		 * display proper "die" error messages and redirect.
68 68
 		 */
69
-		if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
69
+		if (isset($_GET['page']) && ('wl_entity_type_settings' === $_GET['page'])) {
70 70
 
71 71
 			// Validate inputs. Do not return on invalid parameters or capabilities.
72 72
 			$this->validate_proper_term();
73 73
 
74 74
 			// If proper form submission, handle it and redirect back to the settings page.
75
-			if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
75
+			if (isset($_POST['action']) && ('wl_edit_entity_type_term' === $_POST['action'])) {
76 76
 				$this->handle_form_submission();
77 77
 			}
78 78
 
79 79
 			// Register admin notices handler.
80
-			add_action( 'admin_notices', array( $this, 'admin_notice' ) );
80
+			add_action('admin_notices', array($this, 'admin_notice'));
81 81
 
82 82
 		}
83 83
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 		// @todo: use the new {@link Wordlift_Admin_Page}.
89 89
 		add_submenu_page(
90 90
 			null,
91
-			__( 'Edit Entity term', 'wordlift' ),
92
-			__( 'Edit Entity term', 'wordlift' ),
91
+			__('Edit Entity term', 'wordlift'),
92
+			__('Edit Entity term', 'wordlift'),
93 93
 			'manage_options',
94 94
 			'wl_entity_type_settings',
95
-			array( $this, 'render' )
95
+			array($this, 'render')
96 96
 		);
97 97
 	}
98 98
 
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	 * @since 3.11.0
104 104
 	 */
105 105
 	function admin_notice() {
106
-		if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
106
+		if (isset($_GET['message']) && ('1' === $_GET['message'])) {
107 107
 			?>
108 108
 			<div class="notice notice-success is-dismissible">
109
-				<p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p>
109
+				<p><?php esc_html_e('Settings saved', 'wordlift') ?></p>
110 110
 			</div>
111 111
 			<?php
112 112
 		}
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 	function validate_proper_term() {
123 123
 
124 124
 		// Validate capabilities.
125
-		if ( ! current_user_can( 'manage_options' ) ) {
125
+		if ( ! current_user_can('manage_options')) {
126 126
 			wp_die(
127
-				'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
128
-				'<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
127
+				'<h1>'.__('Cheatin&#8217; uh?').'</h1>'.
128
+				'<p>'.__('Sorry, you are not allowed to edit this item.').'</p>',
129 129
 				403
130 130
 			);
131 131
 		}
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 		// Get the term id and the actual term.
134 134
 		$term_id = (int) $_REQUEST['tag_ID'];
135 135
 
136
-		if ( ! term_exists( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ) ) {
137
-			wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
136
+		if ( ! term_exists($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME)) {
137
+			wp_die(__('You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift'));
138 138
 		}
139 139
 
140 140
 	}
@@ -150,20 +150,20 @@  discard block
 block discarded – undo
150 150
 		$term_id = (int) $_POST['tag_ID'];
151 151
 
152 152
 		// Check the nonce.
153
-		check_admin_referer( 'update-entity_type_term_' . $term_id );
153
+		check_admin_referer('update-entity_type_term_'.$term_id);
154 154
 
155
-		$term = get_term( $term_id, 'wl_entity_type' );
155
+		$term = get_term($term_id, 'wl_entity_type');
156 156
 
157 157
 		$this->set_setting(
158 158
 			$term_id,
159
-			trim( wp_unslash( $_POST['title'] ) ),
160
-			wp_unslash( $_POST['description'] )
159
+			trim(wp_unslash($_POST['title'])),
160
+			wp_unslash($_POST['description'])
161 161
 		);
162 162
 
163 163
 		// Redirect back to the term settings page and indicate a save was done.
164
-		$url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
164
+		$url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1");
165 165
 
166
-		wp_redirect( $url );
166
+		wp_redirect($url);
167 167
 		exit;
168 168
 
169 169
 	}
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	function render() {
179 179
 
180 180
 		// Set variables used by the partial
181
-		$term_id  = absint( $_REQUEST['tag_ID'] );
182
-		$settings = $this->get_setting( $term_id );
181
+		$term_id  = absint($_REQUEST['tag_ID']);
182
+		$settings = $this->get_setting($term_id);
183 183
 
184
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
184
+		include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-entity-type-settings.php';
185 185
 
186 186
 	}
187 187
 
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
 	 * @param    string  $description The override for the terms description.
196 196
 	 *
197 197
 	 */
198
-	function set_setting( $term_id, $title, $description ) {
198
+	function set_setting($term_id, $title, $description) {
199 199
 
200
-		$settings             = get_option( 'wl_entity_type_settings', array() );
201
-		$settings[ $term_id ] = array(
200
+		$settings             = get_option('wl_entity_type_settings', array());
201
+		$settings[$term_id] = array(
202 202
 			'title'       => $title,
203 203
 			'description' => $description,
204 204
 		);
205
-		update_option( 'wl_entity_type_settings', $settings );
205
+		update_option('wl_entity_type_settings', $settings);
206 206
 
207 207
 	}
208 208
 
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
 	 * @type    string    description    The overriding description for the term
222 222
 	 *            }
223 223
 	 */
224
-	function get_setting( $term_id ) {
224
+	function get_setting($term_id) {
225 225
 
226
-		$settings = get_option( 'wl_entity_type_settings', array() );
226
+		$settings = get_option('wl_entity_type_settings', array());
227 227
 
228
-		if ( isset( $settings[ $term_id ] ) ) {
229
-			return $settings[ $term_id ];
228
+		if (isset($settings[$term_id])) {
229
+			return $settings[$term_id];
230 230
 		}
231 231
 
232
-		$this->log->warn( "No settings found for term id $term_id." );
232
+		$this->log->warn("No settings found for term id $term_id.");
233 233
 
234 234
 		return null;
235 235
 	}
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -22,161 +22,161 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * The {@link Wordlift_Configuration_Service} instance.
45
-	 *
46
-	 * @since  3.14.0
47
-	 * @access private
48
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
-	 */
50
-	private $configuration_service;
51
-
52
-	/**
53
-	 * The {@link Wordlift_User_Service} instance.
54
-	 *
55
-	 * @since  3.14.0
56
-	 * @access private
57
-	 * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
-	 */
59
-	private $user_service;
60
-
61
-	/**
62
-	 * Initialize the class and set its properties.
63
-	 *
64
-	 * @since  1.0.0
65
-	 *
66
-	 * @param string                          $plugin_name           The name of this plugin.
67
-	 * @param string                          $version               The version of this plugin.
68
-	 * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
-	 * @param \Wordlift_Notice_Service        $notice_service        The notice service.
70
-	 * @param \Wordlift_User_Service          $user_service          The {@link Wordlift_User_Service} instance.
71
-	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
-
74
-		$this->plugin_name = $plugin_name;
75
-		$this->version     = $version;
76
-
77
-		$this->configuration_service = $configuration_service;
78
-		$this->user_service          = $user_service;
79
-
80
-		$dataset_uri = $configuration_service->get_dataset_uri();
81
-		$key         = $configuration_service->get_key();
82
-
83
-		if ( empty( $dataset_uri ) ) {
84
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
-			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
-			}
90
-			$notice_service->add_error( $error );
91
-		}
92
-
93
-	}
94
-
95
-	/**
96
-	 * Register the stylesheets for the admin area.
97
-	 *
98
-	 * @since    1.0.0
99
-	 */
100
-	public function enqueue_styles() {
101
-
102
-		/**
103
-		 * This function is provided for demonstration purposes only.
104
-		 *
105
-		 * An instance of this class should be passed to the run() function
106
-		 * defined in Wordlift_Loader as all of the hooks are defined
107
-		 * in that particular class.
108
-		 *
109
-		 * The Wordlift_Loader will then create the relationship
110
-		 * between the defined hooks and the functions defined in this
111
-		 * class.
112
-		 */
113
-
114
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
115
-
116
-	}
117
-
118
-	/**
119
-	 * Register the JavaScript for the admin area.
120
-	 *
121
-	 * @since    1.0.0
122
-	 */
123
-	public function enqueue_scripts() {
124
-
125
-		/**
126
-		 * This function is provided for demonstration purposes only.
127
-		 *
128
-		 * An instance of this class should be passed to the run() function
129
-		 * defined in Wordlift_Loader as all of the hooks are defined
130
-		 * in that particular class.
131
-		 *
132
-		 * The Wordlift_Loader will then create the relationship
133
-		 * between the defined hooks and the functions defined in this
134
-		 * class.
135
-		 */
136
-
137
-		// Enqueue the admin scripts.
138
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
139
-			'jquery',
140
-			'underscore',
141
-			'backbone',
142
-		), $this->version, false );
143
-
144
-		// Set the basic params.
145
-		$params = array(
146
-			// @todo scripts in admin should use wp.post.
147
-			'ajax_url'            => admin_url( 'admin-ajax.php' ),
148
-			// @todo remove specific actions from settings.
149
-			'action'              => 'entity_by_title',
150
-			'datasetUri'          => $this->configuration_service->get_dataset_uri(),
151
-			'language'            => $this->configuration_service->get_language_code(),
152
-			'link_by_default'     => $this->configuration_service->is_link_by_default(),
153
-			// Whether the current user is allowed to create new entities.
154
-			//
155
-			// @see https://github.com/insideout10/wordlift-plugin/issues/561
156
-			'can_create_entities' => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
157
-			'l10n'                => array(
158
-				'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
159
-				'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
160
-				'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
161
-			),
162
-		);
163
-
164
-		// Set post-related values if there's a current post.
165
-		if ( null !== $post = $entity_being_edited = get_post() ) {
166
-
167
-			$params['post_id']           = $entity_being_edited->ID;
168
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
169
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
170
-			// from the results, since we don't want the current entity to be discovered by the analysis.
171
-			//
172
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
173
-			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
174
-
175
-		}
176
-
177
-		// Finally output the params as `wlSettings` for JavaScript code.
178
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
179
-
180
-	}
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * The {@link Wordlift_Configuration_Service} instance.
45
+     *
46
+     * @since  3.14.0
47
+     * @access private
48
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
+     */
50
+    private $configuration_service;
51
+
52
+    /**
53
+     * The {@link Wordlift_User_Service} instance.
54
+     *
55
+     * @since  3.14.0
56
+     * @access private
57
+     * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
+     */
59
+    private $user_service;
60
+
61
+    /**
62
+     * Initialize the class and set its properties.
63
+     *
64
+     * @since  1.0.0
65
+     *
66
+     * @param string                          $plugin_name           The name of this plugin.
67
+     * @param string                          $version               The version of this plugin.
68
+     * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
+     * @param \Wordlift_Notice_Service        $notice_service        The notice service.
70
+     * @param \Wordlift_User_Service          $user_service          The {@link Wordlift_User_Service} instance.
71
+     */
72
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
+
74
+        $this->plugin_name = $plugin_name;
75
+        $this->version     = $version;
76
+
77
+        $this->configuration_service = $configuration_service;
78
+        $this->user_service          = $user_service;
79
+
80
+        $dataset_uri = $configuration_service->get_dataset_uri();
81
+        $key         = $configuration_service->get_key();
82
+
83
+        if ( empty( $dataset_uri ) ) {
84
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
+            if ( empty( $key ) ) {
86
+                $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
+            } else {
88
+                $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
+            }
90
+            $notice_service->add_error( $error );
91
+        }
92
+
93
+    }
94
+
95
+    /**
96
+     * Register the stylesheets for the admin area.
97
+     *
98
+     * @since    1.0.0
99
+     */
100
+    public function enqueue_styles() {
101
+
102
+        /**
103
+         * This function is provided for demonstration purposes only.
104
+         *
105
+         * An instance of this class should be passed to the run() function
106
+         * defined in Wordlift_Loader as all of the hooks are defined
107
+         * in that particular class.
108
+         *
109
+         * The Wordlift_Loader will then create the relationship
110
+         * between the defined hooks and the functions defined in this
111
+         * class.
112
+         */
113
+
114
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
115
+
116
+    }
117
+
118
+    /**
119
+     * Register the JavaScript for the admin area.
120
+     *
121
+     * @since    1.0.0
122
+     */
123
+    public function enqueue_scripts() {
124
+
125
+        /**
126
+         * This function is provided for demonstration purposes only.
127
+         *
128
+         * An instance of this class should be passed to the run() function
129
+         * defined in Wordlift_Loader as all of the hooks are defined
130
+         * in that particular class.
131
+         *
132
+         * The Wordlift_Loader will then create the relationship
133
+         * between the defined hooks and the functions defined in this
134
+         * class.
135
+         */
136
+
137
+        // Enqueue the admin scripts.
138
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
139
+            'jquery',
140
+            'underscore',
141
+            'backbone',
142
+        ), $this->version, false );
143
+
144
+        // Set the basic params.
145
+        $params = array(
146
+            // @todo scripts in admin should use wp.post.
147
+            'ajax_url'            => admin_url( 'admin-ajax.php' ),
148
+            // @todo remove specific actions from settings.
149
+            'action'              => 'entity_by_title',
150
+            'datasetUri'          => $this->configuration_service->get_dataset_uri(),
151
+            'language'            => $this->configuration_service->get_language_code(),
152
+            'link_by_default'     => $this->configuration_service->is_link_by_default(),
153
+            // Whether the current user is allowed to create new entities.
154
+            //
155
+            // @see https://github.com/insideout10/wordlift-plugin/issues/561
156
+            'can_create_entities' => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
157
+            'l10n'                => array(
158
+                'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
159
+                'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
160
+                'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
161
+            ),
162
+        );
163
+
164
+        // Set post-related values if there's a current post.
165
+        if ( null !== $post = $entity_being_edited = get_post() ) {
166
+
167
+            $params['post_id']           = $entity_being_edited->ID;
168
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
169
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
170
+            // from the results, since we don't want the current entity to be discovered by the analysis.
171
+            //
172
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
173
+            $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
174
+
175
+        }
176
+
177
+        // Finally output the params as `wlSettings` for JavaScript code.
178
+        wp_localize_script( $this->plugin_name, 'wlSettings', $params );
179
+
180
+    }
181 181
 
182 182
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param \Wordlift_Notice_Service        $notice_service        The notice service.
70 70
 	 * @param \Wordlift_User_Service          $user_service          The {@link Wordlift_User_Service} instance.
71 71
 	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
72
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) {
73 73
 
74 74
 		$this->plugin_name = $plugin_name;
75 75
 		$this->version     = $version;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 		$dataset_uri = $configuration_service->get_dataset_uri();
81 81
 		$key         = $configuration_service->get_key();
82 82
 
83
-		if ( empty( $dataset_uri ) ) {
83
+		if (empty($dataset_uri)) {
84 84
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
85
+			if (empty($key)) {
86
+				$error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
87 87
 			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
88
+				$error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
89 89
 			}
90
-			$notice_service->add_error( $error );
90
+			$notice_service->add_error($error);
91 91
 		}
92 92
 
93 93
 	}
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		 * class.
112 112
 		 */
113 113
 
114
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
114
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
115 115
 
116 116
 	}
117 117
 
@@ -135,16 +135,16 @@  discard block
 block discarded – undo
135 135
 		 */
136 136
 
137 137
 		// Enqueue the admin scripts.
138
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
138
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wordlift-admin.bundle.js', array(
139 139
 			'jquery',
140 140
 			'underscore',
141 141
 			'backbone',
142
-		), $this->version, false );
142
+		), $this->version, false);
143 143
 
144 144
 		// Set the basic params.
145 145
 		$params = array(
146 146
 			// @todo scripts in admin should use wp.post.
147
-			'ajax_url'            => admin_url( 'admin-ajax.php' ),
147
+			'ajax_url'            => admin_url('admin-ajax.php'),
148 148
 			// @todo remove specific actions from settings.
149 149
 			'action'              => 'entity_by_title',
150 150
 			'datasetUri'          => $this->configuration_service->get_dataset_uri(),
@@ -153,29 +153,29 @@  discard block
 block discarded – undo
153 153
 			// Whether the current user is allowed to create new entities.
154 154
 			//
155 155
 			// @see https://github.com/insideout10/wordlift-plugin/issues/561
156
-			'can_create_entities' => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
156
+			'can_create_entities' => current_user_can('edit_wordlift_entities') ? 'yes' : 'no',
157 157
 			'l10n'                => array(
158
-				'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
159
-				'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
160
-				'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
158
+				'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'),
159
+				'logo_selection_title'                               => __('WordLift Choose Logo', 'wordlift'),
160
+				'logo_selection_button'                              => array('text' => __('Choose Logo', 'wordlift')),
161 161
 			),
162 162
 		);
163 163
 
164 164
 		// Set post-related values if there's a current post.
165
-		if ( null !== $post = $entity_being_edited = get_post() ) {
165
+		if (null !== $post = $entity_being_edited = get_post()) {
166 166
 
167 167
 			$params['post_id']           = $entity_being_edited->ID;
168
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
168
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric(get_the_ID());
169 169
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
170 170
 			// from the results, since we don't want the current entity to be discovered by the analysis.
171 171
 			//
172 172
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
173
-			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
173
+			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri($entity_being_edited->ID);
174 174
 
175 175
 		}
176 176
 
177 177
 		// Finally output the params as `wlSettings` for JavaScript code.
178
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
178
+		wp_localize_script($this->plugin_name, 'wlSettings', $params);
179 179
 
180 180
 	}
181 181
 
Please login to merge, or discard this patch.