Completed
Push — develop ( e2550f...3d7310 )
by David
02:32
created
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -11,91 +11,91 @@  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
-	// Set the taxonomy data.
17
-	// Note: parent types must be defined before child types.
18
-	$terms = array(
19
-		'thing'         => array(
20
-			'label'       => 'Thing',
21
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
22
-		),
23
-		'creative-work' => array(
24
-			'label'       => 'CreativeWork',
25
-			'description' => 'A creative work (or a Music Album).',
26
-		),
27
-		'event'         => array(
28
-			'label'       => 'Event',
29
-			'description' => 'An event.',
30
-		),
31
-		'organization'  => array(
32
-			'label'       => 'Organization',
33
-			'description' => 'An organization, including a government or a newspaper.',
34
-		),
35
-		'person'        => array(
36
-			'label'       => 'Person',
37
-			'description' => 'A person (or a music artist).',
38
-		),
39
-		'place'         => array(
40
-			'label'       => 'Place',
41
-			'description' => 'A place.',
42
-		),
43
-		'localbusiness' => array(
44
-			'label'       => 'LocalBusiness',
45
-			'description' => 'A local business.',
46
-		),
47
-	);
48
-
49
-	foreach ( $terms as $slug => $term ) {
50
-
51
-		// Create the term if it does not exist, then get its ID
52
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
53
-
54
-		if ( 0 == $term_id || is_null( $term_id ) ) {
55
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
56
-		} else {
57
-			$term_id = $term_id['term_id'];
58
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
59
-		}
60
-
61
-		// Check for errors.
62
-		if ( is_wp_error( $result ) ) {
63
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
64
-			continue;
65
-		}
66
-
67
-		// Check if 'parent' corresponds to an actual term and get its ID.
68
-		if ( ! isset( $term['parents'] ) ) {
69
-			$term['parents'] = array();
70
-		}
71
-
72
-		$parent_ids = array();
73
-		foreach ( $term['parents'] as $parent_slug ) {
74
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
75
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
76
-		}
77
-
78
-		// Define a parent in the WP taxonomy style (not important for WL)
79
-		if ( empty( $parent_ids ) ) {
80
-			// No parent
81
-			$parent_id = 0;
82
-		} else {
83
-			// Get first parent
84
-			$parent_id = $parent_ids[0];
85
-		}
86
-
87
-		// Update term with description, slug and parent
88
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
89
-			'name'        => $term['label'],
90
-			'slug'        => $slug,
91
-			'description' => $term['description'],
92
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
93
-			'parent'      => $parent_id,
94
-		) );
95
-
96
-	}
97
-
98
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
14
+    Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
15
+
16
+    // Set the taxonomy data.
17
+    // Note: parent types must be defined before child types.
18
+    $terms = array(
19
+        'thing'         => array(
20
+            'label'       => 'Thing',
21
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
22
+        ),
23
+        'creative-work' => array(
24
+            'label'       => 'CreativeWork',
25
+            'description' => 'A creative work (or a Music Album).',
26
+        ),
27
+        'event'         => array(
28
+            'label'       => 'Event',
29
+            'description' => 'An event.',
30
+        ),
31
+        'organization'  => array(
32
+            'label'       => 'Organization',
33
+            'description' => 'An organization, including a government or a newspaper.',
34
+        ),
35
+        'person'        => array(
36
+            'label'       => 'Person',
37
+            'description' => 'A person (or a music artist).',
38
+        ),
39
+        'place'         => array(
40
+            'label'       => 'Place',
41
+            'description' => 'A place.',
42
+        ),
43
+        'localbusiness' => array(
44
+            'label'       => 'LocalBusiness',
45
+            'description' => 'A local business.',
46
+        ),
47
+    );
48
+
49
+    foreach ( $terms as $slug => $term ) {
50
+
51
+        // Create the term if it does not exist, then get its ID
52
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
53
+
54
+        if ( 0 == $term_id || is_null( $term_id ) ) {
55
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
56
+        } else {
57
+            $term_id = $term_id['term_id'];
58
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
59
+        }
60
+
61
+        // Check for errors.
62
+        if ( is_wp_error( $result ) ) {
63
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
64
+            continue;
65
+        }
66
+
67
+        // Check if 'parent' corresponds to an actual term and get its ID.
68
+        if ( ! isset( $term['parents'] ) ) {
69
+            $term['parents'] = array();
70
+        }
71
+
72
+        $parent_ids = array();
73
+        foreach ( $term['parents'] as $parent_slug ) {
74
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
75
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
76
+        }
77
+
78
+        // Define a parent in the WP taxonomy style (not important for WL)
79
+        if ( empty( $parent_ids ) ) {
80
+            // No parent
81
+            $parent_id = 0;
82
+        } else {
83
+            // Get first parent
84
+            $parent_id = $parent_ids[0];
85
+        }
86
+
87
+        // Update term with description, slug and parent
88
+        wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
89
+            'name'        => $term['label'],
90
+            'slug'        => $slug,
91
+            'description' => $term['description'],
92
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
93
+            'parent'      => $parent_id,
94
+        ) );
95
+
96
+    }
97
+
98
+    Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
99 99
 
100 100
 }
101 101
 
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
  */
105 105
 function wl_core_install_create_relation_instance_table() {
106 106
 
107
-	global $wpdb;
108
-	// global $wl_db_version;
109
-	$installed_version = get_option( 'wl_db_version' );
107
+    global $wpdb;
108
+    // global $wl_db_version;
109
+    $installed_version = get_option( 'wl_db_version' );
110 110
 
111
-	if ( WL_DB_VERSION != $installed_version ) {
112
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
113
-		$charset_collate = $wpdb->get_charset_collate();
111
+    if ( WL_DB_VERSION != $installed_version ) {
112
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
113
+        $charset_collate = $wpdb->get_charset_collate();
114 114
 
115
-		// Sql statement for the relation instances custom table
116
-		$sql = <<<EOF
115
+        // Sql statement for the relation instances custom table
116
+        $sql = <<<EOF
117 117
 			CREATE TABLE $table_name (
118 118
   				id int(11) NOT NULL AUTO_INCREMENT,
119 119
   				subject_id int(11) NOT NULL,
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 			) $charset_collate;
126 126
 EOF;
127 127
 
128
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
129
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
130
-		$results = dbDelta( $sql );
128
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
129
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
130
+        $results = dbDelta( $sql );
131 131
 
132
-		wl_write_log( $results );
132
+        wl_write_log( $results );
133 133
 
134
-		update_option( 'wl_db_version', WL_DB_VERSION );
135
-	}
134
+        update_option( 'wl_db_version', WL_DB_VERSION );
135
+    }
136 136
 }
137 137
 
138 138
 /**
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
  */
144 144
 function wl_core_upgrade_db_to_1_0() {
145 145
 
146
-	if ( ! get_option( 'wl_db_version' ) ) {
147
-		wl_core_install_create_relation_instance_table();
148
-	}
146
+    if ( ! get_option( 'wl_db_version' ) ) {
147
+        wl_core_install_create_relation_instance_table();
148
+    }
149 149
 
150 150
 }
151 151
 
@@ -158,31 +158,31 @@  discard block
 block discarded – undo
158 158
  */
159 159
 function wl_core_upgrade_db_1_0_to_3_10() {
160 160
 
161
-	// If the DB version is less than 3.10, than flatten the txonomy.
162
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
161
+    // If the DB version is less than 3.10, than flatten the txonomy.
162
+    if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
163 163
 
164
-		$term_slugs = array(
165
-			'thing',
166
-			'creative-work',
167
-			'event',
168
-			'organization',
169
-			'person',
170
-			'place',
171
-			'localbusiness',
172
-		);
164
+        $term_slugs = array(
165
+            'thing',
166
+            'creative-work',
167
+            'event',
168
+            'organization',
169
+            'person',
170
+            'place',
171
+            'localbusiness',
172
+        );
173 173
 
174
-		foreach ( $term_slugs as $slug ) {
174
+        foreach ( $term_slugs as $slug ) {
175 175
 
176
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
176
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
177 177
 
178
-			// Set the term's parent to 0.
179
-			if ( $term ) {
180
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
181
-					'parent' => 0,
182
-				) );
183
-			}
184
-		}
185
-	}
178
+            // Set the term's parent to 0.
179
+            if ( $term ) {
180
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
181
+                    'parent' => 0,
182
+                ) );
183
+            }
184
+        }
185
+    }
186 186
 
187 187
 }
188 188
 
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
  * @since 3.12.0
196 196
  */
197 197
 function wl_core_upgrade_db_3_10_3_12() {
198
-	/*
198
+    /*
199 199
 	 * As this upgrade functionality runs on the init hook, and the AMP plugin
200 200
 	 * initialization does the same, avoid possible race conditions by
201 201
 	 * deferring the actual flush to a later hook.
202 202
 	 */
203
-	add_action( 'wp_loaded', function () {
204
-		flush_rewrite_rules();
205
-	} );
203
+    add_action( 'wp_loaded', function () {
204
+        flush_rewrite_rules();
205
+    } );
206 206
 }
207 207
 
208 208
 /**
@@ -213,64 +213,64 @@  discard block
 block discarded – undo
213 213
  * @since 3.14.0
214 214
  */
215 215
 function wl_core_upgrade_db_3_12_3_14() {
216
-	$result = wp_insert_term(
217
-		'Recipe',
218
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
219
-		array(
220
-			'slug'        => 'recipe',
221
-			'description' => 'A Recipe.',
222
-		)
223
-	);
224
-
225
-	// Assign capabilities to manipulate entities to admins.
226
-	$admins = get_role( 'administrator' );
227
-
228
-	$admins->add_cap( 'edit_wordlift_entity' );
229
-	$admins->add_cap( 'edit_wordlift_entities' );
230
-	$admins->add_cap( 'edit_others_wordlift_entities' );
231
-	$admins->add_cap( 'publish_wordlift_entities' );
232
-	$admins->add_cap( 'read_private_wordlift_entities' );
233
-	$admins->add_cap( 'delete_wordlift_entity' );
234
-	$admins->add_cap( 'delete_wordlift_entities' );
235
-	$admins->add_cap( 'delete_others_wordlift_entities' );
236
-	$admins->add_cap( 'delete_published_wordlift_entities' );
237
-	$admins->add_cap( 'delete_private_wordlift_entities' );
238
-
239
-	// Assign capabilities to manipulate entities to editors.
240
-	$editors = get_role( 'editor' );
241
-
242
-	$editors->add_cap( 'edit_wordlift_entity' );
243
-	$editors->add_cap( 'edit_wordlift_entities' );
244
-	$editors->add_cap( 'edit_others_wordlift_entities' );
245
-	$editors->add_cap( 'publish_wordlift_entities' );
246
-	$editors->add_cap( 'read_private_wordlift_entities' );
247
-	$editors->add_cap( 'delete_wordlift_entity' );
248
-	$editors->add_cap( 'delete_wordlift_entities' );
249
-	$editors->add_cap( 'delete_others_wordlift_entities' );
250
-	$editors->add_cap( 'delete_published_wordlift_entities' );
251
-	$editors->add_cap( 'delete_private_wordlift_entities' );
216
+    $result = wp_insert_term(
217
+        'Recipe',
218
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
219
+        array(
220
+            'slug'        => 'recipe',
221
+            'description' => 'A Recipe.',
222
+        )
223
+    );
224
+
225
+    // Assign capabilities to manipulate entities to admins.
226
+    $admins = get_role( 'administrator' );
227
+
228
+    $admins->add_cap( 'edit_wordlift_entity' );
229
+    $admins->add_cap( 'edit_wordlift_entities' );
230
+    $admins->add_cap( 'edit_others_wordlift_entities' );
231
+    $admins->add_cap( 'publish_wordlift_entities' );
232
+    $admins->add_cap( 'read_private_wordlift_entities' );
233
+    $admins->add_cap( 'delete_wordlift_entity' );
234
+    $admins->add_cap( 'delete_wordlift_entities' );
235
+    $admins->add_cap( 'delete_others_wordlift_entities' );
236
+    $admins->add_cap( 'delete_published_wordlift_entities' );
237
+    $admins->add_cap( 'delete_private_wordlift_entities' );
238
+
239
+    // Assign capabilities to manipulate entities to editors.
240
+    $editors = get_role( 'editor' );
241
+
242
+    $editors->add_cap( 'edit_wordlift_entity' );
243
+    $editors->add_cap( 'edit_wordlift_entities' );
244
+    $editors->add_cap( 'edit_others_wordlift_entities' );
245
+    $editors->add_cap( 'publish_wordlift_entities' );
246
+    $editors->add_cap( 'read_private_wordlift_entities' );
247
+    $editors->add_cap( 'delete_wordlift_entity' );
248
+    $editors->add_cap( 'delete_wordlift_entities' );
249
+    $editors->add_cap( 'delete_others_wordlift_entities' );
250
+    $editors->add_cap( 'delete_published_wordlift_entities' );
251
+    $editors->add_cap( 'delete_private_wordlift_entities' );
252 252
 }
253 253
 
254 254
 // Check db status on automated plugins updates
255 255
 function wl_core_update_db_check() {
256 256
 
257
-	// Ensure the custom type and the taxonomy are registered.
258
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
257
+    // Ensure the custom type and the taxonomy are registered.
258
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
259 259
 
260
-	wl_entity_type_taxonomy_register();
260
+    wl_entity_type_taxonomy_register();
261 261
 
262
-	// Ensure the custom taxonomy for dbpedia topics is registered
263
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
262
+    // Ensure the custom taxonomy for dbpedia topics is registered
263
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
264 264
 
265
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
266
-		wl_core_install_entity_type_data();
267
-		wl_core_upgrade_db_to_1_0();
268
-		wl_core_upgrade_db_1_0_to_3_10();
269
-		wl_core_upgrade_db_3_10_3_12();
270
-		wl_core_upgrade_db_3_12_3_14();
271
-		update_option( 'wl_db_version', WL_DB_VERSION );
265
+    if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
266
+        wl_core_install_entity_type_data();
267
+        wl_core_upgrade_db_to_1_0();
268
+        wl_core_upgrade_db_1_0_to_3_10();
269
+        wl_core_upgrade_db_3_10_3_12();
270
+        wl_core_upgrade_db_3_12_3_14();
271
+        update_option( 'wl_db_version', WL_DB_VERSION );
272 272
 
273
-	}
273
+    }
274 274
 
275 275
 }
276 276
 
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  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...' );
14
+	Wordlift_Log_Service::get_instance()->debug('Installing Entity Type data...');
15 15
 
16 16
 	// Set the taxonomy data.
17 17
 	// Note: parent types must be defined before child types.
@@ -46,37 +46,37 @@  discard block
 block discarded – undo
46 46
 		),
47 47
 	);
48 48
 
49
-	foreach ( $terms as $slug => $term ) {
49
+	foreach ($terms as $slug => $term) {
50 50
 
51 51
 		// Create the term if it does not exist, then get its ID
52
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
52
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
53 53
 
54
-		if ( 0 == $term_id || is_null( $term_id ) ) {
55
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
54
+		if (0 == $term_id || is_null($term_id)) {
55
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
56 56
 		} else {
57 57
 			$term_id = $term_id['term_id'];
58
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
58
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
59 59
 		}
60 60
 
61 61
 		// Check for errors.
62
-		if ( is_wp_error( $result ) ) {
63
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
62
+		if (is_wp_error($result)) {
63
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
64 64
 			continue;
65 65
 		}
66 66
 
67 67
 		// Check if 'parent' corresponds to an actual term and get its ID.
68
-		if ( ! isset( $term['parents'] ) ) {
68
+		if ( ! isset($term['parents'])) {
69 69
 			$term['parents'] = array();
70 70
 		}
71 71
 
72 72
 		$parent_ids = array();
73
-		foreach ( $term['parents'] as $parent_slug ) {
74
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
75
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
73
+		foreach ($term['parents'] as $parent_slug) {
74
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
75
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
76 76
 		}
77 77
 
78 78
 		// Define a parent in the WP taxonomy style (not important for WL)
79
-		if ( empty( $parent_ids ) ) {
79
+		if (empty($parent_ids)) {
80 80
 			// No parent
81 81
 			$parent_id = 0;
82 82
 		} else {
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 		}
86 86
 
87 87
 		// Update term with description, slug and parent
88
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
88
+		wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
89 89
 			'name'        => $term['label'],
90 90
 			'slug'        => $slug,
91 91
 			'description' => $term['description'],
92 92
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
93 93
 			'parent'      => $parent_id,
94
-		) );
94
+		));
95 95
 
96 96
 	}
97 97
 
98
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
98
+	Wordlift_Log_Service::get_instance()->debug('Entity Type data installed.');
99 99
 
100 100
 }
101 101
 
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
 
107 107
 	global $wpdb;
108 108
 	// global $wl_db_version;
109
-	$installed_version = get_option( 'wl_db_version' );
109
+	$installed_version = get_option('wl_db_version');
110 110
 
111
-	if ( WL_DB_VERSION != $installed_version ) {
112
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
111
+	if (WL_DB_VERSION != $installed_version) {
112
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
113 113
 		$charset_collate = $wpdb->get_charset_collate();
114 114
 
115 115
 		// Sql statement for the relation instances custom table
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 EOF;
127 127
 
128 128
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
129
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
130
-		$results = dbDelta( $sql );
129
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
130
+		$results = dbDelta($sql);
131 131
 
132
-		wl_write_log( $results );
132
+		wl_write_log($results);
133 133
 
134
-		update_option( 'wl_db_version', WL_DB_VERSION );
134
+		update_option('wl_db_version', WL_DB_VERSION);
135 135
 	}
136 136
 }
137 137
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
  */
144 144
 function wl_core_upgrade_db_to_1_0() {
145 145
 
146
-	if ( ! get_option( 'wl_db_version' ) ) {
146
+	if ( ! get_option('wl_db_version')) {
147 147
 		wl_core_install_create_relation_instance_table();
148 148
 	}
149 149
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 function wl_core_upgrade_db_1_0_to_3_10() {
160 160
 
161 161
 	// If the DB version is less than 3.10, than flatten the txonomy.
162
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
162
+	if (version_compare(get_option('wl_db_version'), '3.9', '<=')) {
163 163
 
164 164
 		$term_slugs = array(
165 165
 			'thing',
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
 			'localbusiness',
172 172
 		);
173 173
 
174
-		foreach ( $term_slugs as $slug ) {
174
+		foreach ($term_slugs as $slug) {
175 175
 
176
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
176
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
177 177
 
178 178
 			// Set the term's parent to 0.
179
-			if ( $term ) {
180
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
179
+			if ($term) {
180
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
181 181
 					'parent' => 0,
182
-				) );
182
+				));
183 183
 			}
184 184
 		}
185 185
 	}
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * initialization does the same, avoid possible race conditions by
201 201
 	 * deferring the actual flush to a later hook.
202 202
 	 */
203
-	add_action( 'wp_loaded', function () {
203
+	add_action('wp_loaded', function() {
204 204
 		flush_rewrite_rules();
205 205
 	} );
206 206
 }
@@ -223,32 +223,32 @@  discard block
 block discarded – undo
223 223
 	);
224 224
 
225 225
 	// Assign capabilities to manipulate entities to admins.
226
-	$admins = get_role( 'administrator' );
227
-
228
-	$admins->add_cap( 'edit_wordlift_entity' );
229
-	$admins->add_cap( 'edit_wordlift_entities' );
230
-	$admins->add_cap( 'edit_others_wordlift_entities' );
231
-	$admins->add_cap( 'publish_wordlift_entities' );
232
-	$admins->add_cap( 'read_private_wordlift_entities' );
233
-	$admins->add_cap( 'delete_wordlift_entity' );
234
-	$admins->add_cap( 'delete_wordlift_entities' );
235
-	$admins->add_cap( 'delete_others_wordlift_entities' );
236
-	$admins->add_cap( 'delete_published_wordlift_entities' );
237
-	$admins->add_cap( 'delete_private_wordlift_entities' );
226
+	$admins = get_role('administrator');
227
+
228
+	$admins->add_cap('edit_wordlift_entity');
229
+	$admins->add_cap('edit_wordlift_entities');
230
+	$admins->add_cap('edit_others_wordlift_entities');
231
+	$admins->add_cap('publish_wordlift_entities');
232
+	$admins->add_cap('read_private_wordlift_entities');
233
+	$admins->add_cap('delete_wordlift_entity');
234
+	$admins->add_cap('delete_wordlift_entities');
235
+	$admins->add_cap('delete_others_wordlift_entities');
236
+	$admins->add_cap('delete_published_wordlift_entities');
237
+	$admins->add_cap('delete_private_wordlift_entities');
238 238
 
239 239
 	// Assign capabilities to manipulate entities to editors.
240
-	$editors = get_role( 'editor' );
241
-
242
-	$editors->add_cap( 'edit_wordlift_entity' );
243
-	$editors->add_cap( 'edit_wordlift_entities' );
244
-	$editors->add_cap( 'edit_others_wordlift_entities' );
245
-	$editors->add_cap( 'publish_wordlift_entities' );
246
-	$editors->add_cap( 'read_private_wordlift_entities' );
247
-	$editors->add_cap( 'delete_wordlift_entity' );
248
-	$editors->add_cap( 'delete_wordlift_entities' );
249
-	$editors->add_cap( 'delete_others_wordlift_entities' );
250
-	$editors->add_cap( 'delete_published_wordlift_entities' );
251
-	$editors->add_cap( 'delete_private_wordlift_entities' );
240
+	$editors = get_role('editor');
241
+
242
+	$editors->add_cap('edit_wordlift_entity');
243
+	$editors->add_cap('edit_wordlift_entities');
244
+	$editors->add_cap('edit_others_wordlift_entities');
245
+	$editors->add_cap('publish_wordlift_entities');
246
+	$editors->add_cap('read_private_wordlift_entities');
247
+	$editors->add_cap('delete_wordlift_entity');
248
+	$editors->add_cap('delete_wordlift_entities');
249
+	$editors->add_cap('delete_others_wordlift_entities');
250
+	$editors->add_cap('delete_published_wordlift_entities');
251
+	$editors->add_cap('delete_private_wordlift_entities');
252 252
 }
253 253
 
254 254
 // Check db status on automated plugins updates
@@ -262,16 +262,16 @@  discard block
 block discarded – undo
262 262
 	// Ensure the custom taxonomy for dbpedia topics is registered
263 263
 	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
264 264
 
265
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
265
+	if (get_option('wl_db_version') != WL_DB_VERSION) {
266 266
 		wl_core_install_entity_type_data();
267 267
 		wl_core_upgrade_db_to_1_0();
268 268
 		wl_core_upgrade_db_1_0_to_3_10();
269 269
 		wl_core_upgrade_db_3_10_3_12();
270 270
 		wl_core_upgrade_db_3_12_3_14();
271
-		update_option( 'wl_db_version', WL_DB_VERSION );
271
+		update_option('wl_db_version', WL_DB_VERSION);
272 272
 
273 273
 	}
274 274
 
275 275
 }
276 276
 
277
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
277
+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/includes/class-wordlift-jsonld-website-converter.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -15,60 +15,60 @@
 block discarded – undo
15 15
  */
16 16
 class Wordlift_Website_Jsonld_Converter extends Wordlift_Post_To_Jsonld_Converter {
17 17
 
18
-	/**
19
-	 * Convert the home/blog page to a JSON-LD array.
20
-	 *
21
-	 * @since 3.14.0
22
-	 *
23
-	 * @return array A JSON-LD array.
24
-	 */
25
-	public function create_schema() {
18
+    /**
19
+     * Convert the home/blog page to a JSON-LD array.
20
+     *
21
+     * @since 3.14.0
22
+     *
23
+     * @return array A JSON-LD array.
24
+     */
25
+    public function create_schema() {
26 26
 
27
-		// Create new jsonld.
28
-		$home_url = home_url( '/' );
27
+        // Create new jsonld.
28
+        $home_url = home_url( '/' );
29 29
 
30
-		$jsonld = array(
31
-			'@context'      => 'http://schema.org',
32
-			'@type'         => 'WebSite',
33
-			'@id'           => "$home_url#website",
34
-			'name'          => get_bloginfo( 'name' ),
35
-			'alternateName' => get_bloginfo( 'description' ),
36
-			'url'           => $home_url,
37
-		);
30
+        $jsonld = array(
31
+            '@context'      => 'http://schema.org',
32
+            '@type'         => 'WebSite',
33
+            '@id'           => "$home_url#website",
34
+            'name'          => get_bloginfo( 'name' ),
35
+            'alternateName' => get_bloginfo( 'description' ),
36
+            'url'           => $home_url,
37
+        );
38 38
 
39
-		// Add publisher information.
40
-		$this->set_publisher( $jsonld );
39
+        // Add publisher information.
40
+        $this->set_publisher( $jsonld );
41 41
 
42
-		// Add search action.
43
-		$this->set_search_action( $jsonld );
42
+        // Add search action.
43
+        $this->set_search_action( $jsonld );
44 44
 
45
-		// Return the jsonld schema.
46
-		return $jsonld;
47
-	}
45
+        // Return the jsonld schema.
46
+        return $jsonld;
47
+    }
48 48
 
49
-	/**
50
-	 * Add SearchAction part to the schema
51
-	 *
52
-	 * @since 3.14.0
53
-	 *
54
-	 * @param array $params The parameters array.
55
-	 */
56
-	private function set_search_action( &$params ) {
57
-		/**
58
-		 * Filter: 'wordlift_json_ld_search_url' - Allows filtering of the search URL.
59
-		 *
60
-		 * @since  3.14.0
61
-		 * @api    string $search_url The search URL for this site with a `{search_term_string}` variable.
62
-		 */
63
-		$search_url = apply_filters( 'wordlift_json_ld_search_url', home_url( '/' ) . '?s={search_term_string}' );
49
+    /**
50
+     * Add SearchAction part to the schema
51
+     *
52
+     * @since 3.14.0
53
+     *
54
+     * @param array $params The parameters array.
55
+     */
56
+    private function set_search_action( &$params ) {
57
+        /**
58
+         * Filter: 'wordlift_json_ld_search_url' - Allows filtering of the search URL.
59
+         *
60
+         * @since  3.14.0
61
+         * @api    string $search_url The search URL for this site with a `{search_term_string}` variable.
62
+         */
63
+        $search_url = apply_filters( 'wordlift_json_ld_search_url', home_url( '/' ) . '?s={search_term_string}' );
64 64
 
65
-		// Add search action
66
-		$params['potentialAction'] = array(
67
-			'@type'       => 'SearchAction',
68
-			'target'      => $search_url,
69
-			'query-input' => 'required name=search_term_string',
70
-		);
65
+        // Add search action
66
+        $params['potentialAction'] = array(
67
+            '@type'       => 'SearchAction',
68
+            'target'      => $search_url,
69
+            'query-input' => 'required name=search_term_string',
70
+        );
71 71
 
72
-	}
72
+    }
73 73
 
74 74
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,22 +25,22 @@  discard block
 block discarded – undo
25 25
 	public function create_schema() {
26 26
 
27 27
 		// Create new jsonld.
28
-		$home_url = home_url( '/' );
28
+		$home_url = home_url('/');
29 29
 
30 30
 		$jsonld = array(
31 31
 			'@context'      => 'http://schema.org',
32 32
 			'@type'         => 'WebSite',
33 33
 			'@id'           => "$home_url#website",
34
-			'name'          => get_bloginfo( 'name' ),
35
-			'alternateName' => get_bloginfo( 'description' ),
34
+			'name'          => get_bloginfo('name'),
35
+			'alternateName' => get_bloginfo('description'),
36 36
 			'url'           => $home_url,
37 37
 		);
38 38
 
39 39
 		// Add publisher information.
40
-		$this->set_publisher( $jsonld );
40
+		$this->set_publisher($jsonld);
41 41
 
42 42
 		// Add search action.
43
-		$this->set_search_action( $jsonld );
43
+		$this->set_search_action($jsonld);
44 44
 
45 45
 		// Return the jsonld schema.
46 46
 		return $jsonld;
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param array $params The parameters array.
55 55
 	 */
56
-	private function set_search_action( &$params ) {
56
+	private function set_search_action(&$params) {
57 57
 		/**
58 58
 		 * Filter: 'wordlift_json_ld_search_url' - Allows filtering of the search URL.
59 59
 		 *
60 60
 		 * @since  3.14.0
61 61
 		 * @api    string $search_url The search URL for this site with a `{search_term_string}` variable.
62 62
 		 */
63
-		$search_url = apply_filters( 'wordlift_json_ld_search_url', home_url( '/' ) . '?s={search_term_string}' );
63
+		$search_url = apply_filters('wordlift_json_ld_search_url', home_url('/').'?s={search_term_string}');
64 64
 
65 65
 		// Add search action
66 66
 		$params['potentialAction'] = array(
Please login to merge, or discard this patch.
src/includes/class-wordlift-user-service.php 2 patches
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -10,428 +10,428 @@
 block discarded – undo
10 10
  */
11 11
 class Wordlift_User_Service {
12 12
 
13
-	/**
14
-	 * The meta key where the user's URI is stored.
15
-	 *
16
-	 * @since 3.1.7
17
-	 */
18
-	const URI_META_KEY = '_wl_uri';
19
-
20
-	/**
21
-	 * The user meta key where the deny entity edit flag is stored.
22
-	 *
23
-	 * @since 3.14.0
24
-	 */
25
-	const DENY_ENTITY_CREATE_META_KEY = '_wl_deny_entity_create';
26
-
27
-	/**
28
-	 * The meta key holding the entity id representing a {@link WP_User}.
29
-	 *
30
-	 * @since 3.14.0
31
-	 */
32
-	const ENTITY_META_KEY = '_wl_entity';
33
-
34
-	/**
35
-	 * The Log service.
36
-	 *
37
-	 * @since  3.1.7
38
-	 * @access private
39
-	 * @var \Wordlift_Log_Service $log_service The Log service.
40
-	 */
41
-	private $log_service;
42
-
43
-	/**
44
-	 * The singleton instance of the User service.
45
-	 *
46
-	 * @since  3.1.7
47
-	 * @access private
48
-	 * @var \Wordlift_User_Service $user_service The singleton instance of the User service.
49
-	 */
50
-	private static $instance;
51
-
52
-	/**
53
-	 * Create an instance of the User service.
54
-	 *
55
-	 * @since 3.1.7
56
-	 */
57
-	public function __construct() {
58
-
59
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' );
60
-
61
-		self::$instance = $this;
62
-
63
-		add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 );
64
-	}
65
-
66
-	/**
67
-	 * Get the singleton instance of the User service.
68
-	 *
69
-	 * @since 3.1.7
70
-	 * @return \Wordlift_User_Service The singleton instance of the User service.
71
-	 */
72
-	public static function get_instance() {
73
-
74
-		return self::$instance;
75
-	}
76
-
77
-	/**
78
-	 * Get the URI for a user.
79
-	 *
80
-	 * @since 3.1.7
81
-	 *
82
-	 * @param int $user_id The user id
83
-	 *
84
-	 * @return false|string The user's URI or false in case of failure.
85
-	 */
86
-	public function get_uri( $user_id ) {
87
-
88
-		// Try to get the URI stored in the user's meta and return it if available.
89
-		if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) {
90
-			return $user_uri;
91
-		}
92
-
93
-		// Try to build an URI, return false in case of failure.
94
-		if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) {
95
-			return false;
96
-		}
97
-
98
-		// Store the URI for future requests (we need a "permanent" URI).
99
-		$this->_set_uri( $user_id, $user_uri );
100
-
101
-		return $user_uri;
102
-	}
103
-
104
-	/**
105
-	 * Receives wp_insert_post events.
106
-	 *
107
-	 * @since 3.1.7
108
-	 *
109
-	 * @param int     $post_id Post ID.
110
-	 * @param WP_Post $post    Post object.
111
-	 * @param bool    $update  Whether this is an existing post being updated or not.
112
-	 */
113
-	public function wp_insert_post( $post_id, $post, $update ) {
114
-
115
-		// If the post is not published, return.
116
-		if ( 'publish' !== get_post_status( $post_id ) ) {
117
-			return;
118
-		}
119
-
120
-		// We expect a numeric author id.
121
-		if ( ! is_numeric( $post->post_author ) ) {
122
-			return;
123
-		}
124
-
125
-		// Get the delete query,or return in case of failure.
126
-		if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) {
127
-			return;
128
-		}
129
-
130
-		// Get the insert query,or return in case of failure.
131
-		if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) {
132
-			return;
133
-		}
134
-
135
-		// Send the query to the triple store.
136
-		rl_execute_sparql_update_query( $delete . $insert );
137
-
138
-	}
139
-
140
-	/**
141
-	 * Set the `id` of the entity representing a {@link WP_User}.
142
-	 *
143
-	 * If the `id` is set to 0 (or less) then the meta is deleted.
144
-	 *
145
-	 * @since 3.14.0
146
-	 *
147
-	 * @param int $user_id The {@link WP_User}.
148
-	 * @param int $value   The entity {@link WP_Post} `id`.
149
-	 *
150
-	 * @return bool|int  Meta ID if the key didn't exist, true on successful update, false on failure.
151
-	 */
152
-	public function set_entity( $user_id, $value ) {
153
-
154
-		return 0 < $value
155
-			? update_user_meta( $user_id, self::ENTITY_META_KEY, $value )
156
-			: delete_user_meta( $user_id, self::ENTITY_META_KEY );
157
-	}
158
-
159
-	/**
160
-	 * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}.
161
-	 *
162
-	 * @since 3.14.0
163
-	 *
164
-	 * @param int $user_id The {@link WP_User}'s `id`.
165
-	 *
166
-	 * @return string The entity {@link WP_Post} `id` or an empty string if not set.
167
-	 */
168
-	public function get_entity( $user_id ) {
169
-
170
-		return get_user_meta( $user_id, self::ENTITY_META_KEY, true );
171
-	}
172
-
173
-	/**
174
-	 * Get the user's URI stored in the user's meta.
175
-	 *
176
-	 * @since 3.1.7
177
-	 *
178
-	 * @param int $user_id The user id.
179
-	 *
180
-	 * @return false|string The user's URI or false if not found.
181
-	 */
182
-	private function _get_uri( $user_id ) {
183
-
184
-		$user_uri = get_user_meta( $user_id, self::URI_META_KEY, true );
185
-
186
-		if ( empty( $user_uri ) ) {
187
-			return false;
188
-		}
189
-
190
-		return $user_uri;
191
-	}
192
-
193
-	/**
194
-	 * Build an URI for a user.
195
-	 *
196
-	 * @since 3.1.7
197
-	 *
198
-	 * @param int $user_id The user's id.
199
-	 *
200
-	 * @return false|string The user's URI or false in case of failure.
201
-	 */
202
-	private function _build_uri( $user_id ) {
203
-
204
-		// Get the user, return false in case of failure.
205
-		if ( false === ( $user = get_userdata( $user_id ) ) ) {
206
-			return false;
207
-		};
208
-
209
-		// If the nicename is not set, return a failure.
210
-		if ( empty( $user->user_nicename ) ) {
211
-			return false;
212
-		}
213
-
214
-		return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename";
215
-	}
216
-
217
-	/**
218
-	 * Store the URI in user's meta.
219
-	 *
220
-	 * @since 3.1.7
221
-	 *
222
-	 * @param int    $user_id  The user's id.
223
-	 * @param string $user_uri The user's uri.
224
-	 *
225
-	 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
226
-	 */
227
-	private function _set_uri( $user_id, $user_uri ) {
228
-
229
-		return update_user_meta( $user_id, self::URI_META_KEY, $user_uri );
230
-	}
231
-
232
-	/**
233
-	 * Get the delete query.
234
-	 *
235
-	 * @since 3.1.7
236
-	 *
237
-	 * @param int $user_id The user id.
238
-	 *
239
-	 * @return false|string The delete query or false in case of failure.
240
-	 */
241
-	private function get_delete_query( $user_id ) {
242
-
243
-		// Get the URI, return if there's none.
244
-		if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
245
-			return false;
246
-		}
247
-
248
-		// Build the delete query.
249
-		$query = Wordlift_Query_Builder::new_instance()->delete()
250
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' )
251
-		                               ->build()
252
-		         . Wordlift_Query_Builder::new_instance()->delete()
253
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' )
254
-		                                 ->build()
255
-		         . Wordlift_Query_Builder::new_instance()->delete()
256
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' )
257
-		                                 ->build()
258
-		         . Wordlift_Query_Builder::new_instance()->delete()
259
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' )
260
-		                                 ->build()
261
-		         . Wordlift_Query_Builder::new_instance()->delete()
262
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' )
263
-		                                 ->build();
264
-
265
-		return $query;
266
-	}
267
-
268
-	/**
269
-	 * Get the insert query.
270
-	 *
271
-	 * @since 3.1.7
272
-	 *
273
-	 * @param int $user_id The user id.
274
-	 *
275
-	 * @return false|string The insert query or false in case of failure.
276
-	 */
277
-	private function get_insert_query( $user_id ) {
278
-
279
-		// Get the URI, return if there's none.
280
-		if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
281
-			return false;
282
-		}
283
-
284
-		// Try to get the user data, in case of failure return false.
285
-		if ( false === ( $user = get_userdata( $user_id ) ) ) {
286
-			return false;
287
-		};
288
-
289
-		// Build the insert query.
290
-		$query = Wordlift_Query_Builder::new_instance()
291
-		                               ->insert()
292
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI )
293
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name )
294
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname )
295
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname )
296
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) )
297
-		                               ->build();
298
-
299
-		return $query;
300
-	}
301
-
302
-	/**
303
-	 * Mark an editor user as denied from editing entities.
304
-	 * Does nothing if the user is not an editor
305
-	 *
306
-	 * @since 3.14.0
307
-	 *
308
-	 * @param integer $user_id The ID of the user
309
-	 */
310
-	public function deny_editor_entity_create( $user_id ) {
311
-
312
-		// Bail out if the user is not an editor.
313
-		if ( ! $this->is_editor( $user_id ) ) {
314
-			return;
315
-		}
316
-
317
-		// The user explicitly do not have the capability.
318
-		update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' );
319
-
320
-	}
321
-
322
-	/**
323
-	 * Remove the "deny entity editing" mark from an editor user.
324
-	 * Does nothing if the user is not an editor
325
-	 *
326
-	 * @since 3.14.0
327
-	 *
328
-	 * @param integer $user_id The ID of the user
329
-	 */
330
-	public function allow_editor_entity_create( $user_id ) {
331
-
332
-		// Bail out if the user is not an editor.
333
-		if ( ! $this->is_editor( $user_id ) ) {
334
-			return;
335
-		}
336
-
337
-		// The user explicitly do not have the capability.
338
-		delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY );
339
-
340
-	}
341
-
342
-	/**
343
-	 * Get whether the 'deny editor entity editing' flag is set.
344
-	 *
345
-	 * @since 3.14.0
346
-	 *
347
-	 * @param int $user_id The {@link WP_User} `id`.
348
-	 *
349
-	 * @return int bool True if editing is denied otherwise false.
350
-	 */
351
-	public function is_deny_editor_entity_create( $user_id ) {
352
-
353
-		return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id );
354
-	}
355
-
356
-	/**
357
-	 * Check whether the {@link WP_User} with the specified `id` is an editor,
358
-	 * i.e. has the `editor` role.
359
-	 *
360
-	 * @since 3.14.0
361
-	 *
362
-	 * @param int $user_id The {@link WP_User} `id`.
363
-	 *
364
-	 * @return bool True if the {@link WP_User} is an editor otherwise false.
365
-	 */
366
-	public function is_editor( $user_id ) {
367
-
368
-		// Get the user.
369
-		$user = get_user_by( 'id', $user_id );
370
-
371
-		// Return true, if the user is found and has the `editor` role.
372
-		return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles );
373
-	}
374
-
375
-	/**
376
-	 * Check if an editor can create entities.
377
-	 *
378
-	 * @since 3.14.0
379
-	 *
380
-	 * @param int $user_id The user id of the user being checked.
381
-	 *
382
-	 * @return bool    false if it is an editor that is denied from edit entities, true otherwise.
383
-	 */
384
-	public function editor_can_create_entities( $user_id ) {
385
-
386
-		// Return true if not an editor.
387
-		if ( ! $this->is_editor( $user_id ) ) {
388
-			return true;
389
-		}
390
-
391
-		// Check if the user explicitly denied.
392
-		return ! $this->is_deny_editor_entity_create( $user_id );
393
-	}
394
-
395
-	/**
396
-	 * Filter capabilities of user.
397
-	 *
398
-	 * Deny the capability of managing and editing entities for some users.
399
-	 *
400
-	 * @since 3.14.0
401
-	 *
402
-	 * @param array $allcaps All the capabilities of the user
403
-	 * @param array $cap     [0] Required capability
404
-	 * @param array $args    [0] Requested capability
405
-	 *                       [1] User ID
406
-	 *                       [2] Associated object ID
407
-	 *
408
-	 * @return array The capabilities array.
409
-	 */
410
-	public function has_cap( $allcaps, $cap, $args ) {
411
-		/*
13
+    /**
14
+     * The meta key where the user's URI is stored.
15
+     *
16
+     * @since 3.1.7
17
+     */
18
+    const URI_META_KEY = '_wl_uri';
19
+
20
+    /**
21
+     * The user meta key where the deny entity edit flag is stored.
22
+     *
23
+     * @since 3.14.0
24
+     */
25
+    const DENY_ENTITY_CREATE_META_KEY = '_wl_deny_entity_create';
26
+
27
+    /**
28
+     * The meta key holding the entity id representing a {@link WP_User}.
29
+     *
30
+     * @since 3.14.0
31
+     */
32
+    const ENTITY_META_KEY = '_wl_entity';
33
+
34
+    /**
35
+     * The Log service.
36
+     *
37
+     * @since  3.1.7
38
+     * @access private
39
+     * @var \Wordlift_Log_Service $log_service The Log service.
40
+     */
41
+    private $log_service;
42
+
43
+    /**
44
+     * The singleton instance of the User service.
45
+     *
46
+     * @since  3.1.7
47
+     * @access private
48
+     * @var \Wordlift_User_Service $user_service The singleton instance of the User service.
49
+     */
50
+    private static $instance;
51
+
52
+    /**
53
+     * Create an instance of the User service.
54
+     *
55
+     * @since 3.1.7
56
+     */
57
+    public function __construct() {
58
+
59
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' );
60
+
61
+        self::$instance = $this;
62
+
63
+        add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 );
64
+    }
65
+
66
+    /**
67
+     * Get the singleton instance of the User service.
68
+     *
69
+     * @since 3.1.7
70
+     * @return \Wordlift_User_Service The singleton instance of the User service.
71
+     */
72
+    public static function get_instance() {
73
+
74
+        return self::$instance;
75
+    }
76
+
77
+    /**
78
+     * Get the URI for a user.
79
+     *
80
+     * @since 3.1.7
81
+     *
82
+     * @param int $user_id The user id
83
+     *
84
+     * @return false|string The user's URI or false in case of failure.
85
+     */
86
+    public function get_uri( $user_id ) {
87
+
88
+        // Try to get the URI stored in the user's meta and return it if available.
89
+        if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) {
90
+            return $user_uri;
91
+        }
92
+
93
+        // Try to build an URI, return false in case of failure.
94
+        if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) {
95
+            return false;
96
+        }
97
+
98
+        // Store the URI for future requests (we need a "permanent" URI).
99
+        $this->_set_uri( $user_id, $user_uri );
100
+
101
+        return $user_uri;
102
+    }
103
+
104
+    /**
105
+     * Receives wp_insert_post events.
106
+     *
107
+     * @since 3.1.7
108
+     *
109
+     * @param int     $post_id Post ID.
110
+     * @param WP_Post $post    Post object.
111
+     * @param bool    $update  Whether this is an existing post being updated or not.
112
+     */
113
+    public function wp_insert_post( $post_id, $post, $update ) {
114
+
115
+        // If the post is not published, return.
116
+        if ( 'publish' !== get_post_status( $post_id ) ) {
117
+            return;
118
+        }
119
+
120
+        // We expect a numeric author id.
121
+        if ( ! is_numeric( $post->post_author ) ) {
122
+            return;
123
+        }
124
+
125
+        // Get the delete query,or return in case of failure.
126
+        if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) {
127
+            return;
128
+        }
129
+
130
+        // Get the insert query,or return in case of failure.
131
+        if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) {
132
+            return;
133
+        }
134
+
135
+        // Send the query to the triple store.
136
+        rl_execute_sparql_update_query( $delete . $insert );
137
+
138
+    }
139
+
140
+    /**
141
+     * Set the `id` of the entity representing a {@link WP_User}.
142
+     *
143
+     * If the `id` is set to 0 (or less) then the meta is deleted.
144
+     *
145
+     * @since 3.14.0
146
+     *
147
+     * @param int $user_id The {@link WP_User}.
148
+     * @param int $value   The entity {@link WP_Post} `id`.
149
+     *
150
+     * @return bool|int  Meta ID if the key didn't exist, true on successful update, false on failure.
151
+     */
152
+    public function set_entity( $user_id, $value ) {
153
+
154
+        return 0 < $value
155
+            ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value )
156
+            : delete_user_meta( $user_id, self::ENTITY_META_KEY );
157
+    }
158
+
159
+    /**
160
+     * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}.
161
+     *
162
+     * @since 3.14.0
163
+     *
164
+     * @param int $user_id The {@link WP_User}'s `id`.
165
+     *
166
+     * @return string The entity {@link WP_Post} `id` or an empty string if not set.
167
+     */
168
+    public function get_entity( $user_id ) {
169
+
170
+        return get_user_meta( $user_id, self::ENTITY_META_KEY, true );
171
+    }
172
+
173
+    /**
174
+     * Get the user's URI stored in the user's meta.
175
+     *
176
+     * @since 3.1.7
177
+     *
178
+     * @param int $user_id The user id.
179
+     *
180
+     * @return false|string The user's URI or false if not found.
181
+     */
182
+    private function _get_uri( $user_id ) {
183
+
184
+        $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true );
185
+
186
+        if ( empty( $user_uri ) ) {
187
+            return false;
188
+        }
189
+
190
+        return $user_uri;
191
+    }
192
+
193
+    /**
194
+     * Build an URI for a user.
195
+     *
196
+     * @since 3.1.7
197
+     *
198
+     * @param int $user_id The user's id.
199
+     *
200
+     * @return false|string The user's URI or false in case of failure.
201
+     */
202
+    private function _build_uri( $user_id ) {
203
+
204
+        // Get the user, return false in case of failure.
205
+        if ( false === ( $user = get_userdata( $user_id ) ) ) {
206
+            return false;
207
+        };
208
+
209
+        // If the nicename is not set, return a failure.
210
+        if ( empty( $user->user_nicename ) ) {
211
+            return false;
212
+        }
213
+
214
+        return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename";
215
+    }
216
+
217
+    /**
218
+     * Store the URI in user's meta.
219
+     *
220
+     * @since 3.1.7
221
+     *
222
+     * @param int    $user_id  The user's id.
223
+     * @param string $user_uri The user's uri.
224
+     *
225
+     * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
226
+     */
227
+    private function _set_uri( $user_id, $user_uri ) {
228
+
229
+        return update_user_meta( $user_id, self::URI_META_KEY, $user_uri );
230
+    }
231
+
232
+    /**
233
+     * Get the delete query.
234
+     *
235
+     * @since 3.1.7
236
+     *
237
+     * @param int $user_id The user id.
238
+     *
239
+     * @return false|string The delete query or false in case of failure.
240
+     */
241
+    private function get_delete_query( $user_id ) {
242
+
243
+        // Get the URI, return if there's none.
244
+        if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
245
+            return false;
246
+        }
247
+
248
+        // Build the delete query.
249
+        $query = Wordlift_Query_Builder::new_instance()->delete()
250
+                                        ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' )
251
+                                        ->build()
252
+                    . Wordlift_Query_Builder::new_instance()->delete()
253
+                                            ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' )
254
+                                            ->build()
255
+                    . Wordlift_Query_Builder::new_instance()->delete()
256
+                                            ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' )
257
+                                            ->build()
258
+                    . Wordlift_Query_Builder::new_instance()->delete()
259
+                                            ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' )
260
+                                            ->build()
261
+                    . Wordlift_Query_Builder::new_instance()->delete()
262
+                                            ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' )
263
+                                            ->build();
264
+
265
+        return $query;
266
+    }
267
+
268
+    /**
269
+     * Get the insert query.
270
+     *
271
+     * @since 3.1.7
272
+     *
273
+     * @param int $user_id The user id.
274
+     *
275
+     * @return false|string The insert query or false in case of failure.
276
+     */
277
+    private function get_insert_query( $user_id ) {
278
+
279
+        // Get the URI, return if there's none.
280
+        if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
281
+            return false;
282
+        }
283
+
284
+        // Try to get the user data, in case of failure return false.
285
+        if ( false === ( $user = get_userdata( $user_id ) ) ) {
286
+            return false;
287
+        };
288
+
289
+        // Build the insert query.
290
+        $query = Wordlift_Query_Builder::new_instance()
291
+                                        ->insert()
292
+                                        ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI )
293
+                                        ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name )
294
+                                        ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname )
295
+                                        ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname )
296
+                                        ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) )
297
+                                        ->build();
298
+
299
+        return $query;
300
+    }
301
+
302
+    /**
303
+     * Mark an editor user as denied from editing entities.
304
+     * Does nothing if the user is not an editor
305
+     *
306
+     * @since 3.14.0
307
+     *
308
+     * @param integer $user_id The ID of the user
309
+     */
310
+    public function deny_editor_entity_create( $user_id ) {
311
+
312
+        // Bail out if the user is not an editor.
313
+        if ( ! $this->is_editor( $user_id ) ) {
314
+            return;
315
+        }
316
+
317
+        // The user explicitly do not have the capability.
318
+        update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' );
319
+
320
+    }
321
+
322
+    /**
323
+     * Remove the "deny entity editing" mark from an editor user.
324
+     * Does nothing if the user is not an editor
325
+     *
326
+     * @since 3.14.0
327
+     *
328
+     * @param integer $user_id The ID of the user
329
+     */
330
+    public function allow_editor_entity_create( $user_id ) {
331
+
332
+        // Bail out if the user is not an editor.
333
+        if ( ! $this->is_editor( $user_id ) ) {
334
+            return;
335
+        }
336
+
337
+        // The user explicitly do not have the capability.
338
+        delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY );
339
+
340
+    }
341
+
342
+    /**
343
+     * Get whether the 'deny editor entity editing' flag is set.
344
+     *
345
+     * @since 3.14.0
346
+     *
347
+     * @param int $user_id The {@link WP_User} `id`.
348
+     *
349
+     * @return int bool True if editing is denied otherwise false.
350
+     */
351
+    public function is_deny_editor_entity_create( $user_id ) {
352
+
353
+        return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id );
354
+    }
355
+
356
+    /**
357
+     * Check whether the {@link WP_User} with the specified `id` is an editor,
358
+     * i.e. has the `editor` role.
359
+     *
360
+     * @since 3.14.0
361
+     *
362
+     * @param int $user_id The {@link WP_User} `id`.
363
+     *
364
+     * @return bool True if the {@link WP_User} is an editor otherwise false.
365
+     */
366
+    public function is_editor( $user_id ) {
367
+
368
+        // Get the user.
369
+        $user = get_user_by( 'id', $user_id );
370
+
371
+        // Return true, if the user is found and has the `editor` role.
372
+        return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles );
373
+    }
374
+
375
+    /**
376
+     * Check if an editor can create entities.
377
+     *
378
+     * @since 3.14.0
379
+     *
380
+     * @param int $user_id The user id of the user being checked.
381
+     *
382
+     * @return bool    false if it is an editor that is denied from edit entities, true otherwise.
383
+     */
384
+    public function editor_can_create_entities( $user_id ) {
385
+
386
+        // Return true if not an editor.
387
+        if ( ! $this->is_editor( $user_id ) ) {
388
+            return true;
389
+        }
390
+
391
+        // Check if the user explicitly denied.
392
+        return ! $this->is_deny_editor_entity_create( $user_id );
393
+    }
394
+
395
+    /**
396
+     * Filter capabilities of user.
397
+     *
398
+     * Deny the capability of managing and editing entities for some users.
399
+     *
400
+     * @since 3.14.0
401
+     *
402
+     * @param array $allcaps All the capabilities of the user
403
+     * @param array $cap     [0] Required capability
404
+     * @param array $args    [0] Requested capability
405
+     *                       [1] User ID
406
+     *                       [2] Associated object ID
407
+     *
408
+     * @return array The capabilities array.
409
+     */
410
+    public function has_cap( $allcaps, $cap, $args ) {
411
+        /*
412 412
 		 * For entity management/editing related capabilities
413 413
 		 * check that an editor was not explicitly denied (in user profile)
414 414
 		 * the capability.
415 415
 		 */
416
-		if (
417
-			( 'edit_wordlift_entity' == $cap[0] ) ||
418
-			( 'edit_wordlift_entities' == $cap[0] ) ||
419
-			( 'edit_others_wordlift_entities' == $cap[0] ) ||
420
-			( 'publish_wordlift_entities' == $cap[0] ) ||
421
-			( 'read_private_wordlift_entities' == $cap[0] ) ||
422
-			( 'delete_wordlift_entity' == $cap[0] ) ||
423
-			( 'delete_wordlift_entities' == $cap[0] ) ||
424
-			( 'delete_others_wordlift_entities' == $cap[0] ) ||
425
-			( 'delete_published_wordlift_entities' == $cap[0] ) ||
426
-			( 'delete_private_wordlift_entities' == $cap[0] )
427
-		) {
428
-			$user_id = $args[1];
429
-
430
-			if ( ! $this->editor_can_create_entities( $user_id ) ) {
431
-				$allcaps[ $cap[0] ] = false;
432
-			}
433
-		}
434
-
435
-		return $allcaps;
436
-	}
416
+        if (
417
+            ( 'edit_wordlift_entity' == $cap[0] ) ||
418
+            ( 'edit_wordlift_entities' == $cap[0] ) ||
419
+            ( 'edit_others_wordlift_entities' == $cap[0] ) ||
420
+            ( 'publish_wordlift_entities' == $cap[0] ) ||
421
+            ( 'read_private_wordlift_entities' == $cap[0] ) ||
422
+            ( 'delete_wordlift_entity' == $cap[0] ) ||
423
+            ( 'delete_wordlift_entities' == $cap[0] ) ||
424
+            ( 'delete_others_wordlift_entities' == $cap[0] ) ||
425
+            ( 'delete_published_wordlift_entities' == $cap[0] ) ||
426
+            ( 'delete_private_wordlift_entities' == $cap[0] )
427
+        ) {
428
+            $user_id = $args[1];
429
+
430
+            if ( ! $this->editor_can_create_entities( $user_id ) ) {
431
+                $allcaps[ $cap[0] ] = false;
432
+            }
433
+        }
434
+
435
+        return $allcaps;
436
+    }
437 437
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function __construct() {
58 58
 
59
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' );
59
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_User_Service');
60 60
 
61 61
 		self::$instance = $this;
62 62
 
63
-		add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 );
63
+		add_filter('user_has_cap', array($this, 'has_cap'), 10, 3);
64 64
 	}
65 65
 
66 66
 	/**
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return false|string The user's URI or false in case of failure.
85 85
 	 */
86
-	public function get_uri( $user_id ) {
86
+	public function get_uri($user_id) {
87 87
 
88 88
 		// Try to get the URI stored in the user's meta and return it if available.
89
-		if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) {
89
+		if (false !== ($user_uri = $this->_get_uri($user_id))) {
90 90
 			return $user_uri;
91 91
 		}
92 92
 
93 93
 		// Try to build an URI, return false in case of failure.
94
-		if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) {
94
+		if (false === ($user_uri = $this->_build_uri($user_id))) {
95 95
 			return false;
96 96
 		}
97 97
 
98 98
 		// Store the URI for future requests (we need a "permanent" URI).
99
-		$this->_set_uri( $user_id, $user_uri );
99
+		$this->_set_uri($user_id, $user_uri);
100 100
 
101 101
 		return $user_uri;
102 102
 	}
@@ -110,30 +110,30 @@  discard block
 block discarded – undo
110 110
 	 * @param WP_Post $post    Post object.
111 111
 	 * @param bool    $update  Whether this is an existing post being updated or not.
112 112
 	 */
113
-	public function wp_insert_post( $post_id, $post, $update ) {
113
+	public function wp_insert_post($post_id, $post, $update) {
114 114
 
115 115
 		// If the post is not published, return.
116
-		if ( 'publish' !== get_post_status( $post_id ) ) {
116
+		if ('publish' !== get_post_status($post_id)) {
117 117
 			return;
118 118
 		}
119 119
 
120 120
 		// We expect a numeric author id.
121
-		if ( ! is_numeric( $post->post_author ) ) {
121
+		if ( ! is_numeric($post->post_author)) {
122 122
 			return;
123 123
 		}
124 124
 
125 125
 		// Get the delete query,or return in case of failure.
126
-		if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) {
126
+		if (false === ($delete = $this->get_delete_query($post->post_author))) {
127 127
 			return;
128 128
 		}
129 129
 
130 130
 		// Get the insert query,or return in case of failure.
131
-		if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) {
131
+		if (false === ($insert = $this->get_insert_query($post->post_author))) {
132 132
 			return;
133 133
 		}
134 134
 
135 135
 		// Send the query to the triple store.
136
-		rl_execute_sparql_update_query( $delete . $insert );
136
+		rl_execute_sparql_update_query($delete.$insert);
137 137
 
138 138
 	}
139 139
 
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @return bool|int  Meta ID if the key didn't exist, true on successful update, false on failure.
151 151
 	 */
152
-	public function set_entity( $user_id, $value ) {
152
+	public function set_entity($user_id, $value) {
153 153
 
154 154
 		return 0 < $value
155
-			? update_user_meta( $user_id, self::ENTITY_META_KEY, $value )
156
-			: delete_user_meta( $user_id, self::ENTITY_META_KEY );
155
+			? update_user_meta($user_id, self::ENTITY_META_KEY, $value)
156
+			: delete_user_meta($user_id, self::ENTITY_META_KEY);
157 157
 	}
158 158
 
159 159
 	/**
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @return string The entity {@link WP_Post} `id` or an empty string if not set.
167 167
 	 */
168
-	public function get_entity( $user_id ) {
168
+	public function get_entity($user_id) {
169 169
 
170
-		return get_user_meta( $user_id, self::ENTITY_META_KEY, true );
170
+		return get_user_meta($user_id, self::ENTITY_META_KEY, true);
171 171
 	}
172 172
 
173 173
 	/**
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return false|string The user's URI or false if not found.
181 181
 	 */
182
-	private function _get_uri( $user_id ) {
182
+	private function _get_uri($user_id) {
183 183
 
184
-		$user_uri = get_user_meta( $user_id, self::URI_META_KEY, true );
184
+		$user_uri = get_user_meta($user_id, self::URI_META_KEY, true);
185 185
 
186
-		if ( empty( $user_uri ) ) {
186
+		if (empty($user_uri)) {
187 187
 			return false;
188 188
 		}
189 189
 
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return false|string The user's URI or false in case of failure.
201 201
 	 */
202
-	private function _build_uri( $user_id ) {
202
+	private function _build_uri($user_id) {
203 203
 
204 204
 		// Get the user, return false in case of failure.
205
-		if ( false === ( $user = get_userdata( $user_id ) ) ) {
205
+		if (false === ($user = get_userdata($user_id))) {
206 206
 			return false;
207 207
 		};
208 208
 
209 209
 		// If the nicename is not set, return a failure.
210
-		if ( empty( $user->user_nicename ) ) {
210
+		if (empty($user->user_nicename)) {
211 211
 			return false;
212 212
 		}
213 213
 
214
-		return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename";
214
+		return wl_configuration_get_redlink_dataset_uri()."/user/$user->user_nicename";
215 215
 	}
216 216
 
217 217
 	/**
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 	 *
225 225
 	 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
226 226
 	 */
227
-	private function _set_uri( $user_id, $user_uri ) {
227
+	private function _set_uri($user_id, $user_uri) {
228 228
 
229
-		return update_user_meta( $user_id, self::URI_META_KEY, $user_uri );
229
+		return update_user_meta($user_id, self::URI_META_KEY, $user_uri);
230 230
 	}
231 231
 
232 232
 	/**
@@ -238,28 +238,28 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @return false|string The delete query or false in case of failure.
240 240
 	 */
241
-	private function get_delete_query( $user_id ) {
241
+	private function get_delete_query($user_id) {
242 242
 
243 243
 		// Get the URI, return if there's none.
244
-		if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
244
+		if (false === ($user_uri = $this->get_uri($user_id))) {
245 245
 			return false;
246 246
 		}
247 247
 
248 248
 		// Build the delete query.
249 249
 		$query = Wordlift_Query_Builder::new_instance()->delete()
250
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' )
250
+		                               ->statement($user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o')
251 251
 		                               ->build()
252 252
 		         . Wordlift_Query_Builder::new_instance()->delete()
253
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' )
253
+		                                 ->statement($user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o')
254 254
 		                                 ->build()
255 255
 		         . Wordlift_Query_Builder::new_instance()->delete()
256
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' )
256
+		                                 ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o')
257 257
 		                                 ->build()
258 258
 		         . Wordlift_Query_Builder::new_instance()->delete()
259
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' )
259
+		                                 ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o')
260 260
 		                                 ->build()
261 261
 		         . Wordlift_Query_Builder::new_instance()->delete()
262
-		                                 ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' )
262
+		                                 ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o')
263 263
 		                                 ->build();
264 264
 
265 265
 		return $query;
@@ -274,26 +274,26 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @return false|string The insert query or false in case of failure.
276 276
 	 */
277
-	private function get_insert_query( $user_id ) {
277
+	private function get_insert_query($user_id) {
278 278
 
279 279
 		// Get the URI, return if there's none.
280
-		if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) {
280
+		if (false === ($user_uri = $this->get_uri($user_id))) {
281 281
 			return false;
282 282
 		}
283 283
 
284 284
 		// Try to get the user data, in case of failure return false.
285
-		if ( false === ( $user = get_userdata( $user_id ) ) ) {
285
+		if (false === ($user = get_userdata($user_id))) {
286 286
 			return false;
287 287
 		};
288 288
 
289 289
 		// Build the insert query.
290 290
 		$query = Wordlift_Query_Builder::new_instance()
291 291
 		                               ->insert()
292
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI )
293
-		                               ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name )
294
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname )
295
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname )
296
-		                               ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) )
292
+		                               ->statement($user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI)
293
+		                               ->statement($user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name)
294
+		                               ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname)
295
+		                               ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname)
296
+		                               ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty($user->user_url) ? $user->user_url : get_author_posts_url($user_id)))
297 297
 		                               ->build();
298 298
 
299 299
 		return $query;
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @param integer $user_id The ID of the user
309 309
 	 */
310
-	public function deny_editor_entity_create( $user_id ) {
310
+	public function deny_editor_entity_create($user_id) {
311 311
 
312 312
 		// Bail out if the user is not an editor.
313
-		if ( ! $this->is_editor( $user_id ) ) {
313
+		if ( ! $this->is_editor($user_id)) {
314 314
 			return;
315 315
 		}
316 316
 
317 317
 		// The user explicitly do not have the capability.
318
-		update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' );
318
+		update_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes');
319 319
 
320 320
 	}
321 321
 
@@ -327,15 +327,15 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @param integer $user_id The ID of the user
329 329
 	 */
330
-	public function allow_editor_entity_create( $user_id ) {
330
+	public function allow_editor_entity_create($user_id) {
331 331
 
332 332
 		// Bail out if the user is not an editor.
333
-		if ( ! $this->is_editor( $user_id ) ) {
333
+		if ( ! $this->is_editor($user_id)) {
334 334
 			return;
335 335
 		}
336 336
 
337 337
 		// The user explicitly do not have the capability.
338
-		delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY );
338
+		delete_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY);
339 339
 
340 340
 	}
341 341
 
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return int bool True if editing is denied otherwise false.
350 350
 	 */
351
-	public function is_deny_editor_entity_create( $user_id ) {
351
+	public function is_deny_editor_entity_create($user_id) {
352 352
 
353
-		return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id );
353
+		return 'yes' === get_user_option(self::DENY_ENTITY_CREATE_META_KEY, $user_id);
354 354
 	}
355 355
 
356 356
 	/**
@@ -363,13 +363,13 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @return bool True if the {@link WP_User} is an editor otherwise false.
365 365
 	 */
366
-	public function is_editor( $user_id ) {
366
+	public function is_editor($user_id) {
367 367
 
368 368
 		// Get the user.
369
-		$user = get_user_by( 'id', $user_id );
369
+		$user = get_user_by('id', $user_id);
370 370
 
371 371
 		// Return true, if the user is found and has the `editor` role.
372
-		return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles );
372
+		return is_a($user, 'WP_User') && in_array('editor', (array) $user->roles);
373 373
 	}
374 374
 
375 375
 	/**
@@ -381,15 +381,15 @@  discard block
 block discarded – undo
381 381
 	 *
382 382
 	 * @return bool    false if it is an editor that is denied from edit entities, true otherwise.
383 383
 	 */
384
-	public function editor_can_create_entities( $user_id ) {
384
+	public function editor_can_create_entities($user_id) {
385 385
 
386 386
 		// Return true if not an editor.
387
-		if ( ! $this->is_editor( $user_id ) ) {
387
+		if ( ! $this->is_editor($user_id)) {
388 388
 			return true;
389 389
 		}
390 390
 
391 391
 		// Check if the user explicitly denied.
392
-		return ! $this->is_deny_editor_entity_create( $user_id );
392
+		return ! $this->is_deny_editor_entity_create($user_id);
393 393
 	}
394 394
 
395 395
 	/**
@@ -407,28 +407,28 @@  discard block
 block discarded – undo
407 407
 	 *
408 408
 	 * @return array The capabilities array.
409 409
 	 */
410
-	public function has_cap( $allcaps, $cap, $args ) {
410
+	public function has_cap($allcaps, $cap, $args) {
411 411
 		/*
412 412
 		 * For entity management/editing related capabilities
413 413
 		 * check that an editor was not explicitly denied (in user profile)
414 414
 		 * the capability.
415 415
 		 */
416 416
 		if (
417
-			( 'edit_wordlift_entity' == $cap[0] ) ||
418
-			( 'edit_wordlift_entities' == $cap[0] ) ||
419
-			( 'edit_others_wordlift_entities' == $cap[0] ) ||
420
-			( 'publish_wordlift_entities' == $cap[0] ) ||
421
-			( 'read_private_wordlift_entities' == $cap[0] ) ||
422
-			( 'delete_wordlift_entity' == $cap[0] ) ||
423
-			( 'delete_wordlift_entities' == $cap[0] ) ||
424
-			( 'delete_others_wordlift_entities' == $cap[0] ) ||
425
-			( 'delete_published_wordlift_entities' == $cap[0] ) ||
426
-			( 'delete_private_wordlift_entities' == $cap[0] )
417
+			('edit_wordlift_entity' == $cap[0]) ||
418
+			('edit_wordlift_entities' == $cap[0]) ||
419
+			('edit_others_wordlift_entities' == $cap[0]) ||
420
+			('publish_wordlift_entities' == $cap[0]) ||
421
+			('read_private_wordlift_entities' == $cap[0]) ||
422
+			('delete_wordlift_entity' == $cap[0]) ||
423
+			('delete_wordlift_entities' == $cap[0]) ||
424
+			('delete_others_wordlift_entities' == $cap[0]) ||
425
+			('delete_published_wordlift_entities' == $cap[0]) ||
426
+			('delete_private_wordlift_entities' == $cap[0])
427 427
 		) {
428 428
 			$user_id = $args[1];
429 429
 
430
-			if ( ! $this->editor_can_create_entities( $user_id ) ) {
431
-				$allcaps[ $cap[0] ] = false;
430
+			if ( ! $this->editor_can_create_entities($user_id)) {
431
+				$allcaps[$cap[0]] = false;
432 432
 			}
433 433
 		}
434 434
 
Please login to merge, or discard this patch.