Completed
Push — develop ( 5973a0...b5cd4d )
by David
03:45
created
src/modules/core/wordlift_core_constants.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,39 +16,39 @@
 block discarded – undo
16 16
 // Mapping options / validations rules used by wl_core_get_posts to perform validation on args
17 17
 // The array is serialized because array constants are only from php 5.6 on.
18 18
 define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array(
19
-	'get'            => array( 'posts', 'post_ids' ),
20
-	'as'             => array( 'object', 'subject' ),
21
-	'post_type'      => array( 'post', 'entity' ),
22
-	'post_status'    => array( 'draft', 'trash', 'publish' ),
23
-	'with_predicate' => array( WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION ),
19
+    'get'            => array( 'posts', 'post_ids' ),
20
+    'as'             => array( 'object', 'subject' ),
21
+    'post_type'      => array( 'post', 'entity' ),
22
+    'post_status'    => array( 'draft', 'trash', 'publish' ),
23
+    'with_predicate' => array( WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION ),
24 24
 ) ) );
25 25
 
26 26
 // Classification boxes configuration for angularjs edit-post widget
27 27
 // The array is serialized because array constants are only from php 5.6 on.
28 28
 
29 29
 define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array(
30
-	array(
31
-		'id'               => WL_WHAT_RELATION,
32
-		'label'            => 'What',
33
-		'registeredTypes'  => array( 'thing', 'creative-work' ),
34
-		'selectedEntities' => array(),
35
-	),
36
-	array(
37
-		'id'               => WL_WHO_RELATION,
38
-		'label'            => 'Who',
39
-		'registeredTypes'  => array( 'organization', 'person', 'local-business' ),
40
-		'selectedEntities' => array(),
41
-	),
42
-	array(
43
-		'id'               => WL_WHERE_RELATION,
44
-		'label'            => 'Where',
45
-		'registeredTypes'  => array( 'place' ),
46
-		'selectedEntities' => array(),
47
-	),
48
-	array(
49
-		'id'               => WL_WHEN_RELATION,
50
-		'label'            => 'When',
51
-		'registeredTypes'  => array( 'event' ),
52
-		'selectedEntities' => array(),
53
-	),
30
+    array(
31
+        'id'               => WL_WHAT_RELATION,
32
+        'label'            => 'What',
33
+        'registeredTypes'  => array( 'thing', 'creative-work' ),
34
+        'selectedEntities' => array(),
35
+    ),
36
+    array(
37
+        'id'               => WL_WHO_RELATION,
38
+        'label'            => 'Who',
39
+        'registeredTypes'  => array( 'organization', 'person', 'local-business' ),
40
+        'selectedEntities' => array(),
41
+    ),
42
+    array(
43
+        'id'               => WL_WHERE_RELATION,
44
+        'label'            => 'Where',
45
+        'registeredTypes'  => array( 'place' ),
46
+        'selectedEntities' => array(),
47
+    ),
48
+    array(
49
+        'id'               => WL_WHEN_RELATION,
50
+        'label'            => 'When',
51
+        'registeredTypes'  => array( 'event' ),
52
+        'selectedEntities' => array(),
53
+    ),
54 54
 ) ) );
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,54 +1,54 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-define( 'WL_DEFAULT_THUMBNAIL_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/public/images/missing-image-150x150.png' );
4
-define( 'WL_DEFAULT_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/' );
3
+define('WL_DEFAULT_THUMBNAIL_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/public/images/missing-image-150x150.png');
4
+define('WL_DEFAULT_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/');
5 5
 
6 6
 // Database version
7
-define( 'WL_DB_VERSION', '3.10' );
7
+define('WL_DB_VERSION', '3.10');
8 8
 // Custom table name
9
-define( 'WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances' );
9
+define('WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances');
10 10
 
11
-define( 'WL_WHAT_RELATION', 'what' );
12
-define( 'WL_WHO_RELATION', 'who' );
13
-define( 'WL_WHERE_RELATION', 'where' );
14
-define( 'WL_WHEN_RELATION', 'when' );
11
+define('WL_WHAT_RELATION', 'what');
12
+define('WL_WHO_RELATION', 'who');
13
+define('WL_WHERE_RELATION', 'where');
14
+define('WL_WHEN_RELATION', 'when');
15 15
 
16 16
 // Mapping options / validations rules used by wl_core_get_posts to perform validation on args
17 17
 // The array is serialized because array constants are only from php 5.6 on.
18
-define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array(
19
-	'get'            => array( 'posts', 'post_ids' ),
20
-	'as'             => array( 'object', 'subject' ),
21
-	'post_type'      => array( 'post', 'entity' ),
22
-	'post_status'    => array( 'draft', 'trash', 'publish' ),
23
-	'with_predicate' => array( WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION ),
24
-) ) );
18
+define('WL_CORE_GET_POSTS_VALIDATION_RULES', serialize(array(
19
+	'get'            => array('posts', 'post_ids'),
20
+	'as'             => array('object', 'subject'),
21
+	'post_type'      => array('post', 'entity'),
22
+	'post_status'    => array('draft', 'trash', 'publish'),
23
+	'with_predicate' => array(WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION),
24
+)));
25 25
 
26 26
 // Classification boxes configuration for angularjs edit-post widget
27 27
 // The array is serialized because array constants are only from php 5.6 on.
28 28
 
29
-define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array(
29
+define('WL_CORE_POST_CLASSIFICATION_BOXES', serialize(array(
30 30
 	array(
31 31
 		'id'               => WL_WHAT_RELATION,
32 32
 		'label'            => 'What',
33
-		'registeredTypes'  => array( 'thing', 'creative-work' ),
33
+		'registeredTypes'  => array('thing', 'creative-work'),
34 34
 		'selectedEntities' => array(),
35 35
 	),
36 36
 	array(
37 37
 		'id'               => WL_WHO_RELATION,
38 38
 		'label'            => 'Who',
39
-		'registeredTypes'  => array( 'organization', 'person', 'local-business' ),
39
+		'registeredTypes'  => array('organization', 'person', 'local-business'),
40 40
 		'selectedEntities' => array(),
41 41
 	),
42 42
 	array(
43 43
 		'id'               => WL_WHERE_RELATION,
44 44
 		'label'            => 'Where',
45
-		'registeredTypes'  => array( 'place' ),
45
+		'registeredTypes'  => array('place'),
46 46
 		'selectedEntities' => array(),
47 47
 	),
48 48
 	array(
49 49
 		'id'               => WL_WHEN_RELATION,
50 50
 		'label'            => 'When',
51
-		'registeredTypes'  => array( 'event' ),
51
+		'registeredTypes'  => array('event'),
52 52
 		'selectedEntities' => array(),
53 53
 	),
54
-) ) );
54
+)));
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -11,95 +11,95 @@  discard block
 block discarded – undo
11 11
  */
12 12
 function wl_core_install_entity_type_data() {
13 13
 
14
-	// Ensure the custom type and the taxonomy are registered.
15
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
16
-
17
-	wl_entity_type_taxonomy_register();
18
-
19
-	// Ensure the custom taxonomy for dbpedia topics is registered
20
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
21
-
22
-	// Set the taxonomy data.
23
-	// Note: parent types must be defined before child types.
24
-	$terms = array(
25
-		'thing'         => array(
26
-			'label'       => 'Thing',
27
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
28
-		),
29
-		'creative-work' => array(
30
-			'label'       => 'CreativeWork',
31
-			'description' => 'A creative work (or a Music Album).',
32
-		),
33
-		'event'         => array(
34
-			'label'       => 'Event',
35
-			'description' => 'An event.',
36
-		),
37
-		'organization'  => array(
38
-			'label'       => 'Organization',
39
-			'description' => 'An organization, including a government or a newspaper.',
40
-		),
41
-		'person'        => array(
42
-			'label'       => 'Person',
43
-			'description' => 'A person (or a music artist).',
44
-		),
45
-		'place'         => array(
46
-			'label'       => 'Place',
47
-			'description' => 'A place.',
48
-		),
49
-		'localbusiness' => array(
50
-			'label'       => 'LocalBusiness',
51
-			'description' => 'A local business.',
52
-		),
53
-	);
54
-
55
-	foreach ( $terms as $slug => $term ) {
56
-
57
-		// Create the term if it does not exist, then get its ID
58
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
59
-
60
-		if ( 0 == $term_id || is_null( $term_id ) ) {
61
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
62
-		} else {
63
-			$term_id = $term_id['term_id'];
64
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
65
-		}
66
-
67
-		// Check for errors.
68
-		if ( is_wp_error( $result ) ) {
69
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
70
-			continue;
71
-		}
72
-
73
-		// Check if 'parent' corresponds to an actual term and get its ID.
74
-		if ( ! isset( $term['parents'] ) ) {
75
-			$term['parents'] = array();
76
-		}
77
-
78
-		$parent_ids = array();
79
-		foreach ( $term['parents'] as $parent_slug ) {
80
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82
-		}
83
-
84
-		// Define a parent in the WP taxonomy style (not important for WL)
85
-		if ( empty( $parent_ids ) ) {
86
-			// No parent
87
-			$parent_id = 0;
88
-		} else {
89
-			// Get first parent
90
-			$parent_id = $parent_ids[0];
91
-		}
92
-
93
-		// Update term with description, slug and parent
94
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95
-			'name'        => $term['label'],
96
-			'slug'        => $slug,
97
-			'description' => $term['description'],
98
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
99
-			'parent'      => $parent_id,
100
-		) );
101
-
102
-	}
14
+    // Ensure the custom type and the taxonomy are registered.
15
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
16
+
17
+    wl_entity_type_taxonomy_register();
18
+
19
+    // Ensure the custom taxonomy for dbpedia topics is registered
20
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
21
+
22
+    // Set the taxonomy data.
23
+    // Note: parent types must be defined before child types.
24
+    $terms = array(
25
+        'thing'         => array(
26
+            'label'       => 'Thing',
27
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
28
+        ),
29
+        'creative-work' => array(
30
+            'label'       => 'CreativeWork',
31
+            'description' => 'A creative work (or a Music Album).',
32
+        ),
33
+        'event'         => array(
34
+            'label'       => 'Event',
35
+            'description' => 'An event.',
36
+        ),
37
+        'organization'  => array(
38
+            'label'       => 'Organization',
39
+            'description' => 'An organization, including a government or a newspaper.',
40
+        ),
41
+        'person'        => array(
42
+            'label'       => 'Person',
43
+            'description' => 'A person (or a music artist).',
44
+        ),
45
+        'place'         => array(
46
+            'label'       => 'Place',
47
+            'description' => 'A place.',
48
+        ),
49
+        'localbusiness' => array(
50
+            'label'       => 'LocalBusiness',
51
+            'description' => 'A local business.',
52
+        ),
53
+    );
54
+
55
+    foreach ( $terms as $slug => $term ) {
56
+
57
+        // Create the term if it does not exist, then get its ID
58
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
59
+
60
+        if ( 0 == $term_id || is_null( $term_id ) ) {
61
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
62
+        } else {
63
+            $term_id = $term_id['term_id'];
64
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
65
+        }
66
+
67
+        // Check for errors.
68
+        if ( is_wp_error( $result ) ) {
69
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
70
+            continue;
71
+        }
72
+
73
+        // Check if 'parent' corresponds to an actual term and get its ID.
74
+        if ( ! isset( $term['parents'] ) ) {
75
+            $term['parents'] = array();
76
+        }
77
+
78
+        $parent_ids = array();
79
+        foreach ( $term['parents'] as $parent_slug ) {
80
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82
+        }
83
+
84
+        // Define a parent in the WP taxonomy style (not important for WL)
85
+        if ( empty( $parent_ids ) ) {
86
+            // No parent
87
+            $parent_id = 0;
88
+        } else {
89
+            // Get first parent
90
+            $parent_id = $parent_ids[0];
91
+        }
92
+
93
+        // Update term with description, slug and parent
94
+        wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95
+            'name'        => $term['label'],
96
+            'slug'        => $slug,
97
+            'description' => $term['description'],
98
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
99
+            'parent'      => $parent_id,
100
+        ) );
101
+
102
+    }
103 103
 
104 104
 }
105 105
 
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function wl_core_install_create_relation_instance_table() {
110 110
 
111
-	global $wpdb;
112
-	// global $wl_db_version;
113
-	$installed_version = get_option( 'wl_db_version' );
111
+    global $wpdb;
112
+    // global $wl_db_version;
113
+    $installed_version = get_option( 'wl_db_version' );
114 114
 
115
-	if ( WL_DB_VERSION != $installed_version ) {
116
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
117
-		$charset_collate = $wpdb->get_charset_collate();
115
+    if ( WL_DB_VERSION != $installed_version ) {
116
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
117
+        $charset_collate = $wpdb->get_charset_collate();
118 118
 
119
-		// Sql statement for the relation instances custom table
120
-		$sql = <<<EOF
119
+        // Sql statement for the relation instances custom table
120
+        $sql = <<<EOF
121 121
 			CREATE TABLE $table_name (
122 122
   				id int(11) NOT NULL AUTO_INCREMENT,
123 123
   				subject_id int(11) NOT NULL,
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 			) $charset_collate;
130 130
 EOF;
131 131
 
132
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
-		$results = dbDelta( $sql );
132
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
+        $results = dbDelta( $sql );
135 135
 
136
-		wl_write_log( $results );
136
+        wl_write_log( $results );
137 137
 
138
-		update_option( 'wl_db_version', WL_DB_VERSION );
139
-	}
138
+        update_option( 'wl_db_version', WL_DB_VERSION );
139
+    }
140 140
 }
141 141
 
142 142
 /**
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function wl_core_install() {
146 146
 
147
-	// Create a blank application key if there is none
148
-	$key = wl_configuration_get_key();
149
-	if ( empty( $key ) ) {
150
-		wl_configuration_set_key( '' );
151
-	}
147
+    // Create a blank application key if there is none
148
+    $key = wl_configuration_get_key();
149
+    if ( empty( $key ) ) {
150
+        wl_configuration_set_key( '' );
151
+    }
152 152
 
153
-	wl_core_install_entity_type_data();
154
-	wl_core_install_create_relation_instance_table();
155
-	flush_rewrite_rules();
153
+    wl_core_install_entity_type_data();
154
+    wl_core_install_create_relation_instance_table();
155
+    flush_rewrite_rules();
156 156
 }
157 157
 
158 158
 // Installation Hook
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function wl_core_upgrade_db_to_1_0() {
168 168
 
169
-	if ( ! get_site_option( 'wl_db_version' ) ) {
170
-		wl_core_install_create_relation_instance_table();
171
-	}
169
+    if ( ! get_site_option( 'wl_db_version' ) ) {
170
+        wl_core_install_create_relation_instance_table();
171
+    }
172 172
 
173 173
 }
174 174
 
@@ -181,45 +181,45 @@  discard block
 block discarded – undo
181 181
  */
182 182
 function wl_core_upgrade_db_1_0_to_3_10() {
183 183
 
184
-	// If the DB version is less than 3.10, than flatten the txonomy.
185
-	if ( version_compare( get_site_option( 'wl_db_version' ), '3.9', '<=' ) ) {
184
+    // If the DB version is less than 3.10, than flatten the txonomy.
185
+    if ( version_compare( get_site_option( 'wl_db_version' ), '3.9', '<=' ) ) {
186 186
 
187
-		$term_slugs = array(
188
-			'thing',
189
-			'creative-work',
190
-			'event',
191
-			'organization',
192
-			'person',
193
-			'place',
194
-			'localbusiness',
195
-		);
187
+        $term_slugs = array(
188
+            'thing',
189
+            'creative-work',
190
+            'event',
191
+            'organization',
192
+            'person',
193
+            'place',
194
+            'localbusiness',
195
+        );
196 196
 
197
-		foreach ( $term_slugs as $slug ) {
197
+        foreach ( $term_slugs as $slug ) {
198 198
 
199
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
199
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
200 200
 
201
-			// Set the term's parent to 0.
202
-			if ( $term ) {
203
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
204
-					'parent' => 0,
205
-				) );
206
-			}
207
-		}
201
+            // Set the term's parent to 0.
202
+            if ( $term ) {
203
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
204
+                    'parent' => 0,
205
+                ) );
206
+            }
207
+        }
208 208
 
209
-	}
209
+    }
210 210
 
211 211
 }
212 212
 
213 213
 // Check db status on automated plugins updates
214 214
 function wl_core_update_db_check() {
215 215
 
216
-	if ( get_site_option( 'wl_db_version' ) != WL_DB_VERSION ) {
216
+    if ( get_site_option( 'wl_db_version' ) != WL_DB_VERSION ) {
217 217
 
218
-		wl_core_upgrade_db_to_1_0();
219
-		wl_core_upgrade_db_1_0_to_3_10();
220
-		update_site_option( 'wl_db_version', WL_DB_VERSION );
218
+        wl_core_upgrade_db_to_1_0();
219
+        wl_core_upgrade_db_1_0_to_3_10();
220
+        update_site_option( 'wl_db_version', WL_DB_VERSION );
221 221
 
222
-	}
222
+    }
223 223
 
224 224
 }
225 225
 
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -52,37 +52,37 @@  discard block
 block discarded – undo
52 52
 		),
53 53
 	);
54 54
 
55
-	foreach ( $terms as $slug => $term ) {
55
+	foreach ($terms as $slug => $term) {
56 56
 
57 57
 		// Create the term if it does not exist, then get its ID
58
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
58
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
59 59
 
60
-		if ( 0 == $term_id || is_null( $term_id ) ) {
61
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
60
+		if (0 == $term_id || is_null($term_id)) {
61
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
62 62
 		} else {
63 63
 			$term_id = $term_id['term_id'];
64
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
64
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
65 65
 		}
66 66
 
67 67
 		// Check for errors.
68
-		if ( is_wp_error( $result ) ) {
69
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
68
+		if (is_wp_error($result)) {
69
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
70 70
 			continue;
71 71
 		}
72 72
 
73 73
 		// Check if 'parent' corresponds to an actual term and get its ID.
74
-		if ( ! isset( $term['parents'] ) ) {
74
+		if ( ! isset($term['parents'])) {
75 75
 			$term['parents'] = array();
76 76
 		}
77 77
 
78 78
 		$parent_ids = array();
79
-		foreach ( $term['parents'] as $parent_slug ) {
80
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
79
+		foreach ($term['parents'] as $parent_slug) {
80
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
81
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82 82
 		}
83 83
 
84 84
 		// Define a parent in the WP taxonomy style (not important for WL)
85
-		if ( empty( $parent_ids ) ) {
85
+		if (empty($parent_ids)) {
86 86
 			// No parent
87 87
 			$parent_id = 0;
88 88
 		} else {
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 		}
92 92
 
93 93
 		// Update term with description, slug and parent
94
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
94
+		wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95 95
 			'name'        => $term['label'],
96 96
 			'slug'        => $slug,
97 97
 			'description' => $term['description'],
98 98
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
99 99
 			'parent'      => $parent_id,
100
-		) );
100
+		));
101 101
 
102 102
 	}
103 103
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 
111 111
 	global $wpdb;
112 112
 	// global $wl_db_version;
113
-	$installed_version = get_option( 'wl_db_version' );
113
+	$installed_version = get_option('wl_db_version');
114 114
 
115
-	if ( WL_DB_VERSION != $installed_version ) {
116
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
115
+	if (WL_DB_VERSION != $installed_version) {
116
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
117 117
 		$charset_collate = $wpdb->get_charset_collate();
118 118
 
119 119
 		// Sql statement for the relation instances custom table
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
 EOF;
131 131
 
132 132
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
-		$results = dbDelta( $sql );
133
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
134
+		$results = dbDelta($sql);
135 135
 
136
-		wl_write_log( $results );
136
+		wl_write_log($results);
137 137
 
138
-		update_option( 'wl_db_version', WL_DB_VERSION );
138
+		update_option('wl_db_version', WL_DB_VERSION);
139 139
 	}
140 140
 }
141 141
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 
147 147
 	// Create a blank application key if there is none
148 148
 	$key = wl_configuration_get_key();
149
-	if ( empty( $key ) ) {
150
-		wl_configuration_set_key( '' );
149
+	if (empty($key)) {
150
+		wl_configuration_set_key('');
151 151
 	}
152 152
 
153 153
 	wl_core_install_entity_type_data();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 }
157 157
 
158 158
 // Installation Hook
159
-add_action( 'activate_wordlift/wordlift.php', 'wl_core_install' );
159
+add_action('activate_wordlift/wordlift.php', 'wl_core_install');
160 160
 
161 161
 /**
162 162
  * Upgrade the DB structure to the one expected by the 1.0 release
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function wl_core_upgrade_db_to_1_0() {
168 168
 
169
-	if ( ! get_site_option( 'wl_db_version' ) ) {
169
+	if ( ! get_site_option('wl_db_version')) {
170 170
 		wl_core_install_create_relation_instance_table();
171 171
 	}
172 172
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 function wl_core_upgrade_db_1_0_to_3_10() {
183 183
 
184 184
 	// If the DB version is less than 3.10, than flatten the txonomy.
185
-	if ( version_compare( get_site_option( 'wl_db_version' ), '3.9', '<=' ) ) {
185
+	if (version_compare(get_site_option('wl_db_version'), '3.9', '<=')) {
186 186
 
187 187
 		$term_slugs = array(
188 188
 			'thing',
@@ -194,15 +194,15 @@  discard block
 block discarded – undo
194 194
 			'localbusiness',
195 195
 		);
196 196
 
197
-		foreach ( $term_slugs as $slug ) {
197
+		foreach ($term_slugs as $slug) {
198 198
 
199
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
199
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
200 200
 
201 201
 			// Set the term's parent to 0.
202
-			if ( $term ) {
203
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
202
+			if ($term) {
203
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
204 204
 					'parent' => 0,
205
-				) );
205
+				));
206 206
 			}
207 207
 		}
208 208
 
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
 // Check db status on automated plugins updates
214 214
 function wl_core_update_db_check() {
215 215
 
216
-	if ( get_site_option( 'wl_db_version' ) != WL_DB_VERSION ) {
216
+	if (get_site_option('wl_db_version') != WL_DB_VERSION) {
217 217
 
218 218
 		wl_core_upgrade_db_to_1_0();
219 219
 		wl_core_upgrade_db_1_0_to_3_10();
220
-		update_site_option( 'wl_db_version', WL_DB_VERSION );
220
+		update_site_option('wl_db_version', WL_DB_VERSION);
221 221
 
222 222
 	}
223 223
 
224 224
 }
225 225
 
226
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
226
+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-types-taxonomy-walker.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Entity Types taxonomy.
5 5
  */
6 6
 if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
7
-	require_once( ABSPATH . 'wp-admin/includes/template.php' );
7
+    require_once( ABSPATH . 'wp-admin/includes/template.php' );
8 8
 }
9 9
 
10 10
 /**
@@ -14,59 +14,59 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Entity_Types_Taxonomy_Walker extends Walker_Category_Checklist {
16 16
 
17
-	/**
18
-	 * Entity taxonomy metabox must show exclusive options, no checkboxes.
19
-	 *
20
-	 * @since 3.1.0
21
-	 *
22
-	 * @param $args
23
-	 *
24
-	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
25
-	 */
26
-	function terms_checklist_args( $args ) {
17
+    /**
18
+     * Entity taxonomy metabox must show exclusive options, no checkboxes.
19
+     *
20
+     * @since 3.1.0
21
+     *
22
+     * @param $args
23
+     *
24
+     * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
25
+     */
26
+    function terms_checklist_args( $args ) {
27 27
 
28
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
29
-			return $args;
30
-		}
28
+        if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
29
+            return $args;
30
+        }
31 31
 
32
-		// We override the way WP prints the taxonomy metabox HTML.
33
-		$args['walker']        = $this;
34
-		$args['checked_ontop'] = false;
32
+        // We override the way WP prints the taxonomy metabox HTML.
33
+        $args['walker']        = $this;
34
+        $args['checked_ontop'] = false;
35 35
 
36
-		return $args;
36
+        return $args;
37 37
 
38
-	}
38
+    }
39 39
 
40
-	/**
41
-	 * Change checkboxes to radios.
42
-	 *
43
-	 * $max_depth = -1 means flatly display every element.
44
-	 * $max_depth = 0 means display all levels.
45
-	 * $max_depth > 0 specifies the number of display levels.
46
-	 *
47
-	 * @since 3.1.0
48
-	 *
49
-	 * @param array $elements  An array of elements.
50
-	 * @param int   $max_depth The maximum hierarchical depth.
51
-	 *
52
-	 * @param array $args      Additional arguments.
53
-	 *
54
-	 * @return string The hierarchical item output.
55
-	 */
56
-	public function walk( $elements, $max_depth, $args = array() ) {
40
+    /**
41
+     * Change checkboxes to radios.
42
+     *
43
+     * $max_depth = -1 means flatly display every element.
44
+     * $max_depth = 0 means display all levels.
45
+     * $max_depth > 0 specifies the number of display levels.
46
+     *
47
+     * @since 3.1.0
48
+     *
49
+     * @param array $elements  An array of elements.
50
+     * @param int   $max_depth The maximum hierarchical depth.
51
+     *
52
+     * @param array $args      Additional arguments.
53
+     *
54
+     * @return string The hierarchical item output.
55
+     */
56
+    public function walk( $elements, $max_depth, $args = array() ) {
57 57
 
58
-		// `max_depth` force to -1 to display a flat taxonomy.
59
-		//
60
-		// See https://github.com/insideout10/wordlift-plugin/issues/305
61
-		$output = parent::walk( $elements, - 1, $args );
58
+        // `max_depth` force to -1 to display a flat taxonomy.
59
+        //
60
+        // See https://github.com/insideout10/wordlift-plugin/issues/305
61
+        $output = parent::walk( $elements, - 1, $args );
62 62
 
63
-		$output = str_replace(
64
-			array( "type=\"checkbox\"", "type='checkbox'" ),
65
-			array( "type=\"radio\"", "type='radio'" ),
66
-			$output
67
-		);
63
+        $output = str_replace(
64
+            array( "type=\"checkbox\"", "type='checkbox'" ),
65
+            array( "type=\"radio\"", "type='radio'" ),
66
+            $output
67
+        );
68 68
 
69
-		return $output;
70
-	}
69
+        return $output;
70
+    }
71 71
 
72 72
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
  * This file contains the Entity Types Taxonomy Walker whose main role is to turn checkboxes to radios for the
4 4
  * Entity Types taxonomy.
5 5
  */
6
-if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
7
-	require_once( ABSPATH . 'wp-admin/includes/template.php' );
6
+if ( ! class_exists('Walker_Category_Checklist')) {
7
+	require_once(ABSPATH.'wp-admin/includes/template.php');
8 8
 }
9 9
 
10 10
 /**
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
25 25
 	 */
26
-	function terms_checklist_args( $args ) {
26
+	function terms_checklist_args($args) {
27 27
 
28
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
28
+		if ( ! isset($args['taxonomy']) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) {
29 29
 			return $args;
30 30
 		}
31 31
 
@@ -53,16 +53,16 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return string The hierarchical item output.
55 55
 	 */
56
-	public function walk( $elements, $max_depth, $args = array() ) {
56
+	public function walk($elements, $max_depth, $args = array()) {
57 57
 
58 58
 		// `max_depth` force to -1 to display a flat taxonomy.
59 59
 		//
60 60
 		// See https://github.com/insideout10/wordlift-plugin/issues/305
61
-		$output = parent::walk( $elements, - 1, $args );
61
+		$output = parent::walk($elements, - 1, $args);
62 62
 
63 63
 		$output = str_replace(
64
-			array( "type=\"checkbox\"", "type='checkbox'" ),
65
-			array( "type=\"radio\"", "type='radio'" ),
64
+			array("type=\"checkbox\"", "type='checkbox'"),
65
+			array("type=\"radio\"", "type='radio'"),
66 66
 			$output
67 67
 		);
68 68
 
Please login to merge, or discard this patch.