@@ -11,91 +11,91 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,57 +213,57 @@ discard block |
||
| 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 | - |
|
| 235 | - // Assign capabilities to manipulate entities to editors. |
|
| 236 | - $editors = get_role( 'editor' ); |
|
| 237 | - |
|
| 238 | - $editors->add_cap( 'edit_wordlift_entity' ); |
|
| 239 | - $editors->add_cap( 'edit_wordlift_entities' ); |
|
| 240 | - $editors->add_cap( 'edit_others_wordlift_entities' ); |
|
| 241 | - $editors->add_cap( 'publish_wordlift_entities' ); |
|
| 242 | - $editors->add_cap( 'read_private_wordlift_entities' ); |
|
| 243 | - $editors->add_cap( 'delete_wordlift_entity' ); |
|
| 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 | + |
|
| 235 | + // Assign capabilities to manipulate entities to editors. |
|
| 236 | + $editors = get_role( 'editor' ); |
|
| 237 | + |
|
| 238 | + $editors->add_cap( 'edit_wordlift_entity' ); |
|
| 239 | + $editors->add_cap( 'edit_wordlift_entities' ); |
|
| 240 | + $editors->add_cap( 'edit_others_wordlift_entities' ); |
|
| 241 | + $editors->add_cap( 'publish_wordlift_entities' ); |
|
| 242 | + $editors->add_cap( 'read_private_wordlift_entities' ); |
|
| 243 | + $editors->add_cap( 'delete_wordlift_entity' ); |
|
| 244 | 244 | |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Check db status on automated plugins updates |
| 248 | 248 | function wl_core_update_db_check() { |
| 249 | 249 | |
| 250 | - // Ensure the custom type and the taxonomy are registered. |
|
| 251 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 250 | + // Ensure the custom type and the taxonomy are registered. |
|
| 251 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 252 | 252 | |
| 253 | - wl_entity_type_taxonomy_register(); |
|
| 253 | + wl_entity_type_taxonomy_register(); |
|
| 254 | 254 | |
| 255 | - // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 256 | - Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 255 | + // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 256 | + Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 257 | 257 | |
| 258 | - if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 259 | - wl_core_install_entity_type_data(); |
|
| 260 | - wl_core_upgrade_db_to_1_0(); |
|
| 261 | - wl_core_upgrade_db_1_0_to_3_10(); |
|
| 262 | - wl_core_upgrade_db_3_10_3_12(); |
|
| 263 | - wl_core_upgrade_db_3_12_3_14(); |
|
| 264 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 258 | + if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 259 | + wl_core_install_entity_type_data(); |
|
| 260 | + wl_core_upgrade_db_to_1_0(); |
|
| 261 | + wl_core_upgrade_db_1_0_to_3_10(); |
|
| 262 | + wl_core_upgrade_db_3_10_3_12(); |
|
| 263 | + wl_core_upgrade_db_3_12_3_14(); |
|
| 264 | + update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 265 | 265 | |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
@@ -46,37 +46,37 @@ discard block |
||
| 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,13 +85,13 @@ discard block |
||
| 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 | |
@@ -106,10 +106,10 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,24 +223,24 @@ discard block |
||
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | // Assign capabilities to manipulate entities to admins. |
| 226 | - $admins = get_role( 'administrator' ); |
|
| 226 | + $admins = get_role('administrator'); |
|
| 227 | 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' ); |
|
| 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 | 234 | |
| 235 | 235 | // Assign capabilities to manipulate entities to editors. |
| 236 | - $editors = get_role( 'editor' ); |
|
| 236 | + $editors = get_role('editor'); |
|
| 237 | 237 | |
| 238 | - $editors->add_cap( 'edit_wordlift_entity' ); |
|
| 239 | - $editors->add_cap( 'edit_wordlift_entities' ); |
|
| 240 | - $editors->add_cap( 'edit_others_wordlift_entities' ); |
|
| 241 | - $editors->add_cap( 'publish_wordlift_entities' ); |
|
| 242 | - $editors->add_cap( 'read_private_wordlift_entities' ); |
|
| 243 | - $editors->add_cap( 'delete_wordlift_entity' ); |
|
| 238 | + $editors->add_cap('edit_wordlift_entity'); |
|
| 239 | + $editors->add_cap('edit_wordlift_entities'); |
|
| 240 | + $editors->add_cap('edit_others_wordlift_entities'); |
|
| 241 | + $editors->add_cap('publish_wordlift_entities'); |
|
| 242 | + $editors->add_cap('read_private_wordlift_entities'); |
|
| 243 | + $editors->add_cap('delete_wordlift_entity'); |
|
| 244 | 244 | |
| 245 | 245 | } |
| 246 | 246 | |
@@ -255,16 +255,16 @@ discard block |
||
| 255 | 255 | // Ensure the custom taxonomy for dbpedia topics is registered |
| 256 | 256 | Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
| 257 | 257 | |
| 258 | - if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 258 | + if (get_option('wl_db_version') != WL_DB_VERSION) { |
|
| 259 | 259 | wl_core_install_entity_type_data(); |
| 260 | 260 | wl_core_upgrade_db_to_1_0(); |
| 261 | 261 | wl_core_upgrade_db_1_0_to_3_10(); |
| 262 | 262 | wl_core_upgrade_db_3_10_3_12(); |
| 263 | 263 | wl_core_upgrade_db_3_12_3_14(); |
| 264 | - update_option( 'wl_db_version', WL_DB_VERSION ); |
|
| 264 | + update_option('wl_db_version', WL_DB_VERSION); |
|
| 265 | 265 | |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | -add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first |
|
| 270 | +add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first |
|
@@ -22,38 +22,38 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Activator { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Short Description. (use period) |
|
| 27 | - * |
|
| 28 | - * Long Description. |
|
| 29 | - * |
|
| 30 | - * @since 1.0.0 |
|
| 31 | - */ |
|
| 32 | - public static function activate() { |
|
| 33 | - |
|
| 34 | - // Do not let the plugin be activate on wordpress versions before 4.2. |
|
| 35 | - $version = get_bloginfo( 'version' ); |
|
| 36 | - if ( version_compare( $version, '4.2', '<' ) ) { |
|
| 37 | - die( __( 'The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift' ) ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 41 | - |
|
| 42 | - // Create a blank application key if there is none |
|
| 43 | - $key = $configuration_service->get_key(); |
|
| 44 | - if ( empty( $key ) ) { |
|
| 45 | - $configuration_service->set_key( '' ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | - wl_core_update_db_check(); |
|
| 50 | - |
|
| 51 | - // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 52 | - // for granted that we're in a browser admin session. |
|
| 53 | - if ( '' === $configuration_service->get_key() ) { |
|
| 54 | - set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - } |
|
| 25 | + /** |
|
| 26 | + * Short Description. (use period) |
|
| 27 | + * |
|
| 28 | + * Long Description. |
|
| 29 | + * |
|
| 30 | + * @since 1.0.0 |
|
| 31 | + */ |
|
| 32 | + public static function activate() { |
|
| 33 | + |
|
| 34 | + // Do not let the plugin be activate on wordpress versions before 4.2. |
|
| 35 | + $version = get_bloginfo( 'version' ); |
|
| 36 | + if ( version_compare( $version, '4.2', '<' ) ) { |
|
| 37 | + die( __( 'The WordLift plugin requires WordPress version 4.2 or above.', 'wordlift' ) ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 41 | + |
|
| 42 | + // Create a blank application key if there is none |
|
| 43 | + $key = $configuration_service->get_key(); |
|
| 44 | + if ( empty( $key ) ) { |
|
| 45 | + $configuration_service->set_key( '' ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | + wl_core_update_db_check(); |
|
| 50 | + |
|
| 51 | + // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 52 | + // for granted that we're in a browser admin session. |
|
| 53 | + if ( '' === $configuration_service->get_key() ) { |
|
| 54 | + set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |