Completed
Push — develop ( 01a244...59c56b )
by Naveen
01:05
created
src/wordlift/vocabulary/jsonld/class-term-jsonld.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 class Term_Jsonld {
10 10
 
11 11
 	public function init() {
12
-		add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
12
+		add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2);
13 13
 	}
14 14
 
15
-	public function wl_term_jsonld_array( $jsonld_array, $term_id ) {
15
+	public function wl_term_jsonld_array($jsonld_array, $term_id) {
16 16
 
17
-		$entities = Jsonld_Utils::get_matched_entities_for_term( $term_id );
17
+		$entities = Jsonld_Utils::get_matched_entities_for_term($term_id);
18 18
 
19
-		if ( count( $entities ) > 0 ) {
20
-			$entity                     = array_shift( $entities );
19
+		if (count($entities) > 0) {
20
+			$entity                     = array_shift($entities);
21 21
 			$entity['@context']         = 'http://schema.org';
22
-			$entity['@id']              = get_term_link( $term_id ) . "/#id";
23
-			$entity['url']              = get_term_link( $term_id );
24
-			$entity['mainEntityOfPage'] = get_term_link( $term_id );
22
+			$entity['@id']              = get_term_link($term_id)."/#id";
23
+			$entity['url']              = get_term_link($term_id);
24
+			$entity['mainEntityOfPage'] = get_term_link($term_id);
25 25
 			$jsonld_array['jsonld'][]   = $entity;
26 26
 		}
27 27
 
Please login to merge, or discard this patch.
src/wordlift/vocabulary-terms/jsonld/class-jsonld-generator.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	private $entity_service;
31 31
 
32
-	public function __construct( $entity_type_service, $property_getter ) {
32
+	public function __construct($entity_type_service, $property_getter) {
33 33
 		$this->entity_type_service      = $entity_type_service;
34 34
 		$this->property_getter          = $property_getter;
35 35
 		$this->term_entity_type_service = Type_Service::get_instance();
@@ -37,27 +37,27 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 
39 39
 	public function init() {
40
-		add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
40
+		add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2);
41 41
 	}
42 42
 
43
-	public function wl_term_jsonld_array( $data, $term_id ) {
43
+	public function wl_term_jsonld_array($data, $term_id) {
44 44
 		$jsonld     = $data['jsonld'];
45 45
 		$references = $data['references'];
46 46
 
47
-		$term_jsonld_data = $this->get_jsonld_data_for_term( $term_id );
47
+		$term_jsonld_data = $this->get_jsonld_data_for_term($term_id);
48 48
 
49 49
 		// Return early if we dont have the entity data
50 50
 		// for the term.
51
-		if ( ! $term_jsonld_data ) {
51
+		if ( ! $term_jsonld_data) {
52 52
 			return $data;
53 53
 		}
54 54
 
55 55
 		$term_jsonld = $term_jsonld_data['jsonld'];
56 56
 
57
-		$references = array_merge( $references, $term_jsonld_data['references'] );
57
+		$references = array_merge($references, $term_jsonld_data['references']);
58 58
 
59 59
 
60
-		array_unshift( $jsonld, $term_jsonld );
60
+		array_unshift($jsonld, $term_jsonld);
61 61
 
62 62
 		return array(
63 63
 			'jsonld'     => $jsonld,
@@ -65,85 +65,85 @@  discard block
 block discarded – undo
65 65
 		);
66 66
 	}
67 67
 
68
-	private function get_jsonld_data_for_term( $term_id ) {
68
+	private function get_jsonld_data_for_term($term_id) {
69 69
 
70
-		$id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM );
70
+		$id = $this->entity_service->get_uri($term_id, Object_Type_Enum::TERM);
71 71
 
72 72
 		// If we don't have a dataset  URI, then don't publish the term data
73 73
 		// on this page.
74
-		if ( ! $id ) {
74
+		if ( ! $id) {
75 75
 			return false;
76 76
 		}
77 77
 
78 78
 		$references = array();
79
-		$term       = get_term( $term_id );
80
-		$permalink  = get_term_link( $term );
79
+		$term       = get_term($term_id);
80
+		$permalink  = get_term_link($term);
81 81
 
82
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id );
83
-		$term          = get_term( $term_id );
82
+		$custom_fields = $this->entity_type_service->get_custom_fields_for_term($term_id);
83
+		$term          = get_term($term_id);
84 84
 		$jsonld        = array(
85 85
 			'@context'    => 'http://schema.org',
86 86
 			'name'        => $term->name,
87
-			'@type'       => $this->term_entity_type_service->get_entity_types_labels( $term_id ),
87
+			'@type'       => $this->term_entity_type_service->get_entity_types_labels($term_id),
88 88
 			'@id'         => $id,
89 89
 			'description' => $term->description,
90 90
 		);
91 91
 
92
-		if ( ! $custom_fields || ! is_array( $custom_fields ) ) {
92
+		if ( ! $custom_fields || ! is_array($custom_fields)) {
93 93
 			return $jsonld;
94 94
 		}
95 95
 
96
-		foreach ( $custom_fields as $key => $value ) {
97
-			$name  = $this->relative_to_schema_context( $value['predicate'] );
98
-			$value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM );
99
-			$value = $this->process_value( $value, $references );
100
-			if ( ! isset( $value ) ||
101
-			     is_array( $value ) && empty( $value ) ||
102
-			     is_string( $value ) && empty( $value ) ) {
96
+		foreach ($custom_fields as $key => $value) {
97
+			$name  = $this->relative_to_schema_context($value['predicate']);
98
+			$value = $this->property_getter->get($term_id, $key, Object_Type_Enum::TERM);
99
+			$value = $this->process_value($value, $references);
100
+			if ( ! isset($value) ||
101
+			     is_array($value) && empty($value) ||
102
+			     is_string($value) && empty($value)) {
103 103
 				continue;
104 104
 			}
105
-			$jsonld[ $name ] = $value;
105
+			$jsonld[$name] = $value;
106 106
 
107 107
 		}
108 108
 
109
-		if ( $permalink ) {
109
+		if ($permalink) {
110 110
 			$jsonld['mainEntityOfPage'] = $permalink;
111 111
 		}
112 112
 
113
-		return apply_filters( 'wl_no_vocabulary_term_jsonld_array', array(
113
+		return apply_filters('wl_no_vocabulary_term_jsonld_array', array(
114 114
 			'jsonld'     => $jsonld,
115 115
 			'references' => $references
116
-		), $term_id );
116
+		), $term_id);
117 117
 
118 118
 	}
119 119
 
120
-	private function relative_to_schema_context( $predicate ) {
121
-		return str_replace( 'http://schema.org/', '', $predicate );
120
+	private function relative_to_schema_context($predicate) {
121
+		return str_replace('http://schema.org/', '', $predicate);
122 122
 	}
123 123
 
124
-	private function process_value( $value, &$references ) {
124
+	private function process_value($value, &$references) {
125 125
 
126
-		if ( is_array( $value )
127
-		     && count( $value ) > 0
128
-		     && $value[0] instanceof \Wordlift_Property_Entity_Reference ) {
126
+		if (is_array($value)
127
+		     && count($value) > 0
128
+		     && $value[0] instanceof \Wordlift_Property_Entity_Reference) {
129 129
 
130 130
 			// All of the references from the custom fields are post references.
131
-			$references = array_merge( $references, array_map( function ( $property_entity_reference ) {
131
+			$references = array_merge($references, array_map(function($property_entity_reference) {
132 132
 				/**
133 133
 				 * @var $property_entity_reference \Wordlift_Property_Entity_Reference
134 134
 				 */
135
-				return new Post_Reference( $property_entity_reference->get_id() );
136
-			}, $value ) );
135
+				return new Post_Reference($property_entity_reference->get_id());
136
+			}, $value));
137 137
 
138 138
 
139 139
 			$that = $this;
140 140
 
141
-			return array_map( function ( $reference ) use ( $that ) {
141
+			return array_map(function($reference) use ($that) {
142 142
 				/**
143 143
 				 * @var $reference \Wordlift_Property_Entity_Reference
144 144
 				 */
145
-				return array( '@id' => $that->entity_service->get_uri( $reference->get_id() ) );
146
-			}, $value );
145
+				return array('@id' => $that->entity_service->get_uri($reference->get_id()));
146
+			}, $value);
147 147
 
148 148
 		}
149 149
 
Please login to merge, or discard this patch.
src/wordlift/metabox/field/class-wl-metabox-field-sameas.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -25,46 +25,46 @@  discard block
 block discarded – undo
25 25
 	/**
26 26
 	 * @inheritdoc
27 27
 	 */
28
-	public function __construct( $args, $id, $type ) {
29
-		parent::__construct( $args['sameas'], $id, $type );
28
+	public function __construct($args, $id, $type) {
29
+		parent::__construct($args['sameas'], $id, $type);
30 30
 	}
31 31
 
32 32
 	/**
33 33
 	 * @inheritdoc
34 34
 	 */
35
-	public function save_data( $values ) {
35
+	public function save_data($values) {
36 36
 		// The autocomplete select may send JSON arrays in input values.
37 37
 
38 38
 		// Only use mb_* functions when mbstring is available.
39 39
 		//
40 40
 		// See https://github.com/insideout10/wordlift-plugin/issues/693.
41
-		if ( extension_loaded( 'mbstring' ) ) {
42
-			mb_regex_encoding( 'UTF-8' );
41
+		if (extension_loaded('mbstring')) {
42
+			mb_regex_encoding('UTF-8');
43 43
 
44
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
45
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
46
-			}, array() );
44
+			$merged = array_reduce((array) $values, function($carry, $item) {
45
+				return array_merge($carry, mb_split("\x{2063}", wp_unslash($item)));
46
+			}, array());
47 47
 		} else {
48
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
49
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
50
-			}, array() );
48
+			$merged = array_reduce((array) $values, function($carry, $item) {
49
+				return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item)));
50
+			}, array());
51 51
 		}
52 52
 
53 53
 		// Convert all escaped special characters to their original.
54
-		$merged = array_map( 'urldecode', $merged );
54
+		$merged = array_map('urldecode', $merged);
55 55
 
56
-		$merged = $this->filter_urls( $merged );
56
+		$merged = $this->filter_urls($merged);
57 57
 
58
-		parent::save_data( $merged );
58
+		parent::save_data($merged);
59 59
 	}
60 60
 
61 61
 	/**
62 62
 	 * @inheritdoc
63 63
 	 */
64
-	public function sanitize_data_filter( $value ) {
64
+	public function sanitize_data_filter($value) {
65 65
 
66 66
 		// Call our sanitizer helper.
67
-		return Wordlift_Sanitizer::sanitize_url( $value );
67
+		return Wordlift_Sanitizer::sanitize_url($value);
68 68
 	}
69 69
 
70 70
 	/**
@@ -86,33 +86,33 @@  discard block
 block discarded – undo
86 86
 	private function get_select_html() {
87 87
 		// Return an element where the new Autocomplete Select will attach to.
88 88
 		return '<p>'
89
-		       . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
89
+		       . esc_html__('Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift')
90 90
 		       . '<div id="wl-metabox-field-sameas"></div></p>';
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @inheritdoc
95 95
 	 */
96
-	protected function get_add_button_html( $count ) {
96
+	protected function get_add_button_html($count) {
97 97
 
98
-		$placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
98
+		$placeholder = esc_attr_x('Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift');
99 99
 
100 100
 		return
101
-			'<button type="button" class="wl-add-input wl-add-input--link">' . esc_html__( 'Click here to manually add URLs', 'wordlift' ) . '</button>'
101
+			'<button type="button" class="wl-add-input wl-add-input--link">'.esc_html__('Click here to manually add URLs', 'wordlift').'</button>'
102 102
 			. '<div style="display: none;"><div class="wl-input-wrapper">'
103 103
 			. "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' />"
104 104
 			. '<button type="button" class="wl-remove-input wl-remove-input--sameas"></button>'
105 105
 			. '</div></div>'
106
-			. '<fieldset id="wl-input-container">' . $this->get_stored_values_html( $count ) . '</fieldset>'
107
-			. parent::get_add_custom_button_html( $count, 'Add Another URL', 'hide' );
106
+			. '<fieldset id="wl-input-container">'.$this->get_stored_values_html($count).'</fieldset>'
107
+			. parent::get_add_custom_button_html($count, 'Add Another URL', 'hide');
108 108
 	}
109 109
 
110 110
 	/**
111 111
 	 * @inheritdoc
112 112
 	 */
113
-	protected function get_stored_values_html( &$count ) {
113
+	protected function get_stored_values_html(&$count) {
114 114
 
115
-		return parent::get_stored_values_html( $count );
115
+		return parent::get_stored_values_html($count);
116 116
 	}
117 117
 
118 118
 	/**
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * @return bool
129 129
 		 * @since 3.29.1
130 130
 		 */
131
-		if ( apply_filters( 'wl_feature__enable__metabox-sameas', true ) ) {
131
+		if (apply_filters('wl_feature__enable__metabox-sameas', true)) {
132 132
 
133 133
 			// Open main <div> for the Field.
134 134
 			$html = $this->html_wrapper_open();
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			$count = 0;
144 144
 
145 145
 			// If cardinality allows it, print button to add new values.
146
-			$html .= $this->get_add_button_html( $count );
146
+			$html .= $this->get_add_button_html($count);
147 147
 
148 148
 			// Close the HTML wrapper.
149 149
 			$html .= $this->html_wrapper_close();
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	/**
156 156
 	 * @inheritdoc
157 157
 	 */
158
-	public function html_input( $value ) {
158
+	public function html_input($value) {
159 159
 		@ob_start();
160 160
 		?>
161 161
         <div class="wl-input-wrapper wl-input-wrapper-readonly">
162 162
             <input
163 163
                     type="text"
164 164
                     readonly="readonly"
165
-                    id="<?php echo esc_attr( $this->meta_name ); ?>"
166
-                    name="wl_metaboxes[<?php echo esc_attr( $this->meta_name ); ?>][]"
167
-                    value="<?php echo esc_attr( $value ); ?>"
165
+                    id="<?php echo esc_attr($this->meta_name); ?>"
166
+                    name="wl_metaboxes[<?php echo esc_attr($this->meta_name); ?>][]"
167
+                    value="<?php echo esc_attr($value); ?>"
168 168
             />
169 169
 
170 170
             <button class="wl-remove-input wl-remove-input--sameas"></button>
@@ -181,18 +181,18 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return array
183 183
 	 */
184
-	private function filter_urls( $urls ) {
184
+	private function filter_urls($urls) {
185 185
 		$configuration_service = Wordlift_Configuration_Service::get_instance();
186 186
 		$dataset_uri           = $configuration_service->get_dataset_uri();
187 187
 
188
-		return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
189
-			$url_validation = filter_var( $url, FILTER_VALIDATE_URL );
190
-			if ( null === $dataset_uri ) {
188
+		return array_filter($urls, function($url) use ($dataset_uri) {
189
+			$url_validation = filter_var($url, FILTER_VALIDATE_URL);
190
+			if (null === $dataset_uri) {
191 191
 				return $url_validation;
192 192
 			}
193 193
 
194 194
 			// URLs should not start with local dataset uri.
195
-			return $url_validation && ( empty( $dataset_uri ) || 0 !== strpos( $url, $dataset_uri ) );
195
+			return $url_validation && (empty($dataset_uri) || 0 !== strpos($url, $dataset_uri));
196 196
 		} );
197 197
 	}
198 198
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-service.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @since 3.2.0
82 82
 	 */
83 83
 	protected function __construct() {
84
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
84
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service');
85 85
 
86 86
 		$this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87 87
 		$this->relation_service   = Wordlift_Relation_Service::get_instance();
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public static function get_instance() {
107 107
 
108
-		if ( ! isset( self::$instance ) ) {
108
+		if ( ! isset(self::$instance)) {
109 109
 			self::$instance = new self();
110 110
 		}
111 111
 
@@ -122,22 +122,22 @@  discard block
 block discarded – undo
122 122
 	 * @since 3.1.0
123 123
 	 *
124 124
 	 */
125
-	public function is_entity( $post_id ) {
125
+	public function is_entity($post_id) {
126 126
 
127 127
 		// Improve performance by giving for granted that a product is an entity.
128
-		if ( 'product' === get_post_type( $post_id ) ) {
128
+		if ('product' === get_post_type($post_id)) {
129 129
 			return true;
130 130
 		}
131 131
 
132
-		$terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
+		$terms = wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
133 133
 
134
-		if ( is_wp_error( $terms ) ) {
135
-			$this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
134
+		if (is_wp_error($terms)) {
135
+			$this->log->error("Cannot get the terms for post $post_id: ".$terms->get_error_message());
136 136
 
137 137
 			return false;
138 138
 		}
139 139
 
140
-		if ( empty( $terms ) ) {
140
+		if (empty($terms)) {
141 141
 			return false;
142 142
 		}
143 143
 
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 		 *
149 149
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
150 150
 		 */
151
-		foreach ( $terms as $term ) {
152
-			if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
151
+		foreach ($terms as $term) {
152
+			if (1 !== preg_match('~(^|-)article$~', $term->slug)) {
153 153
 				return true;
154 154
 			}
155 155
 		}
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
 	 * @since 3.5.0
170 170
 	 *
171 171
 	 */
172
-	public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
172
+	public function get_classification_scope_for($post_id, $default = WL_WHAT_RELATION) {
173 173
 
174
-		if ( false === $this->is_entity( $post_id ) ) {
174
+		if (false === $this->is_entity($post_id)) {
175 175
 			return $default;
176 176
 		}
177 177
 
178 178
 		// Retrieve the entity type
179
-		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
180
-		$entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
179
+		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get($post_id);
180
+		$entity_type     = str_replace('wl-', '', $entity_type_arr['css_class']);
181 181
 		// Retrieve classification boxes configuration
182
-		$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
183
-		foreach ( $classification_boxes as $cb ) {
184
-			if ( in_array( $entity_type, $cb['registeredTypes'] ) ) {
182
+		$classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES);
183
+		foreach ($classification_boxes as $cb) {
184
+			if (in_array($entity_type, $cb['registeredTypes'])) {
185 185
 				return $cb['id'];
186 186
 			}
187 187
 		}
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return bool|null Null if it's not an entity, otherwise true if it's used.
198 198
 	 */
199
-	public function is_used( $post_id ) {
199
+	public function is_used($post_id) {
200 200
 
201
-		if ( false === $this->is_entity( $post_id ) ) {
201
+		if (false === $this->is_entity($post_id)) {
202 202
 			return null;
203 203
 		}
204 204
 		// Retrieve the post
205
-		$entity = get_post( $post_id );
205
+		$entity = get_post($post_id);
206 206
 
207 207
 		global $wpdb;
208 208
 		// Retrieve Wordlift relation instances table name
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 		);
216 216
 
217 217
 		// Perform the query
218
-		$relation_instances = (int) $wpdb->get_var( $stmt );
218
+		$relation_instances = (int) $wpdb->get_var($stmt);
219 219
 		// If there is at least one relation instance for the current entity, then it's used
220
-		if ( 0 < $relation_instances ) {
220
+		if (0 < $relation_instances) {
221 221
 			return true;
222 222
 		}
223 223
 
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
 		$stmt = $wpdb->prepare(
226 226
 			"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
227 227
 			$entity->ID,
228
-			wl_get_entity_uri( $entity->ID )
228
+			wl_get_entity_uri($entity->ID)
229 229
 		);
230 230
 		// Perform the query
231
-		$meta_instances = (int) $wpdb->get_var( $stmt );
231
+		$meta_instances = (int) $wpdb->get_var($stmt);
232 232
 
233 233
 		// If there is at least one meta that refers the current entity uri, then current entity is used
234
-		if ( 0 < $meta_instances ) {
234
+		if (0 < $meta_instances) {
235 235
 			return true;
236 236
 		}
237 237
 
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 	 * @since      3.2.0
252 252
 	 *
253 253
 	 */
254
-	public function get_entity_post_by_uri( $uri ) {
254
+	public function get_entity_post_by_uri($uri) {
255 255
 
256
-		return $this->entity_uri_service->get_entity( $uri );
256
+		return $this->entity_uri_service->get_entity($uri);
257 257
 	}
258 258
 
259 259
 	/**
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 	 * @param WP_Post $post Post object.
269 269
 	 * @param bool $update Whether this is an existing post being updated or not.
270 270
 	 */
271
-	public function save_post( $post_id, $post, $update ) {
271
+	public function save_post($post_id, $post, $update) {
272 272
 
273 273
 		// Avoid doing anything if post is autosave or a revision.
274
-		if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
274
+		if (wp_is_post_autosave($post) || wp_is_post_revision($post)) {
275 275
 			return;
276 276
 		}
277 277
 
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 		// the $post_id in the save_post call matches the post id set in the request.
282 282
 		//
283 283
 		// If this is not the current post being saved or if it's not an entity, return.
284
-		if ( ! isset( $_REQUEST['post_ID'] ) || $_REQUEST['post_ID'] != $post_id || ! $this->is_entity( $post_id ) ) {
284
+		if ( ! isset($_REQUEST['post_ID']) || $_REQUEST['post_ID'] != $post_id || ! $this->is_entity($post_id)) {
285 285
 			return;
286 286
 		}
287 287
 
288 288
 		// Get the alt labels from the request (or empty array).
289
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? (array) $_REQUEST['wl_alternative_label'] : array();
289
+		$alt_labels = isset($_REQUEST['wl_alternative_label']) ? (array) $_REQUEST['wl_alternative_label'] : array();
290 290
 
291
-		if ( ( ! empty( $_POST['content'] ) && ! empty( $_POST['post_content'] ) ) || isset( $_REQUEST['wl_alternative_label'] ) ) {
291
+		if (( ! empty($_POST['content']) && ! empty($_POST['post_content'])) || isset($_REQUEST['wl_alternative_label'])) {
292 292
 			// This is via classic editor, so set the alternative labels.
293
-			$this->set_alternative_labels( $post_id, $alt_labels );
293
+			$this->set_alternative_labels($post_id, $alt_labels);
294 294
 		}
295 295
 
296 296
 
@@ -305,48 +305,48 @@  discard block
 block discarded – undo
305 305
 	 * @since 3.2.0
306 306
 	 *
307 307
 	 */
308
-	public function set_alternative_labels( $post_id, $alt_labels ) {
308
+	public function set_alternative_labels($post_id, $alt_labels) {
309 309
 
310 310
 		// Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
311 311
 		// instead of post id.
312
-		if ( ! is_numeric( $post_id ) ) {
312
+		if ( ! is_numeric($post_id)) {
313 313
 			return;
314 314
 		}
315 315
 
316 316
 		// Force $alt_labels to be an array
317
-		if ( ! is_array( $alt_labels ) ) {
318
-			$alt_labels = array( $alt_labels );
317
+		if ( ! is_array($alt_labels)) {
318
+			$alt_labels = array($alt_labels);
319 319
 		}
320 320
 
321
-		$this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
321
+		$this->log->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels)." ]");
322 322
 
323 323
 		// Delete all the existing alternate labels.
324
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
324
+		delete_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
325 325
 
326 326
 		// Save only unique synonymns.
327
-		$alt_labels = array_unique( $alt_labels );
327
+		$alt_labels = array_unique($alt_labels);
328 328
 
329 329
 		// Set the alternative labels.
330
-		foreach ( $alt_labels as $alt_label ) {
330
+		foreach ($alt_labels as $alt_label) {
331 331
 
332 332
 			// Strip html code from synonym.
333
-			$alt_label = wp_strip_all_tags( $alt_label );
333
+			$alt_label = wp_strip_all_tags($alt_label);
334 334
 
335
-			if ( ! empty( $alt_label ) ) {
336
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
335
+			if ( ! empty($alt_label)) {
336
+				add_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label);
337 337
 			}
338 338
 		}
339 339
 
340 340
 	}
341 341
 
342
-	public function append_alternative_labels( $post_id, $labels_to_append ) {
342
+	public function append_alternative_labels($post_id, $labels_to_append) {
343 343
 
344
-		$merged_labels = $this->get_alternative_labels( $post_id );
344
+		$merged_labels = $this->get_alternative_labels($post_id);
345 345
 
346 346
 		// Append new synonyms to the end.
347
-		$merged_labels = array_merge( $merged_labels, $labels_to_append );
347
+		$merged_labels = array_merge($merged_labels, $labels_to_append);
348 348
 
349
-		$this->set_alternative_labels( $post_id, $merged_labels );
349
+		$this->set_alternative_labels($post_id, $merged_labels);
350 350
 
351 351
 	}
352 352
 
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
 	 * @since 3.2.0
360 360
 	 *
361 361
 	 */
362
-	public function get_alternative_labels( $post_id ) {
362
+	public function get_alternative_labels($post_id) {
363 363
 
364
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
364
+		return get_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
365 365
 	}
366 366
 
367 367
 	/**
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 	 * @return array An array with the entity title and labels.
374 374
 	 * @since 3.12.0
375 375
 	 */
376
-	public function get_labels( $post_id, $object_type = Object_Type_Enum::POST ) {
377
-		if ( $object_type === Object_Type_Enum::POST ) {
378
-			return array_merge( (array) get_the_title( $post_id ), $this->get_alternative_labels( $post_id ) );
376
+	public function get_labels($post_id, $object_type = Object_Type_Enum::POST) {
377
+		if ($object_type === Object_Type_Enum::POST) {
378
+			return array_merge((array) get_the_title($post_id), $this->get_alternative_labels($post_id));
379 379
 		}
380 380
 
381 381
 		// Term Reference dont have synonyms yet.
@@ -390,45 +390,45 @@  discard block
 block discarded – undo
390 390
 	 * @since 3.2.0
391 391
 	 *
392 392
 	 */
393
-	public function edit_form_before_permalink( $post ) {
393
+	public function edit_form_before_permalink($post) {
394 394
 
395 395
 		// If it's not an entity, return.
396
-		if ( ! $this->is_entity( $post->ID ) ) {
396
+		if ( ! $this->is_entity($post->ID)) {
397 397
 			return;
398 398
 		}
399 399
 
400 400
 		// If disabled by filter, return.
401
-		if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
401
+		if ( ! apply_filters('wl_feature__enable__add-synonyms', true)) {
402 402
 			return;
403 403
 		}
404 404
 
405 405
 		// Print the input template.
406
-		Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
406
+		Wordlift_UI_Service::print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input());
407 407
 
408 408
 		// Print all the currently set alternative labels.
409
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
409
+		foreach ($this->get_alternative_labels($post->ID) as $alt_label) {
410 410
 
411
-			echo $this->get_alternative_label_input( $alt_label );
411
+			echo $this->get_alternative_label_input($alt_label);
412 412
 
413 413
 		};
414 414
 
415 415
 		// Print the button.
416
-		Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
416
+		Wordlift_UI_Service::print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift'));
417 417
 
418 418
 	}
419 419
 
420
-	public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
420
+	public function get_uri($object_id, $type = Object_Type_Enum::POST) {
421 421
 		$content_service = Wordpress_Content_Service::get_instance();
422
-		$entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
422
+		$entity_id       = $content_service->get_entity_id(new Wordpress_Content_Id($object_id, $type));
423 423
 		$dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
424 424
 
425
-		if ( ! isset( $entity_id ) ||
426
-		     ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
427
-			$rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
425
+		if ( ! isset($entity_id) ||
426
+		     ( ! empty($dataset_uri) && 0 !== strpos($entity_id, $dataset_uri))) {
427
+			$rel_uri = Entity_Uri_Generator::create_uri($type, $object_id);
428 428
 			try {
429
-				$content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
430
-				$entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
431
-			} catch ( Exception $e ) {
429
+				$content_service->set_entity_id(new Wordpress_Content_Id($object_id, $type), $rel_uri);
430
+				$entity_id = $content_service->get_entity_id(new Wordpress_Content_Id($object_id, $type));
431
+			} catch (Exception $e) {
432 432
 				return null;
433 433
 			}
434 434
 		}
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
 	 * @since 3.2.0
446 446
 	 *
447 447
 	 */
448
-	private function get_alternative_label_input( $value = '' ) {
448
+	private function get_alternative_label_input($value = '') {
449 449
 
450
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
450
+		return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), __('Delete', 'wordlift'));
451 451
 	}
452 452
 
453 453
 	/**
@@ -461,13 +461,13 @@  discard block
 block discarded – undo
461 461
 		global $wpdb;
462 462
 
463 463
 		// Try to get the count from the transient.
464
-		$count = get_transient( '_wl_entity_service__count' );
465
-		if ( false !== $count ) {
464
+		$count = get_transient('_wl_entity_service__count');
465
+		if (false !== $count) {
466 466
 			return $count;
467 467
 		}
468 468
 
469 469
 		// Query the count.
470
-		$count = $wpdb->get_var( $wpdb->prepare(
470
+		$count = $wpdb->get_var($wpdb->prepare(
471 471
 			"SELECT COUNT( DISTINCT( tr.object_id ) )"
472 472
 			. " FROM {$wpdb->term_relationships} tr"
473 473
 			. " INNER JOIN {$wpdb->term_taxonomy} tt"
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 			. "  ON t.term_id = tt.term_id AND t.name != %s",
477 477
 			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
478 478
 			'article'
479
-		) );
479
+		));
480 480
 
481 481
 		// Store the count in cache.
482
-		set_transient( '_wl_entity_service__count', $count, 900 );
482
+		set_transient('_wl_entity_service__count', $count, 900);
483 483
 
484 484
 		return $count;
485 485
 	}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 	 * @since 3.15.0
495 495
 	 *
496 496
 	 */
497
-	public static function add_criterias( $args ) {
497
+	public static function add_criterias($args) {
498 498
 
499 499
 		// Build an optimal tax-query.
500 500
 		$tax_query = array(
@@ -538,28 +538,28 @@  discard block
 block discarded – undo
538 538
 	 * @since 3.9.0
539 539
 	 *
540 540
 	 */
541
-	public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
541
+	public function create($name, $type_uri, $logo = null, $status = 'publish') {
542 542
 
543 543
 		// Create an entity for the publisher.
544
-		$post_id = @wp_insert_post( array(
544
+		$post_id = @wp_insert_post(array(
545 545
 			'post_type'    => self::TYPE_NAME,
546 546
 			'post_title'   => $name,
547 547
 			'post_status'  => $status,
548 548
 			'post_content' => '',
549
-		) );
549
+		));
550 550
 
551 551
 		// Return the error if any.
552
-		if ( is_wp_error( $post_id ) ) {
552
+		if (is_wp_error($post_id)) {
553 553
 			return $post_id;
554 554
 		}
555 555
 
556 556
 		// Set the entity logo.
557
-		if ( $logo && is_numeric( $logo ) ) {
558
-			set_post_thumbnail( $post_id, $logo );
557
+		if ($logo && is_numeric($logo)) {
558
+			set_post_thumbnail($post_id, $logo);
559 559
 		}
560 560
 
561 561
 		// Set the entity type.
562
-		Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
562
+		Wordlift_Entity_Type_Service::get_instance()->set($post_id, $type_uri);
563 563
 
564 564
 		return $post_id;
565 565
 	}
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 	 * @since 3.10.0
576 576
 	 *
577 577
 	 */
578
-	public function get_related_entities( $id, $post_status = 'publish' ) {
578
+	public function get_related_entities($id, $post_status = 'publish') {
579 579
 
580
-		return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
580
+		return $this->relation_service->get_objects($id, 'ids', null, $post_status);
581 581
 	}
582 582
 
583 583
 	/**
@@ -589,16 +589,16 @@  discard block
 block discarded – undo
589 589
 	 * @since 3.12.2
590 590
 	 *
591 591
 	 */
592
-	public function get( $params = array() ) {
592
+	public function get($params = array()) {
593 593
 
594 594
 		// Set the defaults.
595
-		$defaults = array( 'post_type' => 'entity' );
595
+		$defaults = array('post_type' => 'entity');
596 596
 
597 597
 		// Merge the defaults with the provided parameters.
598
-		$args = wp_parse_args( $params, $defaults );
598
+		$args = wp_parse_args($params, $defaults);
599 599
 
600 600
 		// Call the `get_posts` function.
601
-		return get_posts( $args );
601
+		return get_posts($args);
602 602
 	}
603 603
 
604 604
 	/**
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	static function valid_entity_post_types() {
615 615
 
616 616
 		// Ignore builtins in the call to avoid getting attachments.
617
-		$post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
617
+		$post_types = array('post', 'page', self::TYPE_NAME, 'product');
618 618
 
619
-		return apply_filters( 'wl_valid_entity_post_types', $post_types );
619
+		return apply_filters('wl_valid_entity_post_types', $post_types);
620 620
 	}
621 621
 
622 622
 }
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-url-property-service.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return array An array of URLs.
31 31
 	 */
32
-	public function get( $id, $meta_key, $type ) {
32
+	public function get($id, $meta_key, $type) {
33 33
 
34 34
 		// Get the meta values and push the <permalink> to
35 35
 		// ensure that default url will be added to the schema:url's.
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
 		 *
41 41
 		 * @since 3.21.1
42 42
 		 */
43
-		$urls = array_filter( parent::get( $id, $meta_key, $type ) ?: array( '<permalink>' ) );
43
+		$urls = array_filter(parent::get($id, $meta_key, $type) ?: array('<permalink>'));
44 44
 
45 45
 		// Convert <permalink> in actual permalink values.
46
-		return array_map( function ( $item ) use ( $id, $type ) {
46
+		return array_map(function($item) use ($id, $type) {
47 47
 			/*
48 48
 			 * If `<permalink>` get the production permalink.
49 49
 			 *
@@ -52,20 +52,20 @@  discard block
 block discarded – undo
52 52
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/850.
53 53
 			 */
54 54
 
55
-			if ( '<permalink>' !== $item ) {
55
+			if ('<permalink>' !== $item) {
56 56
 				return $item;
57 57
 			}
58 58
 
59 59
 			// Permalinks.
60
-			switch ( $type ) {
60
+			switch ($type) {
61 61
 				case Object_Type_Enum::POST:
62
-					return Wordlift_Post_Adapter::get_production_permalink( $id );
62
+					return Wordlift_Post_Adapter::get_production_permalink($id);
63 63
 				case Object_Type_Enum::TERM:
64
-					return get_term_link( $id );
64
+					return get_term_link($id);
65 65
 				default:
66 66
 					return $item;
67 67
 			}
68
-		}, array_unique( $urls ) );
68
+		}, array_unique($urls));
69 69
 	}
70 70
 
71 71
 }
Please login to merge, or discard this patch.
src/modules/linked_data/wordlift_linked_data.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
  * @since 3.0.0
21 21
  *
22 22
  */
23
-function wl_linked_data_save_post( $post_id ) {
23
+function wl_linked_data_save_post($post_id) {
24 24
 
25
-	$log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post' );
25
+	$log = Wordlift_Log_Service::get_logger('wl_linked_data_save_post');
26 26
 
27
-	$log->trace( "Saving post $post_id to Linked Data..." );
27
+	$log->trace("Saving post $post_id to Linked Data...");
28 28
 
29 29
 	// If it's not numeric exit from here.
30
-	if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) {
31
-		$log->debug( "Skipping $post_id, because id is not numeric or is a post revision." );
30
+	if ( ! is_numeric($post_id) || is_numeric(wp_is_post_revision($post_id))) {
31
+		$log->debug("Skipping $post_id, because id is not numeric or is a post revision.");
32 32
 
33 33
 		return;
34 34
 	}
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	// Get the post type and check whether it supports the editor.
37 37
 	//
38 38
 	// @see https://github.com/insideout10/wordlift-plugin/issues/659.
39
-	$post_type = get_post_type( $post_id );
39
+	$post_type = get_post_type($post_id);
40 40
 	/**
41 41
 	 * Use `wl_post_type_supports_editor` which calls a filter to allow 3rd parties to change the setting.
42 42
 	 *
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/847.
46 46
 	 */
47
-	$is_editor_supported = wl_post_type_supports_editor( $post_type );
47
+	$is_editor_supported = wl_post_type_supports_editor($post_type);
48 48
 
49
-	$is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id );
49
+	$is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used($post_id);
50 50
 	// Bail out if it's not an entity.
51 51
 	if ( ! $is_editor_supported
52
-	     && ! $is_no_editor_analysis_enabled ) {
53
-		$log->debug( "Skipping $post_id, because $post_type doesn't support the editor (content)." );
52
+	     && ! $is_no_editor_analysis_enabled) {
53
+		$log->debug("Skipping $post_id, because $post_type doesn't support the editor (content).");
54 54
 
55 55
 		return;
56 56
 	}
@@ -64,23 +64,23 @@  discard block
 block discarded – undo
64 64
 	$supported_types = Wordlift_Entity_Service::valid_entity_post_types();
65 65
 
66 66
 	// Bail out if it's not a valid entity.
67
-	if ( ! in_array( $post_type, $supported_types ) && ! $is_no_editor_analysis_enabled ) {
68
-		$log->debug( "Skipping $post_id, because $post_type is not a valid entity." );
67
+	if ( ! in_array($post_type, $supported_types) && ! $is_no_editor_analysis_enabled) {
68
+		$log->debug("Skipping $post_id, because $post_type is not a valid entity.");
69 69
 
70 70
 		return;
71 71
 	}
72 72
 
73 73
 	// Unhook this function so it doesn't loop infinitely.
74
-	remove_action( 'save_post', 'wl_linked_data_save_post' );
74
+	remove_action('save_post', 'wl_linked_data_save_post');
75 75
 
76 76
 	// raise the *wl_linked_data_save_post* event.
77
-	do_action( 'wl_linked_data_save_post', $post_id );
77
+	do_action('wl_linked_data_save_post', $post_id);
78 78
 
79 79
 	// Re-hook this function.
80
-	add_action( 'save_post', 'wl_linked_data_save_post' );
80
+	add_action('save_post', 'wl_linked_data_save_post');
81 81
 }
82 82
 
83
-add_action( 'save_post', 'wl_linked_data_save_post' );
83
+add_action('save_post', 'wl_linked_data_save_post');
84 84
 
85 85
 /**
86 86
  * Save the post to the triple store. Also saves the entities locally and on the triple store.
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
  * @since 3.0.0
91 91
  *
92 92
  */
93
-function wl_linked_data_save_post_and_related_entities( $post_id ) {
93
+function wl_linked_data_save_post_and_related_entities($post_id) {
94 94
 
95
-	$log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post_and_related_entities' );
95
+	$log = Wordlift_Log_Service::get_logger('wl_linked_data_save_post_and_related_entities');
96 96
 
97
-	$log->trace( "Saving $post_id to Linked Data along with related entities..." );
97
+	$log->trace("Saving $post_id to Linked Data along with related entities...");
98 98
 
99 99
 	// Ignore auto-saves
100
-	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
101
-		$log->trace( 'Doing autosave, skipping...' );
100
+	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
101
+		$log->trace('Doing autosave, skipping...');
102 102
 
103 103
 		return;
104 104
 	}
105 105
 
106 106
 	// get the current post.
107
-	$post = get_post( $post_id );
107
+	$post = get_post($post_id);
108 108
 
109
-	remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
109
+	remove_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
110 110
 
111 111
 	// wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
112 112
 
@@ -122,21 +122,21 @@  discard block
 block discarded – undo
122 122
 	$internal_entity_uris = array();
123 123
 
124 124
 	// Save the entities coming with POST data.
125
-	if ( isset( $_POST['wl_entities'] ) ) {
126
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
127
-		wl_write_log( json_encode( $_POST['wl_entities'] ) );
128
-		wl_write_log( "]" );
125
+	if (isset($_POST['wl_entities'])) {
126
+		wl_write_log("[ post id :: $post_id ][ POST(wl_entities) :: ");
127
+		wl_write_log(json_encode($_POST['wl_entities']));
128
+		wl_write_log("]");
129 129
 
130 130
 		$entities_via_post = $_POST['wl_entities'];
131 131
 
132
-		foreach ( $entities_via_post as $entity_uri => $entity ) {
132
+		foreach ($entities_via_post as $entity_uri => $entity) {
133 133
 
134
-			if ( preg_match( '/^local-entity-.+/', $entity_uri ) ) {
135
-				$existing_entity = get_page_by_title( $entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types() );
136
-				if ( isset( $existing_entity ) ) {
137
-					$existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get( $existing_entity->ID );
134
+			if (preg_match('/^local-entity-.+/', $entity_uri)) {
135
+				$existing_entity = get_page_by_title($entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types());
136
+				if (isset($existing_entity)) {
137
+					$existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get($existing_entity->ID);
138 138
 					// Type doesn't match, continue to create a new entity.
139
-					if ( ! isset( $existing_entity_type ) || $existing_entity_type['css_class'] !== $entity['main_type'] ) {
139
+					if ( ! isset($existing_entity_type) || $existing_entity_type['css_class'] !== $entity['main_type']) {
140 140
 						$existing_entity = null;
141 141
 					}
142 142
 				}
@@ -144,36 +144,36 @@  discard block
 block discarded – undo
144 144
 				// Look if current entity uri matches an internal existing entity, meaning:
145 145
 				// 1. when $entity_uri is an internal uri
146 146
 				// 2. when $entity_uri is an external uri used as sameAs of an internal entity
147
-				$existing_entity = $entity_service->get_entity_post_by_uri( $entity_uri );
147
+				$existing_entity = $entity_service->get_entity_post_by_uri($entity_uri);
148 148
 			}
149 149
 
150 150
 			// Don't save the entities which are not found, but also local.
151
-			if ( ! isset( $existing_entity ) && $uri_service->is_internal( $entity_uri ) ) {
151
+			if ( ! isset($existing_entity) && $uri_service->is_internal($entity_uri)) {
152 152
 				$internal_entity_uris[] = $entity_uri;
153 153
 				continue;
154 154
 			}
155 155
 
156
-			if ( ! isset( $existing_entity ) ) {
156
+			if ( ! isset($existing_entity)) {
157 157
 				// New entity, save it.
158
-				$existing_entity = wl_save_entity( $entity );
158
+				$existing_entity = wl_save_entity($entity);
159 159
 			} else {
160 160
 				// Existing entity, update post status.
161
-				if ( $existing_entity instanceof WP_Post && $existing_entity->post_status !== 'publish' ) {
162
-					$post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true )
161
+				if ($existing_entity instanceof WP_Post && $existing_entity->post_status !== 'publish') {
162
+					$post_status = apply_filters('wl_feature__enable__entity-auto-publish', true)
163 163
 						? $post->post_status : 'draft';
164
-					wl_update_post_status( $existing_entity->ID, $post_status );
164
+					wl_update_post_status($existing_entity->ID, $post_status);
165 165
 				}
166 166
 			}
167 167
 
168
-			$uri = $content_service->get_entity_id( Wordpress_Content_Id::create_post( $existing_entity->ID ) );
168
+			$uri = $content_service->get_entity_id(Wordpress_Content_Id::create_post($existing_entity->ID));
169 169
 
170 170
 
171 171
 			// Update entity data with related post
172 172
 			$entity['related_post_id'] = $post_id;
173 173
 
174 174
 			$internal_entity_uris[] = $uri;
175
-			wl_write_log( "Map $entity_uri on $uri" );
176
-			$entities_uri_mapping[ $entity_uri ] = $uri;
175
+			wl_write_log("Map $entity_uri on $uri");
176
+			$entities_uri_mapping[$entity_uri] = $uri;
177 177
 
178 178
 		}
179 179
 
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	$updated_post_content = $post->post_content;
184 184
 
185 185
 	// Update the post content if we found mappings of new entities.
186
-	if ( ! empty( $entities_uri_mapping ) ) {
186
+	if ( ! empty($entities_uri_mapping)) {
187 187
 		// Save each entity and store the post id.
188
-		foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
189
-			if ( 1 !== preg_match( '@^(https?://|local-entity-)@', $tmp_uri ) ) {
188
+		foreach ($entities_uri_mapping as $tmp_uri => $uri) {
189
+			if (1 !== preg_match('@^(https?://|local-entity-)@', $tmp_uri)) {
190 190
 				continue;
191 191
 			}
192 192
 
193
-			$updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
193
+			$updated_post_content = str_replace($tmp_uri, $uri, $updated_post_content);
194 194
 		}
195 195
 
196 196
 		// Update the post content.
@@ -199,16 +199,16 @@  discard block
 block discarded – undo
199 199
 		 * content, so add the slashes to prevent back slash getting
200 200
 		 * removed.
201 201
 		 */
202
-		wp_update_post( array(
202
+		wp_update_post(array(
203 203
 			'ID'           => $post->ID,
204
-			'post_content' => addslashes( $updated_post_content ),
205
-		) );
204
+			'post_content' => addslashes($updated_post_content),
205
+		));
206 206
 	}
207 207
 
208 208
 	// Reset previously saved instances.
209
-	wl_core_delete_relation_instances( $post_id );
209
+	wl_core_delete_relation_instances($post_id);
210 210
 
211
-	$relations = Object_Relation_Factory::get_instance( $post_id )
211
+	$relations = Object_Relation_Factory::get_instance($post_id)
212 212
 	                                    ->get_relations_from_content(
213 213
 		                                    $updated_post_content,
214 214
 		                                    Object_Type_Enum::POST,
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	                                    );
217 217
 
218 218
 	// Save relation instances
219
-	foreach ( $relations as $relation ) {
219
+	foreach ($relations as $relation) {
220 220
 
221 221
 		wl_core_add_relation_instance(
222 222
 		// subject id.
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 
234 234
 	}
235 235
 
236
-	if ( isset( $_POST['wl_entities'] ) ) {
236
+	if (isset($_POST['wl_entities'])) {
237 237
 		// Save post metadata if available
238
-		$metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ?
238
+		$metadata_via_post = (isset($_POST['wl_metadata'])) ?
239 239
 			$_POST['wl_metadata'] : array();
240 240
 
241 241
 		$fields = array(
@@ -244,35 +244,35 @@  discard block
 block discarded – undo
244 244
 		);
245 245
 
246 246
 		// Unlink topic taxonomy terms
247
-		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
247
+		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for($post->ID);
248 248
 
249
-		foreach ( $fields as $field ) {
249
+		foreach ($fields as $field) {
250 250
 
251 251
 			// Delete current values
252
-			delete_post_meta( $post->ID, $field );
252
+			delete_post_meta($post->ID, $field);
253 253
 			// Retrieve the entity uri
254
-			$uri = ( isset( $metadata_via_post[ $field ] ) ) ?
255
-				stripslashes( $metadata_via_post[ $field ] ) : '';
254
+			$uri = (isset($metadata_via_post[$field])) ?
255
+				stripslashes($metadata_via_post[$field]) : '';
256 256
 
257
-			if ( empty( $uri ) ) {
257
+			if (empty($uri)) {
258 258
 				continue;
259 259
 			}
260
-			$entity = $entity_service->get_entity_post_by_uri( $uri );
260
+			$entity = $entity_service->get_entity_post_by_uri($uri);
261 261
 
262
-			if ( $entity ) {
263
-				add_post_meta( $post->ID, $field, $entity->ID, true );
262
+			if ($entity) {
263
+				add_post_meta($post->ID, $field, $entity->ID, true);
264 264
 				// Set also the topic taxonomy
265
-				if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
266
-					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
265
+				if ($field === Wordlift_Schema_Service::FIELD_TOPIC) {
266
+					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for($post->ID, $entity);
267 267
 				}
268 268
 			}
269 269
 		}
270 270
 	}
271 271
 
272
-	add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
272
+	add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
273 273
 }
274 274
 
275
-add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
275
+add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
276 276
 
277 277
 /**
278 278
  * Save the specified data as an entity in WordPress. This method only create new entities. When an existing entity is
@@ -290,14 +290,14 @@  discard block
 block discarded – undo
290 290
  *
291 291
  * @return null|WP_Post A post instance or null in case of failure.
292 292
  */
293
-function wl_save_entity( $entity_data ) {
293
+function wl_save_entity($entity_data) {
294 294
 
295 295
 	// Required for REST API calls
296
-	if ( ! function_exists( 'wp_crop_image' ) ) {
297
-		require_once( ABSPATH . 'wp-admin/includes/image.php' );
296
+	if ( ! function_exists('wp_crop_image')) {
297
+		require_once(ABSPATH.'wp-admin/includes/image.php');
298 298
 	}
299 299
 
300
-	$log = Wordlift_Log_Service::get_logger( 'wl_save_entity' );
300
+	$log = Wordlift_Log_Service::get_logger('wl_save_entity');
301 301
 
302 302
 	/*
303 303
 	 * Data is coming from a $_POST, sanitize it.
@@ -306,29 +306,29 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/841
308 308
 	 */
309
-	$label            = preg_replace( '/\xEF\xBB\xBF/', '', sanitize_text_field( $entity_data['label'] ) );
309
+	$label            = preg_replace('/\xEF\xBB\xBF/', '', sanitize_text_field($entity_data['label']));
310 310
 	$type_uri         = $entity_data['main_type'];
311
-	$entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
311
+	$entity_types     = isset($entity_data['type']) ? $entity_data['type'] : array();
312 312
 	$description      = $entity_data['description'];
313
-	$images           = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array();
314
-	$same_as          = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array();
315
-	$related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
316
-	$other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
313
+	$images           = isset($entity_data['image']) ? (array) $entity_data['image'] : array();
314
+	$same_as          = isset($entity_data['sameas']) ? (array) $entity_data['sameas'] : array();
315
+	$related_post_id  = isset($entity_data['related_post_id']) ? $entity_data['related_post_id'] : null;
316
+	$other_properties = isset($entity_data['properties']) ? $entity_data['properties'] : array();
317 317
 
318 318
 	// Get the synonyms.
319
-	$synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array();
319
+	$synonyms = isset($entity_data['synonym']) ? $entity_data['synonym'] : array();
320 320
 
321 321
 	// Check whether an entity already exists with the provided URI.
322 322
 	$uri = $entity_data['uri'];
323
-	if ( isset ( $uri ) && null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ) ) {
324
-		$log->debug( "Post already exists for URI $uri." );
323
+	if (isset ($uri) && null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri)) {
324
+		$log->debug("Post already exists for URI $uri.");
325 325
 
326 326
 		return $post;
327 327
 	}
328 328
 
329 329
 	// Prepare properties of the new entity.
330
-	$post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) && is_numeric( $related_post_id )
331
-		? get_post_status( $related_post_id ) : 'draft';
330
+	$post_status = apply_filters('wl_feature__enable__entity-auto-publish', true) && is_numeric($related_post_id)
331
+		? get_post_status($related_post_id) : 'draft';
332 332
 
333 333
 	$params = array(
334 334
 		// @@todo: we don't want an entity to be automatically published.
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		// new entities.
343 343
 		//
344 344
 		// See https://github.com/insideout10/wordlift-plugin/issues/282
345
-		'post_name'    => sanitize_title( $label ),
345
+		'post_name'    => sanitize_title($label),
346 346
 	);
347 347
 
348 348
 	// If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
 	// This does NOT affect saving an entity from the entity admin page since this function is called when an entity
352 352
 	// is created when saving a post.
353 353
 	global $wpseo_metabox, $seo_ultimate;
354
-	if ( isset( $wpseo_metabox ) ) {
355
-		remove_action( 'wp_insert_post', array(
354
+	if (isset($wpseo_metabox)) {
355
+		remove_action('wp_insert_post', array(
356 356
 			$wpseo_metabox,
357 357
 			'save_postdata',
358
-		) );
358
+		));
359 359
 	}
360 360
 
361
-	if ( isset( $seo_ultimate ) ) {
362
-		remove_action( 'save_post', array(
361
+	if (isset($seo_ultimate)) {
362
+		remove_action('save_post', array(
363 363
 			$seo_ultimate,
364 364
 			'save_postmeta_box',
365
-		) );
365
+		));
366 366
 	}
367 367
 
368 368
 	// The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
@@ -372,94 +372,94 @@  discard block
 block discarded – undo
372 372
 	// see https://github.com/insideout10/wordlift-plugin/issues/156
373 373
 	// see https://github.com/insideout10/wordlift-plugin/issues/148
374 374
 	global $wp_filter;
375
-	$save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
376
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
375
+	$save_post_filters = is_array($wp_filter['save_post']) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
376
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
377 377
 
378 378
 
379
-	$log->trace( 'Going to insert new post...' );
379
+	$log->trace('Going to insert new post...');
380 380
 
381 381
 	// create or update the post.
382
-	$post_id = wp_insert_post( $params, true );
382
+	$post_id = wp_insert_post($params, true);
383 383
 
384 384
 	// Setting the alternative labels for this entity.
385 385
 	Wordlift_Entity_Service::get_instance()
386
-	                       ->set_alternative_labels( $post_id, $synonyms );
386
+	                       ->set_alternative_labels($post_id, $synonyms);
387 387
 
388 388
 	// Restore all the existing filters.
389
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
389
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
390 390
 
391 391
 	// If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
392
-	if ( isset( $wpseo_metabox ) ) {
393
-		add_action( 'wp_insert_post', array(
392
+	if (isset($wpseo_metabox)) {
393
+		add_action('wp_insert_post', array(
394 394
 			$wpseo_metabox,
395 395
 			'save_postdata',
396
-		) );
396
+		));
397 397
 	}
398 398
 
399 399
 	// If SEO Ultimate is installed, add back the hook we removed a few lines above.
400
-	if ( isset( $seo_ultimate ) ) {
401
-		add_action( 'save_post', array(
400
+	if (isset($seo_ultimate)) {
401
+		add_action('save_post', array(
402 402
 			$seo_ultimate,
403 403
 			'save_postmeta_box',
404
-		), 10, 2 );
404
+		), 10, 2);
405 405
 	}
406 406
 
407 407
 	// TODO: handle errors.
408
-	if ( is_wp_error( $post_id ) ) {
409
-		$log->error( 'An error occurred: ' . $post_id->get_error_message() );
408
+	if (is_wp_error($post_id)) {
409
+		$log->error('An error occurred: '.$post_id->get_error_message());
410 410
 
411 411
 		// inform an error occurred.
412 412
 		return null;
413 413
 	}
414 414
 
415
-	wl_set_entity_main_type( $post_id, $type_uri );
415
+	wl_set_entity_main_type($post_id, $type_uri);
416 416
 
417 417
 	// Save the entity types.
418
-	wl_set_entity_rdf_types( $post_id, $entity_types );
418
+	wl_set_entity_rdf_types($post_id, $entity_types);
419 419
 
420 420
 	// Get a dataset URI for the entity.
421
-	$wl_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post_id );
421
+	$wl_uri = Wordlift_Entity_Service::get_instance()->get_uri($post_id);
422 422
 
423 423
 	// Add the uri to the sameAs data if it's not a local URI.
424
-	if ( isset( $uri ) && preg_match( '@https?://.*@', $uri ) &&
424
+	if (isset($uri) && preg_match('@https?://.*@', $uri) &&
425 425
 	     $wl_uri !== $uri &&
426 426
 	     // Only remote entities
427
-	     0 !== strpos( $uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri() )
427
+	     0 !== strpos($uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri())
428 428
 	) {
429
-		array_push( $same_as, $uri );
429
+		array_push($same_as, $uri);
430 430
 	}
431 431
 
432 432
 	// Save the sameAs data for the entity.
433
-	wl_schema_set_value( $post_id, 'sameAs', $same_as );
433
+	wl_schema_set_value($post_id, 'sameAs', $same_as);
434 434
 
435 435
 	// Save the other properties (latitude, langitude, startDate, endDate, etc.)
436
-	foreach ( $other_properties as $property_name => $property_value ) {
437
-		wl_schema_set_value( $post_id, $property_name, $property_value );
436
+	foreach ($other_properties as $property_name => $property_value) {
437
+		wl_schema_set_value($post_id, $property_name, $property_value);
438 438
 	}
439 439
 
440 440
 	// Call hooks.
441
-	do_action( 'wl_save_entity', $post_id );
441
+	do_action('wl_save_entity', $post_id);
442 442
 
443
-	foreach ( $images as $image_remote_url ) {
443
+	foreach ($images as $image_remote_url) {
444 444
 
445 445
 		// Check if image is already present in local DB
446
-		if ( strpos( $image_remote_url, site_url() ) !== false ) {
446
+		if (strpos($image_remote_url, site_url()) !== false) {
447 447
 			// Do nothing.
448 448
 			continue;
449 449
 		}
450 450
 
451 451
 		// Check if there is an existing attachment for this post ID and source URL.
452
-		$existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
452
+		$existing_image = wl_get_attachment_for_source_url($post_id, $image_remote_url);
453 453
 
454 454
 		// Skip if an existing image is found.
455
-		if ( null !== $existing_image ) {
455
+		if (null !== $existing_image) {
456 456
 			continue;
457 457
 		}
458 458
 
459 459
 		// Save the image and get the local path.
460
-		$image = Wordlift_Remote_Image_Service::save_from_url( $image_remote_url );
460
+		$image = Wordlift_Remote_Image_Service::save_from_url($image_remote_url);
461 461
 
462
-		if ( false === $image || is_wp_error( $image ) ) {
462
+		if (false === $image || is_wp_error($image)) {
463 463
 			continue;
464 464
 		}
465 465
 
@@ -479,18 +479,18 @@  discard block
 block discarded – undo
479 479
 		);
480 480
 
481 481
 		// Create the attachment in WordPress and generate the related metadata.
482
-		$attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
482
+		$attachment_id = wp_insert_attachment($attachment, $filename, $post_id);
483 483
 
484 484
 		// Set the source URL for the image.
485
-		wl_set_source_url( $attachment_id, $image_remote_url );
485
+		wl_set_source_url($attachment_id, $image_remote_url);
486 486
 
487
-		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
488
-		wp_update_attachment_metadata( $attachment_id, $attachment_data );
487
+		$attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
488
+		wp_update_attachment_metadata($attachment_id, $attachment_data);
489 489
 
490 490
 		// Set it as the featured image.
491
-		set_post_thumbnail( $post_id, $attachment_id );
491
+		set_post_thumbnail($post_id, $attachment_id);
492 492
 	}
493 493
 
494 494
 	// finally return the entity post.
495
-	return get_post( $post_id );
495
+	return get_post($post_id);
496 496
 }
Please login to merge, or discard this patch.