@@ -18,59 +18,59 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
| 20 | 20 | |
| 21 | - if ( get_transient( 'DISABLE_ENTITY_PUSH') ) { |
|
| 22 | - return true; |
|
| 23 | - } |
|
| 21 | + if ( get_transient( 'DISABLE_ENTITY_PUSH') ) { |
|
| 22 | + return true; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - // Queue the update query. |
|
| 26 | - if ( $queue ) { |
|
| 25 | + // Queue the update query. |
|
| 26 | + if ( $queue ) { |
|
| 27 | 27 | |
| 28 | - if ( WP_DEBUG ) { |
|
| 29 | - global $wl_logger; |
|
| 30 | - $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 31 | - } |
|
| 28 | + if ( WP_DEBUG ) { |
|
| 29 | + global $wl_logger; |
|
| 30 | + $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - wl_queue_sparql_update_query( $query ); |
|
| 33 | + wl_queue_sparql_update_query( $query ); |
|
| 34 | 34 | |
| 35 | - return true; |
|
| 36 | - } |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - // Get the update end-point. |
|
| 39 | - $url = wl_configuration_get_query_update_url(); |
|
| 38 | + // Get the update end-point. |
|
| 39 | + $url = wl_configuration_get_query_update_url(); |
|
| 40 | 40 | |
| 41 | - // Prepare the request. |
|
| 42 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 43 | - 'method' => 'POST', |
|
| 44 | - 'headers' => array( |
|
| 45 | - 'Accept' => 'application/json', |
|
| 46 | - 'Content-type' => 'application/sparql-update; charset=utf-8', |
|
| 47 | - ), |
|
| 48 | - 'body' => $query, |
|
| 49 | - ) ); |
|
| 41 | + // Prepare the request. |
|
| 42 | + $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 43 | + 'method' => 'POST', |
|
| 44 | + 'headers' => array( |
|
| 45 | + 'Accept' => 'application/json', |
|
| 46 | + 'Content-type' => 'application/sparql-update; charset=utf-8', |
|
| 47 | + ), |
|
| 48 | + 'body' => $query, |
|
| 49 | + ) ); |
|
| 50 | 50 | |
| 51 | - // Send the request. |
|
| 52 | - $response = wp_remote_post( $url, $args ); |
|
| 51 | + // Send the request. |
|
| 52 | + $response = wp_remote_post( $url, $args ); |
|
| 53 | 53 | |
| 54 | - // If an error has been raised, return the error. |
|
| 55 | - if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 54 | + // If an error has been raised, return the error. |
|
| 55 | + if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 56 | 56 | |
| 57 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 57 | + $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 58 | 58 | |
| 59 | - wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 60 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 61 | - wl_write_log( "[ response :: " ); |
|
| 62 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 63 | - wl_write_log( "][ body :: " ); |
|
| 64 | - wl_write_log( "\n" . $body ); |
|
| 65 | - wl_write_log( "]" ); |
|
| 59 | + wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 60 | + wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 61 | + wl_write_log( "[ response :: " ); |
|
| 62 | + wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 63 | + wl_write_log( "][ body :: " ); |
|
| 64 | + wl_write_log( "\n" . $body ); |
|
| 65 | + wl_write_log( "]" ); |
|
| 66 | 66 | |
| 67 | - return false; |
|
| 68 | - } |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if ( WP_DEBUG ) { |
|
| 71 | - global $wl_logger; |
|
| 72 | - $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 73 | - } |
|
| 70 | + if ( WP_DEBUG ) { |
|
| 71 | + global $wl_logger; |
|
| 72 | + $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return true; |
|
| 75 | + return true; |
|
| 76 | 76 | } |
@@ -16,21 +16,21 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return bool True if successful otherwise false. |
| 18 | 18 | */ |
| 19 | -function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 19 | +function rl_execute_sparql_update_query($query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) { |
|
| 20 | 20 | |
| 21 | - if ( get_transient( 'DISABLE_ENTITY_PUSH') ) { |
|
| 21 | + if (get_transient('DISABLE_ENTITY_PUSH')) { |
|
| 22 | 22 | return true; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Queue the update query. |
| 26 | - if ( $queue ) { |
|
| 26 | + if ($queue) { |
|
| 27 | 27 | |
| 28 | - if ( WP_DEBUG ) { |
|
| 28 | + if (WP_DEBUG) { |
|
| 29 | 29 | global $wl_logger; |
| 30 | - $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 30 | + $wl_logger->trace("Buffering a query [ query :: $query ]"); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - wl_queue_sparql_update_query( $query ); |
|
| 33 | + wl_queue_sparql_update_query($query); |
|
| 34 | 34 | |
| 35 | 35 | return true; |
| 36 | 36 | } |
@@ -39,37 +39,37 @@ discard block |
||
| 39 | 39 | $url = wl_configuration_get_query_update_url(); |
| 40 | 40 | |
| 41 | 41 | // Prepare the request. |
| 42 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 42 | + $args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array( |
|
| 43 | 43 | 'method' => 'POST', |
| 44 | 44 | 'headers' => array( |
| 45 | 45 | 'Accept' => 'application/json', |
| 46 | 46 | 'Content-type' => 'application/sparql-update; charset=utf-8', |
| 47 | 47 | ), |
| 48 | 48 | 'body' => $query, |
| 49 | - ) ); |
|
| 49 | + )); |
|
| 50 | 50 | |
| 51 | 51 | // Send the request. |
| 52 | - $response = wp_remote_post( $url, $args ); |
|
| 52 | + $response = wp_remote_post($url, $args); |
|
| 53 | 53 | |
| 54 | 54 | // If an error has been raised, return the error. |
| 55 | - if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 55 | + if (is_wp_error($response) || 200 !== (int) $response['response']['code']) { |
|
| 56 | 56 | |
| 57 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 57 | + $body = (is_wp_error($response) ? $response->get_error_message() : $response['body']); |
|
| 58 | 58 | |
| 59 | - wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 60 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 61 | - wl_write_log( "[ response :: " ); |
|
| 62 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 63 | - wl_write_log( "][ body :: " ); |
|
| 64 | - wl_write_log( "\n" . $body ); |
|
| 65 | - wl_write_log( "]" ); |
|
| 59 | + wl_write_log("rl_execute_sparql_update_query : error [ url :: $url ][ args :: "); |
|
| 60 | + wl_write_log("\n".var_export($args, true)); |
|
| 61 | + wl_write_log("[ response :: "); |
|
| 62 | + wl_write_log("\n".var_export($response, true)); |
|
| 63 | + wl_write_log("][ body :: "); |
|
| 64 | + wl_write_log("\n".$body); |
|
| 65 | + wl_write_log("]"); |
|
| 66 | 66 | |
| 67 | 67 | return false; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( WP_DEBUG ) { |
|
| 70 | + if (WP_DEBUG) { |
|
| 71 | 71 | global $wl_logger; |
| 72 | - $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 72 | + $wl_logger->trace("Query executed successfully [ query :: $query ]"); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return true; |
@@ -13,35 +13,35 @@ discard block |
||
| 13 | 13 | function wl_get_entity_post_ids_by_uris( $uris ) { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - if ( empty( $uris ) ) { |
|
| 17 | - return array(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - $query = new WP_Query( array( |
|
| 21 | - 'fields' => 'ids', |
|
| 22 | - 'post_status' => 'any', |
|
| 23 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 24 | - 'meta_query' => array( |
|
| 25 | - 'relation' => 'OR', |
|
| 26 | - array( |
|
| 27 | - 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
| 28 | - 'value' => $uris, |
|
| 29 | - 'compare' => 'IN', |
|
| 30 | - ), |
|
| 31 | - array( |
|
| 32 | - 'key' => 'entity_url', |
|
| 33 | - 'value' => $uris, |
|
| 34 | - 'compare' => 'IN', |
|
| 35 | - ), |
|
| 36 | - ), |
|
| 37 | - ) |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - // Get the matching entity posts. |
|
| 41 | - $posts = $query->get_posts(); |
|
| 42 | - |
|
| 43 | - // Return the array |
|
| 44 | - return $posts; |
|
| 16 | + if ( empty( $uris ) ) { |
|
| 17 | + return array(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + $query = new WP_Query( array( |
|
| 21 | + 'fields' => 'ids', |
|
| 22 | + 'post_status' => 'any', |
|
| 23 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 24 | + 'meta_query' => array( |
|
| 25 | + 'relation' => 'OR', |
|
| 26 | + array( |
|
| 27 | + 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
| 28 | + 'value' => $uris, |
|
| 29 | + 'compare' => 'IN', |
|
| 30 | + ), |
|
| 31 | + array( |
|
| 32 | + 'key' => 'entity_url', |
|
| 33 | + 'value' => $uris, |
|
| 34 | + 'compare' => 'IN', |
|
| 35 | + ), |
|
| 36 | + ), |
|
| 37 | + ) |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + // Get the matching entity posts. |
|
| 41 | + $posts = $query->get_posts(); |
|
| 42 | + |
|
| 43 | + // Return the array |
|
| 44 | + return $posts; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,29 +56,29 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function wl_build_entity_uri( $post_id ) { |
| 58 | 58 | |
| 59 | - // Get the post. |
|
| 60 | - $post = get_post( $post_id ); |
|
| 59 | + // Get the post. |
|
| 60 | + $post = get_post( $post_id ); |
|
| 61 | 61 | |
| 62 | - if ( NULL === $post ) { |
|
| 63 | - wl_write_log( "wl_build_entity_uri : error [ post ID :: $post_id ][ post :: null ]" ); |
|
| 62 | + if ( NULL === $post ) { |
|
| 63 | + wl_write_log( "wl_build_entity_uri : error [ post ID :: $post_id ][ post :: null ]" ); |
|
| 64 | 64 | |
| 65 | - return NULL; |
|
| 66 | - } |
|
| 65 | + return NULL; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // Create an ID given the title. |
|
| 69 | - $entity_slug = wl_sanitize_uri_path( $post->post_title ); |
|
| 70 | - // If the entity slug is empty, i.e. there's no title, use the post ID as path. |
|
| 71 | - if ( empty( $entity_slug ) ) { |
|
| 72 | - return sprintf( '%s/%s/%s', |
|
| 73 | - wl_configuration_get_redlink_dataset_uri(), |
|
| 74 | - $post->post_type, |
|
| 75 | - "id/$post->ID" |
|
| 76 | - ); |
|
| 77 | - } |
|
| 68 | + // Create an ID given the title. |
|
| 69 | + $entity_slug = wl_sanitize_uri_path( $post->post_title ); |
|
| 70 | + // If the entity slug is empty, i.e. there's no title, use the post ID as path. |
|
| 71 | + if ( empty( $entity_slug ) ) { |
|
| 72 | + return sprintf( '%s/%s/%s', |
|
| 73 | + wl_configuration_get_redlink_dataset_uri(), |
|
| 74 | + $post->post_type, |
|
| 75 | + "id/$post->ID" |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return Wordlift_Uri_Service::get_instance()->build_uri( |
|
| 80 | - $entity_slug, |
|
| 81 | - $post->post_type ); |
|
| 79 | + return Wordlift_Uri_Service::get_instance()->build_uri( |
|
| 80 | + $entity_slug, |
|
| 81 | + $post->post_type ); |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function wl_get_entity_uri( $post_id ) { |
| 98 | 98 | |
| 99 | - return Wordlift_Entity_Service::get_instance()->get_uri( $post_id ); |
|
| 99 | + return Wordlift_Entity_Service::get_instance()->get_uri( $post_id ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | function wl_set_entity_uri( $post_id, $uri ) { |
| 111 | 111 | |
| 112 | - // wl_write_log( "wl_set_entity_uri [ post id :: $post_id ][ uri :: $uri ]" ); |
|
| 112 | + // wl_write_log( "wl_set_entity_uri [ post id :: $post_id ][ uri :: $uri ]" ); |
|
| 113 | 113 | |
| 114 | - return update_post_meta( $post_id, WL_ENTITY_URL_META_NAME, $uri ); |
|
| 114 | + return update_post_meta( $post_id, WL_ENTITY_URL_META_NAME, $uri ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return array An array of terms. |
| 126 | 126 | */ |
| 127 | 127 | function wl_get_entity_rdf_types( $post_id ) { |
| 128 | - return get_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE ); |
|
| 128 | + return get_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -136,21 +136,21 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | function wl_set_entity_rdf_types( $post_id, $type_uris = array() ) { |
| 138 | 138 | |
| 139 | - // Avoid errors because of null values. |
|
| 140 | - if ( is_null( $type_uris ) ) { |
|
| 141 | - $type_uris = array(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // Ensure there are no duplicates. |
|
| 145 | - $type_uris = array_unique( $type_uris ); |
|
| 146 | - |
|
| 147 | - delete_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE ); |
|
| 148 | - foreach ( $type_uris as $type_uri ) { |
|
| 149 | - if ( empty( $type_uri ) ) { |
|
| 150 | - continue; |
|
| 151 | - } |
|
| 152 | - add_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE, $type_uri ); |
|
| 153 | - } |
|
| 139 | + // Avoid errors because of null values. |
|
| 140 | + if ( is_null( $type_uris ) ) { |
|
| 141 | + $type_uris = array(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // Ensure there are no duplicates. |
|
| 145 | + $type_uris = array_unique( $type_uris ); |
|
| 146 | + |
|
| 147 | + delete_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE ); |
|
| 148 | + foreach ( $type_uris as $type_uri ) { |
|
| 149 | + if ( empty( $type_uri ) ) { |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 152 | + add_post_meta( $post_id, Wordlift_Schema_Service::FIELD_ENTITY_TYPE, $type_uri ); |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function wl_get_meta_type( $property_name ) { |
| 165 | 165 | |
| 166 | - // Property name must be defined. |
|
| 167 | - if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 168 | - return NULL; |
|
| 169 | - } |
|
| 166 | + // Property name must be defined. |
|
| 167 | + if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 168 | + return NULL; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // store eventual schema name in different variable |
|
| 172 | - $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 171 | + // store eventual schema name in different variable |
|
| 172 | + $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 173 | 173 | |
| 174 | - // Loop over custom_fields |
|
| 175 | - $entity_terms = wl_entity_taxonomy_get_custom_fields(); |
|
| 174 | + // Loop over custom_fields |
|
| 175 | + $entity_terms = wl_entity_taxonomy_get_custom_fields(); |
|
| 176 | 176 | |
| 177 | - foreach ( $entity_terms as $term ) { |
|
| 177 | + foreach ( $entity_terms as $term ) { |
|
| 178 | 178 | |
| 179 | - foreach ( $term as $wl_constant => $field ) { |
|
| 179 | + foreach ( $term as $wl_constant => $field ) { |
|
| 180 | 180 | |
| 181 | - // Is this the predicate we are searching for? |
|
| 182 | - if ( isset( $field['type'] ) ) { |
|
| 183 | - $found_predicate = isset( $field['predicate'] ) && ( $field['predicate'] == $property_schema_name ); |
|
| 184 | - $found_constant = ( $wl_constant == $property_name ); |
|
| 185 | - if ( $found_predicate || $found_constant ) { |
|
| 186 | - return $field['type']; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 181 | + // Is this the predicate we are searching for? |
|
| 182 | + if ( isset( $field['type'] ) ) { |
|
| 183 | + $found_predicate = isset( $field['predicate'] ) && ( $field['predicate'] == $property_schema_name ); |
|
| 184 | + $found_constant = ( $wl_constant == $property_name ); |
|
| 185 | + if ( $found_predicate || $found_constant ) { |
|
| 186 | + return $field['type']; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - return NULL; |
|
| 192 | + return NULL; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -202,31 +202,31 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | function wl_get_meta_constraints( $property_name ) { |
| 204 | 204 | |
| 205 | - // Property name must be defined. |
|
| 206 | - if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 207 | - return NULL; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // store eventual schema name in different variable |
|
| 211 | - $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 212 | - |
|
| 213 | - // Get WL taxonomy mapping. |
|
| 214 | - $types = wl_entity_taxonomy_get_custom_fields(); |
|
| 215 | - |
|
| 216 | - // Loop over types |
|
| 217 | - foreach ( $types as $type ) { |
|
| 218 | - // Loop over custom fields of this type |
|
| 219 | - foreach ( $type as $property => $field ) { |
|
| 220 | - if ( isset( $field['constraints'] ) && ! empty( $field['constraints'] ) ) { |
|
| 221 | - // Is this the property we are searhing for? |
|
| 222 | - if ( ( $property == $property_name ) || ( $field['predicate'] == $property_schema_name ) ) { |
|
| 223 | - return $field['constraints']; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return NULL; |
|
| 205 | + // Property name must be defined. |
|
| 206 | + if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 207 | + return NULL; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // store eventual schema name in different variable |
|
| 211 | + $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 212 | + |
|
| 213 | + // Get WL taxonomy mapping. |
|
| 214 | + $types = wl_entity_taxonomy_get_custom_fields(); |
|
| 215 | + |
|
| 216 | + // Loop over types |
|
| 217 | + foreach ( $types as $type ) { |
|
| 218 | + // Loop over custom fields of this type |
|
| 219 | + foreach ( $type as $property => $field ) { |
|
| 220 | + if ( isset( $field['constraints'] ) && ! empty( $field['constraints'] ) ) { |
|
| 221 | + // Is this the property we are searhing for? |
|
| 222 | + if ( ( $property == $property_name ) || ( $field['predicate'] == $property_schema_name ) ) { |
|
| 223 | + return $field['constraints']; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return NULL; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -238,36 +238,36 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | function wl_entity_taxonomy_get_custom_fields( $entity_id = NULL ) { |
| 240 | 240 | |
| 241 | - if ( is_null( $entity_id ) ) { |
|
| 241 | + if ( is_null( $entity_id ) ) { |
|
| 242 | 242 | |
| 243 | - // Return all custom fields. |
|
| 244 | - // Get taxonomy terms |
|
| 245 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( 'hide_empty' => 0 ) ); |
|
| 243 | + // Return all custom fields. |
|
| 244 | + // Get taxonomy terms |
|
| 245 | + $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( 'hide_empty' => 0 ) ); |
|
| 246 | 246 | |
| 247 | - if ( is_wp_error( $terms ) ) { |
|
| 248 | - return NULL; |
|
| 249 | - } |
|
| 247 | + if ( is_wp_error( $terms ) ) { |
|
| 248 | + return NULL; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - $custom_fields = array(); |
|
| 252 | - foreach ( $terms as $term ) { |
|
| 253 | - // Get custom_fields |
|
| 254 | - $term_options = Wordlift_Schema_Service::get_instance() |
|
| 255 | - ->get_schema( $term->slug ); |
|
| 256 | - $custom_fields[ $term_options['uri'] ] = $term_options['custom_fields']; |
|
| 257 | - } |
|
| 251 | + $custom_fields = array(); |
|
| 252 | + foreach ( $terms as $term ) { |
|
| 253 | + // Get custom_fields |
|
| 254 | + $term_options = Wordlift_Schema_Service::get_instance() |
|
| 255 | + ->get_schema( $term->slug ); |
|
| 256 | + $custom_fields[ $term_options['uri'] ] = $term_options['custom_fields']; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - return $custom_fields; |
|
| 259 | + return $custom_fields; |
|
| 260 | 260 | |
| 261 | - } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - // Return custom fields for this specific entity's type. |
|
| 264 | - $type = wl_entity_type_taxonomy_get_type( $entity_id ); |
|
| 263 | + // Return custom fields for this specific entity's type. |
|
| 264 | + $type = wl_entity_type_taxonomy_get_type( $entity_id ); |
|
| 265 | 265 | |
| 266 | - if ( ! isset( $type['custom_fields'] ) ) { |
|
| 267 | - Wordlift_Log_Service::get_logger( 'wl_entity_taxonomy_get_custom_fields' ) |
|
| 268 | - ->error( "custom_fields not set [ entity id :: $entity_id ]" ); |
|
| 269 | - } |
|
| 266 | + if ( ! isset( $type['custom_fields'] ) ) { |
|
| 267 | + Wordlift_Log_Service::get_logger( 'wl_entity_taxonomy_get_custom_fields' ) |
|
| 268 | + ->error( "custom_fields not set [ entity id :: $entity_id ]" ); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return $type['custom_fields']; |
|
| 271 | + return $type['custom_fields']; |
|
| 272 | 272 | |
| 273 | 273 | } |
@@ -15,160 +15,160 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Wordlift_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * A {@link Wordlift_Configuration_Service} instance. |
|
| 20 | - * |
|
| 21 | - * @since 3.10.0 |
|
| 22 | - * @access private |
|
| 23 | - * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 24 | - */ |
|
| 25 | - private $configuration_service; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * A {@link Wordlift_Log_Service} instance. |
|
| 29 | - * |
|
| 30 | - * @since 3.10.0 |
|
| 31 | - * @access private |
|
| 32 | - * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 33 | - */ |
|
| 34 | - private $log; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 38 | - * |
|
| 39 | - * @since 3.10.0 |
|
| 40 | - * |
|
| 41 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 42 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 43 | - * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 44 | - * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 45 | - * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 46 | - */ |
|
| 47 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $configuration_service ) { |
|
| 48 | - parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 49 | - |
|
| 50 | - $this->configuration_service = $configuration_service; |
|
| 51 | - |
|
| 52 | - // Set a reference to the logger. |
|
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 58 | - * found while processing the post is set in the $references array. |
|
| 59 | - * |
|
| 60 | - * @since 3.10.0 |
|
| 61 | - * |
|
| 62 | - * |
|
| 63 | - * @param int $post_id The post id. |
|
| 64 | - * @param array $references An array of entity references. |
|
| 65 | - * |
|
| 66 | - * @return array A JSON-LD array. |
|
| 67 | - */ |
|
| 68 | - public function convert( $post_id, &$references = array() ) { |
|
| 69 | - |
|
| 70 | - // Get the post instance. |
|
| 71 | - if ( null === $post = get_post( $post_id ) ) { |
|
| 72 | - // Post not found. |
|
| 73 | - return null; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Get the base JSON-LD and the list of entities referenced by this entity. |
|
| 77 | - $jsonld = parent::convert( $post_id, $references ); |
|
| 78 | - |
|
| 79 | - // Get the entity name. |
|
| 80 | - $jsonld['headline'] = $post->post_title; |
|
| 81 | - |
|
| 82 | - // Get the author. |
|
| 83 | - $author = get_the_author_meta( 'display_name', $post->post_author ); |
|
| 84 | - $author_id = $this->user_service->get_uri( $post->post_author ); |
|
| 85 | - |
|
| 86 | - $jsonld['author'] = array( |
|
| 87 | - '@type' => 'Person', |
|
| 88 | - '@id' => $author_id, |
|
| 89 | - 'name' => $author, |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - // Set the published and modified dates. |
|
| 93 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 94 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 95 | - |
|
| 96 | - // Set the publisher. |
|
| 97 | - $this->set_publisher( $jsonld ); |
|
| 98 | - |
|
| 99 | - // Add the references ids as mentions. |
|
| 100 | - $entity_service = $this->entity_service; |
|
| 101 | - if ( 0 < sizeof( $references ) ) { |
|
| 102 | - $jsonld['mentions'] = array_map( function ( $item ) use ( $entity_service ) { |
|
| 103 | - return array( '@id' => $entity_service->get_uri( $item ) ); |
|
| 104 | - }, $references ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $jsonld; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Enrich the provided params array with publisher data, if available. |
|
| 112 | - * |
|
| 113 | - * @since 3.10.0 |
|
| 114 | - * |
|
| 115 | - * @param array $params The parameters array. |
|
| 116 | - */ |
|
| 117 | - private function set_publisher( &$params ) { |
|
| 118 | - |
|
| 119 | - // If the publisher id isn't set don't do anything. |
|
| 120 | - if ( null === $publisher_id = $this->configuration_service->get_publisher_id() ) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Get the post instance. |
|
| 125 | - if ( null === $post = get_post( $publisher_id ) ) { |
|
| 126 | - // Publisher not found. |
|
| 127 | - return; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // Get the item id |
|
| 131 | - $id = $this->entity_service->get_uri( $publisher_id ); |
|
| 132 | - |
|
| 133 | - // Get the type. |
|
| 134 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
| 135 | - |
|
| 136 | - // Get the name. |
|
| 137 | - $name = $post->post_title; |
|
| 138 | - |
|
| 139 | - // Set the publisher data. |
|
| 140 | - $params['publisher'] = array( |
|
| 141 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
| 142 | - '@id' => $id, |
|
| 143 | - 'name' => $name, |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - // Set the logo, only for http://schema.org/Organization as Person doesn't |
|
| 147 | - // support the logo property. |
|
| 148 | - // |
|
| 149 | - // See http://schema.org/logo |
|
| 150 | - if ( 'http://schema.org/Organization' !== $type['uri'] ) { |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Get the logo, WP < 4.4 way: only post ID accepted here. |
|
| 155 | - if ( '' === $thumbnail_id = get_post_thumbnail_id( $post->ID ) ) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Get the image URL. |
|
| 160 | - if ( false === $attachment = wp_get_attachment_image_src( $thumbnail_id, 'full' ) ) { |
|
| 161 | - return; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // Copy over some useful properties. |
|
| 165 | - // |
|
| 166 | - // See https://developers.google.com/search/docs/data-types/articles |
|
| 167 | - $params['publisher']['logo']['@type'] = 'ImageObject'; |
|
| 168 | - $params['publisher']['logo']['url'] = $attachment[0]; |
|
| 169 | - $params['publisher']['logo']['width'] = $attachment[1] . 'px'; |
|
| 170 | - $params['publisher']['logo']['height'] = $attachment[2] . 'px'; |
|
| 171 | - |
|
| 172 | - } |
|
| 18 | + /** |
|
| 19 | + * A {@link Wordlift_Configuration_Service} instance. |
|
| 20 | + * |
|
| 21 | + * @since 3.10.0 |
|
| 22 | + * @access private |
|
| 23 | + * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 24 | + */ |
|
| 25 | + private $configuration_service; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * A {@link Wordlift_Log_Service} instance. |
|
| 29 | + * |
|
| 30 | + * @since 3.10.0 |
|
| 31 | + * @access private |
|
| 32 | + * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 33 | + */ |
|
| 34 | + private $log; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 38 | + * |
|
| 39 | + * @since 3.10.0 |
|
| 40 | + * |
|
| 41 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 42 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 43 | + * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 44 | + * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 45 | + * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 46 | + */ |
|
| 47 | + public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $configuration_service ) { |
|
| 48 | + parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 49 | + |
|
| 50 | + $this->configuration_service = $configuration_service; |
|
| 51 | + |
|
| 52 | + // Set a reference to the logger. |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 58 | + * found while processing the post is set in the $references array. |
|
| 59 | + * |
|
| 60 | + * @since 3.10.0 |
|
| 61 | + * |
|
| 62 | + * |
|
| 63 | + * @param int $post_id The post id. |
|
| 64 | + * @param array $references An array of entity references. |
|
| 65 | + * |
|
| 66 | + * @return array A JSON-LD array. |
|
| 67 | + */ |
|
| 68 | + public function convert( $post_id, &$references = array() ) { |
|
| 69 | + |
|
| 70 | + // Get the post instance. |
|
| 71 | + if ( null === $post = get_post( $post_id ) ) { |
|
| 72 | + // Post not found. |
|
| 73 | + return null; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Get the base JSON-LD and the list of entities referenced by this entity. |
|
| 77 | + $jsonld = parent::convert( $post_id, $references ); |
|
| 78 | + |
|
| 79 | + // Get the entity name. |
|
| 80 | + $jsonld['headline'] = $post->post_title; |
|
| 81 | + |
|
| 82 | + // Get the author. |
|
| 83 | + $author = get_the_author_meta( 'display_name', $post->post_author ); |
|
| 84 | + $author_id = $this->user_service->get_uri( $post->post_author ); |
|
| 85 | + |
|
| 86 | + $jsonld['author'] = array( |
|
| 87 | + '@type' => 'Person', |
|
| 88 | + '@id' => $author_id, |
|
| 89 | + 'name' => $author, |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + // Set the published and modified dates. |
|
| 93 | + $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 94 | + $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 95 | + |
|
| 96 | + // Set the publisher. |
|
| 97 | + $this->set_publisher( $jsonld ); |
|
| 98 | + |
|
| 99 | + // Add the references ids as mentions. |
|
| 100 | + $entity_service = $this->entity_service; |
|
| 101 | + if ( 0 < sizeof( $references ) ) { |
|
| 102 | + $jsonld['mentions'] = array_map( function ( $item ) use ( $entity_service ) { |
|
| 103 | + return array( '@id' => $entity_service->get_uri( $item ) ); |
|
| 104 | + }, $references ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $jsonld; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Enrich the provided params array with publisher data, if available. |
|
| 112 | + * |
|
| 113 | + * @since 3.10.0 |
|
| 114 | + * |
|
| 115 | + * @param array $params The parameters array. |
|
| 116 | + */ |
|
| 117 | + private function set_publisher( &$params ) { |
|
| 118 | + |
|
| 119 | + // If the publisher id isn't set don't do anything. |
|
| 120 | + if ( null === $publisher_id = $this->configuration_service->get_publisher_id() ) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Get the post instance. |
|
| 125 | + if ( null === $post = get_post( $publisher_id ) ) { |
|
| 126 | + // Publisher not found. |
|
| 127 | + return; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // Get the item id |
|
| 131 | + $id = $this->entity_service->get_uri( $publisher_id ); |
|
| 132 | + |
|
| 133 | + // Get the type. |
|
| 134 | + $type = $this->entity_type_service->get( $publisher_id ); |
|
| 135 | + |
|
| 136 | + // Get the name. |
|
| 137 | + $name = $post->post_title; |
|
| 138 | + |
|
| 139 | + // Set the publisher data. |
|
| 140 | + $params['publisher'] = array( |
|
| 141 | + '@type' => $this->relative_to_context( $type['uri'] ), |
|
| 142 | + '@id' => $id, |
|
| 143 | + 'name' => $name, |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + // Set the logo, only for http://schema.org/Organization as Person doesn't |
|
| 147 | + // support the logo property. |
|
| 148 | + // |
|
| 149 | + // See http://schema.org/logo |
|
| 150 | + if ( 'http://schema.org/Organization' !== $type['uri'] ) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Get the logo, WP < 4.4 way: only post ID accepted here. |
|
| 155 | + if ( '' === $thumbnail_id = get_post_thumbnail_id( $post->ID ) ) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Get the image URL. |
|
| 160 | + if ( false === $attachment = wp_get_attachment_image_src( $thumbnail_id, 'full' ) ) { |
|
| 161 | + return; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // Copy over some useful properties. |
|
| 165 | + // |
|
| 166 | + // See https://developers.google.com/search/docs/data-types/articles |
|
| 167 | + $params['publisher']['logo']['@type'] = 'ImageObject'; |
|
| 168 | + $params['publisher']['logo']['url'] = $attachment[0]; |
|
| 169 | + $params['publisher']['logo']['width'] = $attachment[1] . 'px'; |
|
| 170 | + $params['publisher']['logo']['height'] = $attachment[2] . 'px'; |
|
| 171 | + |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
| 45 | 45 | * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
| 46 | 46 | */ |
| 47 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $configuration_service ) { |
|
| 48 | - parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 47 | + public function __construct($entity_type_service, $entity_service, $user_service, $attachment_service, $configuration_service) { |
|
| 48 | + parent::__construct($entity_type_service, $entity_service, $user_service, $attachment_service); |
|
| 49 | 49 | |
| 50 | 50 | $this->configuration_service = $configuration_service; |
| 51 | 51 | |
| 52 | 52 | // Set a reference to the logger. |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -65,23 +65,23 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return array A JSON-LD array. |
| 67 | 67 | */ |
| 68 | - public function convert( $post_id, &$references = array() ) { |
|
| 68 | + public function convert($post_id, &$references = array()) { |
|
| 69 | 69 | |
| 70 | 70 | // Get the post instance. |
| 71 | - if ( null === $post = get_post( $post_id ) ) { |
|
| 71 | + if (null === $post = get_post($post_id)) { |
|
| 72 | 72 | // Post not found. |
| 73 | 73 | return null; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Get the base JSON-LD and the list of entities referenced by this entity. |
| 77 | - $jsonld = parent::convert( $post_id, $references ); |
|
| 77 | + $jsonld = parent::convert($post_id, $references); |
|
| 78 | 78 | |
| 79 | 79 | // Get the entity name. |
| 80 | 80 | $jsonld['headline'] = $post->post_title; |
| 81 | 81 | |
| 82 | 82 | // Get the author. |
| 83 | - $author = get_the_author_meta( 'display_name', $post->post_author ); |
|
| 84 | - $author_id = $this->user_service->get_uri( $post->post_author ); |
|
| 83 | + $author = get_the_author_meta('display_name', $post->post_author); |
|
| 84 | + $author_id = $this->user_service->get_uri($post->post_author); |
|
| 85 | 85 | |
| 86 | 86 | $jsonld['author'] = array( |
| 87 | 87 | '@type' => 'Person', |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | // Set the published and modified dates. |
| 93 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 94 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 93 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
| 94 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
| 95 | 95 | |
| 96 | 96 | // Set the publisher. |
| 97 | - $this->set_publisher( $jsonld ); |
|
| 97 | + $this->set_publisher($jsonld); |
|
| 98 | 98 | |
| 99 | 99 | // Add the references ids as mentions. |
| 100 | 100 | $entity_service = $this->entity_service; |
| 101 | - if ( 0 < sizeof( $references ) ) { |
|
| 102 | - $jsonld['mentions'] = array_map( function ( $item ) use ( $entity_service ) { |
|
| 103 | - return array( '@id' => $entity_service->get_uri( $item ) ); |
|
| 104 | - }, $references ); |
|
| 101 | + if (0 < sizeof($references)) { |
|
| 102 | + $jsonld['mentions'] = array_map(function($item) use ($entity_service) { |
|
| 103 | + return array('@id' => $entity_service->get_uri($item)); |
|
| 104 | + }, $references); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | return $jsonld; |
@@ -114,31 +114,31 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @param array $params The parameters array. |
| 116 | 116 | */ |
| 117 | - private function set_publisher( &$params ) { |
|
| 117 | + private function set_publisher(&$params) { |
|
| 118 | 118 | |
| 119 | 119 | // If the publisher id isn't set don't do anything. |
| 120 | - if ( null === $publisher_id = $this->configuration_service->get_publisher_id() ) { |
|
| 120 | + if (null === $publisher_id = $this->configuration_service->get_publisher_id()) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Get the post instance. |
| 125 | - if ( null === $post = get_post( $publisher_id ) ) { |
|
| 125 | + if (null === $post = get_post($publisher_id)) { |
|
| 126 | 126 | // Publisher not found. |
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Get the item id |
| 131 | - $id = $this->entity_service->get_uri( $publisher_id ); |
|
| 131 | + $id = $this->entity_service->get_uri($publisher_id); |
|
| 132 | 132 | |
| 133 | 133 | // Get the type. |
| 134 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
| 134 | + $type = $this->entity_type_service->get($publisher_id); |
|
| 135 | 135 | |
| 136 | 136 | // Get the name. |
| 137 | 137 | $name = $post->post_title; |
| 138 | 138 | |
| 139 | 139 | // Set the publisher data. |
| 140 | 140 | $params['publisher'] = array( |
| 141 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
| 141 | + '@type' => $this->relative_to_context($type['uri']), |
|
| 142 | 142 | '@id' => $id, |
| 143 | 143 | 'name' => $name, |
| 144 | 144 | ); |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | // support the logo property. |
| 148 | 148 | // |
| 149 | 149 | // See http://schema.org/logo |
| 150 | - if ( 'http://schema.org/Organization' !== $type['uri'] ) { |
|
| 150 | + if ('http://schema.org/Organization' !== $type['uri']) { |
|
| 151 | 151 | return; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Get the logo, WP < 4.4 way: only post ID accepted here. |
| 155 | - if ( '' === $thumbnail_id = get_post_thumbnail_id( $post->ID ) ) { |
|
| 155 | + if ('' === $thumbnail_id = get_post_thumbnail_id($post->ID)) { |
|
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Get the image URL. |
| 160 | - if ( false === $attachment = wp_get_attachment_image_src( $thumbnail_id, 'full' ) ) { |
|
| 160 | + if (false === $attachment = wp_get_attachment_image_src($thumbnail_id, 'full')) { |
|
| 161 | 161 | return; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | // See https://developers.google.com/search/docs/data-types/articles |
| 167 | 167 | $params['publisher']['logo']['@type'] = 'ImageObject'; |
| 168 | 168 | $params['publisher']['logo']['url'] = $attachment[0]; |
| 169 | - $params['publisher']['logo']['width'] = $attachment[1] . 'px'; |
|
| 170 | - $params['publisher']['logo']['height'] = $attachment[2] . 'px'; |
|
| 169 | + $params['publisher']['logo']['width'] = $attachment[1].'px'; |
|
| 170 | + $params['publisher']['logo']['height'] = $attachment[2].'px'; |
|
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | |
@@ -16,150 +16,150 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Attachment_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Get an attachment ID given a URL. |
|
| 21 | - * |
|
| 22 | - * Inspired from https://wpscholar.com/blog/get-attachment-id-from-wp-image-url/ |
|
| 23 | - * |
|
| 24 | - * @since 3.10.0 |
|
| 25 | - * |
|
| 26 | - * @param string $url The attachment URL. |
|
| 27 | - * |
|
| 28 | - * @return int|false Attachment ID on success, false on failure |
|
| 29 | - */ |
|
| 30 | - public function get_attachment_id( $url ) { |
|
| 31 | - |
|
| 32 | - // Get the upload directory data, we need the base URL to check whether |
|
| 33 | - // the URL we received is within WP. |
|
| 34 | - $dir = wp_upload_dir(); |
|
| 35 | - |
|
| 36 | - // If the image is not inside WP's base url, return. |
|
| 37 | - if ( false === strpos( $url, $dir['baseurl'] . '/' ) ) { |
|
| 38 | - return false; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // Get the filename, the extension is kept. |
|
| 42 | - $filename = basename( $url ); |
|
| 43 | - |
|
| 44 | - // Query for attachments with the specified filename. |
|
| 45 | - $query = new WP_Query( array( |
|
| 46 | - 'post_type' => 'attachment', |
|
| 47 | - 'post_status' => 'inherit', |
|
| 48 | - 'fields' => 'ids', |
|
| 49 | - 'meta_query' => array( |
|
| 50 | - array( |
|
| 51 | - 'value' => $filename, |
|
| 52 | - 'compare' => 'LIKE', |
|
| 53 | - 'key' => '_wp_attachment_metadata', |
|
| 54 | - ), |
|
| 55 | - ), |
|
| 56 | - ) ); |
|
| 57 | - |
|
| 58 | - // If there are no posts, return. |
|
| 59 | - if ( $query->have_posts() ) { |
|
| 60 | - foreach ( $query->posts as $attachment_id ) { |
|
| 61 | - |
|
| 62 | - // Get the attachment metadata, we need the filename. |
|
| 63 | - $metadata = wp_get_attachment_metadata( $attachment_id ); |
|
| 64 | - $original_filename = basename( $metadata['file'] ); |
|
| 65 | - |
|
| 66 | - // Get the cropped filenames, or an empty array in case there are no files. |
|
| 67 | - $sizes_filenames = isset( $metadata['sizes'] ) ? wp_list_pluck( $metadata['sizes'], 'file' ) : array(); |
|
| 68 | - |
|
| 69 | - // If the provided filename matches the attachment filename (or one of its resized images), return the id. |
|
| 70 | - if ( $original_filename === $filename || in_array( $filename, $sizes_filenames ) ) { |
|
| 71 | - return $attachment_id; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // If we got here, we couldn't find any attachment. |
|
| 77 | - return false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get images embedded in the post content. |
|
| 82 | - * |
|
| 83 | - * @since 3.10.0 |
|
| 84 | - * |
|
| 85 | - * @param string $content The post content. |
|
| 86 | - * |
|
| 87 | - * @return array An array of attachment ids. |
|
| 88 | - */ |
|
| 89 | - public function get_image_embeds( $content ) { |
|
| 90 | - |
|
| 91 | - // Go over all the images included in the post content, check if they are |
|
| 92 | - // in the DB, and if so include them. |
|
| 93 | - $images = array(); |
|
| 94 | - if ( false === preg_match_all( '#<img [^>]*src="([^\\">]*)"[^>]*>#', $content, $images ) ) { |
|
| 95 | - return array(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Map the image URLs to attachment ids. |
|
| 99 | - $that = $this; |
|
| 100 | - $ids = array_map( function ( $url ) use ( $that ) { |
|
| 101 | - return $that->get_attachment_id( $url ); |
|
| 102 | - }, $images[1] ); |
|
| 103 | - |
|
| 104 | - // Filter out not found ids (i.e. id is false). |
|
| 105 | - return array_filter( $ids, function ( $item ) { |
|
| 106 | - return false !== $item; |
|
| 107 | - } ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get images linked via the `gallery` shortcode. |
|
| 112 | - * |
|
| 113 | - * @since 3.10.0 |
|
| 114 | - * |
|
| 115 | - * @param \WP_Post $post A {@link WP_Post} instance. |
|
| 116 | - * |
|
| 117 | - * @return array An array of attachment ids. |
|
| 118 | - */ |
|
| 119 | - public function get_gallery( $post ) { |
|
| 120 | - |
|
| 121 | - // @todo: the `gallery` shortcode has an `exclude` attribute which isn't |
|
| 122 | - // checked at the moment. |
|
| 123 | - |
|
| 124 | - // Prepare the return value. |
|
| 125 | - $ids = array(); |
|
| 126 | - |
|
| 127 | - // As the above for images in galleries. |
|
| 128 | - // Code inspired by http://wordpress.stackexchange.com/questions/80408/how-to-get-page-post-gallery-attachment-images-in-order-they-are-set-in-backend |
|
| 129 | - $pattern = get_shortcode_regex(); |
|
| 130 | - |
|
| 131 | - if ( preg_match_all( '/' . $pattern . '/s', $post->post_content, $matches ) |
|
| 132 | - && array_key_exists( 2, $matches ) |
|
| 133 | - && in_array( 'gallery', $matches[2] ) |
|
| 134 | - ) { |
|
| 135 | - |
|
| 136 | - $keys = array_keys( $matches[2], 'gallery' ); |
|
| 137 | - |
|
| 138 | - foreach ( $keys as $key ) { |
|
| 139 | - $atts = shortcode_parse_atts( $matches[3][ $key ] ); |
|
| 140 | - |
|
| 141 | - if ( is_array( $atts ) && array_key_exists( 'ids', $atts ) ) { |
|
| 142 | - // gallery images insert explicitly by their ids. |
|
| 143 | - |
|
| 144 | - foreach ( explode( ',', $atts['ids'] ) as $attachment_id ) { |
|
| 145 | - // Since we do not check for actual image existence |
|
| 146 | - // when generating the json content, check it now. |
|
| 147 | - if ( wp_get_attachment_image_src( $attachment_id, 'full' ) ) { |
|
| 148 | - $ids[ $attachment_id ] = true; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } else { |
|
| 152 | - // gallery shortcode with no ids uses all the images |
|
| 153 | - // attached to the post. |
|
| 154 | - $images = get_attached_media( 'image', $post->ID ); |
|
| 155 | - foreach ( $images as $attachment ) { |
|
| 156 | - $ids[ $attachment->ID ] = true; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return array_keys( $ids ); |
|
| 163 | - } |
|
| 19 | + /** |
|
| 20 | + * Get an attachment ID given a URL. |
|
| 21 | + * |
|
| 22 | + * Inspired from https://wpscholar.com/blog/get-attachment-id-from-wp-image-url/ |
|
| 23 | + * |
|
| 24 | + * @since 3.10.0 |
|
| 25 | + * |
|
| 26 | + * @param string $url The attachment URL. |
|
| 27 | + * |
|
| 28 | + * @return int|false Attachment ID on success, false on failure |
|
| 29 | + */ |
|
| 30 | + public function get_attachment_id( $url ) { |
|
| 31 | + |
|
| 32 | + // Get the upload directory data, we need the base URL to check whether |
|
| 33 | + // the URL we received is within WP. |
|
| 34 | + $dir = wp_upload_dir(); |
|
| 35 | + |
|
| 36 | + // If the image is not inside WP's base url, return. |
|
| 37 | + if ( false === strpos( $url, $dir['baseurl'] . '/' ) ) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // Get the filename, the extension is kept. |
|
| 42 | + $filename = basename( $url ); |
|
| 43 | + |
|
| 44 | + // Query for attachments with the specified filename. |
|
| 45 | + $query = new WP_Query( array( |
|
| 46 | + 'post_type' => 'attachment', |
|
| 47 | + 'post_status' => 'inherit', |
|
| 48 | + 'fields' => 'ids', |
|
| 49 | + 'meta_query' => array( |
|
| 50 | + array( |
|
| 51 | + 'value' => $filename, |
|
| 52 | + 'compare' => 'LIKE', |
|
| 53 | + 'key' => '_wp_attachment_metadata', |
|
| 54 | + ), |
|
| 55 | + ), |
|
| 56 | + ) ); |
|
| 57 | + |
|
| 58 | + // If there are no posts, return. |
|
| 59 | + if ( $query->have_posts() ) { |
|
| 60 | + foreach ( $query->posts as $attachment_id ) { |
|
| 61 | + |
|
| 62 | + // Get the attachment metadata, we need the filename. |
|
| 63 | + $metadata = wp_get_attachment_metadata( $attachment_id ); |
|
| 64 | + $original_filename = basename( $metadata['file'] ); |
|
| 65 | + |
|
| 66 | + // Get the cropped filenames, or an empty array in case there are no files. |
|
| 67 | + $sizes_filenames = isset( $metadata['sizes'] ) ? wp_list_pluck( $metadata['sizes'], 'file' ) : array(); |
|
| 68 | + |
|
| 69 | + // If the provided filename matches the attachment filename (or one of its resized images), return the id. |
|
| 70 | + if ( $original_filename === $filename || in_array( $filename, $sizes_filenames ) ) { |
|
| 71 | + return $attachment_id; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // If we got here, we couldn't find any attachment. |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get images embedded in the post content. |
|
| 82 | + * |
|
| 83 | + * @since 3.10.0 |
|
| 84 | + * |
|
| 85 | + * @param string $content The post content. |
|
| 86 | + * |
|
| 87 | + * @return array An array of attachment ids. |
|
| 88 | + */ |
|
| 89 | + public function get_image_embeds( $content ) { |
|
| 90 | + |
|
| 91 | + // Go over all the images included in the post content, check if they are |
|
| 92 | + // in the DB, and if so include them. |
|
| 93 | + $images = array(); |
|
| 94 | + if ( false === preg_match_all( '#<img [^>]*src="([^\\">]*)"[^>]*>#', $content, $images ) ) { |
|
| 95 | + return array(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Map the image URLs to attachment ids. |
|
| 99 | + $that = $this; |
|
| 100 | + $ids = array_map( function ( $url ) use ( $that ) { |
|
| 101 | + return $that->get_attachment_id( $url ); |
|
| 102 | + }, $images[1] ); |
|
| 103 | + |
|
| 104 | + // Filter out not found ids (i.e. id is false). |
|
| 105 | + return array_filter( $ids, function ( $item ) { |
|
| 106 | + return false !== $item; |
|
| 107 | + } ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get images linked via the `gallery` shortcode. |
|
| 112 | + * |
|
| 113 | + * @since 3.10.0 |
|
| 114 | + * |
|
| 115 | + * @param \WP_Post $post A {@link WP_Post} instance. |
|
| 116 | + * |
|
| 117 | + * @return array An array of attachment ids. |
|
| 118 | + */ |
|
| 119 | + public function get_gallery( $post ) { |
|
| 120 | + |
|
| 121 | + // @todo: the `gallery` shortcode has an `exclude` attribute which isn't |
|
| 122 | + // checked at the moment. |
|
| 123 | + |
|
| 124 | + // Prepare the return value. |
|
| 125 | + $ids = array(); |
|
| 126 | + |
|
| 127 | + // As the above for images in galleries. |
|
| 128 | + // Code inspired by http://wordpress.stackexchange.com/questions/80408/how-to-get-page-post-gallery-attachment-images-in-order-they-are-set-in-backend |
|
| 129 | + $pattern = get_shortcode_regex(); |
|
| 130 | + |
|
| 131 | + if ( preg_match_all( '/' . $pattern . '/s', $post->post_content, $matches ) |
|
| 132 | + && array_key_exists( 2, $matches ) |
|
| 133 | + && in_array( 'gallery', $matches[2] ) |
|
| 134 | + ) { |
|
| 135 | + |
|
| 136 | + $keys = array_keys( $matches[2], 'gallery' ); |
|
| 137 | + |
|
| 138 | + foreach ( $keys as $key ) { |
|
| 139 | + $atts = shortcode_parse_atts( $matches[3][ $key ] ); |
|
| 140 | + |
|
| 141 | + if ( is_array( $atts ) && array_key_exists( 'ids', $atts ) ) { |
|
| 142 | + // gallery images insert explicitly by their ids. |
|
| 143 | + |
|
| 144 | + foreach ( explode( ',', $atts['ids'] ) as $attachment_id ) { |
|
| 145 | + // Since we do not check for actual image existence |
|
| 146 | + // when generating the json content, check it now. |
|
| 147 | + if ( wp_get_attachment_image_src( $attachment_id, 'full' ) ) { |
|
| 148 | + $ids[ $attachment_id ] = true; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } else { |
|
| 152 | + // gallery shortcode with no ids uses all the images |
|
| 153 | + // attached to the post. |
|
| 154 | + $images = get_attached_media( 'image', $post->ID ); |
|
| 155 | + foreach ( $images as $attachment ) { |
|
| 156 | + $ids[ $attachment->ID ] = true; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return array_keys( $ids ); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | } |
@@ -27,22 +27,22 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @return int|false Attachment ID on success, false on failure |
| 29 | 29 | */ |
| 30 | - public function get_attachment_id( $url ) { |
|
| 30 | + public function get_attachment_id($url) { |
|
| 31 | 31 | |
| 32 | 32 | // Get the upload directory data, we need the base URL to check whether |
| 33 | 33 | // the URL we received is within WP. |
| 34 | 34 | $dir = wp_upload_dir(); |
| 35 | 35 | |
| 36 | 36 | // If the image is not inside WP's base url, return. |
| 37 | - if ( false === strpos( $url, $dir['baseurl'] . '/' ) ) { |
|
| 37 | + if (false === strpos($url, $dir['baseurl'].'/')) { |
|
| 38 | 38 | return false; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // Get the filename, the extension is kept. |
| 42 | - $filename = basename( $url ); |
|
| 42 | + $filename = basename($url); |
|
| 43 | 43 | |
| 44 | 44 | // Query for attachments with the specified filename. |
| 45 | - $query = new WP_Query( array( |
|
| 45 | + $query = new WP_Query(array( |
|
| 46 | 46 | 'post_type' => 'attachment', |
| 47 | 47 | 'post_status' => 'inherit', |
| 48 | 48 | 'fields' => 'ids', |
@@ -53,21 +53,21 @@ discard block |
||
| 53 | 53 | 'key' => '_wp_attachment_metadata', |
| 54 | 54 | ), |
| 55 | 55 | ), |
| 56 | - ) ); |
|
| 56 | + )); |
|
| 57 | 57 | |
| 58 | 58 | // If there are no posts, return. |
| 59 | - if ( $query->have_posts() ) { |
|
| 60 | - foreach ( $query->posts as $attachment_id ) { |
|
| 59 | + if ($query->have_posts()) { |
|
| 60 | + foreach ($query->posts as $attachment_id) { |
|
| 61 | 61 | |
| 62 | 62 | // Get the attachment metadata, we need the filename. |
| 63 | - $metadata = wp_get_attachment_metadata( $attachment_id ); |
|
| 64 | - $original_filename = basename( $metadata['file'] ); |
|
| 63 | + $metadata = wp_get_attachment_metadata($attachment_id); |
|
| 64 | + $original_filename = basename($metadata['file']); |
|
| 65 | 65 | |
| 66 | 66 | // Get the cropped filenames, or an empty array in case there are no files. |
| 67 | - $sizes_filenames = isset( $metadata['sizes'] ) ? wp_list_pluck( $metadata['sizes'], 'file' ) : array(); |
|
| 67 | + $sizes_filenames = isset($metadata['sizes']) ? wp_list_pluck($metadata['sizes'], 'file') : array(); |
|
| 68 | 68 | |
| 69 | 69 | // If the provided filename matches the attachment filename (or one of its resized images), return the id. |
| 70 | - if ( $original_filename === $filename || in_array( $filename, $sizes_filenames ) ) { |
|
| 70 | + if ($original_filename === $filename || in_array($filename, $sizes_filenames)) { |
|
| 71 | 71 | return $attachment_id; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -86,23 +86,23 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return array An array of attachment ids. |
| 88 | 88 | */ |
| 89 | - public function get_image_embeds( $content ) { |
|
| 89 | + public function get_image_embeds($content) { |
|
| 90 | 90 | |
| 91 | 91 | // Go over all the images included in the post content, check if they are |
| 92 | 92 | // in the DB, and if so include them. |
| 93 | 93 | $images = array(); |
| 94 | - if ( false === preg_match_all( '#<img [^>]*src="([^\\">]*)"[^>]*>#', $content, $images ) ) { |
|
| 94 | + if (false === preg_match_all('#<img [^>]*src="([^\\">]*)"[^>]*>#', $content, $images)) { |
|
| 95 | 95 | return array(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Map the image URLs to attachment ids. |
| 99 | 99 | $that = $this; |
| 100 | - $ids = array_map( function ( $url ) use ( $that ) { |
|
| 101 | - return $that->get_attachment_id( $url ); |
|
| 102 | - }, $images[1] ); |
|
| 100 | + $ids = array_map(function($url) use ($that) { |
|
| 101 | + return $that->get_attachment_id($url); |
|
| 102 | + }, $images[1]); |
|
| 103 | 103 | |
| 104 | 104 | // Filter out not found ids (i.e. id is false). |
| 105 | - return array_filter( $ids, function ( $item ) { |
|
| 105 | + return array_filter($ids, function($item) { |
|
| 106 | 106 | return false !== $item; |
| 107 | 107 | } ); |
| 108 | 108 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return array An array of attachment ids. |
| 118 | 118 | */ |
| 119 | - public function get_gallery( $post ) { |
|
| 119 | + public function get_gallery($post) { |
|
| 120 | 120 | |
| 121 | 121 | // @todo: the `gallery` shortcode has an `exclude` attribute which isn't |
| 122 | 122 | // checked at the moment. |
@@ -128,38 +128,38 @@ discard block |
||
| 128 | 128 | // Code inspired by http://wordpress.stackexchange.com/questions/80408/how-to-get-page-post-gallery-attachment-images-in-order-they-are-set-in-backend |
| 129 | 129 | $pattern = get_shortcode_regex(); |
| 130 | 130 | |
| 131 | - if ( preg_match_all( '/' . $pattern . '/s', $post->post_content, $matches ) |
|
| 132 | - && array_key_exists( 2, $matches ) |
|
| 133 | - && in_array( 'gallery', $matches[2] ) |
|
| 131 | + if (preg_match_all('/'.$pattern.'/s', $post->post_content, $matches) |
|
| 132 | + && array_key_exists(2, $matches) |
|
| 133 | + && in_array('gallery', $matches[2]) |
|
| 134 | 134 | ) { |
| 135 | 135 | |
| 136 | - $keys = array_keys( $matches[2], 'gallery' ); |
|
| 136 | + $keys = array_keys($matches[2], 'gallery'); |
|
| 137 | 137 | |
| 138 | - foreach ( $keys as $key ) { |
|
| 139 | - $atts = shortcode_parse_atts( $matches[3][ $key ] ); |
|
| 138 | + foreach ($keys as $key) { |
|
| 139 | + $atts = shortcode_parse_atts($matches[3][$key]); |
|
| 140 | 140 | |
| 141 | - if ( is_array( $atts ) && array_key_exists( 'ids', $atts ) ) { |
|
| 141 | + if (is_array($atts) && array_key_exists('ids', $atts)) { |
|
| 142 | 142 | // gallery images insert explicitly by their ids. |
| 143 | 143 | |
| 144 | - foreach ( explode( ',', $atts['ids'] ) as $attachment_id ) { |
|
| 144 | + foreach (explode(',', $atts['ids']) as $attachment_id) { |
|
| 145 | 145 | // Since we do not check for actual image existence |
| 146 | 146 | // when generating the json content, check it now. |
| 147 | - if ( wp_get_attachment_image_src( $attachment_id, 'full' ) ) { |
|
| 148 | - $ids[ $attachment_id ] = true; |
|
| 147 | + if (wp_get_attachment_image_src($attachment_id, 'full')) { |
|
| 148 | + $ids[$attachment_id] = true; |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } else { |
| 152 | 152 | // gallery shortcode with no ids uses all the images |
| 153 | 153 | // attached to the post. |
| 154 | - $images = get_attached_media( 'image', $post->ID ); |
|
| 155 | - foreach ( $images as $attachment ) { |
|
| 156 | - $ids[ $attachment->ID ] = true; |
|
| 154 | + $images = get_attached_media('image', $post->ID); |
|
| 155 | + foreach ($images as $attachment) { |
|
| 156 | + $ids[$attachment->ID] = true; |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return array_keys( $ids ); |
|
| 162 | + return array_keys($ids); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | } |
@@ -17,176 +17,176 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Uri_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The title regex to sanitize titles in paths. |
|
| 22 | - * |
|
| 23 | - * According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved: |
|
| 24 | - * ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | |
|
| 25 | - * "$" | "," |
|
| 26 | - * |
|
| 27 | - * We also remove the space and the UTF-8 BOM sequence. |
|
| 28 | - * |
|
| 29 | - * @since 3.7.1 |
|
| 30 | - */ |
|
| 31 | - const INVALID_CHARACTERS = "/[ ;\\/?:@&=\\+\\\$,]|(?:\\xEF\\xBB\\xBF)/"; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * A {@link Wordlift_Log_Service} instance. |
|
| 35 | - * |
|
| 36 | - * @since 3.6.0 |
|
| 37 | - * @access private |
|
| 38 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 39 | - */ |
|
| 40 | - private $log; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The global WordPress database connection. |
|
| 44 | - * |
|
| 45 | - * @since 3.6.0 |
|
| 46 | - * @access private |
|
| 47 | - * @var \wpdb $wpdb The global WordPress database connection. |
|
| 48 | - */ |
|
| 49 | - private $wpdb; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The {@link Wordlift_Uri_Service} singleton instance. |
|
| 53 | - * |
|
| 54 | - * @since 3.7.2 |
|
| 55 | - * @access private |
|
| 56 | - * @var \Wordlift_Uri_Service The {@link Wordlift_Uri_Service} singleton instance. |
|
| 57 | - */ |
|
| 58 | - private static $instance; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Create an instance of Wordlift_Uri_Service. |
|
| 62 | - * |
|
| 63 | - * @since 3.6.0 |
|
| 64 | - * |
|
| 65 | - * @param \wpdb $wpdb The global WordPress database connection. |
|
| 66 | - */ |
|
| 67 | - public function __construct( $wpdb ) { |
|
| 68 | - |
|
| 69 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Uri_Service' ); |
|
| 70 | - |
|
| 71 | - $this->wpdb = $wpdb; |
|
| 72 | - |
|
| 73 | - self::$instance = $this; |
|
| 74 | - |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get the {@link Wordlift_Uri_Service} singleton instance. |
|
| 79 | - * |
|
| 80 | - * @since 3.7.2 |
|
| 81 | - * @return \Wordlift_Uri_Service The {@link Wordlift_Uri_Service} singleton instance. |
|
| 82 | - */ |
|
| 83 | - public static function get_instance() { |
|
| 84 | - |
|
| 85 | - return self::$instance; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Delete all generated URIs from the database. |
|
| 90 | - * |
|
| 91 | - * @since 3.6.0 |
|
| 92 | - */ |
|
| 93 | - public function delete_all() { |
|
| 94 | - |
|
| 95 | - // Delete URIs associated with posts/entities. |
|
| 96 | - $this->wpdb->delete( $this->wpdb->postmeta, array( 'meta_key' => 'entity_url' ) ); |
|
| 97 | - |
|
| 98 | - // Delete URIs associated with authors. |
|
| 99 | - $this->wpdb->delete( $this->wpdb->usermeta, array( 'meta_key' => '_wl_uri' ) ); |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
|
| 105 | - * |
|
| 106 | - * @since 3.7.2 |
|
| 107 | - * @uses sanitize_title() to manage not ASCII chars |
|
| 108 | - * |
|
| 109 | - * @see https://codex.wordpress.org/Function_Reference/sanitize_title |
|
| 110 | - * |
|
| 111 | - * @param string $path The path to sanitize. |
|
| 112 | - * @param string $char The replacement character (by default an underscore). |
|
| 113 | - * |
|
| 114 | - * @return string The sanitized path. |
|
| 115 | - */ |
|
| 116 | - public function sanitize_path( $path, $char = '_' ) { |
|
| 117 | - |
|
| 118 | - // Ensure the path is ASCII. |
|
| 119 | - // see https://github.com/insideout10/wordlift-plugin/issues/386 |
|
| 20 | + /** |
|
| 21 | + * The title regex to sanitize titles in paths. |
|
| 22 | + * |
|
| 23 | + * According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved: |
|
| 24 | + * ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | |
|
| 25 | + * "$" | "," |
|
| 26 | + * |
|
| 27 | + * We also remove the space and the UTF-8 BOM sequence. |
|
| 28 | + * |
|
| 29 | + * @since 3.7.1 |
|
| 30 | + */ |
|
| 31 | + const INVALID_CHARACTERS = "/[ ;\\/?:@&=\\+\\\$,]|(?:\\xEF\\xBB\\xBF)/"; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * A {@link Wordlift_Log_Service} instance. |
|
| 35 | + * |
|
| 36 | + * @since 3.6.0 |
|
| 37 | + * @access private |
|
| 38 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 39 | + */ |
|
| 40 | + private $log; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The global WordPress database connection. |
|
| 44 | + * |
|
| 45 | + * @since 3.6.0 |
|
| 46 | + * @access private |
|
| 47 | + * @var \wpdb $wpdb The global WordPress database connection. |
|
| 48 | + */ |
|
| 49 | + private $wpdb; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The {@link Wordlift_Uri_Service} singleton instance. |
|
| 53 | + * |
|
| 54 | + * @since 3.7.2 |
|
| 55 | + * @access private |
|
| 56 | + * @var \Wordlift_Uri_Service The {@link Wordlift_Uri_Service} singleton instance. |
|
| 57 | + */ |
|
| 58 | + private static $instance; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Create an instance of Wordlift_Uri_Service. |
|
| 62 | + * |
|
| 63 | + * @since 3.6.0 |
|
| 64 | + * |
|
| 65 | + * @param \wpdb $wpdb The global WordPress database connection. |
|
| 66 | + */ |
|
| 67 | + public function __construct( $wpdb ) { |
|
| 68 | + |
|
| 69 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Uri_Service' ); |
|
| 70 | + |
|
| 71 | + $this->wpdb = $wpdb; |
|
| 72 | + |
|
| 73 | + self::$instance = $this; |
|
| 74 | + |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get the {@link Wordlift_Uri_Service} singleton instance. |
|
| 79 | + * |
|
| 80 | + * @since 3.7.2 |
|
| 81 | + * @return \Wordlift_Uri_Service The {@link Wordlift_Uri_Service} singleton instance. |
|
| 82 | + */ |
|
| 83 | + public static function get_instance() { |
|
| 84 | + |
|
| 85 | + return self::$instance; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Delete all generated URIs from the database. |
|
| 90 | + * |
|
| 91 | + * @since 3.6.0 |
|
| 92 | + */ |
|
| 93 | + public function delete_all() { |
|
| 94 | + |
|
| 95 | + // Delete URIs associated with posts/entities. |
|
| 96 | + $this->wpdb->delete( $this->wpdb->postmeta, array( 'meta_key' => 'entity_url' ) ); |
|
| 97 | + |
|
| 98 | + // Delete URIs associated with authors. |
|
| 99 | + $this->wpdb->delete( $this->wpdb->usermeta, array( 'meta_key' => '_wl_uri' ) ); |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
|
| 105 | + * |
|
| 106 | + * @since 3.7.2 |
|
| 107 | + * @uses sanitize_title() to manage not ASCII chars |
|
| 108 | + * |
|
| 109 | + * @see https://codex.wordpress.org/Function_Reference/sanitize_title |
|
| 110 | + * |
|
| 111 | + * @param string $path The path to sanitize. |
|
| 112 | + * @param string $char The replacement character (by default an underscore). |
|
| 113 | + * |
|
| 114 | + * @return string The sanitized path. |
|
| 115 | + */ |
|
| 116 | + public function sanitize_path( $path, $char = '_' ) { |
|
| 117 | + |
|
| 118 | + // Ensure the path is ASCII. |
|
| 119 | + // see https://github.com/insideout10/wordlift-plugin/issues/386 |
|
| 120 | 120 | // $path_ascii = mb_convert_encoding( $path, 'ASCII' ); |
| 121 | 121 | |
| 122 | - return sanitize_title( preg_replace( self::INVALID_CHARACTERS, $char, stripslashes( $path ) ) ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Build an entity uri for a given title. The uri is composed using a given |
|
| 127 | - * post_type and a title. If already exists an entity e2 with a given uri a |
|
| 128 | - * numeric suffix is added. If a schema type is given entities with same label |
|
| 129 | - * and same type are overridden. |
|
| 130 | - * |
|
| 131 | - * @since 3.5.0 |
|
| 132 | - * |
|
| 133 | - * @param string $title A post title. |
|
| 134 | - * @param string $post_type A post type. Default value is 'entity' |
|
| 135 | - * @param string $schema_type A schema org type. |
|
| 136 | - * @param integer $increment_digit A digit used to call recursively the same function. |
|
| 137 | - * |
|
| 138 | - * @return string Returns an uri. |
|
| 139 | - */ |
|
| 140 | - public function build_uri( $title, $post_type, $schema_type = null, $increment_digit = 0 ) { |
|
| 141 | - |
|
| 142 | - // Get the entity slug suffix digit |
|
| 143 | - $suffix_digit = $increment_digit + 1; |
|
| 144 | - |
|
| 145 | - // Get a sanitized uri for a given title |
|
| 146 | - $entity_slug = ( 0 == $increment_digit ) ? |
|
| 147 | - wl_sanitize_uri_path( $title ) : |
|
| 148 | - wl_sanitize_uri_path( $title . '_' . $suffix_digit ); |
|
| 149 | - |
|
| 150 | - // Compose a candidate uri. |
|
| 151 | - $new_entity_uri = sprintf( '%s/%s/%s', |
|
| 152 | - wl_configuration_get_redlink_dataset_uri(), |
|
| 153 | - $post_type, |
|
| 154 | - $entity_slug |
|
| 155 | - ); |
|
| 156 | - |
|
| 157 | - $this->log->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" ); |
|
| 158 | - |
|
| 159 | - global $wpdb; |
|
| 160 | - |
|
| 161 | - // Check if the candidated uri already is used |
|
| 162 | - $stmt = $wpdb->prepare( |
|
| 163 | - "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", |
|
| 164 | - WL_ENTITY_URL_META_NAME, |
|
| 165 | - $new_entity_uri |
|
| 166 | - ); |
|
| 167 | - |
|
| 168 | - // Perform the query |
|
| 169 | - $post_id = $wpdb->get_var( $stmt ); |
|
| 170 | - |
|
| 171 | - // If the post does not exist, then the new uri is returned |
|
| 172 | - if ( ! is_numeric( $post_id ) ) { |
|
| 173 | - $this->log->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 174 | - |
|
| 175 | - return $new_entity_uri; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // If schema_type is equal to schema org type of post x, then the new uri is returned |
|
| 179 | - $schema_post_type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 180 | - |
|
| 181 | - // @todo: we shouldn't rely on css classes to take such decisions. |
|
| 182 | - if ( $schema_type === $schema_post_type['css_class'] ) { |
|
| 183 | - $this->log->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 184 | - |
|
| 185 | - return $new_entity_uri; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Otherwise the same function is called recursively |
|
| 189 | - return $this->build_uri( $title, $post_type, $schema_type, ++ $increment_digit ); |
|
| 190 | - } |
|
| 122 | + return sanitize_title( preg_replace( self::INVALID_CHARACTERS, $char, stripslashes( $path ) ) ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Build an entity uri for a given title. The uri is composed using a given |
|
| 127 | + * post_type and a title. If already exists an entity e2 with a given uri a |
|
| 128 | + * numeric suffix is added. If a schema type is given entities with same label |
|
| 129 | + * and same type are overridden. |
|
| 130 | + * |
|
| 131 | + * @since 3.5.0 |
|
| 132 | + * |
|
| 133 | + * @param string $title A post title. |
|
| 134 | + * @param string $post_type A post type. Default value is 'entity' |
|
| 135 | + * @param string $schema_type A schema org type. |
|
| 136 | + * @param integer $increment_digit A digit used to call recursively the same function. |
|
| 137 | + * |
|
| 138 | + * @return string Returns an uri. |
|
| 139 | + */ |
|
| 140 | + public function build_uri( $title, $post_type, $schema_type = null, $increment_digit = 0 ) { |
|
| 141 | + |
|
| 142 | + // Get the entity slug suffix digit |
|
| 143 | + $suffix_digit = $increment_digit + 1; |
|
| 144 | + |
|
| 145 | + // Get a sanitized uri for a given title |
|
| 146 | + $entity_slug = ( 0 == $increment_digit ) ? |
|
| 147 | + wl_sanitize_uri_path( $title ) : |
|
| 148 | + wl_sanitize_uri_path( $title . '_' . $suffix_digit ); |
|
| 149 | + |
|
| 150 | + // Compose a candidate uri. |
|
| 151 | + $new_entity_uri = sprintf( '%s/%s/%s', |
|
| 152 | + wl_configuration_get_redlink_dataset_uri(), |
|
| 153 | + $post_type, |
|
| 154 | + $entity_slug |
|
| 155 | + ); |
|
| 156 | + |
|
| 157 | + $this->log->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" ); |
|
| 158 | + |
|
| 159 | + global $wpdb; |
|
| 160 | + |
|
| 161 | + // Check if the candidated uri already is used |
|
| 162 | + $stmt = $wpdb->prepare( |
|
| 163 | + "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", |
|
| 164 | + WL_ENTITY_URL_META_NAME, |
|
| 165 | + $new_entity_uri |
|
| 166 | + ); |
|
| 167 | + |
|
| 168 | + // Perform the query |
|
| 169 | + $post_id = $wpdb->get_var( $stmt ); |
|
| 170 | + |
|
| 171 | + // If the post does not exist, then the new uri is returned |
|
| 172 | + if ( ! is_numeric( $post_id ) ) { |
|
| 173 | + $this->log->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 174 | + |
|
| 175 | + return $new_entity_uri; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // If schema_type is equal to schema org type of post x, then the new uri is returned |
|
| 179 | + $schema_post_type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 180 | + |
|
| 181 | + // @todo: we shouldn't rely on css classes to take such decisions. |
|
| 182 | + if ( $schema_type === $schema_post_type['css_class'] ) { |
|
| 183 | + $this->log->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 184 | + |
|
| 185 | + return $new_entity_uri; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Otherwise the same function is called recursively |
|
| 189 | + return $this->build_uri( $title, $post_type, $schema_type, ++ $increment_digit ); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | } |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @param \wpdb $wpdb The global WordPress database connection. |
| 66 | 66 | */ |
| 67 | - public function __construct( $wpdb ) { |
|
| 67 | + public function __construct($wpdb) { |
|
| 68 | 68 | |
| 69 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Uri_Service' ); |
|
| 69 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Uri_Service'); |
|
| 70 | 70 | |
| 71 | 71 | $this->wpdb = $wpdb; |
| 72 | 72 | |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | public function delete_all() { |
| 94 | 94 | |
| 95 | 95 | // Delete URIs associated with posts/entities. |
| 96 | - $this->wpdb->delete( $this->wpdb->postmeta, array( 'meta_key' => 'entity_url' ) ); |
|
| 96 | + $this->wpdb->delete($this->wpdb->postmeta, array('meta_key' => 'entity_url')); |
|
| 97 | 97 | |
| 98 | 98 | // Delete URIs associated with authors. |
| 99 | - $this->wpdb->delete( $this->wpdb->usermeta, array( 'meta_key' => '_wl_uri' ) ); |
|
| 99 | + $this->wpdb->delete($this->wpdb->usermeta, array('meta_key' => '_wl_uri')); |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return string The sanitized path. |
| 115 | 115 | */ |
| 116 | - public function sanitize_path( $path, $char = '_' ) { |
|
| 116 | + public function sanitize_path($path, $char = '_') { |
|
| 117 | 117 | |
| 118 | 118 | // Ensure the path is ASCII. |
| 119 | 119 | // see https://github.com/insideout10/wordlift-plugin/issues/386 |
| 120 | 120 | // $path_ascii = mb_convert_encoding( $path, 'ASCII' ); |
| 121 | 121 | |
| 122 | - return sanitize_title( preg_replace( self::INVALID_CHARACTERS, $char, stripslashes( $path ) ) ); |
|
| 122 | + return sanitize_title(preg_replace(self::INVALID_CHARACTERS, $char, stripslashes($path))); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -137,24 +137,23 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return string Returns an uri. |
| 139 | 139 | */ |
| 140 | - public function build_uri( $title, $post_type, $schema_type = null, $increment_digit = 0 ) { |
|
| 140 | + public function build_uri($title, $post_type, $schema_type = null, $increment_digit = 0) { |
|
| 141 | 141 | |
| 142 | 142 | // Get the entity slug suffix digit |
| 143 | 143 | $suffix_digit = $increment_digit + 1; |
| 144 | 144 | |
| 145 | 145 | // Get a sanitized uri for a given title |
| 146 | - $entity_slug = ( 0 == $increment_digit ) ? |
|
| 147 | - wl_sanitize_uri_path( $title ) : |
|
| 148 | - wl_sanitize_uri_path( $title . '_' . $suffix_digit ); |
|
| 146 | + $entity_slug = (0 == $increment_digit) ? |
|
| 147 | + wl_sanitize_uri_path($title) : wl_sanitize_uri_path($title.'_'.$suffix_digit); |
|
| 149 | 148 | |
| 150 | 149 | // Compose a candidate uri. |
| 151 | - $new_entity_uri = sprintf( '%s/%s/%s', |
|
| 150 | + $new_entity_uri = sprintf('%s/%s/%s', |
|
| 152 | 151 | wl_configuration_get_redlink_dataset_uri(), |
| 153 | 152 | $post_type, |
| 154 | 153 | $entity_slug |
| 155 | 154 | ); |
| 156 | 155 | |
| 157 | - $this->log->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" ); |
|
| 156 | + $this->log->trace("Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]"); |
|
| 158 | 157 | |
| 159 | 158 | global $wpdb; |
| 160 | 159 | |
@@ -166,27 +165,27 @@ discard block |
||
| 166 | 165 | ); |
| 167 | 166 | |
| 168 | 167 | // Perform the query |
| 169 | - $post_id = $wpdb->get_var( $stmt ); |
|
| 168 | + $post_id = $wpdb->get_var($stmt); |
|
| 170 | 169 | |
| 171 | 170 | // If the post does not exist, then the new uri is returned |
| 172 | - if ( ! is_numeric( $post_id ) ) { |
|
| 173 | - $this->log->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 171 | + if ( ! is_numeric($post_id)) { |
|
| 172 | + $this->log->trace("Going to return uri [ new_entity_uri :: $new_entity_uri ]"); |
|
| 174 | 173 | |
| 175 | 174 | return $new_entity_uri; |
| 176 | 175 | } |
| 177 | 176 | |
| 178 | 177 | // If schema_type is equal to schema org type of post x, then the new uri is returned |
| 179 | - $schema_post_type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 178 | + $schema_post_type = wl_entity_type_taxonomy_get_type($post_id); |
|
| 180 | 179 | |
| 181 | 180 | // @todo: we shouldn't rely on css classes to take such decisions. |
| 182 | - if ( $schema_type === $schema_post_type['css_class'] ) { |
|
| 183 | - $this->log->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 181 | + if ($schema_type === $schema_post_type['css_class']) { |
|
| 182 | + $this->log->trace("An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]"); |
|
| 184 | 183 | |
| 185 | 184 | return $new_entity_uri; |
| 186 | 185 | } |
| 187 | 186 | |
| 188 | 187 | // Otherwise the same function is called recursively |
| 189 | - return $this->build_uri( $title, $post_type, $schema_type, ++ $increment_digit ); |
|
| 188 | + return $this->build_uri($title, $post_type, $schema_type, ++ $increment_digit); |
|
| 190 | 189 | } |
| 191 | 190 | |
| 192 | 191 | } |
@@ -16,61 +16,61 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Property_Entity_Reference { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The URL associated with this entity reference. |
|
| 21 | - * |
|
| 22 | - * @since 3.8.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var string $url The URL associated with the entity reference. |
|
| 25 | - */ |
|
| 26 | - private $url; |
|
| 19 | + /** |
|
| 20 | + * The URL associated with this entity reference. |
|
| 21 | + * |
|
| 22 | + * @since 3.8.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var string $url The URL associated with the entity reference. |
|
| 25 | + */ |
|
| 26 | + private $url; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The entity post id. |
|
| 30 | - * |
|
| 31 | - * @since 3.10.0 |
|
| 32 | - * @access private |
|
| 33 | - * @var int $id The entity post id. |
|
| 34 | - */ |
|
| 35 | - private $id; |
|
| 28 | + /** |
|
| 29 | + * The entity post id. |
|
| 30 | + * |
|
| 31 | + * @since 3.10.0 |
|
| 32 | + * @access private |
|
| 33 | + * @var int $id The entity post id. |
|
| 34 | + */ |
|
| 35 | + private $id; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Create a Wordlift_Property_Entity_Reference instance with the provided URL. |
|
| 39 | - * |
|
| 40 | - * @since 3.8.0 |
|
| 41 | - * |
|
| 42 | - * @param string $url The URL. |
|
| 43 | - * @param int $id The entity post id. |
|
| 44 | - */ |
|
| 45 | - public function __construct( $url, $id ) { |
|
| 37 | + /** |
|
| 38 | + * Create a Wordlift_Property_Entity_Reference instance with the provided URL. |
|
| 39 | + * |
|
| 40 | + * @since 3.8.0 |
|
| 41 | + * |
|
| 42 | + * @param string $url The URL. |
|
| 43 | + * @param int $id The entity post id. |
|
| 44 | + */ |
|
| 45 | + public function __construct( $url, $id ) { |
|
| 46 | 46 | |
| 47 | - $this->url = $url; |
|
| 48 | - $this->id = $id; |
|
| 47 | + $this->url = $url; |
|
| 48 | + $this->id = $id; |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get the URL associated with this entity reference. |
|
| 54 | - * |
|
| 55 | - * @since 3.8.0 |
|
| 56 | - * |
|
| 57 | - * @return string The URL associated with the entity reference. |
|
| 58 | - */ |
|
| 59 | - public function getURL() { |
|
| 52 | + /** |
|
| 53 | + * Get the URL associated with this entity reference. |
|
| 54 | + * |
|
| 55 | + * @since 3.8.0 |
|
| 56 | + * |
|
| 57 | + * @return string The URL associated with the entity reference. |
|
| 58 | + */ |
|
| 59 | + public function getURL() { |
|
| 60 | 60 | |
| 61 | - return $this->url; |
|
| 62 | - } |
|
| 61 | + return $this->url; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Get the entity id. |
|
| 66 | - * |
|
| 67 | - * @since 3.10.0 |
|
| 68 | - * |
|
| 69 | - * @return int The entity id. |
|
| 70 | - */ |
|
| 71 | - public function getID() { |
|
| 64 | + /** |
|
| 65 | + * Get the entity id. |
|
| 66 | + * |
|
| 67 | + * @since 3.10.0 |
|
| 68 | + * |
|
| 69 | + * @return int The entity id. |
|
| 70 | + */ |
|
| 71 | + public function getID() { |
|
| 72 | 72 | |
| 73 | - return $this->id; |
|
| 74 | - } |
|
| 73 | + return $this->id; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | * @param string $url The URL. |
| 43 | 43 | * @param int $id The entity post id. |
| 44 | 44 | */ |
| 45 | - public function __construct( $url, $id ) { |
|
| 45 | + public function __construct($url, $id) { |
|
| 46 | 46 | |
| 47 | 47 | $this->url = $url; |
| 48 | 48 | $this->id = $id; |
@@ -7,38 +7,38 @@ |
||
| 7 | 7 | * @since 3.8.0 |
| 8 | 8 | */ |
| 9 | 9 | class Wordlift_Entity_Property_Service extends Wordlift_Simple_Property_Service { |
| 10 | - /** |
|
| 11 | - * @var \Wordlift_Entity_Service $entity_service |
|
| 12 | - */ |
|
| 13 | - private $entity_service; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Wordlift_Entity_Property_Service constructor. |
|
| 17 | - * |
|
| 18 | - * @param \Wordlift_Entity_Service $entity_service |
|
| 19 | - */ |
|
| 20 | - public function __construct( $entity_service ) { |
|
| 21 | - |
|
| 22 | - $this->entity_service = $entity_service; |
|
| 23 | - |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - public function get( $post_id, $meta_key ) { |
|
| 30 | - |
|
| 31 | - $entity_service = $this->entity_service; |
|
| 32 | - |
|
| 33 | - // Map each returned value to a Wordlift_Property_Entity_Reference. |
|
| 34 | - return array_map( function ( $item ) use ( $entity_service ) { |
|
| 35 | - |
|
| 36 | - // If the $item is a number and it's an existing post, return the |
|
| 37 | - // URI of the referenced entity. Otherwise return the value. |
|
| 38 | - return is_numeric( $item ) && null !== get_post( $item ) |
|
| 39 | - ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item ) |
|
| 40 | - : $item; |
|
| 41 | - }, get_post_meta( $post_id, $meta_key ) ); |
|
| 42 | - } |
|
| 10 | + /** |
|
| 11 | + * @var \Wordlift_Entity_Service $entity_service |
|
| 12 | + */ |
|
| 13 | + private $entity_service; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Wordlift_Entity_Property_Service constructor. |
|
| 17 | + * |
|
| 18 | + * @param \Wordlift_Entity_Service $entity_service |
|
| 19 | + */ |
|
| 20 | + public function __construct( $entity_service ) { |
|
| 21 | + |
|
| 22 | + $this->entity_service = $entity_service; |
|
| 23 | + |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + public function get( $post_id, $meta_key ) { |
|
| 30 | + |
|
| 31 | + $entity_service = $this->entity_service; |
|
| 32 | + |
|
| 33 | + // Map each returned value to a Wordlift_Property_Entity_Reference. |
|
| 34 | + return array_map( function ( $item ) use ( $entity_service ) { |
|
| 35 | + |
|
| 36 | + // If the $item is a number and it's an existing post, return the |
|
| 37 | + // URI of the referenced entity. Otherwise return the value. |
|
| 38 | + return is_numeric( $item ) && null !== get_post( $item ) |
|
| 39 | + ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item ) |
|
| 40 | + : $item; |
|
| 41 | + }, get_post_meta( $post_id, $meta_key ) ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param \Wordlift_Entity_Service $entity_service |
| 19 | 19 | */ |
| 20 | - public function __construct( $entity_service ) { |
|
| 20 | + public function __construct($entity_service) { |
|
| 21 | 21 | |
| 22 | 22 | $this->entity_service = $entity_service; |
| 23 | 23 | |
@@ -26,19 +26,19 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * {@inheritdoc} |
| 28 | 28 | */ |
| 29 | - public function get( $post_id, $meta_key ) { |
|
| 29 | + public function get($post_id, $meta_key) { |
|
| 30 | 30 | |
| 31 | 31 | $entity_service = $this->entity_service; |
| 32 | 32 | |
| 33 | 33 | // Map each returned value to a Wordlift_Property_Entity_Reference. |
| 34 | - return array_map( function ( $item ) use ( $entity_service ) { |
|
| 34 | + return array_map(function($item) use ($entity_service) { |
|
| 35 | 35 | |
| 36 | 36 | // If the $item is a number and it's an existing post, return the |
| 37 | 37 | // URI of the referenced entity. Otherwise return the value. |
| 38 | - return is_numeric( $item ) && null !== get_post( $item ) |
|
| 39 | - ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), $item ) |
|
| 38 | + return is_numeric($item) && null !== get_post($item) |
|
| 39 | + ? new Wordlift_Property_Entity_Reference($entity_service->get_uri($item), $item) |
|
| 40 | 40 | : $item; |
| 41 | - }, get_post_meta( $post_id, $meta_key ) ); |
|
| 41 | + }, get_post_meta($post_id, $meta_key)); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | } |
@@ -14,161 +14,161 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Entity_Type_Service { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The {@link Wordlift_Schema_Service} instance. |
|
| 19 | - * |
|
| 20 | - * @since 3.7.0 |
|
| 21 | - * @access private |
|
| 22 | - * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
| 23 | - */ |
|
| 24 | - private $schema_service; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * A {@link Wordlift_Log_Service} instance. |
|
| 28 | - * |
|
| 29 | - * @since 3.8.0 |
|
| 30 | - * @access private |
|
| 31 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 32 | - */ |
|
| 33 | - private $log; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 37 | - * |
|
| 38 | - * @since 3.7.0 |
|
| 39 | - * @access private |
|
| 40 | - * @var \Wordlift_Entity_Type_Service $instance The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 41 | - */ |
|
| 42 | - private static $instance; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Wordlift_Entity_Type_Service constructor. |
|
| 46 | - * |
|
| 47 | - * @since 3.7.0 |
|
| 48 | - * |
|
| 49 | - * @param \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
| 50 | - */ |
|
| 51 | - public function __construct( $schema_service ) { |
|
| 52 | - |
|
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
| 54 | - |
|
| 55 | - $this->schema_service = $schema_service; |
|
| 56 | - |
|
| 57 | - self::$instance = $this; |
|
| 58 | - |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get the {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 63 | - * |
|
| 64 | - * @since 3.7.0 |
|
| 65 | - * @return \Wordlift_Entity_Type_Service The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 66 | - */ |
|
| 67 | - public static function get_instance() { |
|
| 68 | - |
|
| 69 | - return self::$instance; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Get the types associated with the specified entity post id. |
|
| 74 | - * |
|
| 75 | - * @since 3.7.0 |
|
| 76 | - * |
|
| 77 | - * @param int $post_id The post id. |
|
| 78 | - * |
|
| 79 | - * @return array|null An array of type properties or null if no term is associated |
|
| 80 | - */ |
|
| 81 | - public function get( $post_id ) { |
|
| 82 | - |
|
| 83 | - // Return the correct entity type according to the post type. |
|
| 84 | - switch ( get_post_type( $post_id ) ) { |
|
| 85 | - |
|
| 86 | - case 'entity': |
|
| 87 | - // Get the type from the associated classification. |
|
| 88 | - |
|
| 89 | - $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 90 | - |
|
| 91 | - if ( is_wp_error( $terms ) ) { |
|
| 92 | - // TODO: handle error |
|
| 93 | - return null; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // If there are not terms associated, return null. |
|
| 97 | - if ( 0 === count( $terms ) ) { |
|
| 98 | - return null; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // Return the entity type with the specified id. |
|
| 102 | - return $this->schema_service->get_schema( $terms[0]->slug ); |
|
| 103 | - |
|
| 104 | - case 'post': |
|
| 105 | - case 'page': |
|
| 106 | - // Posts and pages are considered Articles. |
|
| 107 | - return array( |
|
| 108 | - 'uri' => 'http://schema.org/Article', |
|
| 109 | - 'css_class' => 'wl-post', |
|
| 110 | - ); |
|
| 111 | - |
|
| 112 | - default: |
|
| 113 | - // Everything else is considered a Creative Work. |
|
| 114 | - return array( |
|
| 115 | - 'uri' => 'http://schema.org/CreativeWork', |
|
| 116 | - 'css_class' => 'wl-creative-work', |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Set the main type for the specified entity post, given the type URI. |
|
| 124 | - * |
|
| 125 | - * @since 3.8.0 |
|
| 126 | - * |
|
| 127 | - * @param int $post_id The post id. |
|
| 128 | - * @param string $type_uri The type URI. |
|
| 129 | - */ |
|
| 130 | - public function set( $post_id, $type_uri ) { |
|
| 131 | - |
|
| 132 | - // If the type URI is empty we remove the type. |
|
| 133 | - if ( empty( $type_uri ) ) { |
|
| 134 | - |
|
| 135 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 136 | - |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // Get all the terms bound to the wl_entity_type taxonomy. |
|
| 141 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 142 | - 'hide_empty' => false, |
|
| 143 | - // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
| 144 | - // An issue has been opened with the AAM plugin author as well. |
|
| 145 | - // |
|
| 146 | - // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
| 147 | - // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
| 148 | - 'fields' => 'all', |
|
| 149 | - ) ); |
|
| 150 | - |
|
| 151 | - $this->log->error( "Type not found [ post id :: $post_id ][ type uri :: $type_uri ]" ); |
|
| 152 | - |
|
| 153 | - // Check which term matches the specified URI. |
|
| 154 | - foreach ( $terms as $term ) { |
|
| 155 | - |
|
| 156 | - $term_id = $term->term_id; |
|
| 157 | - $term_slug = $term->slug; |
|
| 158 | - |
|
| 159 | - // Load the type data. |
|
| 160 | - $type = $this->schema_service->get_schema( $term_slug ); |
|
| 161 | - // Set the related term ID. |
|
| 162 | - if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 163 | - |
|
| 164 | - $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term_id ][ term slug :: $term_slug ][ type uri :: {$type['uri']} ][ type css class :: {$type['css_class']} ]" ); |
|
| 165 | - |
|
| 166 | - wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 167 | - |
|
| 168 | - return; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - } |
|
| 17 | + /** |
|
| 18 | + * The {@link Wordlift_Schema_Service} instance. |
|
| 19 | + * |
|
| 20 | + * @since 3.7.0 |
|
| 21 | + * @access private |
|
| 22 | + * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
| 23 | + */ |
|
| 24 | + private $schema_service; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * A {@link Wordlift_Log_Service} instance. |
|
| 28 | + * |
|
| 29 | + * @since 3.8.0 |
|
| 30 | + * @access private |
|
| 31 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 32 | + */ |
|
| 33 | + private $log; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 37 | + * |
|
| 38 | + * @since 3.7.0 |
|
| 39 | + * @access private |
|
| 40 | + * @var \Wordlift_Entity_Type_Service $instance The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 41 | + */ |
|
| 42 | + private static $instance; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Wordlift_Entity_Type_Service constructor. |
|
| 46 | + * |
|
| 47 | + * @since 3.7.0 |
|
| 48 | + * |
|
| 49 | + * @param \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
| 50 | + */ |
|
| 51 | + public function __construct( $schema_service ) { |
|
| 52 | + |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
| 54 | + |
|
| 55 | + $this->schema_service = $schema_service; |
|
| 56 | + |
|
| 57 | + self::$instance = $this; |
|
| 58 | + |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get the {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 63 | + * |
|
| 64 | + * @since 3.7.0 |
|
| 65 | + * @return \Wordlift_Entity_Type_Service The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
| 66 | + */ |
|
| 67 | + public static function get_instance() { |
|
| 68 | + |
|
| 69 | + return self::$instance; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Get the types associated with the specified entity post id. |
|
| 74 | + * |
|
| 75 | + * @since 3.7.0 |
|
| 76 | + * |
|
| 77 | + * @param int $post_id The post id. |
|
| 78 | + * |
|
| 79 | + * @return array|null An array of type properties or null if no term is associated |
|
| 80 | + */ |
|
| 81 | + public function get( $post_id ) { |
|
| 82 | + |
|
| 83 | + // Return the correct entity type according to the post type. |
|
| 84 | + switch ( get_post_type( $post_id ) ) { |
|
| 85 | + |
|
| 86 | + case 'entity': |
|
| 87 | + // Get the type from the associated classification. |
|
| 88 | + |
|
| 89 | + $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 90 | + |
|
| 91 | + if ( is_wp_error( $terms ) ) { |
|
| 92 | + // TODO: handle error |
|
| 93 | + return null; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // If there are not terms associated, return null. |
|
| 97 | + if ( 0 === count( $terms ) ) { |
|
| 98 | + return null; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // Return the entity type with the specified id. |
|
| 102 | + return $this->schema_service->get_schema( $terms[0]->slug ); |
|
| 103 | + |
|
| 104 | + case 'post': |
|
| 105 | + case 'page': |
|
| 106 | + // Posts and pages are considered Articles. |
|
| 107 | + return array( |
|
| 108 | + 'uri' => 'http://schema.org/Article', |
|
| 109 | + 'css_class' => 'wl-post', |
|
| 110 | + ); |
|
| 111 | + |
|
| 112 | + default: |
|
| 113 | + // Everything else is considered a Creative Work. |
|
| 114 | + return array( |
|
| 115 | + 'uri' => 'http://schema.org/CreativeWork', |
|
| 116 | + 'css_class' => 'wl-creative-work', |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Set the main type for the specified entity post, given the type URI. |
|
| 124 | + * |
|
| 125 | + * @since 3.8.0 |
|
| 126 | + * |
|
| 127 | + * @param int $post_id The post id. |
|
| 128 | + * @param string $type_uri The type URI. |
|
| 129 | + */ |
|
| 130 | + public function set( $post_id, $type_uri ) { |
|
| 131 | + |
|
| 132 | + // If the type URI is empty we remove the type. |
|
| 133 | + if ( empty( $type_uri ) ) { |
|
| 134 | + |
|
| 135 | + wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 136 | + |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // Get all the terms bound to the wl_entity_type taxonomy. |
|
| 141 | + $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 142 | + 'hide_empty' => false, |
|
| 143 | + // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
| 144 | + // An issue has been opened with the AAM plugin author as well. |
|
| 145 | + // |
|
| 146 | + // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
| 147 | + // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
| 148 | + 'fields' => 'all', |
|
| 149 | + ) ); |
|
| 150 | + |
|
| 151 | + $this->log->error( "Type not found [ post id :: $post_id ][ type uri :: $type_uri ]" ); |
|
| 152 | + |
|
| 153 | + // Check which term matches the specified URI. |
|
| 154 | + foreach ( $terms as $term ) { |
|
| 155 | + |
|
| 156 | + $term_id = $term->term_id; |
|
| 157 | + $term_slug = $term->slug; |
|
| 158 | + |
|
| 159 | + // Load the type data. |
|
| 160 | + $type = $this->schema_service->get_schema( $term_slug ); |
|
| 161 | + // Set the related term ID. |
|
| 162 | + if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 163 | + |
|
| 164 | + $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term_id ][ term slug :: $term_slug ][ type uri :: {$type['uri']} ][ type css class :: {$type['css_class']} ]" ); |
|
| 165 | + |
|
| 166 | + wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 167 | + |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | } |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @param \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
| 50 | 50 | */ |
| 51 | - public function __construct( $schema_service ) { |
|
| 51 | + public function __construct($schema_service) { |
|
| 52 | 52 | |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Type_Service'); |
|
| 54 | 54 | |
| 55 | 55 | $this->schema_service = $schema_service; |
| 56 | 56 | |
@@ -78,28 +78,28 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return array|null An array of type properties or null if no term is associated |
| 80 | 80 | */ |
| 81 | - public function get( $post_id ) { |
|
| 81 | + public function get($post_id) { |
|
| 82 | 82 | |
| 83 | 83 | // Return the correct entity type according to the post type. |
| 84 | - switch ( get_post_type( $post_id ) ) { |
|
| 84 | + switch (get_post_type($post_id)) { |
|
| 85 | 85 | |
| 86 | 86 | case 'entity': |
| 87 | 87 | // Get the type from the associated classification. |
| 88 | 88 | |
| 89 | - $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 89 | + $terms = wp_get_object_terms($post_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 90 | 90 | |
| 91 | - if ( is_wp_error( $terms ) ) { |
|
| 91 | + if (is_wp_error($terms)) { |
|
| 92 | 92 | // TODO: handle error |
| 93 | 93 | return null; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // If there are not terms associated, return null. |
| 97 | - if ( 0 === count( $terms ) ) { |
|
| 97 | + if (0 === count($terms)) { |
|
| 98 | 98 | return null; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Return the entity type with the specified id. |
| 102 | - return $this->schema_service->get_schema( $terms[0]->slug ); |
|
| 102 | + return $this->schema_service->get_schema($terms[0]->slug); |
|
| 103 | 103 | |
| 104 | 104 | case 'post': |
| 105 | 105 | case 'page': |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | * @param int $post_id The post id. |
| 128 | 128 | * @param string $type_uri The type URI. |
| 129 | 129 | */ |
| 130 | - public function set( $post_id, $type_uri ) { |
|
| 130 | + public function set($post_id, $type_uri) { |
|
| 131 | 131 | |
| 132 | 132 | // If the type URI is empty we remove the type. |
| 133 | - if ( empty( $type_uri ) ) { |
|
| 133 | + if (empty($type_uri)) { |
|
| 134 | 134 | |
| 135 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 135 | + wp_set_object_terms($post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 136 | 136 | |
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Get all the terms bound to the wl_entity_type taxonomy. |
| 141 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 141 | + $terms = get_terms(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 142 | 142 | 'hide_empty' => false, |
| 143 | 143 | // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
| 144 | 144 | // An issue has been opened with the AAM plugin author as well. |
@@ -146,24 +146,24 @@ discard block |
||
| 146 | 146 | // see https://github.com/insideout10/wordlift-plugin/issues/334 |
| 147 | 147 | // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
| 148 | 148 | 'fields' => 'all', |
| 149 | - ) ); |
|
| 149 | + )); |
|
| 150 | 150 | |
| 151 | - $this->log->error( "Type not found [ post id :: $post_id ][ type uri :: $type_uri ]" ); |
|
| 151 | + $this->log->error("Type not found [ post id :: $post_id ][ type uri :: $type_uri ]"); |
|
| 152 | 152 | |
| 153 | 153 | // Check which term matches the specified URI. |
| 154 | - foreach ( $terms as $term ) { |
|
| 154 | + foreach ($terms as $term) { |
|
| 155 | 155 | |
| 156 | 156 | $term_id = $term->term_id; |
| 157 | 157 | $term_slug = $term->slug; |
| 158 | 158 | |
| 159 | 159 | // Load the type data. |
| 160 | - $type = $this->schema_service->get_schema( $term_slug ); |
|
| 160 | + $type = $this->schema_service->get_schema($term_slug); |
|
| 161 | 161 | // Set the related term ID. |
| 162 | - if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 162 | + if ($type_uri === $type['uri'] || $type_uri === $type['css_class']) { |
|
| 163 | 163 | |
| 164 | - $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term_id ][ term slug :: $term_slug ][ type uri :: {$type['uri']} ][ type css class :: {$type['css_class']} ]" ); |
|
| 164 | + $this->log->debug("Setting entity type [ post id :: $post_id ][ term id :: $term_id ][ term slug :: $term_slug ][ type uri :: {$type['uri']} ][ type css class :: {$type['css_class']} ]"); |
|
| 165 | 165 | |
| 166 | - wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 166 | + wp_set_object_terms($post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 167 | 167 | |
| 168 | 168 | return; |
| 169 | 169 | } |
@@ -16,143 +16,143 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Entity_Post_Type_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The entity post type. |
|
| 21 | - * |
|
| 22 | - * @since 3.6.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var string $post_type The entity post type. |
|
| 25 | - */ |
|
| 26 | - private $post_type; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The entity type slug. |
|
| 30 | - * |
|
| 31 | - * @since 3.6.0 |
|
| 32 | - * @access private |
|
| 33 | - * @var string $slug The entity type slug. |
|
| 34 | - */ |
|
| 35 | - private $slug; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * A singleton instance of the entity type service. |
|
| 39 | - * |
|
| 40 | - * @since 3.6.0 |
|
| 41 | - * @access private |
|
| 42 | - * @var Wordlift_Entity_Post_Type_Service |
|
| 43 | - */ |
|
| 44 | - private static $instance; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Create an entity type service instance. |
|
| 48 | - * |
|
| 49 | - * @since 3.6.0 |
|
| 50 | - * |
|
| 51 | - * @param string $post_type The post type, e.g. entity. |
|
| 52 | - * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
|
| 53 | - */ |
|
| 54 | - public function __construct( $post_type, $slug ) { |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - $this->post_type = $post_type; |
|
| 58 | - |
|
| 59 | - // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default |
|
| 60 | - // to the type name. |
|
| 61 | - $this->slug = $slug ?: $post_type; |
|
| 62 | - |
|
| 63 | - self::$instance = $this; |
|
| 64 | - |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Get the entity type service singleton instance. |
|
| 69 | - * |
|
| 70 | - * @since 3.6.0 |
|
| 71 | - * |
|
| 72 | - * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance. |
|
| 73 | - */ |
|
| 74 | - public static function get_instance() { |
|
| 75 | - |
|
| 76 | - return self::$instance; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Get the entity type slug. |
|
| 81 | - * |
|
| 82 | - * @since 3.6.0 |
|
| 83 | - * |
|
| 84 | - * @return string The entity type slug. |
|
| 85 | - */ |
|
| 86 | - public function get_slug() { |
|
| 87 | - |
|
| 88 | - return $this->slug; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get the entity post type name. |
|
| 93 | - * |
|
| 94 | - * @since 3.6.0 |
|
| 95 | - * |
|
| 96 | - * @return string The entity post type. |
|
| 97 | - */ |
|
| 98 | - public function get_post_type() { |
|
| 99 | - |
|
| 100 | - return $this->post_type; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Register the WordLift entity post type. This method is hooked to WordPress' init action. |
|
| 106 | - * |
|
| 107 | - * @since 3.6.0 |
|
| 108 | - */ |
|
| 109 | - public function register() { |
|
| 110 | - |
|
| 111 | - $labels = array( |
|
| 112 | - 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 113 | - 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 114 | - 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 115 | - 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 116 | - 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 117 | - 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 118 | - 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 119 | - 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 120 | - 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 121 | - 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 122 | - 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 123 | - 'parent_item_colon' => '', |
|
| 124 | - 'menu_name' => __( 'Vocabulary', 'wordlift' ), |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - $args = array( |
|
| 128 | - 'labels' => $labels, |
|
| 129 | - 'description' => 'Holds our vocabulary (set of entities) and entity specific data', |
|
| 130 | - 'public' => true, |
|
| 131 | - 'menu_position' => 20, |
|
| 132 | - // after the pages menu. |
|
| 133 | - // Add support for 'authors' and 'revisions': |
|
| 134 | - // * see https://github.com/insideout10/wordlift-plugin/issues/395 |
|
| 135 | - // * see https://github.com/insideout10/wordlift-plugin/issues/376 |
|
| 136 | - 'supports' => array( |
|
| 137 | - 'title', |
|
| 138 | - 'editor', |
|
| 139 | - 'thumbnail', |
|
| 140 | - 'excerpt', |
|
| 141 | - 'comments', |
|
| 142 | - 'author', |
|
| 143 | - // Disabling revisions support. |
|
| 144 | - // |
|
| 145 | - // See https://github.com/insideout10/wordlift-plugin/issues/462 |
|
| 146 | - // 'revisions', |
|
| 147 | - ), |
|
| 148 | - 'has_archive' => true, |
|
| 149 | - 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 150 | - // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
|
| 151 | - 'rewrite' => array( 'slug' => $this->slug ), |
|
| 152 | - ); |
|
| 153 | - |
|
| 154 | - register_post_type( $this->post_type, $args ); |
|
| 155 | - |
|
| 156 | - } |
|
| 19 | + /** |
|
| 20 | + * The entity post type. |
|
| 21 | + * |
|
| 22 | + * @since 3.6.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var string $post_type The entity post type. |
|
| 25 | + */ |
|
| 26 | + private $post_type; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The entity type slug. |
|
| 30 | + * |
|
| 31 | + * @since 3.6.0 |
|
| 32 | + * @access private |
|
| 33 | + * @var string $slug The entity type slug. |
|
| 34 | + */ |
|
| 35 | + private $slug; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * A singleton instance of the entity type service. |
|
| 39 | + * |
|
| 40 | + * @since 3.6.0 |
|
| 41 | + * @access private |
|
| 42 | + * @var Wordlift_Entity_Post_Type_Service |
|
| 43 | + */ |
|
| 44 | + private static $instance; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Create an entity type service instance. |
|
| 48 | + * |
|
| 49 | + * @since 3.6.0 |
|
| 50 | + * |
|
| 51 | + * @param string $post_type The post type, e.g. entity. |
|
| 52 | + * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
|
| 53 | + */ |
|
| 54 | + public function __construct( $post_type, $slug ) { |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + $this->post_type = $post_type; |
|
| 58 | + |
|
| 59 | + // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default |
|
| 60 | + // to the type name. |
|
| 61 | + $this->slug = $slug ?: $post_type; |
|
| 62 | + |
|
| 63 | + self::$instance = $this; |
|
| 64 | + |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Get the entity type service singleton instance. |
|
| 69 | + * |
|
| 70 | + * @since 3.6.0 |
|
| 71 | + * |
|
| 72 | + * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance. |
|
| 73 | + */ |
|
| 74 | + public static function get_instance() { |
|
| 75 | + |
|
| 76 | + return self::$instance; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Get the entity type slug. |
|
| 81 | + * |
|
| 82 | + * @since 3.6.0 |
|
| 83 | + * |
|
| 84 | + * @return string The entity type slug. |
|
| 85 | + */ |
|
| 86 | + public function get_slug() { |
|
| 87 | + |
|
| 88 | + return $this->slug; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get the entity post type name. |
|
| 93 | + * |
|
| 94 | + * @since 3.6.0 |
|
| 95 | + * |
|
| 96 | + * @return string The entity post type. |
|
| 97 | + */ |
|
| 98 | + public function get_post_type() { |
|
| 99 | + |
|
| 100 | + return $this->post_type; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Register the WordLift entity post type. This method is hooked to WordPress' init action. |
|
| 106 | + * |
|
| 107 | + * @since 3.6.0 |
|
| 108 | + */ |
|
| 109 | + public function register() { |
|
| 110 | + |
|
| 111 | + $labels = array( |
|
| 112 | + 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 113 | + 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 114 | + 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 115 | + 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 116 | + 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 117 | + 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 118 | + 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 119 | + 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 120 | + 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 121 | + 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 122 | + 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 123 | + 'parent_item_colon' => '', |
|
| 124 | + 'menu_name' => __( 'Vocabulary', 'wordlift' ), |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + $args = array( |
|
| 128 | + 'labels' => $labels, |
|
| 129 | + 'description' => 'Holds our vocabulary (set of entities) and entity specific data', |
|
| 130 | + 'public' => true, |
|
| 131 | + 'menu_position' => 20, |
|
| 132 | + // after the pages menu. |
|
| 133 | + // Add support for 'authors' and 'revisions': |
|
| 134 | + // * see https://github.com/insideout10/wordlift-plugin/issues/395 |
|
| 135 | + // * see https://github.com/insideout10/wordlift-plugin/issues/376 |
|
| 136 | + 'supports' => array( |
|
| 137 | + 'title', |
|
| 138 | + 'editor', |
|
| 139 | + 'thumbnail', |
|
| 140 | + 'excerpt', |
|
| 141 | + 'comments', |
|
| 142 | + 'author', |
|
| 143 | + // Disabling revisions support. |
|
| 144 | + // |
|
| 145 | + // See https://github.com/insideout10/wordlift-plugin/issues/462 |
|
| 146 | + // 'revisions', |
|
| 147 | + ), |
|
| 148 | + 'has_archive' => true, |
|
| 149 | + 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 150 | + // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
|
| 151 | + 'rewrite' => array( 'slug' => $this->slug ), |
|
| 152 | + ); |
|
| 153 | + |
|
| 154 | + register_post_type( $this->post_type, $args ); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param string $post_type The post type, e.g. entity. |
| 52 | 52 | * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
| 53 | 53 | */ |
| 54 | - public function __construct( $post_type, $slug ) { |
|
| 54 | + public function __construct($post_type, $slug) { |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | $this->post_type = $post_type; |
@@ -109,19 +109,19 @@ discard block |
||
| 109 | 109 | public function register() { |
| 110 | 110 | |
| 111 | 111 | $labels = array( |
| 112 | - 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 113 | - 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 114 | - 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 115 | - 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 116 | - 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 117 | - 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 118 | - 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 119 | - 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 120 | - 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 121 | - 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 122 | - 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 112 | + 'name' => _x('Vocabulary', 'post type general name', 'wordlift'), |
|
| 113 | + 'singular_name' => _x('Entity', 'post type singular name', 'wordlift'), |
|
| 114 | + 'add_new' => _x('Add New Entity', 'entity', 'wordlift'), |
|
| 115 | + 'add_new_item' => __('Add New Entity', 'wordlift'), |
|
| 116 | + 'edit_item' => __('Edit Entity', 'wordlift'), |
|
| 117 | + 'new_item' => __('New Entity', 'wordlift'), |
|
| 118 | + 'all_items' => __('All Entities', 'wordlift'), |
|
| 119 | + 'view_item' => __('View Entity', 'wordlift'), |
|
| 120 | + 'search_items' => __('Search in Vocabulary', 'wordlift'), |
|
| 121 | + 'not_found' => __('No entities found', 'wordlift'), |
|
| 122 | + 'not_found_in_trash' => __('No entities found in the Trash', 'wordlift'), |
|
| 123 | 123 | 'parent_item_colon' => '', |
| 124 | - 'menu_name' => __( 'Vocabulary', 'wordlift' ), |
|
| 124 | + 'menu_name' => __('Vocabulary', 'wordlift'), |
|
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | $args = array( |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | // 'revisions', |
| 147 | 147 | ), |
| 148 | 148 | 'has_archive' => true, |
| 149 | - 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 149 | + 'menu_icon' => WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 150 | 150 | // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
| 151 | - 'rewrite' => array( 'slug' => $this->slug ), |
|
| 151 | + 'rewrite' => array('slug' => $this->slug), |
|
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | - register_post_type( $this->post_type, $args ); |
|
| 154 | + register_post_type($this->post_type, $args); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |