@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * @param string $new_title Optional. New title. |
| 13 | 13 | * @param string $new_slug Optional. New slug. |
| 14 | 14 | * |
| 15 | - * @return The enhanced html. |
|
| 15 | + * @return string enhanced html. |
|
| 16 | 16 | */ |
| 17 | 17 | function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
| 18 | 18 | |
@@ -16,23 +16,23 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
| 18 | 18 | |
| 19 | - // If the post is published, add the button to view Redlink's linked data. |
|
| 20 | - if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | - if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | - $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | - $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | - $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | - esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 26 | - "</a></span>\n"; |
|
| 27 | - } |
|
| 28 | - $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | - urlencode( get_permalink( $post_id ) ) . |
|
| 30 | - "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | - esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 32 | - "</a></span>\n"; |
|
| 33 | - } |
|
| 19 | + // If the post is published, add the button to view Redlink's linked data. |
|
| 20 | + if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | + if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | + $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | + $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | + $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | + esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 26 | + "</a></span>\n"; |
|
| 27 | + } |
|
| 28 | + $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | + urlencode( get_permalink( $post_id ) ) . |
|
| 30 | + "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | + esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 32 | + "</a></span>\n"; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - return $html; |
|
| 35 | + return $html; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4 ); |
@@ -14,25 +14,25 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @return The enhanced html. |
| 16 | 16 | */ |
| 17 | -function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
|
| 17 | +function wl_admin_permalink_html($html, $post_id, $new_title, $new_slug) { |
|
| 18 | 18 | |
| 19 | 19 | // If the post is published, add the button to view Redlink's linked data. |
| 20 | - if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | - if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | - $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | - $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | - $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | - esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 20 | + if ('publish' == get_post_status($post_id)) { |
|
| 21 | + if ($uri = wl_get_entity_uri($post_id)) { |
|
| 22 | + $uri_esc = esc_attr(wl_get_entity_uri($post_id)); |
|
| 23 | + $lod_view_href = 'http://lodview.it/lodview/?IRI='.$uri_esc; |
|
| 24 | + $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>". |
|
| 25 | + esc_html__('View Linked Data', 'wordlift'). |
|
| 26 | 26 | "</a></span>\n"; |
| 27 | 27 | } |
| 28 | - $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | - urlencode( get_permalink( $post_id ) ) . |
|
| 30 | - "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | - esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 28 | + $html .= "<span id='view-post-btn'><a href='".WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL. |
|
| 29 | + urlencode(get_permalink($post_id)). |
|
| 30 | + "' class='button button-small wl-button' target='_blank'>". |
|
| 31 | + esc_html__('Test Google Rich Snippets', 'wordlift'). |
|
| 32 | 32 | "</a></span>\n"; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | return $html; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4 ); |
|
| 38 | +add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4); |
|
@@ -160,7 +160,6 @@ |
||
| 160 | 160 | * @uses wl_shortcode_geomap_get_places() in order to retrieve places |
| 161 | 161 | * @uses wl_shortcode_geomap_prepare_map() in order to encode retireved places in a Leaflet friendly format |
| 162 | 162 | * |
| 163 | - * @param array $places An array of place posts. |
|
| 164 | 163 | * |
| 165 | 164 | * @return array An array of place posts. |
| 166 | 165 | */ |
@@ -14,56 +14,56 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wl_shortcode_geomap_get_places( $post_id = null ) { |
| 16 | 16 | |
| 17 | - // If $post_id is null or is not numeric it means this is a global geomap |
|
| 18 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 17 | + // If $post_id is null or is not numeric it means this is a global geomap |
|
| 18 | + $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 19 | 19 | |
| 20 | - // If the current one is not a global geomap, retrieve related entities ids |
|
| 21 | - if ( $is_global ) { |
|
| 22 | - $related_ids = array(); |
|
| 23 | - } else { |
|
| 24 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 25 | - 'status' => 'publish' |
|
| 26 | - ) ); |
|
| 20 | + // If the current one is not a global geomap, retrieve related entities ids |
|
| 21 | + if ( $is_global ) { |
|
| 22 | + $related_ids = array(); |
|
| 23 | + } else { |
|
| 24 | + $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 25 | + 'status' => 'publish' |
|
| 26 | + ) ); |
|
| 27 | 27 | |
| 28 | - // Also include current entity |
|
| 29 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 30 | - $related_ids[] = $post_id; |
|
| 31 | - } |
|
| 32 | - } |
|
| 28 | + // Also include current entity |
|
| 29 | + if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 30 | + $related_ids[] = $post_id; |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 35 | - // An empty array can be returned in this case |
|
| 36 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 37 | - return array(); |
|
| 38 | - } |
|
| 34 | + // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 35 | + // An empty array can be returned in this case |
|
| 36 | + if ( ! $is_global && empty( $related_ids ) ) { |
|
| 37 | + return array(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - // Retrieve all 'published' places with geo coordinates defined |
|
| 41 | - // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 42 | - // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 43 | - return get_posts( array( |
|
| 44 | - 'post__in' => $related_ids, |
|
| 45 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 46 | - 'nopaging' => true, |
|
| 47 | - 'post_status' => 'publish', |
|
| 48 | - 'meta_query' => array( |
|
| 49 | - 'relation' => 'AND', |
|
| 50 | - array( |
|
| 51 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 52 | - 'value' => null, |
|
| 53 | - 'compare' => '!=', |
|
| 54 | - ), |
|
| 55 | - array( |
|
| 56 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 57 | - 'value' => null, |
|
| 58 | - 'compare' => '!=', |
|
| 59 | - ) |
|
| 60 | - ), |
|
| 61 | - 'tax_query' => array( |
|
| 62 | - 'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 63 | - 'field' => 'slug', |
|
| 64 | - 'terms' => 'place' |
|
| 65 | - ) |
|
| 66 | - ) ); |
|
| 40 | + // Retrieve all 'published' places with geo coordinates defined |
|
| 41 | + // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 42 | + // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 43 | + return get_posts( array( |
|
| 44 | + 'post__in' => $related_ids, |
|
| 45 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 46 | + 'nopaging' => true, |
|
| 47 | + 'post_status' => 'publish', |
|
| 48 | + 'meta_query' => array( |
|
| 49 | + 'relation' => 'AND', |
|
| 50 | + array( |
|
| 51 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 52 | + 'value' => null, |
|
| 53 | + 'compare' => '!=', |
|
| 54 | + ), |
|
| 55 | + array( |
|
| 56 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 57 | + 'value' => null, |
|
| 58 | + 'compare' => '!=', |
|
| 59 | + ) |
|
| 60 | + ), |
|
| 61 | + 'tax_query' => array( |
|
| 62 | + 'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 63 | + 'field' => 'slug', |
|
| 64 | + 'terms' => 'place' |
|
| 65 | + ) |
|
| 66 | + ) ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,88 +78,88 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function wl_shortcode_geomap_prepare_map( $places ) { |
| 80 | 80 | |
| 81 | - // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 82 | - $min_latitude = PHP_INT_MAX; |
|
| 83 | - $min_longitude = PHP_INT_MAX; |
|
| 84 | - $max_latitude = ~PHP_INT_MAX; |
|
| 85 | - $max_longitude = ~PHP_INT_MAX; |
|
| 81 | + // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 82 | + $min_latitude = PHP_INT_MAX; |
|
| 83 | + $min_longitude = PHP_INT_MAX; |
|
| 84 | + $max_latitude = ~PHP_INT_MAX; |
|
| 85 | + $max_longitude = ~PHP_INT_MAX; |
|
| 86 | 86 | |
| 87 | - // Prepare an empty array of POIs in geoJSON format. |
|
| 88 | - $pois = array(); |
|
| 89 | - // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 90 | - // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 91 | - $boundaries = array(); |
|
| 87 | + // Prepare an empty array of POIs in geoJSON format. |
|
| 88 | + $pois = array(); |
|
| 89 | + // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 90 | + // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 91 | + $boundaries = array(); |
|
| 92 | 92 | |
| 93 | - // Add a POI for each entity that has coordinates. |
|
| 94 | - foreach ( $places as $entity ) { |
|
| 93 | + // Add a POI for each entity that has coordinates. |
|
| 94 | + foreach ( $places as $entity ) { |
|
| 95 | 95 | |
| 96 | - // Get the coordinates. |
|
| 97 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 96 | + // Get the coordinates. |
|
| 97 | + $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 98 | 98 | |
| 99 | - // Don't show the widget if the coordinates aren't set. |
|
| 100 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 101 | - continue; |
|
| 102 | - } |
|
| 99 | + // Don't show the widget if the coordinates aren't set. |
|
| 100 | + if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 105 | - // This function should be focused on returning pure data instead |
|
| 104 | + // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 105 | + // This function should be focused on returning pure data instead |
|
| 106 | 106 | |
| 107 | - // Get the title, URL and thumb of the entity. |
|
| 108 | - $title = esc_attr( $entity->post_title ); |
|
| 109 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 112 | - ) { |
|
| 113 | - $img_src = esc_attr( $attachment[0] ); |
|
| 114 | - } |
|
| 107 | + // Get the title, URL and thumb of the entity. |
|
| 108 | + $title = esc_attr( $entity->post_title ); |
|
| 109 | + $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | + if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | + false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 112 | + ) { |
|
| 113 | + $img_src = esc_attr( $attachment[0] ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - // Build HTML popup. TODO: move thumb width in css |
|
| 117 | - $content = "<a href=$link><h6>$title</h6>"; |
|
| 118 | - if ( isset( $img_src ) ) { |
|
| 119 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 120 | - } |
|
| 121 | - $content = $content . "</a><ul>"; |
|
| 122 | - // Get the related posts (published) and print them in the popup. |
|
| 123 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 124 | - 'status' => 'publish' |
|
| 125 | - ) ); |
|
| 126 | - foreach ( $related_posts as $rp_id ) { |
|
| 116 | + // Build HTML popup. TODO: move thumb width in css |
|
| 117 | + $content = "<a href=$link><h6>$title</h6>"; |
|
| 118 | + if ( isset( $img_src ) ) { |
|
| 119 | + $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 120 | + } |
|
| 121 | + $content = $content . "</a><ul>"; |
|
| 122 | + // Get the related posts (published) and print them in the popup. |
|
| 123 | + $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 124 | + 'status' => 'publish' |
|
| 125 | + ) ); |
|
| 126 | + foreach ( $related_posts as $rp_id ) { |
|
| 127 | 127 | |
| 128 | - $rp = get_post( $rp_id ); |
|
| 129 | - $title = esc_attr( $rp->post_title ); |
|
| 130 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 132 | - } |
|
| 133 | - $content = $content . "</ul>"; |
|
| 128 | + $rp = get_post( $rp_id ); |
|
| 129 | + $title = esc_attr( $rp->post_title ); |
|
| 130 | + $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | + $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 132 | + } |
|
| 133 | + $content = $content . "</ul>"; |
|
| 134 | 134 | |
| 135 | - // Formatting POI in geoJSON. |
|
| 136 | - // http://leafletjs.com/examples/geojson.html |
|
| 137 | - $poi = array( |
|
| 138 | - 'type' => 'Feature', |
|
| 139 | - 'properties' => array( 'popupContent' => $content ), |
|
| 140 | - 'geometry' => array( |
|
| 141 | - 'type' => 'Point', |
|
| 142 | - 'coordinates' => array( |
|
| 143 | - // Leaflet geoJSON wants them swapped |
|
| 144 | - $coordinates['longitude'], |
|
| 145 | - $coordinates['latitude'] |
|
| 146 | - ) |
|
| 147 | - ) |
|
| 148 | - ); |
|
| 135 | + // Formatting POI in geoJSON. |
|
| 136 | + // http://leafletjs.com/examples/geojson.html |
|
| 137 | + $poi = array( |
|
| 138 | + 'type' => 'Feature', |
|
| 139 | + 'properties' => array( 'popupContent' => $content ), |
|
| 140 | + 'geometry' => array( |
|
| 141 | + 'type' => 'Point', |
|
| 142 | + 'coordinates' => array( |
|
| 143 | + // Leaflet geoJSON wants them swapped |
|
| 144 | + $coordinates['longitude'], |
|
| 145 | + $coordinates['latitude'] |
|
| 146 | + ) |
|
| 147 | + ) |
|
| 148 | + ); |
|
| 149 | 149 | |
| 150 | - $pois[] = $poi; |
|
| 150 | + $pois[] = $poi; |
|
| 151 | 151 | |
| 152 | - // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 153 | - // http://leafletjs.com/reference.html#latlngbounds |
|
| 154 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 152 | + // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 153 | + // http://leafletjs.com/reference.html#latlngbounds |
|
| 154 | + $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 155 | 155 | |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - $map_data = array(); |
|
| 159 | - $map_data['features'] = $pois; |
|
| 160 | - $map_data['boundaries'] = $boundaries; |
|
| 158 | + $map_data = array(); |
|
| 159 | + $map_data['features'] = $pois; |
|
| 160 | + $map_data['boundaries'] = $boundaries; |
|
| 161 | 161 | |
| 162 | - return $map_data; |
|
| 162 | + return $map_data; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | * @return array An array of place posts. |
| 174 | 174 | */ |
| 175 | 175 | function wl_shortcode_geomap_ajax() { |
| 176 | - // Get the post Id. |
|
| 177 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 176 | + // Get the post Id. |
|
| 177 | + $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 178 | 178 | |
| 179 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 179 | + $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | + $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 181 | 181 | |
| 182 | - wl_core_send_json( $map_data ); |
|
| 182 | + wl_core_send_json( $map_data ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
@@ -12,35 +12,35 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return array An array of place posts. |
| 14 | 14 | */ |
| 15 | -function wl_shortcode_geomap_get_places( $post_id = null ) { |
|
| 15 | +function wl_shortcode_geomap_get_places($post_id = null) { |
|
| 16 | 16 | |
| 17 | 17 | // If $post_id is null or is not numeric it means this is a global geomap |
| 18 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 18 | + $is_global = is_null($post_id) || ! is_numeric($post_id); |
|
| 19 | 19 | |
| 20 | 20 | // If the current one is not a global geomap, retrieve related entities ids |
| 21 | - if ( $is_global ) { |
|
| 21 | + if ($is_global) { |
|
| 22 | 22 | $related_ids = array(); |
| 23 | 23 | } else { |
| 24 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 24 | + $related_ids = wl_core_get_related_entity_ids($post_id, array( |
|
| 25 | 25 | 'status' => 'publish' |
| 26 | - ) ); |
|
| 26 | + )); |
|
| 27 | 27 | |
| 28 | 28 | // Also include current entity |
| 29 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 29 | + if (Wordlift_Entity_Service::get_instance()->is_entity($post_id)) { |
|
| 30 | 30 | $related_ids[] = $post_id; |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
| 35 | 35 | // An empty array can be returned in this case |
| 36 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 36 | + if ( ! $is_global && empty($related_ids)) { |
|
| 37 | 37 | return array(); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Retrieve all 'published' places with geo coordinates defined |
| 41 | 41 | // If $related_ids is not empty, it's used to limit query results to the current post related places |
| 42 | 42 | // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
| 43 | - return get_posts( array( |
|
| 43 | + return get_posts(array( |
|
| 44 | 44 | 'post__in' => $related_ids, |
| 45 | 45 | 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
| 46 | 46 | 'nopaging' => true, |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | 'field' => 'slug', |
| 64 | 64 | 'terms' => 'place' |
| 65 | 65 | ) |
| 66 | - ) ); |
|
| 66 | + )); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return array An array of markers and boundaries for Leaflet. |
| 78 | 78 | */ |
| 79 | -function wl_shortcode_geomap_prepare_map( $places ) { |
|
| 79 | +function wl_shortcode_geomap_prepare_map($places) { |
|
| 80 | 80 | |
| 81 | 81 | // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
| 82 | 82 | $min_latitude = PHP_INT_MAX; |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | $boundaries = array(); |
| 92 | 92 | |
| 93 | 93 | // Add a POI for each entity that has coordinates. |
| 94 | - foreach ( $places as $entity ) { |
|
| 94 | + foreach ($places as $entity) { |
|
| 95 | 95 | |
| 96 | 96 | // Get the coordinates. |
| 97 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 97 | + $coordinates = wl_get_coordinates($entity->ID); |
|
| 98 | 98 | |
| 99 | 99 | // Don't show the widget if the coordinates aren't set. |
| 100 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 100 | + if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) { |
|
| 101 | 101 | continue; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,38 +105,38 @@ discard block |
||
| 105 | 105 | // This function should be focused on returning pure data instead |
| 106 | 106 | |
| 107 | 107 | // Get the title, URL and thumb of the entity. |
| 108 | - $title = esc_attr( $entity->post_title ); |
|
| 109 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 108 | + $title = esc_attr($entity->post_title); |
|
| 109 | + $link = esc_attr(get_permalink($entity->ID)); |
|
| 110 | + if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) && |
|
| 111 | + false !== ($attachment = wp_get_attachment_image_src($thumbnail_id)) |
|
| 112 | 112 | ) { |
| 113 | - $img_src = esc_attr( $attachment[0] ); |
|
| 113 | + $img_src = esc_attr($attachment[0]); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Build HTML popup. TODO: move thumb width in css |
| 117 | 117 | $content = "<a href=$link><h6>$title</h6>"; |
| 118 | - if ( isset( $img_src ) ) { |
|
| 119 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 118 | + if (isset($img_src)) { |
|
| 119 | + $content = $content."<img src=$img_src style='width:100%'/>"; |
|
| 120 | 120 | } |
| 121 | - $content = $content . "</a><ul>"; |
|
| 121 | + $content = $content."</a><ul>"; |
|
| 122 | 122 | // Get the related posts (published) and print them in the popup. |
| 123 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 123 | + $related_posts = wl_core_get_related_post_ids($entity->ID, array( |
|
| 124 | 124 | 'status' => 'publish' |
| 125 | - ) ); |
|
| 126 | - foreach ( $related_posts as $rp_id ) { |
|
| 125 | + )); |
|
| 126 | + foreach ($related_posts as $rp_id) { |
|
| 127 | 127 | |
| 128 | - $rp = get_post( $rp_id ); |
|
| 129 | - $title = esc_attr( $rp->post_title ); |
|
| 130 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 128 | + $rp = get_post($rp_id); |
|
| 129 | + $title = esc_attr($rp->post_title); |
|
| 130 | + $link = esc_attr(get_permalink($rp->ID)); |
|
| 131 | + $content = $content."<li><a href=$link>$title</a></li>"; |
|
| 132 | 132 | } |
| 133 | - $content = $content . "</ul>"; |
|
| 133 | + $content = $content."</ul>"; |
|
| 134 | 134 | |
| 135 | 135 | // Formatting POI in geoJSON. |
| 136 | 136 | // http://leafletjs.com/examples/geojson.html |
| 137 | 137 | $poi = array( |
| 138 | 138 | 'type' => 'Feature', |
| 139 | - 'properties' => array( 'popupContent' => $content ), |
|
| 139 | + 'properties' => array('popupContent' => $content), |
|
| 140 | 140 | 'geometry' => array( |
| 141 | 141 | 'type' => 'Point', |
| 142 | 142 | 'coordinates' => array( |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
| 153 | 153 | // http://leafletjs.com/reference.html#latlngbounds |
| 154 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 154 | + $boundaries[] = array($coordinates['latitude'], $coordinates['longitude']); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | function wl_shortcode_geomap_ajax() { |
| 176 | 176 | // Get the post Id. |
| 177 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 177 | + $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null); |
|
| 178 | 178 | |
| 179 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 179 | + $places = wl_shortcode_geomap_get_places($post_id); |
|
| 180 | + $map_data = wl_shortcode_geomap_prepare_map($places); |
|
| 181 | 181 | |
| 182 | - wl_core_send_json( $map_data ); |
|
| 182 | + wl_core_send_json($map_data); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | -add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 186 | -add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 185 | +add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 186 | +add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 187 | 187 | |
| 188 | 188 | ///** |
| 189 | 189 | // * Print geomap shortcode |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class WL_Metabox_Field_coordinates extends WL_Metabox_Field { |
| 5 | 5 | |
| 6 | - public function __construct( $args ) { |
|
| 6 | + public function __construct($args) { |
|
| 7 | 7 | |
| 8 | 8 | // Just set up the necessary info without calling the parent constructor. |
| 9 | 9 | // TODO: write a parent class for grouped properties |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function get_data() { |
| 17 | 17 | $entity_id = get_the_ID(); |
| 18 | - $this->data = wl_get_coordinates( $entity_id ); |
|
| 18 | + $this->data = wl_get_coordinates($entity_id); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function html() { |
@@ -33,20 +33,20 @@ discard block |
||
| 33 | 33 | $data = $this->data; |
| 34 | 34 | // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
| 35 | 35 | // want to use the current user location for the marker. |
| 36 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 36 | + $coordinates = ( ! empty($data['latitude']) && ! empty($data['longitude']) ? sprintf('[%f,%f]', $data['latitude'], $data['longitude']) : '[0,0]'); |
|
| 37 | 37 | $map_init = '[0,0]' === $coordinates |
| 38 | 38 | ? 'locate( {setView: true, maxZoom: 16} )' |
| 39 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 39 | + : sprintf("setView( [%f,%f], 9 )", $data['latitude'], $data['longitude']); |
|
| 40 | 40 | |
| 41 | 41 | // Print input fields |
| 42 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 42 | + $html .= '<label for="wl_place_lat">'.__('Latitude', 'wordlift').'</label>'; |
|
| 43 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="'.$data['latitude'].'" style="width:100%" />'; |
|
| 44 | 44 | |
| 45 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 45 | + $html .= '<label for="wl_place_lon">'.__('Longitude', 'wordlift').'</label>'; |
|
| 46 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="'.$data['longitude'].'" style="width:100%" />'; |
|
| 47 | 47 | |
| 48 | 48 | // Show Leaflet map to pick coordinates |
| 49 | - $element_id = uniqid( 'wl-gep-map-' ); |
|
| 49 | + $element_id = uniqid('wl-gep-map-'); |
|
| 50 | 50 | $html .= <<<EOF |
| 51 | 51 | |
| 52 | 52 | <div id="$element_id"></div> |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | return $html; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function save_data( $coords ) { |
|
| 87 | + public function save_data($coords) { |
|
| 88 | 88 | |
| 89 | - $this->sanitize_data( $coords ); |
|
| 89 | + $this->sanitize_data($coords); |
|
| 90 | 90 | |
| 91 | 91 | $entity_id = get_the_ID(); |
| 92 | 92 | |
| 93 | 93 | // Take away old values |
| 94 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 94 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE); |
|
| 95 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE); |
|
| 96 | 96 | |
| 97 | 97 | $latitude = $this->data[0]; |
| 98 | 98 | $longitude = $this->data[1]; |
| 99 | 99 | |
| 100 | 100 | // insert new coordinate values |
| 101 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 101 | + if ( ! empty($latitude) && ! empty($longitude)) { |
|
| 102 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true); |
|
| 103 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | } |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * Only accept float numbers |
| 110 | 110 | */ |
| 111 | - public function sanitize_data_filter( $value ) { |
|
| 111 | + public function sanitize_data_filter($value) { |
|
| 112 | 112 | |
| 113 | 113 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 114 | 114 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 115 | - if ( ! is_numeric( $value ) ) { |
|
| 115 | + if ( ! is_numeric($value)) { |
|
| 116 | 116 | return ''; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -3,51 +3,51 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class WL_Metabox_Field_coordinates extends WL_Metabox_Field { |
| 5 | 5 | |
| 6 | - public function __construct( $args ) { |
|
| 6 | + public function __construct( $args ) { |
|
| 7 | 7 | |
| 8 | - // Just set up the necessary info without calling the parent constructor. |
|
| 9 | - // TODO: write a parent class for grouped properties |
|
| 8 | + // Just set up the necessary info without calling the parent constructor. |
|
| 9 | + // TODO: write a parent class for grouped properties |
|
| 10 | 10 | |
| 11 | - // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 12 | - // In the DB the correct meta names will be used. |
|
| 13 | - $this->meta_name = 'coordinates'; |
|
| 14 | - } |
|
| 11 | + // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 12 | + // In the DB the correct meta names will be used. |
|
| 13 | + $this->meta_name = 'coordinates'; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function get_data() { |
|
| 17 | - $entity_id = get_the_ID(); |
|
| 18 | - $this->data = wl_get_coordinates( $entity_id ); |
|
| 19 | - } |
|
| 16 | + public function get_data() { |
|
| 17 | + $entity_id = get_the_ID(); |
|
| 18 | + $this->data = wl_get_coordinates( $entity_id ); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function html() { |
|
| 21 | + public function html() { |
|
| 22 | 22 | |
| 23 | - // Open main <div> for the Field |
|
| 24 | - $html = $this->html_wrapper_open(); |
|
| 23 | + // Open main <div> for the Field |
|
| 24 | + $html = $this->html_wrapper_open(); |
|
| 25 | 25 | |
| 26 | - // Label |
|
| 27 | - $html .= '<h3>coordinates</h3>'; |
|
| 26 | + // Label |
|
| 27 | + $html .= '<h3>coordinates</h3>'; |
|
| 28 | 28 | |
| 29 | - // print nonce |
|
| 30 | - $html .= $this->html_nonce(); |
|
| 29 | + // print nonce |
|
| 30 | + $html .= $this->html_nonce(); |
|
| 31 | 31 | |
| 32 | - // Get coordinates |
|
| 33 | - $data = $this->data; |
|
| 34 | - // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 35 | - // want to use the current user location for the marker. |
|
| 36 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 37 | - $map_init = '[0,0]' === $coordinates |
|
| 38 | - ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 39 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 32 | + // Get coordinates |
|
| 33 | + $data = $this->data; |
|
| 34 | + // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 35 | + // want to use the current user location for the marker. |
|
| 36 | + $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 37 | + $map_init = '[0,0]' === $coordinates |
|
| 38 | + ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 39 | + : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 40 | 40 | |
| 41 | - // Print input fields |
|
| 42 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 41 | + // Print input fields |
|
| 42 | + $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 44 | 44 | |
| 45 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 45 | + $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 47 | 47 | |
| 48 | - // Show Leaflet map to pick coordinates |
|
| 49 | - $element_id = uniqid( 'wl-gep-map-' ); |
|
| 50 | - $html .= <<<EOF |
|
| 48 | + // Show Leaflet map to pick coordinates |
|
| 49 | + $element_id = uniqid( 'wl-gep-map-' ); |
|
| 50 | + $html .= <<<EOF |
|
| 51 | 51 | |
| 52 | 52 | <div id="$element_id"></div> |
| 53 | 53 | |
@@ -79,44 +79,44 @@ discard block |
||
| 79 | 79 | EOF; |
| 80 | 80 | |
| 81 | 81 | |
| 82 | - $html .= $this->html_wrapper_close(); |
|
| 82 | + $html .= $this->html_wrapper_close(); |
|
| 83 | 83 | |
| 84 | - return $html; |
|
| 85 | - } |
|
| 84 | + return $html; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function save_data( $coords ) { |
|
| 87 | + public function save_data( $coords ) { |
|
| 88 | 88 | |
| 89 | - $this->sanitize_data( $coords ); |
|
| 89 | + $this->sanitize_data( $coords ); |
|
| 90 | 90 | |
| 91 | - $entity_id = get_the_ID(); |
|
| 91 | + $entity_id = get_the_ID(); |
|
| 92 | 92 | |
| 93 | - // Take away old values |
|
| 94 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 93 | + // Take away old values |
|
| 94 | + delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | + delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 96 | 96 | |
| 97 | - $latitude = $this->data[0]; |
|
| 98 | - $longitude = $this->data[1]; |
|
| 97 | + $latitude = $this->data[0]; |
|
| 98 | + $longitude = $this->data[1]; |
|
| 99 | 99 | |
| 100 | - // insert new coordinate values |
|
| 101 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 104 | - } |
|
| 100 | + // insert new coordinate values |
|
| 101 | + if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | + add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | + add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Only accept float numbers |
|
| 110 | - */ |
|
| 111 | - public function sanitize_data_filter( $value ) { |
|
| 108 | + /** |
|
| 109 | + * Only accept float numbers |
|
| 110 | + */ |
|
| 111 | + public function sanitize_data_filter( $value ) { |
|
| 112 | 112 | |
| 113 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 114 | - // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 115 | - if ( ! is_numeric( $value ) ) { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 113 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 114 | + // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 115 | + if ( ! is_numeric( $value ) ) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return $value; |
|
| 120 | - } |
|
| 119 | + return $value; |
|
| 120 | + } |
|
| 121 | 121 | } |
| 122 | 122 | |
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
| 25 | 25 | |
| 26 | - // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 27 | - |
|
| 28 | - // transition from *published* to any other status: delete the post. |
|
| 29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | - rl_delete_post( $post ); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - // when a post is published, then all the referenced entities must be published. |
|
| 34 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 37 | - } |
|
| 38 | - } |
|
| 26 | + // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 27 | + |
|
| 28 | + // transition from *published* to any other status: delete the post. |
|
| 29 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | + rl_delete_post( $post ); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + // when a post is published, then all the referenced entities must be published. |
|
| 34 | + if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | + wl_update_post_status( $entity_id, 'publish' ); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // hook save events. |
@@ -49,49 +49,49 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | function rl_delete_post( $post ) { |
| 51 | 51 | |
| 52 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 52 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 53 | 53 | |
| 54 | - // hide all entities that are not referenced by any published post. |
|
| 55 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 54 | + // hide all entities that are not referenced by any published post. |
|
| 55 | + foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 56 | 56 | |
| 57 | - // check if there is at least one referencing post published. |
|
| 58 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 57 | + // check if there is at least one referencing post published. |
|
| 58 | + $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 59 | 59 | $post = get_post( $item ); |
| 60 | 60 | return ( $carry || ( 'publish' === $post->post_status ) ); |
| 61 | - } ); |
|
| 62 | - // set the entity to draft if no referencing posts are published. |
|
| 63 | - if ( ! $is_published ) { |
|
| 64 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // get the entity URI (valid also for posts) |
|
| 69 | - $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 70 | - |
|
| 71 | - wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 72 | - |
|
| 73 | - // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
|
| 74 | - $stmt = rl_sparql_prefixes(); |
|
| 75 | - foreach ( wl_predicates() as $predicate ) { |
|
| 76 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 77 | - "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // if the post is an entity and has exported properties, delete the related predicates. |
|
| 81 | - if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | - $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 83 | - |
|
| 84 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | - foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 86 | - // TODO: enclose in <> only if predicate starts with http(s):// |
|
| 87 | - $predicate = '<' . $params['predicate'] . '>'; |
|
| 88 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // finally execute the query. |
|
| 94 | - rl_execute_sparql_update_query( $stmt ); |
|
| 61 | + } ); |
|
| 62 | + // set the entity to draft if no referencing posts are published. |
|
| 63 | + if ( ! $is_published ) { |
|
| 64 | + wl_update_post_status( $entity_id, 'draft' ); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // get the entity URI (valid also for posts) |
|
| 69 | + $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 70 | + |
|
| 71 | + wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 72 | + |
|
| 73 | + // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
|
| 74 | + $stmt = rl_sparql_prefixes(); |
|
| 75 | + foreach ( wl_predicates() as $predicate ) { |
|
| 76 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 77 | + "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // if the post is an entity and has exported properties, delete the related predicates. |
|
| 81 | + if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | + $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 83 | + |
|
| 84 | + if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | + foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 86 | + // TODO: enclose in <> only if predicate starts with http(s):// |
|
| 87 | + $predicate = '<' . $params['predicate'] . '>'; |
|
| 88 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // finally execute the query. |
|
| 94 | + rl_execute_sparql_update_query( $stmt ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,34 +102,34 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function wl_update_post_status( $post_id, $status ) { |
| 104 | 104 | |
| 105 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 105 | + wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 106 | 106 | |
| 107 | - global $wpdb; |
|
| 107 | + global $wpdb; |
|
| 108 | 108 | |
| 109 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 109 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - if ( $status === $post->post_status ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 113 | + if ( $status === $post->post_status ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 117 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 118 | 118 | |
| 119 | - clean_post_cache( $post->ID ); |
|
| 119 | + clean_post_cache( $post->ID ); |
|
| 120 | 120 | |
| 121 | - $old_status = $post->post_status; |
|
| 122 | - $post->post_status = $status; |
|
| 121 | + $old_status = $post->post_status; |
|
| 122 | + $post->post_status = $status; |
|
| 123 | 123 | |
| 124 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 124 | + wp_transition_post_status( $status, $old_status, $post ); |
|
| 125 | 125 | |
| 126 | - /** This action is documented in wp-includes/post.php */ |
|
| 127 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 128 | - /** This action is documented in wp-includes/post.php */ |
|
| 129 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 130 | - /** This action is documented in wp-includes/post.php */ |
|
| 131 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 132 | - /** This action is documented in wp-includes/post.php */ |
|
| 133 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 126 | + /** This action is documented in wp-includes/post.php */ |
|
| 127 | + do_action( 'edit_post', $post->ID, $post ); |
|
| 128 | + /** This action is documented in wp-includes/post.php */ |
|
| 129 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 130 | + /** This action is documented in wp-includes/post.php */ |
|
| 131 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 132 | + /** This action is documented in wp-includes/post.php */ |
|
| 133 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 134 | 134 | } |
| 135 | 135 | |
@@ -21,25 +21,25 @@ discard block |
||
| 21 | 21 | * @param string $old_status The old post status |
| 22 | 22 | * @param array $post An array with the post data |
| 23 | 23 | */ |
| 24 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 24 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 25 | 25 | |
| 26 | 26 | // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
| 27 | 27 | |
| 28 | 28 | // transition from *published* to any other status: delete the post. |
| 29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | - rl_delete_post( $post ); |
|
| 29 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 30 | + rl_delete_post($post); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // when a post is published, then all the referenced entities must be published. |
| 34 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 34 | + if ('publish' !== $old_status && 'publish' === $new_status) { |
|
| 35 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 36 | + wl_update_post_status($entity_id, 'publish'); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // hook save events. |
| 42 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 42 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -47,51 +47,51 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param array|int $post An array of post data |
| 49 | 49 | */ |
| 50 | -function rl_delete_post( $post ) { |
|
| 50 | +function rl_delete_post($post) { |
|
| 51 | 51 | |
| 52 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 52 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 53 | 53 | |
| 54 | 54 | // hide all entities that are not referenced by any published post. |
| 55 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 55 | + foreach (wl_core_get_related_entity_ids($post_id) as $entity_id) { |
|
| 56 | 56 | |
| 57 | 57 | // check if there is at least one referencing post published. |
| 58 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 59 | - $post = get_post( $item ); |
|
| 60 | - return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 58 | + $is_published = array_reduce(wl_core_get_related_post_ids($entity_id), function($carry, $item) { |
|
| 59 | + $post = get_post($item); |
|
| 60 | + return ($carry || ('publish' === $post->post_status)); |
|
| 61 | 61 | } ); |
| 62 | 62 | // set the entity to draft if no referencing posts are published. |
| 63 | - if ( ! $is_published ) { |
|
| 64 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 63 | + if ( ! $is_published) { |
|
| 64 | + wl_update_post_status($entity_id, 'draft'); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // get the entity URI (valid also for posts) |
| 69 | - $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 69 | + $uri_esc = wl_sparql_escape_uri(wl_get_entity_uri($post_id)); |
|
| 70 | 70 | |
| 71 | - wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 71 | + wl_write_log("rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]"); |
|
| 72 | 72 | |
| 73 | 73 | // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
| 74 | 74 | $stmt = rl_sparql_prefixes(); |
| 75 | - foreach ( wl_predicates() as $predicate ) { |
|
| 76 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 75 | + foreach (wl_predicates() as $predicate) { |
|
| 76 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n". |
|
| 77 | 77 | "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // if the post is an entity and has exported properties, delete the related predicates. |
| 81 | - if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | - $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 81 | + if (Wordlift_Entity_Service::TYPE_NAME === $post->post_type) { |
|
| 82 | + $type = wl_entity_type_taxonomy_get_type($post->ID); |
|
| 83 | 83 | |
| 84 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | - foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 84 | + if (isset($type['custom_fields'])) { |
|
| 85 | + foreach ($type['custom_fields'] as $field => $params) { |
|
| 86 | 86 | // TODO: enclose in <> only if predicate starts with http(s):// |
| 87 | - $predicate = '<' . $params['predicate'] . '>'; |
|
| 87 | + $predicate = '<'.$params['predicate'].'>'; |
|
| 88 | 88 | $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // finally execute the query. |
| 94 | - rl_execute_sparql_update_query( $stmt ); |
|
| 94 | + rl_execute_sparql_update_query($stmt); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -100,36 +100,36 @@ discard block |
||
| 100 | 100 | * @param int $post_id The post ID |
| 101 | 101 | * @param string $status The new status |
| 102 | 102 | */ |
| 103 | -function wl_update_post_status( $post_id, $status ) { |
|
| 103 | +function wl_update_post_status($post_id, $status) { |
|
| 104 | 104 | |
| 105 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 105 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 106 | 106 | |
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 109 | + if ( ! $post = get_post($post_id)) { |
|
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( $status === $post->post_status ) { |
|
| 113 | + if ($status === $post->post_status) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 117 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 118 | 118 | |
| 119 | - clean_post_cache( $post->ID ); |
|
| 119 | + clean_post_cache($post->ID); |
|
| 120 | 120 | |
| 121 | 121 | $old_status = $post->post_status; |
| 122 | 122 | $post->post_status = $status; |
| 123 | 123 | |
| 124 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 124 | + wp_transition_post_status($status, $old_status, $post); |
|
| 125 | 125 | |
| 126 | 126 | /** This action is documented in wp-includes/post.php */ |
| 127 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 127 | + do_action('edit_post', $post->ID, $post); |
|
| 128 | 128 | /** This action is documented in wp-includes/post.php */ |
| 129 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 129 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 130 | 130 | /** This action is documented in wp-includes/post.php */ |
| 131 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 131 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 132 | 132 | /** This action is documented in wp-includes/post.php */ |
| 133 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 133 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 134 | 134 | } |
| 135 | 135 | |
@@ -22,15 +22,15 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Deactivator { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Short Description. (use period) |
|
| 27 | - * |
|
| 28 | - * Long Description. |
|
| 29 | - * |
|
| 30 | - * @since 1.0.0 |
|
| 31 | - */ |
|
| 32 | - public static function deactivate() { |
|
| 25 | + /** |
|
| 26 | + * Short Description. (use period) |
|
| 27 | + * |
|
| 28 | + * Long Description. |
|
| 29 | + * |
|
| 30 | + * @since 1.0.0 |
|
| 31 | + */ |
|
| 32 | + public static function deactivate() { |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -7,6 +7,6 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Entity_Types_Taxonomy_Service { |
| 9 | 9 | |
| 10 | - const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 10 | + const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 11 | 11 | |
| 12 | 12 | } |
@@ -26,38 +26,38 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Wordlift_i18n { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The domain specified for this plugin. |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * @access private |
|
| 34 | - * @var string $domain The domain identifier for this plugin. |
|
| 35 | - */ |
|
| 36 | - private $domain; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Load the plugin text domain for translation. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - */ |
|
| 43 | - public function load_plugin_textdomain() { |
|
| 44 | - |
|
| 45 | - load_plugin_textdomain( |
|
| 46 | - $this->domain, |
|
| 47 | - false, |
|
| 48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set the domain equal to that of the specified domain. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.0 |
|
| 57 | - * @param string $domain The domain that represents the locale of this plugin. |
|
| 58 | - */ |
|
| 59 | - public function set_domain( $domain ) { |
|
| 60 | - $this->domain = $domain; |
|
| 61 | - } |
|
| 29 | + /** |
|
| 30 | + * The domain specified for this plugin. |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * @access private |
|
| 34 | + * @var string $domain The domain identifier for this plugin. |
|
| 35 | + */ |
|
| 36 | + private $domain; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Load the plugin text domain for translation. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + */ |
|
| 43 | + public function load_plugin_textdomain() { |
|
| 44 | + |
|
| 45 | + load_plugin_textdomain( |
|
| 46 | + $this->domain, |
|
| 47 | + false, |
|
| 48 | + dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set the domain equal to that of the specified domain. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.0 |
|
| 57 | + * @param string $domain The domain that represents the locale of this plugin. |
|
| 58 | + */ |
|
| 59 | + public function set_domain( $domain ) { |
|
| 60 | + $this->domain = $domain; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | load_plugin_textdomain( |
| 46 | 46 | $this->domain, |
| 47 | 47 | false, |
| 48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 48 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @since 1.0.0 |
| 57 | 57 | * @param string $domain The domain that represents the locale of this plugin. |
| 58 | 58 | */ |
| 59 | - public function set_domain( $domain ) { |
|
| 59 | + public function set_domain($domain) { |
|
| 60 | 60 | $this->domain = $domain; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -23,107 +23,107 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Wordlift_Loader { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The array of actions registered with WordPress. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - * @access protected |
|
| 31 | - * @var array $actions The actions registered with WordPress to fire when the plugin loads. |
|
| 32 | - */ |
|
| 33 | - protected $actions; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The array of filters registered with WordPress. |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @access protected |
|
| 40 | - * @var array $filters The filters registered with WordPress to fire when the plugin loads. |
|
| 41 | - */ |
|
| 42 | - protected $filters; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Initialize the collections used to maintain the actions and filters. |
|
| 46 | - * |
|
| 47 | - * @since 1.0.0 |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - |
|
| 51 | - $this->actions = array(); |
|
| 52 | - $this->filters = array(); |
|
| 53 | - |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Add a new action to the collection to be registered with WordPress. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - * @param string $hook The name of the WordPress action that is being registered. |
|
| 61 | - * @param object $component A reference to the instance of the object on which the action is defined. |
|
| 62 | - * @param string $callback The name of the function definition on the $component. |
|
| 63 | - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 64 | - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
|
| 65 | - */ |
|
| 66 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Add a new filter to the collection to be registered with WordPress. |
|
| 72 | - * |
|
| 73 | - * @since 1.0.0 |
|
| 74 | - * @param string $hook The name of the WordPress filter that is being registered. |
|
| 75 | - * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 76 | - * @param string $callback The name of the function definition on the $component. |
|
| 77 | - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 78 | - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
|
| 79 | - */ |
|
| 80 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A utility function that is used to register the actions and hooks into a single |
|
| 86 | - * collection. |
|
| 87 | - * |
|
| 88 | - * @since 1.0.0 |
|
| 89 | - * @access private |
|
| 90 | - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
|
| 91 | - * @param string $hook The name of the WordPress filter that is being registered. |
|
| 92 | - * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 93 | - * @param string $callback The name of the function definition on the $component. |
|
| 94 | - * @param int $priority The priority at which the function should be fired. |
|
| 95 | - * @param int $accepted_args The number of arguments that should be passed to the $callback. |
|
| 96 | - * @return array The collection of actions and filters registered with WordPress. |
|
| 97 | - */ |
|
| 98 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 99 | - |
|
| 100 | - $hooks[] = array( |
|
| 101 | - 'hook' => $hook, |
|
| 102 | - 'component' => $component, |
|
| 103 | - 'callback' => $callback, |
|
| 104 | - 'priority' => $priority, |
|
| 105 | - 'accepted_args' => $accepted_args |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - return $hooks; |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Register the filters and actions with WordPress. |
|
| 114 | - * |
|
| 115 | - * @since 1.0.0 |
|
| 116 | - */ |
|
| 117 | - public function run() { |
|
| 118 | - |
|
| 119 | - foreach ( $this->filters as $hook ) { |
|
| 120 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - foreach ( $this->actions as $hook ) { |
|
| 124 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - } |
|
| 26 | + /** |
|
| 27 | + * The array of actions registered with WordPress. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + * @access protected |
|
| 31 | + * @var array $actions The actions registered with WordPress to fire when the plugin loads. |
|
| 32 | + */ |
|
| 33 | + protected $actions; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The array of filters registered with WordPress. |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @access protected |
|
| 40 | + * @var array $filters The filters registered with WordPress to fire when the plugin loads. |
|
| 41 | + */ |
|
| 42 | + protected $filters; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Initialize the collections used to maintain the actions and filters. |
|
| 46 | + * |
|
| 47 | + * @since 1.0.0 |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + |
|
| 51 | + $this->actions = array(); |
|
| 52 | + $this->filters = array(); |
|
| 53 | + |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Add a new action to the collection to be registered with WordPress. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + * @param string $hook The name of the WordPress action that is being registered. |
|
| 61 | + * @param object $component A reference to the instance of the object on which the action is defined. |
|
| 62 | + * @param string $callback The name of the function definition on the $component. |
|
| 63 | + * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 64 | + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
|
| 65 | + */ |
|
| 66 | + public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | + $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Add a new filter to the collection to be registered with WordPress. |
|
| 72 | + * |
|
| 73 | + * @since 1.0.0 |
|
| 74 | + * @param string $hook The name of the WordPress filter that is being registered. |
|
| 75 | + * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 76 | + * @param string $callback The name of the function definition on the $component. |
|
| 77 | + * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 78 | + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
|
| 79 | + */ |
|
| 80 | + public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | + $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A utility function that is used to register the actions and hooks into a single |
|
| 86 | + * collection. |
|
| 87 | + * |
|
| 88 | + * @since 1.0.0 |
|
| 89 | + * @access private |
|
| 90 | + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
|
| 91 | + * @param string $hook The name of the WordPress filter that is being registered. |
|
| 92 | + * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 93 | + * @param string $callback The name of the function definition on the $component. |
|
| 94 | + * @param int $priority The priority at which the function should be fired. |
|
| 95 | + * @param int $accepted_args The number of arguments that should be passed to the $callback. |
|
| 96 | + * @return array The collection of actions and filters registered with WordPress. |
|
| 97 | + */ |
|
| 98 | + private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 99 | + |
|
| 100 | + $hooks[] = array( |
|
| 101 | + 'hook' => $hook, |
|
| 102 | + 'component' => $component, |
|
| 103 | + 'callback' => $callback, |
|
| 104 | + 'priority' => $priority, |
|
| 105 | + 'accepted_args' => $accepted_args |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + return $hooks; |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Register the filters and actions with WordPress. |
|
| 114 | + * |
|
| 115 | + * @since 1.0.0 |
|
| 116 | + */ |
|
| 117 | + public function run() { |
|
| 118 | + |
|
| 119 | + foreach ( $this->filters as $hook ) { |
|
| 120 | + add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + foreach ( $this->actions as $hook ) { |
|
| 124 | + add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 64 | 64 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 65 | 65 | */ |
| 66 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 66 | + public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 67 | + $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 78 | 78 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
| 79 | 79 | */ |
| 80 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 80 | + public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 81 | + $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param int $accepted_args The number of arguments that should be passed to the $callback. |
| 96 | 96 | * @return array The collection of actions and filters registered with WordPress. |
| 97 | 97 | */ |
| 98 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 98 | + private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) { |
|
| 99 | 99 | |
| 100 | 100 | $hooks[] = array( |
| 101 | 101 | 'hook' => $hook, |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function run() { |
| 118 | 118 | |
| 119 | - foreach ( $this->filters as $hook ) { |
|
| 120 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 119 | + foreach ($this->filters as $hook) { |
|
| 120 | + add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( $this->actions as $hook ) { |
|
| 124 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 123 | + foreach ($this->actions as $hook) { |
|
| 124 | + add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | } |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Include constants |
| 4 | -require_once( 'wordlift_core_constants.php' ); |
|
| 4 | +require_once('wordlift_core_constants.php'); |
|
| 5 | 5 | |
| 6 | 6 | // Include methods that deal with post/entity relations |
| 7 | -require_once( 'wordlift_core_post_entity_relations.php' ); |
|
| 7 | +require_once('wordlift_core_post_entity_relations.php'); |
|
| 8 | 8 | |
| 9 | 9 | // Include wl_schema api |
| 10 | -require_once( 'wordlift_core_schema_api.php' ); |
|
| 10 | +require_once('wordlift_core_schema_api.php'); |
|
| 11 | 11 | |
| 12 | 12 | // Include the Entity API which allow to query for entity posts. |
| 13 | -require_once( 'wordlift_core_entity_api.php' ); |
|
| 13 | +require_once('wordlift_core_entity_api.php'); |
|
| 14 | 14 | |
| 15 | 15 | // Include methods for Wordlift plugin install |
| 16 | -require_once( 'wordlift_core_install.php' ); |
|
| 16 | +require_once('wordlift_core_install.php'); |
|
| 17 | 17 | |
| 18 | 18 | // Include utility global functions |
| 19 | -require_once( 'wordlift_core_functions.php' ); |
|
| 20 | 19 | \ No newline at end of file |
| 20 | +require_once('wordlift_core_functions.php'); |
|
| 21 | 21 | \ No newline at end of file |