Completed
Push — develop ( 45d990...ead86b )
by David
03:02
created
src/admin/WL_Metabox/class-wl-metabox.php 2 patches
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -25,297 +25,297 @@
 block discarded – undo
25 25
  */
26 26
 class WL_Metabox {
27 27
 
28
-	/**
29
-	 * The metabox custom fields for the current {@link WP_Post}.
30
-	 *
31
-	 * @since  3.1.0
32
-	 * @access public
33
-	 * @var array $fields The metabox custom fields.
34
-	 */
35
-	public $fields;
36
-
37
-	/**
38
-	 * WL_Metabox constructor.
39
-	 *
40
-	 * @since 3.1.0
41
-	 */
42
-	public function __construct() {
43
-
44
-		// Add hooks to print metaboxes and save submitted data.
45
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
46
-		add_action( 'wl_linked_data_save_post', array(
47
-			&$this,
48
-			'save_form_data',
49
-		) );
50
-
51
-		// Enqueue js and css.
52
-		$this->enqueue_scripts_and_styles();
53
-
54
-	}
55
-
56
-	/**
57
-	 * Add a callback to print the metabox in page.
58
-	 * Wordpress will fire the $this->html() callback at the right time.
59
-	 */
60
-	public function add_main_metabox() {
61
-
62
-		// Add main metabox (will print also the inner fields).
63
-		$id    = uniqid( 'wl-metabox-' );
64
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
65
-		add_meta_box( $id, $title, array(
66
-			$this,
67
-			'html',
68
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
69
-
70
-		// Add filter to change the metabox CSS class.
71
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
72
-	}
73
-
74
-	/**
75
-	 * Called from WP to print the metabox content in page.
76
-	 *
77
-	 * @since 3.1.0
78
-	 *
79
-	 * @param WP_Post $post The post.
80
-	 */
81
-	public function html( $post ) {
82
-
83
-		// Build the fields we need to print.
84
-		$this->instantiate_fields( $post->ID );
85
-
86
-		// Loop over the fields.
87
-		foreach ( $this->fields as $field ) {
88
-
89
-			// load data from DB (values will be available in $field->data).
90
-			$field->get_data();
91
-
92
-			// print field HTML (nonce included).
93
-			echo $field->html();
94
-		}
95
-
96
-	}
97
-
98
-	/**
99
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
100
-	 *
101
-	 * Note: the first function that calls this method will instantiate the fields.
102
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
103
-	 *
104
-	 * @since 3.1.0
105
-	 *
106
-	 * @param int $post_id The post id.
107
-	 */
108
-	public function instantiate_fields( $post_id ) {
109
-
110
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
111
-		if ( isset( $this->fields ) ) {
112
-			return;
113
-		}
114
-
115
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
116
-
117
-		if ( isset( $entity_type ) ) {
118
-
119
-			/**
120
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
121
-			 * We must divide fields in two groups:
122
-			 * - simple: accept values for one property
123
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
124
-			 */
125
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
126
-			$simple_metaboxes  = $metaboxes[0];
127
-			$grouped_metaboxes = $metaboxes[1];
128
-
129
-			// Loop over simple entity properties.
130
-			foreach ( $simple_metaboxes as $key => $property ) {
131
-
132
-				// Info passed to the metabox.
133
-				$info         = array();
134
-				$info[ $key ] = $property;
135
-
136
-				// Build the requested field as WL_Metabox_Field_ object.
137
-				$this->add_field( $info );
138
-
139
-			}
28
+    /**
29
+     * The metabox custom fields for the current {@link WP_Post}.
30
+     *
31
+     * @since  3.1.0
32
+     * @access public
33
+     * @var array $fields The metabox custom fields.
34
+     */
35
+    public $fields;
36
+
37
+    /**
38
+     * WL_Metabox constructor.
39
+     *
40
+     * @since 3.1.0
41
+     */
42
+    public function __construct() {
43
+
44
+        // Add hooks to print metaboxes and save submitted data.
45
+        add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
46
+        add_action( 'wl_linked_data_save_post', array(
47
+            &$this,
48
+            'save_form_data',
49
+        ) );
50
+
51
+        // Enqueue js and css.
52
+        $this->enqueue_scripts_and_styles();
53
+
54
+    }
55
+
56
+    /**
57
+     * Add a callback to print the metabox in page.
58
+     * Wordpress will fire the $this->html() callback at the right time.
59
+     */
60
+    public function add_main_metabox() {
61
+
62
+        // Add main metabox (will print also the inner fields).
63
+        $id    = uniqid( 'wl-metabox-' );
64
+        $title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
65
+        add_meta_box( $id, $title, array(
66
+            $this,
67
+            'html',
68
+        ), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
69
+
70
+        // Add filter to change the metabox CSS class.
71
+        add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
72
+    }
73
+
74
+    /**
75
+     * Called from WP to print the metabox content in page.
76
+     *
77
+     * @since 3.1.0
78
+     *
79
+     * @param WP_Post $post The post.
80
+     */
81
+    public function html( $post ) {
82
+
83
+        // Build the fields we need to print.
84
+        $this->instantiate_fields( $post->ID );
85
+
86
+        // Loop over the fields.
87
+        foreach ( $this->fields as $field ) {
88
+
89
+            // load data from DB (values will be available in $field->data).
90
+            $field->get_data();
91
+
92
+            // print field HTML (nonce included).
93
+            echo $field->html();
94
+        }
95
+
96
+    }
97
+
98
+    /**
99
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
100
+     *
101
+     * Note: the first function that calls this method will instantiate the fields.
102
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
103
+     *
104
+     * @since 3.1.0
105
+     *
106
+     * @param int $post_id The post id.
107
+     */
108
+    public function instantiate_fields( $post_id ) {
109
+
110
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
111
+        if ( isset( $this->fields ) ) {
112
+            return;
113
+        }
114
+
115
+        $entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
116
+
117
+        if ( isset( $entity_type ) ) {
118
+
119
+            /**
120
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
121
+             * We must divide fields in two groups:
122
+             * - simple: accept values for one property
123
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
124
+             */
125
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
126
+            $simple_metaboxes  = $metaboxes[0];
127
+            $grouped_metaboxes = $metaboxes[1];
128
+
129
+            // Loop over simple entity properties.
130
+            foreach ( $simple_metaboxes as $key => $property ) {
131
+
132
+                // Info passed to the metabox.
133
+                $info         = array();
134
+                $info[ $key ] = $property;
135
+
136
+                // Build the requested field as WL_Metabox_Field_ object.
137
+                $this->add_field( $info );
138
+
139
+            }
140 140
 
141
-			// Loop over grouped properties.
142
-			foreach ( $grouped_metaboxes as $key => $property ) {
141
+            // Loop over grouped properties.
142
+            foreach ( $grouped_metaboxes as $key => $property ) {
143 143
 
144
-				// Info passed to the metabox.
145
-				$info         = array();
146
-				$info[ $key ] = $property;
144
+                // Info passed to the metabox.
145
+                $info         = array();
146
+                $info[ $key ] = $property;
147 147
 
148
-				// Build the requested field group as WL_Metabox_Field_ object.
149
-				$this->add_field( $info, true );
148
+                // Build the requested field group as WL_Metabox_Field_ object.
149
+                $this->add_field( $info, true );
150 150
 
151
-			}
151
+            }
152 152
 
153
-		}
154
-
155
-	}
156
-
157
-	/**
158
-	 * Separates metaboxes in simple and grouped.
159
-	 *
160
-	 * @param array $custom_fields Information on the entity type.
161
-	 *
162
-	 * @return array
163
-	 */
164
-	public function group_properties_by_input_field( $custom_fields ) {
153
+        }
154
+
155
+    }
156
+
157
+    /**
158
+     * Separates metaboxes in simple and grouped.
159
+     *
160
+     * @param array $custom_fields Information on the entity type.
161
+     *
162
+     * @return array
163
+     */
164
+    public function group_properties_by_input_field( $custom_fields ) {
165 165
 
166
-		$simple_properties  = array();
167
-		$grouped_properties = array();
166
+        $simple_properties  = array();
167
+        $grouped_properties = array();
168 168
 
169
-		// Loop over possible entity properties.
170
-		foreach ( $custom_fields as $key => $property ) {
169
+        // Loop over possible entity properties.
170
+        foreach ( $custom_fields as $key => $property ) {
171 171
 
172
-			// Check presence of predicate and type.
173
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
172
+            // Check presence of predicate and type.
173
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
174 174
 
175
-				// Check if input_field is defined.
176
-				if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
175
+                // Check if input_field is defined.
176
+                if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
177 177
 
178
-					$grouped_key = $property['input_field'];
178
+                    $grouped_key = $property['input_field'];
179 179
 
180
-					// Update list of grouped properties.
181
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
180
+                    // Update list of grouped properties.
181
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
182 182
 
183
-				} else {
183
+                } else {
184 184
 
185
-					// input_field not defined, add simple metabox.
186
-					$simple_properties[ $key ] = $property;
187
-				}
188
-			}
189
-		}
185
+                    // input_field not defined, add simple metabox.
186
+                    $simple_properties[ $key ] = $property;
187
+                }
188
+            }
189
+        }
190 190
 
191
-		return array( $simple_properties, $grouped_properties );
192
-	}
191
+        return array( $simple_properties, $grouped_properties );
192
+    }
193 193
 
194
-	/**
195
-	 * Add a Field to the current Metabox, based on the description of the Field.
196
-	 * This method is a rude factory for Field objects.
197
-	 *
198
-	 * @param array $args    The field's information.
199
-	 * @param bool  $grouped Flag to distinguish between simple and grouped fields.
200
-	 */
201
-	public function add_field( $args, $grouped = false ) {
194
+    /**
195
+     * Add a Field to the current Metabox, based on the description of the Field.
196
+     * This method is a rude factory for Field objects.
197
+     *
198
+     * @param array $args    The field's information.
199
+     * @param bool  $grouped Flag to distinguish between simple and grouped fields.
200
+     */
201
+    public function add_field( $args, $grouped = false ) {
202 202
 
203
-		if ( $grouped ) {
203
+        if ( $grouped ) {
204 204
 
205
-			// Special fields (sameas, coordinates, etc.).
206
-			//
207
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
208
-			$field_class = 'WL_Metabox_Field_' . key( $args );
205
+            // Special fields (sameas, coordinates, etc.).
206
+            //
207
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date).
208
+            $field_class = 'WL_Metabox_Field_' . key( $args );
209 209
 
210
-		} else {
210
+        } else {
211 211
 
212
-			// Simple fields (string, uri, boolean, etc.).
213
-			//
214
-			// Which field? We want to use the class that is specific for the field.
215
-			$meta      = key( $args );
216
-			$this_meta = $args[ $meta ];
212
+            // Simple fields (string, uri, boolean, etc.).
213
+            //
214
+            // Which field? We want to use the class that is specific for the field.
215
+            $meta      = key( $args );
216
+            $this_meta = $args[ $meta ];
217 217
 
218
-			// If the field declares what metabox it wants, use that one.
219
-			if ( isset( $this_meta['metabox']['class'] ) ) {
218
+            // If the field declares what metabox it wants, use that one.
219
+            if ( isset( $this_meta['metabox']['class'] ) ) {
220 220
 
221
-				$field_class = $this_meta['metabox']['class'];
221
+                $field_class = $this_meta['metabox']['class'];
222 222
 
223
-			} elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
223
+            } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
224 224
 
225
-				// TODO: all fields should explicitly declare the required WL_Metabox.
226
-				// When they will remove this.
227
-				//
228
-				// Use default WL_Metabox_Field (manages strings).
229
-				$field_class = 'WL_Metabox_Field';
225
+                // TODO: all fields should explicitly declare the required WL_Metabox.
226
+                // When they will remove this.
227
+                //
228
+                // Use default WL_Metabox_Field (manages strings).
229
+                $field_class = 'WL_Metabox_Field';
230 230
 
231
-			} else {
231
+            } else {
232 232
 
233
-				// TODO: all fields should explicitly declare the required WL_Metabox.
234
-				// When they will remove this.
235
-				//
236
-				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
237
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
233
+                // TODO: all fields should explicitly declare the required WL_Metabox.
234
+                // When they will remove this.
235
+                //
236
+                // Build Field with a custom class (e.g. WL_Metabox_Field_date).
237
+                $field_class = 'WL_Metabox_Field_' . $this_meta['type'];
238 238
 
239
-			}
239
+            }
240 240
 
241
-		}
242
-		// End if().
241
+        }
242
+        // End if().
243 243
 
244
-		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
245
-		$this->fields[] = new $field_class( $args );
246
-	}
244
+        // Call apropriate constructor (e.g. WL_Metabox_Field_... ).
245
+        $this->fields[] = new $field_class( $args );
246
+    }
247 247
 
248
-	/**
249
-	 * Save the form data for the specified entity {@link WP_Post}'s id.
250
-	 *
251
-	 * @since 3.5.4
252
-	 *
253
-	 * @param int $entity_id The entity's {@link WP_Post}'s id.
254
-	 */
255
-	public function save_form_data( $entity_id ) {
256
-
257
-		// Build Field objects.
258
-		$this->instantiate_fields( $entity_id );
259
-
260
-		// Check if WL metabox form was posted.
261
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
262
-			return;
263
-		}
248
+    /**
249
+     * Save the form data for the specified entity {@link WP_Post}'s id.
250
+     *
251
+     * @since 3.5.4
252
+     *
253
+     * @param int $entity_id The entity's {@link WP_Post}'s id.
254
+     */
255
+    public function save_form_data( $entity_id ) {
256
+
257
+        // Build Field objects.
258
+        $this->instantiate_fields( $entity_id );
259
+
260
+        // Check if WL metabox form was posted.
261
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
262
+            return;
263
+        }
264 264
 
265
-		foreach ( $this->fields as $field ) {
265
+        foreach ( $this->fields as $field ) {
266 266
 
267
-			// Verify nonce.
268
-			$valid_nonce = $field->verify_nonce();
269
-			if ( $valid_nonce ) {
267
+            // Verify nonce.
268
+            $valid_nonce = $field->verify_nonce();
269
+            if ( $valid_nonce ) {
270 270
 
271
-				$posted_data = $_POST['wl_metaboxes'];
272
-				$field_name  = $field->meta_name;
271
+                $posted_data = $_POST['wl_metaboxes'];
272
+                $field_name  = $field->meta_name;
273 273
 
274
-				// Each Filed only deals with its values.
275
-				if ( isset( $posted_data[ $field_name ] ) ) {
276
-
277
-					$values = $posted_data[ $field_name ];
278
-					if ( ! is_array( $values ) ) {
279
-						$values = array( $values );
280
-					}
281
-
282
-					// Save data permanently
283
-					$field->save_data( $values );
284
-				}
285
-			}
286
-		}
287
-
288
-		wl_linked_data_push_to_redlink( $entity_id );
289
-	}
290
-
291
-	/**
292
-	 * Enqueue scripts and styles.
293
-	 *
294
-	 * @since 3.0.0
295
-	 */
296
-	public function enqueue_scripts_and_styles() {
297
-
298
-		// Load the jquery-ui-timepicker-addon library.
299
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
300
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
274
+                // Each Filed only deals with its values.
275
+                if ( isset( $posted_data[ $field_name ] ) ) {
276
+
277
+                    $values = $posted_data[ $field_name ];
278
+                    if ( ! is_array( $values ) ) {
279
+                        $values = array( $values );
280
+                    }
281
+
282
+                    // Save data permanently
283
+                    $field->save_data( $values );
284
+                }
285
+            }
286
+        }
287
+
288
+        wl_linked_data_push_to_redlink( $entity_id );
289
+    }
290
+
291
+    /**
292
+     * Enqueue scripts and styles.
293
+     *
294
+     * @since 3.0.0
295
+     */
296
+    public function enqueue_scripts_and_styles() {
297
+
298
+        // Load the jquery-ui-timepicker-addon library.
299
+        wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
300
+        wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
301 301
 
302
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
303
-			'jquery-ui-datepicker',
304
-			'jquery-ui-timepicker-addon',
305
-		) );
306
-
307
-		// Leaflet.
308
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
309
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
310
-
311
-		// Add AJAX autocomplete to facilitate metabox editing.
312
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
313
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
314
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
315
-				'action'   => 'entity_by_title',
316
-			)
317
-		);
318
-
319
-	}
302
+        wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
303
+            'jquery-ui-datepicker',
304
+            'jquery-ui-timepicker-addon',
305
+        ) );
306
+
307
+        // Leaflet.
308
+        wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
309
+        wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
310
+
311
+        // Add AJAX autocomplete to facilitate metabox editing.
312
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
313
+        wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
314
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
315
+                'action'   => 'entity_by_title',
316
+            )
317
+        );
318
+
319
+    }
320 320
 
321 321
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/admin/WL_Metabox
8 8
  */
9 9
 
10
-require_once( 'WL_Metabox_Field.php' );
11
-require_once( 'WL_Metabox_Field_date.php' );
12
-require_once( 'WL_Metabox_Field_uri.php' );
13
-require_once( 'WL_Metabox_Field_coordinates.php' );
14
-require_once( 'WL_Metabox_Field_sameas.php' );
15
-require_once( 'WL_Metabox_Field_address.php' );
16
-require_once( 'class-wordlift-metabox-field-duration.php' );
17
-require_once( 'class-wordlift-metabox-field-multiline.php' );
10
+require_once('WL_Metabox_Field.php');
11
+require_once('WL_Metabox_Field_date.php');
12
+require_once('WL_Metabox_Field_uri.php');
13
+require_once('WL_Metabox_Field_coordinates.php');
14
+require_once('WL_Metabox_Field_sameas.php');
15
+require_once('WL_Metabox_Field_address.php');
16
+require_once('class-wordlift-metabox-field-duration.php');
17
+require_once('class-wordlift-metabox-field-multiline.php');
18 18
 
19 19
 /**
20 20
  * Define the {@link WL_Metabox} class.
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 	public function __construct() {
43 43
 
44 44
 		// Add hooks to print metaboxes and save submitted data.
45
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
46
-		add_action( 'wl_linked_data_save_post', array(
45
+		add_action('add_meta_boxes', array(&$this, 'add_main_metabox'));
46
+		add_action('wl_linked_data_save_post', array(
47 47
 			&$this,
48 48
 			'save_form_data',
49
-		) );
49
+		));
50 50
 
51 51
 		// Enqueue js and css.
52 52
 		$this->enqueue_scripts_and_styles();
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	public function add_main_metabox() {
61 61
 
62 62
 		// Add main metabox (will print also the inner fields).
63
-		$id    = uniqid( 'wl-metabox-' );
64
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
65
-		add_meta_box( $id, $title, array(
63
+		$id    = uniqid('wl-metabox-');
64
+		$title = get_the_title().' '.__('properties', 'wordlift');
65
+		add_meta_box($id, $title, array(
66 66
 			$this,
67 67
 			'html',
68
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
68
+		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high');
69 69
 
70 70
 		// Add filter to change the metabox CSS class.
71
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
71
+		add_filter("postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class');
72 72
 	}
73 73
 
74 74
 	/**
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param WP_Post $post The post.
80 80
 	 */
81
-	public function html( $post ) {
81
+	public function html($post) {
82 82
 
83 83
 		// Build the fields we need to print.
84
-		$this->instantiate_fields( $post->ID );
84
+		$this->instantiate_fields($post->ID);
85 85
 
86 86
 		// Loop over the fields.
87
-		foreach ( $this->fields as $field ) {
87
+		foreach ($this->fields as $field) {
88 88
 
89 89
 			// load data from DB (values will be available in $field->data).
90 90
 			$field->get_data();
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @param int $post_id The post id.
107 107
 	 */
108
-	public function instantiate_fields( $post_id ) {
108
+	public function instantiate_fields($post_id) {
109 109
 
110 110
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
111
-		if ( isset( $this->fields ) ) {
111
+		if (isset($this->fields)) {
112 112
 			return;
113 113
 		}
114 114
 
115
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
115
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
116 116
 
117
-		if ( isset( $entity_type ) ) {
117
+		if (isset($entity_type)) {
118 118
 
119 119
 			/**
120 120
 			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 			 * - simple: accept values for one property
123 123
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
124 124
 			 */
125
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
125
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
126 126
 			$simple_metaboxes  = $metaboxes[0];
127 127
 			$grouped_metaboxes = $metaboxes[1];
128 128
 
129 129
 			// Loop over simple entity properties.
130
-			foreach ( $simple_metaboxes as $key => $property ) {
130
+			foreach ($simple_metaboxes as $key => $property) {
131 131
 
132 132
 				// Info passed to the metabox.
133 133
 				$info         = array();
134
-				$info[ $key ] = $property;
134
+				$info[$key] = $property;
135 135
 
136 136
 				// Build the requested field as WL_Metabox_Field_ object.
137
-				$this->add_field( $info );
137
+				$this->add_field($info);
138 138
 
139 139
 			}
140 140
 
141 141
 			// Loop over grouped properties.
142
-			foreach ( $grouped_metaboxes as $key => $property ) {
142
+			foreach ($grouped_metaboxes as $key => $property) {
143 143
 
144 144
 				// Info passed to the metabox.
145 145
 				$info         = array();
146
-				$info[ $key ] = $property;
146
+				$info[$key] = $property;
147 147
 
148 148
 				// Build the requested field group as WL_Metabox_Field_ object.
149
-				$this->add_field( $info, true );
149
+				$this->add_field($info, true);
150 150
 
151 151
 			}
152 152
 
@@ -161,34 +161,34 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @return array
163 163
 	 */
164
-	public function group_properties_by_input_field( $custom_fields ) {
164
+	public function group_properties_by_input_field($custom_fields) {
165 165
 
166 166
 		$simple_properties  = array();
167 167
 		$grouped_properties = array();
168 168
 
169 169
 		// Loop over possible entity properties.
170
-		foreach ( $custom_fields as $key => $property ) {
170
+		foreach ($custom_fields as $key => $property) {
171 171
 
172 172
 			// Check presence of predicate and type.
173
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
173
+			if (isset($property['predicate']) && isset($property['type'])) {
174 174
 
175 175
 				// Check if input_field is defined.
176
-				if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
176
+				if (isset($property['input_field']) && '' !== $property['input_field']) {
177 177
 
178 178
 					$grouped_key = $property['input_field'];
179 179
 
180 180
 					// Update list of grouped properties.
181
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
181
+					$grouped_properties[$grouped_key][$key] = $property;
182 182
 
183 183
 				} else {
184 184
 
185 185
 					// input_field not defined, add simple metabox.
186
-					$simple_properties[ $key ] = $property;
186
+					$simple_properties[$key] = $property;
187 187
 				}
188 188
 			}
189 189
 		}
190 190
 
191
-		return array( $simple_properties, $grouped_properties );
191
+		return array($simple_properties, $grouped_properties);
192 192
 	}
193 193
 
194 194
 	/**
@@ -198,29 +198,29 @@  discard block
 block discarded – undo
198 198
 	 * @param array $args    The field's information.
199 199
 	 * @param bool  $grouped Flag to distinguish between simple and grouped fields.
200 200
 	 */
201
-	public function add_field( $args, $grouped = false ) {
201
+	public function add_field($args, $grouped = false) {
202 202
 
203
-		if ( $grouped ) {
203
+		if ($grouped) {
204 204
 
205 205
 			// Special fields (sameas, coordinates, etc.).
206 206
 			//
207 207
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
208
-			$field_class = 'WL_Metabox_Field_' . key( $args );
208
+			$field_class = 'WL_Metabox_Field_'.key($args);
209 209
 
210 210
 		} else {
211 211
 
212 212
 			// Simple fields (string, uri, boolean, etc.).
213 213
 			//
214 214
 			// Which field? We want to use the class that is specific for the field.
215
-			$meta      = key( $args );
216
-			$this_meta = $args[ $meta ];
215
+			$meta      = key($args);
216
+			$this_meta = $args[$meta];
217 217
 
218 218
 			// If the field declares what metabox it wants, use that one.
219
-			if ( isset( $this_meta['metabox']['class'] ) ) {
219
+			if (isset($this_meta['metabox']['class'])) {
220 220
 
221 221
 				$field_class = $this_meta['metabox']['class'];
222 222
 
223
-			} elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
223
+			} elseif ( ! isset($this_meta['type']) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type']) {
224 224
 
225 225
 				// TODO: all fields should explicitly declare the required WL_Metabox.
226 226
 				// When they will remove this.
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 				// When they will remove this.
235 235
 				//
236 236
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
237
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
237
+				$field_class = 'WL_Metabox_Field_'.$this_meta['type'];
238 238
 
239 239
 			}
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 		// End if().
243 243
 
244 244
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
245
-		$this->fields[] = new $field_class( $args );
245
+		$this->fields[] = new $field_class($args);
246 246
 	}
247 247
 
248 248
 	/**
@@ -252,40 +252,40 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @param int $entity_id The entity's {@link WP_Post}'s id.
254 254
 	 */
255
-	public function save_form_data( $entity_id ) {
255
+	public function save_form_data($entity_id) {
256 256
 
257 257
 		// Build Field objects.
258
-		$this->instantiate_fields( $entity_id );
258
+		$this->instantiate_fields($entity_id);
259 259
 
260 260
 		// Check if WL metabox form was posted.
261
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
261
+		if ( ! isset($_POST['wl_metaboxes'])) {
262 262
 			return;
263 263
 		}
264 264
 
265
-		foreach ( $this->fields as $field ) {
265
+		foreach ($this->fields as $field) {
266 266
 
267 267
 			// Verify nonce.
268 268
 			$valid_nonce = $field->verify_nonce();
269
-			if ( $valid_nonce ) {
269
+			if ($valid_nonce) {
270 270
 
271 271
 				$posted_data = $_POST['wl_metaboxes'];
272 272
 				$field_name  = $field->meta_name;
273 273
 
274 274
 				// Each Filed only deals with its values.
275
-				if ( isset( $posted_data[ $field_name ] ) ) {
275
+				if (isset($posted_data[$field_name])) {
276 276
 
277
-					$values = $posted_data[ $field_name ];
278
-					if ( ! is_array( $values ) ) {
279
-						$values = array( $values );
277
+					$values = $posted_data[$field_name];
278
+					if ( ! is_array($values)) {
279
+						$values = array($values);
280 280
 					}
281 281
 
282 282
 					// Save data permanently
283
-					$field->save_data( $values );
283
+					$field->save_data($values);
284 284
 				}
285 285
 			}
286 286
 		}
287 287
 
288
-		wl_linked_data_push_to_redlink( $entity_id );
288
+		wl_linked_data_push_to_redlink($entity_id);
289 289
 	}
290 290
 
291 291
 	/**
@@ -296,22 +296,22 @@  discard block
 block discarded – undo
296 296
 	public function enqueue_scripts_and_styles() {
297 297
 
298 298
 		// Load the jquery-ui-timepicker-addon library.
299
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
300
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
299
+		wp_enqueue_style('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css');
300
+		wp_enqueue_script('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array('jquery-ui-datepicker'), '1.6.3', true);
301 301
 
302
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
302
+		wp_enqueue_script('jquery-ui-timepicker-no-conflict', dirname(plugin_dir_url(__FILE__)).'/js/jquery.datetimepicker.no-conflict.js', array(
303 303
 			'jquery-ui-datepicker',
304 304
 			'jquery-ui-timepicker-addon',
305
-		) );
305
+		));
306 306
 
307 307
 		// Leaflet.
308
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
309
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
308
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
309
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
310 310
 
311 311
 		// Add AJAX autocomplete to facilitate metabox editing.
312
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
313
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
314
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
312
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
313
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
314
+				'ajax_url' => admin_url('admin-ajax.php'),
315 315
 				'action'   => 'entity_by_title',
316 316
 			)
317 317
 		);
Please login to merge, or discard this patch.
src/admin/wordlift_admin_meta_box_entities.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@  discard block
 block discarded – undo
10 10
  */
11 11
 function wl_register_metaboxes() {
12 12
 
13
-	// Load metabox classes
14
-	require_once( 'WL_Metabox/class-wl-metabox.php' );
13
+    // Load metabox classes
14
+    require_once( 'WL_Metabox/class-wl-metabox.php' );
15 15
 
16
-	$wl_metabox = new WL_Metabox();     // Everything is done inside here with the correct timing
16
+    $wl_metabox = new WL_Metabox();     // Everything is done inside here with the correct timing
17 17
 }
18 18
 
19 19
 if ( is_admin() ) {
20
-	add_action( 'load-post.php', 'wl_register_metaboxes' );
21
-	add_action( 'load-post-new.php', 'wl_register_metaboxes' );
20
+    add_action( 'load-post.php', 'wl_register_metaboxes' );
21
+    add_action( 'load-post-new.php', 'wl_register_metaboxes' );
22 22
 }
23 23
 
24 24
 
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
  */
30 30
 function wl_admin_add_entities_meta_box( $post_type ) {
31 31
 
32
-	// wl_write_log( "wl_admin_add_entities_meta_box [ post type :: $post_type ]" );
32
+    // wl_write_log( "wl_admin_add_entities_meta_box [ post type :: $post_type ]" );
33 33
 
34
-	// Add main meta box for related entities and 4W
35
-	add_meta_box(
36
-		'wordlift_entities_box', __( 'WordLift', 'wordlift' ), 'wl_entities_box_content', $post_type, 'side', 'high'
37
-	);
34
+    // Add main meta box for related entities and 4W
35
+    add_meta_box(
36
+        'wordlift_entities_box', __( 'WordLift', 'wordlift' ), 'wl_entities_box_content', $post_type, 'side', 'high'
37
+    );
38 38
 }
39 39
 
40 40
 add_action( 'add_meta_boxes', 'wl_admin_add_entities_meta_box' );
@@ -46,90 +46,90 @@  discard block
 block discarded – undo
46 46
  */
47 47
 function wl_entities_box_content( $post ) {
48 48
 
49
-	// wl_write_log( "wl_entities_box_content [ post id :: $post->ID ]" );
50
-
51
-	// Angularjs edit-post widget wrapper
52
-	echo '<div id="wordlift-edit-post-outer-wrapper"></div>';
53
-
54
-	// Angularjs edit-post widget classification boxes configuration
55
-	$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
56
-
57
-	// Array to store all related entities ids
58
-	$all_referenced_entities_ids = array();
59
-
60
-	// Add selected entities to classification_boxes
61
-	foreach ( $classification_boxes as $i => $box ) {
62
-		// Build the proper relation name
63
-		$relation_name = $box['id'];
64
-
65
-		// wl_write_log( "Going to related of $relation_name" );
66
-
67
-		// Get entity ids related to the current post for the given relation name (both draft and published entities)
68
-		$draft_entity_ids   = wl_core_get_related_entity_ids( $post->ID, array(
69
-			'predicate' => $relation_name,
70
-			'status'    => 'draft',
71
-		) );
72
-		$publish_entity_ids = wl_core_get_related_entity_ids( $post->ID, array(
73
-			'predicate' => $relation_name,
74
-			'status'    => 'publish',
75
-		) );
76
-		$entity_ids         = array_unique( array_merge( $draft_entity_ids, $publish_entity_ids ) );
77
-
78
-		// Store the entity ids for all the 4W
79
-		$all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids );
80
-
81
-		// Transform entity ids array in entity uris array
82
-		array_walk( $entity_ids, function ( &$entity_id ) {
83
-			// Retrieve the entity uri for the given entity id
84
-			$entity_id = wl_get_entity_uri( $entity_id );
85
-		} );
86
-
87
-		// Enhance current box selected entities
88
-		$classification_boxes[ $i ]['selectedEntities'] = $entity_ids;
89
-	}
90
-	// Json encoding for classification boxes structure
91
-	$classification_boxes = json_encode( $classification_boxes );
92
-
93
-	// Ensure there are no repetitions of the referenced entities
94
-	$all_referenced_entities_ids = array_unique( $all_referenced_entities_ids );
95
-
96
-	// Build the entity storage object
97
-	$referenced_entities_obj = array();
98
-	foreach ( $all_referenced_entities_ids as $referenced_entity ) {
99
-		$entity                                   = wl_serialize_entity( $referenced_entity );
100
-		$referenced_entities_obj[ $entity['id'] ] = $entity;
101
-	}
102
-
103
-	$referenced_entities_obj = empty( $referenced_entities_obj ) ?
104
-		'{}' : json_encode( $referenced_entities_obj );
105
-
106
-	$published_place_id  = get_post_meta(
107
-		$post->ID, Wordlift_Schema_Service::FIELD_LOCATION_CREATED, true
108
-	);
109
-	$published_place_obj = ( $published_place_id ) ?
110
-		json_encode( wl_serialize_entity( $published_place_id ) ) :
111
-		'undefined';
112
-
113
-	$topic_id  = get_post_meta(
114
-		$post->ID, Wordlift_Schema_Service::FIELD_TOPIC, true
115
-	);
116
-	$topic_obj = ( $topic_id ) ?
117
-		json_encode( wl_serialize_entity( $topic_id ) ) :
118
-		'undefined';
119
-
120
-	$default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH;
121
-	$default_path           = WL_DEFAULT_PATH;
122
-	$dataset_uri            = wl_configuration_get_redlink_dataset_uri();
123
-	$current_post_uri       = wl_get_entity_uri( $post->ID );
124
-
125
-	// Retrieve the current post author
126
-	$post_author = get_userdata( $post->post_author )->display_name;
127
-	// Retrive the published date
128
-	$published_date = get_the_time( 'Y-m-d', $post->ID );
129
-	// Current language
130
-	$current_language = wl_configuration_get_site_language();
131
-
132
-	echo <<<EOF
49
+    // wl_write_log( "wl_entities_box_content [ post id :: $post->ID ]" );
50
+
51
+    // Angularjs edit-post widget wrapper
52
+    echo '<div id="wordlift-edit-post-outer-wrapper"></div>';
53
+
54
+    // Angularjs edit-post widget classification boxes configuration
55
+    $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
56
+
57
+    // Array to store all related entities ids
58
+    $all_referenced_entities_ids = array();
59
+
60
+    // Add selected entities to classification_boxes
61
+    foreach ( $classification_boxes as $i => $box ) {
62
+        // Build the proper relation name
63
+        $relation_name = $box['id'];
64
+
65
+        // wl_write_log( "Going to related of $relation_name" );
66
+
67
+        // Get entity ids related to the current post for the given relation name (both draft and published entities)
68
+        $draft_entity_ids   = wl_core_get_related_entity_ids( $post->ID, array(
69
+            'predicate' => $relation_name,
70
+            'status'    => 'draft',
71
+        ) );
72
+        $publish_entity_ids = wl_core_get_related_entity_ids( $post->ID, array(
73
+            'predicate' => $relation_name,
74
+            'status'    => 'publish',
75
+        ) );
76
+        $entity_ids         = array_unique( array_merge( $draft_entity_ids, $publish_entity_ids ) );
77
+
78
+        // Store the entity ids for all the 4W
79
+        $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids );
80
+
81
+        // Transform entity ids array in entity uris array
82
+        array_walk( $entity_ids, function ( &$entity_id ) {
83
+            // Retrieve the entity uri for the given entity id
84
+            $entity_id = wl_get_entity_uri( $entity_id );
85
+        } );
86
+
87
+        // Enhance current box selected entities
88
+        $classification_boxes[ $i ]['selectedEntities'] = $entity_ids;
89
+    }
90
+    // Json encoding for classification boxes structure
91
+    $classification_boxes = json_encode( $classification_boxes );
92
+
93
+    // Ensure there are no repetitions of the referenced entities
94
+    $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids );
95
+
96
+    // Build the entity storage object
97
+    $referenced_entities_obj = array();
98
+    foreach ( $all_referenced_entities_ids as $referenced_entity ) {
99
+        $entity                                   = wl_serialize_entity( $referenced_entity );
100
+        $referenced_entities_obj[ $entity['id'] ] = $entity;
101
+    }
102
+
103
+    $referenced_entities_obj = empty( $referenced_entities_obj ) ?
104
+        '{}' : json_encode( $referenced_entities_obj );
105
+
106
+    $published_place_id  = get_post_meta(
107
+        $post->ID, Wordlift_Schema_Service::FIELD_LOCATION_CREATED, true
108
+    );
109
+    $published_place_obj = ( $published_place_id ) ?
110
+        json_encode( wl_serialize_entity( $published_place_id ) ) :
111
+        'undefined';
112
+
113
+    $topic_id  = get_post_meta(
114
+        $post->ID, Wordlift_Schema_Service::FIELD_TOPIC, true
115
+    );
116
+    $topic_obj = ( $topic_id ) ?
117
+        json_encode( wl_serialize_entity( $topic_id ) ) :
118
+        'undefined';
119
+
120
+    $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH;
121
+    $default_path           = WL_DEFAULT_PATH;
122
+    $dataset_uri            = wl_configuration_get_redlink_dataset_uri();
123
+    $current_post_uri       = wl_get_entity_uri( $post->ID );
124
+
125
+    // Retrieve the current post author
126
+    $post_author = get_userdata( $post->post_author )->display_name;
127
+    // Retrive the published date
128
+    $published_date = get_the_time( 'Y-m-d', $post->ID );
129
+    // Current language
130
+    $current_language = wl_configuration_get_site_language();
131
+
132
+    echo <<<EOF
133 133
     <script type="text/javascript">
134 134
         jQuery( function() {
135 135
 
Please login to merge, or discard this patch.
Spacing   +34 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 function wl_register_metaboxes() {
12 12
 
13 13
 	// Load metabox classes
14
-	require_once( 'WL_Metabox/class-wl-metabox.php' );
14
+	require_once('WL_Metabox/class-wl-metabox.php');
15 15
 
16
-	$wl_metabox = new WL_Metabox();     // Everything is done inside here with the correct timing
16
+	$wl_metabox = new WL_Metabox(); // Everything is done inside here with the correct timing
17 17
 }
18 18
 
19
-if ( is_admin() ) {
20
-	add_action( 'load-post.php', 'wl_register_metaboxes' );
21
-	add_action( 'load-post-new.php', 'wl_register_metaboxes' );
19
+if (is_admin()) {
20
+	add_action('load-post.php', 'wl_register_metaboxes');
21
+	add_action('load-post-new.php', 'wl_register_metaboxes');
22 22
 }
23 23
 
24 24
 
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
  *
28 28
  * @param string $post_type The type of the current open post.
29 29
  */
30
-function wl_admin_add_entities_meta_box( $post_type ) {
30
+function wl_admin_add_entities_meta_box($post_type) {
31 31
 
32 32
 	// wl_write_log( "wl_admin_add_entities_meta_box [ post type :: $post_type ]" );
33 33
 
34 34
 	// Add main meta box for related entities and 4W
35 35
 	add_meta_box(
36
-		'wordlift_entities_box', __( 'WordLift', 'wordlift' ), 'wl_entities_box_content', $post_type, 'side', 'high'
36
+		'wordlift_entities_box', __('WordLift', 'wordlift'), 'wl_entities_box_content', $post_type, 'side', 'high'
37 37
 	);
38 38
 }
39 39
 
40
-add_action( 'add_meta_boxes', 'wl_admin_add_entities_meta_box' );
40
+add_action('add_meta_boxes', 'wl_admin_add_entities_meta_box');
41 41
 
42 42
 /**
43 43
  * Displays the meta box contents (called by *add_meta_box* callback).
44 44
  *
45 45
  * @param WP_Post $post The current post.
46 46
  */
47
-function wl_entities_box_content( $post ) {
47
+function wl_entities_box_content($post) {
48 48
 
49 49
 	// wl_write_log( "wl_entities_box_content [ post id :: $post->ID ]" );
50 50
 
@@ -52,80 +52,78 @@  discard block
 block discarded – undo
52 52
 	echo '<div id="wordlift-edit-post-outer-wrapper"></div>';
53 53
 
54 54
 	// Angularjs edit-post widget classification boxes configuration
55
-	$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
55
+	$classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES);
56 56
 
57 57
 	// Array to store all related entities ids
58 58
 	$all_referenced_entities_ids = array();
59 59
 
60 60
 	// Add selected entities to classification_boxes
61
-	foreach ( $classification_boxes as $i => $box ) {
61
+	foreach ($classification_boxes as $i => $box) {
62 62
 		// Build the proper relation name
63 63
 		$relation_name = $box['id'];
64 64
 
65 65
 		// wl_write_log( "Going to related of $relation_name" );
66 66
 
67 67
 		// Get entity ids related to the current post for the given relation name (both draft and published entities)
68
-		$draft_entity_ids   = wl_core_get_related_entity_ids( $post->ID, array(
68
+		$draft_entity_ids = wl_core_get_related_entity_ids($post->ID, array(
69 69
 			'predicate' => $relation_name,
70 70
 			'status'    => 'draft',
71
-		) );
72
-		$publish_entity_ids = wl_core_get_related_entity_ids( $post->ID, array(
71
+		));
72
+		$publish_entity_ids = wl_core_get_related_entity_ids($post->ID, array(
73 73
 			'predicate' => $relation_name,
74 74
 			'status'    => 'publish',
75
-		) );
76
-		$entity_ids         = array_unique( array_merge( $draft_entity_ids, $publish_entity_ids ) );
75
+		));
76
+		$entity_ids = array_unique(array_merge($draft_entity_ids, $publish_entity_ids));
77 77
 
78 78
 		// Store the entity ids for all the 4W
79
-		$all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids );
79
+		$all_referenced_entities_ids = array_merge($all_referenced_entities_ids, $entity_ids);
80 80
 
81 81
 		// Transform entity ids array in entity uris array
82
-		array_walk( $entity_ids, function ( &$entity_id ) {
82
+		array_walk($entity_ids, function(&$entity_id) {
83 83
 			// Retrieve the entity uri for the given entity id
84
-			$entity_id = wl_get_entity_uri( $entity_id );
84
+			$entity_id = wl_get_entity_uri($entity_id);
85 85
 		} );
86 86
 
87 87
 		// Enhance current box selected entities
88
-		$classification_boxes[ $i ]['selectedEntities'] = $entity_ids;
88
+		$classification_boxes[$i]['selectedEntities'] = $entity_ids;
89 89
 	}
90 90
 	// Json encoding for classification boxes structure
91
-	$classification_boxes = json_encode( $classification_boxes );
91
+	$classification_boxes = json_encode($classification_boxes);
92 92
 
93 93
 	// Ensure there are no repetitions of the referenced entities
94
-	$all_referenced_entities_ids = array_unique( $all_referenced_entities_ids );
94
+	$all_referenced_entities_ids = array_unique($all_referenced_entities_ids);
95 95
 
96 96
 	// Build the entity storage object
97 97
 	$referenced_entities_obj = array();
98
-	foreach ( $all_referenced_entities_ids as $referenced_entity ) {
99
-		$entity                                   = wl_serialize_entity( $referenced_entity );
100
-		$referenced_entities_obj[ $entity['id'] ] = $entity;
98
+	foreach ($all_referenced_entities_ids as $referenced_entity) {
99
+		$entity                                   = wl_serialize_entity($referenced_entity);
100
+		$referenced_entities_obj[$entity['id']] = $entity;
101 101
 	}
102 102
 
103
-	$referenced_entities_obj = empty( $referenced_entities_obj ) ?
104
-		'{}' : json_encode( $referenced_entities_obj );
103
+	$referenced_entities_obj = empty($referenced_entities_obj) ?
104
+		'{}' : json_encode($referenced_entities_obj);
105 105
 
106 106
 	$published_place_id  = get_post_meta(
107 107
 		$post->ID, Wordlift_Schema_Service::FIELD_LOCATION_CREATED, true
108 108
 	);
109
-	$published_place_obj = ( $published_place_id ) ?
110
-		json_encode( wl_serialize_entity( $published_place_id ) ) :
111
-		'undefined';
109
+	$published_place_obj = ($published_place_id) ?
110
+		json_encode(wl_serialize_entity($published_place_id)) : 'undefined';
112 111
 
113 112
 	$topic_id  = get_post_meta(
114 113
 		$post->ID, Wordlift_Schema_Service::FIELD_TOPIC, true
115 114
 	);
116
-	$topic_obj = ( $topic_id ) ?
117
-		json_encode( wl_serialize_entity( $topic_id ) ) :
118
-		'undefined';
115
+	$topic_obj = ($topic_id) ?
116
+		json_encode(wl_serialize_entity($topic_id)) : 'undefined';
119 117
 
120 118
 	$default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH;
121 119
 	$default_path           = WL_DEFAULT_PATH;
122 120
 	$dataset_uri            = wl_configuration_get_redlink_dataset_uri();
123
-	$current_post_uri       = wl_get_entity_uri( $post->ID );
121
+	$current_post_uri       = wl_get_entity_uri($post->ID);
124 122
 
125 123
 	// Retrieve the current post author
126
-	$post_author = get_userdata( $post->post_author )->display_name;
124
+	$post_author = get_userdata($post->post_author)->display_name;
127 125
 	// Retrive the published date
128
-	$published_date = get_the_time( 'Y-m-d', $post->ID );
126
+	$published_date = get_the_time('Y-m-d', $post->ID);
129 127
 	// Current language
130 128
 	$current_language = wl_configuration_get_site_language();
131 129
 
Please login to merge, or discard this patch.