Completed
Push — develop ( 39f279...fe90ef )
by David
05:06
created
src/admin/wordlift_admin_edit_post.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,23 +16,23 @@
 block discarded – undo
16 16
  */
17 17
 function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) {
18 18
 
19
-	// If the post is published, add the button to view Redlink's linked data.
20
-	if ( 'publish' == get_post_status( $post_id ) ) {
21
-		if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
-			$uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
-			$lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
-			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small' target='_blank'>" .
25
-			         __( 'View Linked Data', 'wordlift' ) .
26
-			         "</a></span>\n";
27
-		}
28
-		$html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
-		         urlencode( get_permalink( $post_id ) ) .
30
-		         "' class='button button-small' target='_blank'>" .
31
-		         __( 'Test Google Rich Snippets', 'wordlift' ) .
32
-		         "</a></span>\n";
33
-	}
19
+    // If the post is published, add the button to view Redlink's linked data.
20
+    if ( 'publish' == get_post_status( $post_id ) ) {
21
+        if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
+            $uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
+            $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
+            $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small' target='_blank'>" .
25
+                        __( 'View Linked Data', 'wordlift' ) .
26
+                        "</a></span>\n";
27
+        }
28
+        $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
+                    urlencode( get_permalink( $post_id ) ) .
30
+                    "' class='button button-small' target='_blank'>" .
31
+                    __( 'Test Google Rich Snippets', 'wordlift' ) .
32
+                    "</a></span>\n";
33
+    }
34 34
 
35
-	return $html;
35
+    return $html;
36 36
 }
37 37
 
38 38
 add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4 );
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,25 +14,25 @@
 block discarded – undo
14 14
  *
15 15
  * @return The enhanced html.
16 16
  */
17
-function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) {
17
+function wl_admin_permalink_html($html, $post_id, $new_title, $new_slug) {
18 18
 
19 19
 	// If the post is published, add the button to view Redlink's linked data.
20
-	if ( 'publish' == get_post_status( $post_id ) ) {
21
-		if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
-			$uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
-			$lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
-			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small' target='_blank'>" .
25
-			         __( 'View Linked Data', 'wordlift' ) .
20
+	if ('publish' == get_post_status($post_id)) {
21
+		if ($uri = wl_get_entity_uri($post_id)) {
22
+			$uri_esc       = esc_attr(wl_get_entity_uri($post_id));
23
+			$lod_view_href = 'http://lodview.it/lodview/?IRI='.$uri_esc;
24
+			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small' target='_blank'>".
25
+			         __('View Linked Data', 'wordlift').
26 26
 			         "</a></span>\n";
27 27
 		}
28
-		$html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
-		         urlencode( get_permalink( $post_id ) ) .
30
-		         "' class='button button-small' target='_blank'>" .
31
-		         __( 'Test Google Rich Snippets', 'wordlift' ) .
28
+		$html .= "<span id='view-post-btn'><a href='".WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL.
29
+		         urlencode(get_permalink($post_id)).
30
+		         "' class='button button-small' target='_blank'>".
31
+		         __('Test Google Rich Snippets', 'wordlift').
32 32
 		         "</a></span>\n";
33 33
 	}
34 34
 
35 35
 	return $html;
36 36
 }
37 37
 
38
-add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4 );
39 38
\ No newline at end of file
39
+add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4);
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-service.php 2 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -7,287 +7,287 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Entity_Service {
9 9
 
10
-	/**
11
-	 * The Log service.
12
-	 *
13
-	 * @since 3.2.0
14
-	 * @access private
15
-	 * @var \Wordlift_Log_Service $log_service The Log service.
16
-	 */
17
-	private $log_service;
18
-
19
-	/**
20
-	 * The UI service.
21
-	 *
22
-	 * @since 3.2.0
23
-	 * @access private
24
-	 * @var \Wordlift_UI_Service $ui_service The UI service.
25
-	 */
26
-	private $ui_service;
27
-
28
-	/**
29
-	 * The entity post type name.
30
-	 *
31
-	 * @since 3.1.0
32
-	 */
33
-	const TYPE_NAME = 'entity';
34
-
35
-	/**
36
-	 * The alternative label meta key.
37
-	 *
38
-	 * @since 3.2.0
39
-	 */
40
-	const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
41
-
42
-	/**
43
-	 * The alternative label input template.
44
-	 *
45
-	 * @since 3.2.0
46
-	 */
47
-	// TODO: this should be moved to a class that deals with HTML code.
48
-	const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
10
+    /**
11
+     * The Log service.
12
+     *
13
+     * @since 3.2.0
14
+     * @access private
15
+     * @var \Wordlift_Log_Service $log_service The Log service.
16
+     */
17
+    private $log_service;
18
+
19
+    /**
20
+     * The UI service.
21
+     *
22
+     * @since 3.2.0
23
+     * @access private
24
+     * @var \Wordlift_UI_Service $ui_service The UI service.
25
+     */
26
+    private $ui_service;
27
+
28
+    /**
29
+     * The entity post type name.
30
+     *
31
+     * @since 3.1.0
32
+     */
33
+    const TYPE_NAME = 'entity';
34
+
35
+    /**
36
+     * The alternative label meta key.
37
+     *
38
+     * @since 3.2.0
39
+     */
40
+    const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
41
+
42
+    /**
43
+     * The alternative label input template.
44
+     *
45
+     * @since 3.2.0
46
+     */
47
+    // TODO: this should be moved to a class that deals with HTML code.
48
+    const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
49 49
                 <label class="screen-reader-text" id="wl-alternative-label-prompt-text" for="wl-alternative-label">Enter alternative label here</label>
50 50
                 <input name="wl_alternative_label[]" size="30" value="%s" id="wl-alternative-label" type="text">
51 51
                 <button class="button wl-delete-button">%s</button>
52 52
                 </div>';
53 53
 
54
-	/**
55
-	 * A singleton instance of the Entity service.
56
-	 *
57
-	 * @since 3.2.0
58
-	 * @access private
59
-	 * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
60
-	 */
61
-	private static $instance;
62
-
63
-	/**
64
-	 * Create a Wordlift_Entity_Service instance.
65
-	 *
66
-	 * @since 3.2.0
67
-	 *
68
-	 * @param \Wordlift_UI_Service $ui_service The UI service.
69
-	 */
70
-	public function __construct( $ui_service ) {
71
-
72
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
73
-
74
-		// Set the UI service.
75
-		$this->ui_service = $ui_service;
76
-
77
-		// Set the singleton instance.
78
-		self::$instance = $this;
79
-
80
-	}
81
-
82
-	/**
83
-	 * Get the singleton instance of the Entity service.
84
-	 *
85
-	 * @since 3.2.0
86
-	 * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
87
-	 */
88
-	public static function get_instance() {
89
-
90
-		return self::$instance;
91
-	}
92
-
93
-	/**
94
-	 * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
95
-	 * its specific function).
96
-	 *
97
-	 * @since 3.1.0
98
-	 *
99
-	 * @return array An array of post IDs.
100
-	 */
101
-	public function get_all_related_to_last_50_published_posts() {
102
-
103
-		// Global timeline. Get entities from the latest posts.
104
-		$latest_posts_ids = get_posts( array(
105
-			'numberposts' => 50,
106
-			'fields'      => 'ids', //only get post IDs
107
-			'post_type'   => 'post',
108
-			'post_status' => 'publish'
109
-		) );
110
-
111
-		if ( empty( $latest_posts_ids ) ) {
112
-			// There are no posts.
113
-			return array();
114
-		}
115
-
116
-		// Collect entities related to latest posts
117
-		$entity_ids = array();
118
-		foreach ( $latest_posts_ids as $id ) {
119
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
120
-				'status' => 'publish'
121
-			) ) );
122
-		}
123
-
124
-		return $entity_ids;
125
-	}
126
-
127
-	/**
128
-	 * Determines whether a post is an entity or not.
129
-	 *
130
-	 * @since 3.1.0
131
-	 *
132
-	 * @param int $post_id A post id.
133
-	 *
134
-	 * @return true if the post is an entity otherwise false.
135
-	 */
136
-	public function is_entity( $post_id ) {
137
-
138
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
139
-	}
140
-
141
-	/**
142
-	 * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
143
-	 *
144
-	 * @since 3.2.0
145
-	 *
146
-	 * @param string $uri The entity URI.
147
-	 *
148
-	 * @return WP_Post|null A WP_Post instance or null if not found.
149
-	 */
150
-	public function get_entity_post_by_uri( $uri ) {
151
-
152
-		$query = new WP_Query( array(
153
-				'posts_per_page' => 1,
154
-				'post_status'    => 'any',
155
-				'post_type'      => self::TYPE_NAME,
156
-				'meta_query'     => array(
157
-					'relation' => 'OR',
158
-					array(
159
-						'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
160
-						'value'   => $uri,
161
-						'compare' => '='
162
-					),
163
-					array(
164
-						'key'     => WL_ENTITY_URL_META_NAME,
165
-						'value'   => $uri,
166
-						'compare' => '='
167
-					)
168
-				)
169
-			)
170
-		);
171
-
172
-		// Get the matching entity posts.
173
-		$posts = $query->get_posts();
174
-
175
-		// Return null if no post is found.
176
-		if ( 0 === count( $posts ) ) {
177
-			return null;
178
-		}
179
-
180
-		// Return the found post.
181
-		return $posts[0];
182
-	}
183
-
184
-	/**
185
-	 * Fires once a post has been saved.
186
-	 *
187
-	 * @since 3.2.0
188
-	 *
189
-	 * @param int $post_id Post ID.
190
-	 * @param WP_Post $post Post object.
191
-	 * @param bool $update Whether this is an existing post being updated or not.
192
-	 */
193
-	public function save_post( $post_id, $post, $update ) {
194
-
195
-		// If it's not an entity, return.
196
-		if ( ! $this->is_entity( $post_id ) ) {
197
-			return;
198
-		}
199
-
200
-		// Get the alt labels from the request (or empty array).
201
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
202
-
203
-		// Set the alternative labels.
204
-		$this->set_alternative_labels( $post_id, $alt_labels );
205
-
206
-	}
207
-
208
-	/**
209
-	 * Set the alternative labels.
210
-	 *
211
-	 * @since 3.2.0
212
-	 *
213
-	 * @param int $post_id The post id.
214
-	 * @param array $alt_labels An array of labels.
215
-	 */
216
-	public function set_alternative_labels( $post_id, $alt_labels ) {
54
+    /**
55
+     * A singleton instance of the Entity service.
56
+     *
57
+     * @since 3.2.0
58
+     * @access private
59
+     * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
60
+     */
61
+    private static $instance;
62
+
63
+    /**
64
+     * Create a Wordlift_Entity_Service instance.
65
+     *
66
+     * @since 3.2.0
67
+     *
68
+     * @param \Wordlift_UI_Service $ui_service The UI service.
69
+     */
70
+    public function __construct( $ui_service ) {
71
+
72
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
73
+
74
+        // Set the UI service.
75
+        $this->ui_service = $ui_service;
76
+
77
+        // Set the singleton instance.
78
+        self::$instance = $this;
79
+
80
+    }
81
+
82
+    /**
83
+     * Get the singleton instance of the Entity service.
84
+     *
85
+     * @since 3.2.0
86
+     * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
87
+     */
88
+    public static function get_instance() {
89
+
90
+        return self::$instance;
91
+    }
92
+
93
+    /**
94
+     * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
95
+     * its specific function).
96
+     *
97
+     * @since 3.1.0
98
+     *
99
+     * @return array An array of post IDs.
100
+     */
101
+    public function get_all_related_to_last_50_published_posts() {
102
+
103
+        // Global timeline. Get entities from the latest posts.
104
+        $latest_posts_ids = get_posts( array(
105
+            'numberposts' => 50,
106
+            'fields'      => 'ids', //only get post IDs
107
+            'post_type'   => 'post',
108
+            'post_status' => 'publish'
109
+        ) );
110
+
111
+        if ( empty( $latest_posts_ids ) ) {
112
+            // There are no posts.
113
+            return array();
114
+        }
115
+
116
+        // Collect entities related to latest posts
117
+        $entity_ids = array();
118
+        foreach ( $latest_posts_ids as $id ) {
119
+            $entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
120
+                'status' => 'publish'
121
+            ) ) );
122
+        }
123
+
124
+        return $entity_ids;
125
+    }
126
+
127
+    /**
128
+     * Determines whether a post is an entity or not.
129
+     *
130
+     * @since 3.1.0
131
+     *
132
+     * @param int $post_id A post id.
133
+     *
134
+     * @return true if the post is an entity otherwise false.
135
+     */
136
+    public function is_entity( $post_id ) {
137
+
138
+        return ( self::TYPE_NAME === get_post_type( $post_id ) );
139
+    }
140
+
141
+    /**
142
+     * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
143
+     *
144
+     * @since 3.2.0
145
+     *
146
+     * @param string $uri The entity URI.
147
+     *
148
+     * @return WP_Post|null A WP_Post instance or null if not found.
149
+     */
150
+    public function get_entity_post_by_uri( $uri ) {
151
+
152
+        $query = new WP_Query( array(
153
+                'posts_per_page' => 1,
154
+                'post_status'    => 'any',
155
+                'post_type'      => self::TYPE_NAME,
156
+                'meta_query'     => array(
157
+                    'relation' => 'OR',
158
+                    array(
159
+                        'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
160
+                        'value'   => $uri,
161
+                        'compare' => '='
162
+                    ),
163
+                    array(
164
+                        'key'     => WL_ENTITY_URL_META_NAME,
165
+                        'value'   => $uri,
166
+                        'compare' => '='
167
+                    )
168
+                )
169
+            )
170
+        );
171
+
172
+        // Get the matching entity posts.
173
+        $posts = $query->get_posts();
174
+
175
+        // Return null if no post is found.
176
+        if ( 0 === count( $posts ) ) {
177
+            return null;
178
+        }
179
+
180
+        // Return the found post.
181
+        return $posts[0];
182
+    }
183
+
184
+    /**
185
+     * Fires once a post has been saved.
186
+     *
187
+     * @since 3.2.0
188
+     *
189
+     * @param int $post_id Post ID.
190
+     * @param WP_Post $post Post object.
191
+     * @param bool $update Whether this is an existing post being updated or not.
192
+     */
193
+    public function save_post( $post_id, $post, $update ) {
194
+
195
+        // If it's not an entity, return.
196
+        if ( ! $this->is_entity( $post_id ) ) {
197
+            return;
198
+        }
199
+
200
+        // Get the alt labels from the request (or empty array).
201
+        $alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
202
+
203
+        // Set the alternative labels.
204
+        $this->set_alternative_labels( $post_id, $alt_labels );
205
+
206
+    }
207
+
208
+    /**
209
+     * Set the alternative labels.
210
+     *
211
+     * @since 3.2.0
212
+     *
213
+     * @param int $post_id The post id.
214
+     * @param array $alt_labels An array of labels.
215
+     */
216
+    public function set_alternative_labels( $post_id, $alt_labels ) {
217 217
 		
218
-		// Force $alt_labels to be an array
219
-		if( !is_array( $alt_labels ) ) {
220
-			$alt_labels = array( $alt_labels );
221
-		}
218
+        // Force $alt_labels to be an array
219
+        if( !is_array( $alt_labels ) ) {
220
+            $alt_labels = array( $alt_labels );
221
+        }
222 222
 
223
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
223
+        $this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
224 224
 
225
-		// Delete all the existing alternate labels.
226
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
225
+        // Delete all the existing alternate labels.
226
+        delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
227 227
 		
228
-		// Set the alternative labels.
229
-		foreach ( $alt_labels as $alt_label ) {
230
-			if ( ! empty( $alt_label ) ) {
231
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
232
-			}
233
-		}
234
-
235
-	}
236
-
237
-	/**
238
-	 * Retrieve the alternate labels.
239
-	 *
240
-	 * @since 3.2.0
241
-	 *
242
-	 * @param int $post_id Post id.
243
-	 *
244
-	 * @return mixed An array  of alternative labels.
245
-	 */
246
-	public function get_alternative_labels( $post_id ) {
247
-
248
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
249
-	}
250
-
251
-	/**
252
-	 * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
253
-	 *
254
-	 * @since 3.2.0
255
-	 *
256
-	 * @param WP_Post $post Post object.
257
-	 */
258
-	public function edit_form_before_permalink( $post ) {
259
-
260
-		// If it's not an entity, return.
261
-		if ( ! $this->is_entity( $post->ID ) ) {
262
-			return;
263
-		}
264
-
265
-		// Print the input template.
266
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
267
-
268
-		// Print all the currently set alternative labels.
269
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
270
-
271
-			echo $this->get_alternative_label_input( $alt_label );
272
-
273
-		};
274
-
275
-		// Print the button.
276
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
277
-
278
-	}
279
-
280
-	/**
281
-	 * Get the alternative label input HTML code.
282
-	 *
283
-	 * @since 3.2.0
284
-	 *
285
-	 * @param string $value The input value.
286
-	 *
287
-	 * @return string The input HTML code.
288
-	 */
289
-	private function get_alternative_label_input( $value = '' ) {
290
-
291
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
292
-	}
228
+        // Set the alternative labels.
229
+        foreach ( $alt_labels as $alt_label ) {
230
+            if ( ! empty( $alt_label ) ) {
231
+                add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
232
+            }
233
+        }
234
+
235
+    }
236
+
237
+    /**
238
+     * Retrieve the alternate labels.
239
+     *
240
+     * @since 3.2.0
241
+     *
242
+     * @param int $post_id Post id.
243
+     *
244
+     * @return mixed An array  of alternative labels.
245
+     */
246
+    public function get_alternative_labels( $post_id ) {
247
+
248
+        return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
249
+    }
250
+
251
+    /**
252
+     * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
253
+     *
254
+     * @since 3.2.0
255
+     *
256
+     * @param WP_Post $post Post object.
257
+     */
258
+    public function edit_form_before_permalink( $post ) {
259
+
260
+        // If it's not an entity, return.
261
+        if ( ! $this->is_entity( $post->ID ) ) {
262
+            return;
263
+        }
264
+
265
+        // Print the input template.
266
+        $this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
267
+
268
+        // Print all the currently set alternative labels.
269
+        foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
270
+
271
+            echo $this->get_alternative_label_input( $alt_label );
272
+
273
+        };
274
+
275
+        // Print the button.
276
+        $this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
277
+
278
+    }
279
+
280
+    /**
281
+     * Get the alternative label input HTML code.
282
+     *
283
+     * @since 3.2.0
284
+     *
285
+     * @param string $value The input value.
286
+     *
287
+     * @return string The input HTML code.
288
+     */
289
+    private function get_alternative_label_input( $value = '' ) {
290
+
291
+        return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
292
+    }
293 293
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @param \Wordlift_UI_Service $ui_service The UI service.
69 69
 	 */
70
-	public function __construct( $ui_service ) {
70
+	public function __construct($ui_service) {
71 71
 
72
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
72
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service');
73 73
 
74 74
 		// Set the UI service.
75 75
 		$this->ui_service = $ui_service;
@@ -101,24 +101,24 @@  discard block
 block discarded – undo
101 101
 	public function get_all_related_to_last_50_published_posts() {
102 102
 
103 103
 		// Global timeline. Get entities from the latest posts.
104
-		$latest_posts_ids = get_posts( array(
104
+		$latest_posts_ids = get_posts(array(
105 105
 			'numberposts' => 50,
106 106
 			'fields'      => 'ids', //only get post IDs
107 107
 			'post_type'   => 'post',
108 108
 			'post_status' => 'publish'
109
-		) );
109
+		));
110 110
 
111
-		if ( empty( $latest_posts_ids ) ) {
111
+		if (empty($latest_posts_ids)) {
112 112
 			// There are no posts.
113 113
 			return array();
114 114
 		}
115 115
 
116 116
 		// Collect entities related to latest posts
117 117
 		$entity_ids = array();
118
-		foreach ( $latest_posts_ids as $id ) {
119
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
118
+		foreach ($latest_posts_ids as $id) {
119
+			$entity_ids = array_merge($entity_ids, wl_core_get_related_entity_ids($id, array(
120 120
 				'status' => 'publish'
121
-			) ) );
121
+			)));
122 122
 		}
123 123
 
124 124
 		return $entity_ids;
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return true if the post is an entity otherwise false.
135 135
 	 */
136
-	public function is_entity( $post_id ) {
136
+	public function is_entity($post_id) {
137 137
 
138
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
138
+		return (self::TYPE_NAME === get_post_type($post_id));
139 139
 	}
140 140
 
141 141
 	/**
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @return WP_Post|null A WP_Post instance or null if not found.
149 149
 	 */
150
-	public function get_entity_post_by_uri( $uri ) {
150
+	public function get_entity_post_by_uri($uri) {
151 151
 
152
-		$query = new WP_Query( array(
152
+		$query = new WP_Query(array(
153 153
 				'posts_per_page' => 1,
154 154
 				'post_status'    => 'any',
155 155
 				'post_type'      => self::TYPE_NAME,
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		$posts = $query->get_posts();
174 174
 
175 175
 		// Return null if no post is found.
176
-		if ( 0 === count( $posts ) ) {
176
+		if (0 === count($posts)) {
177 177
 			return null;
178 178
 		}
179 179
 
@@ -190,18 +190,18 @@  discard block
 block discarded – undo
190 190
 	 * @param WP_Post $post Post object.
191 191
 	 * @param bool $update Whether this is an existing post being updated or not.
192 192
 	 */
193
-	public function save_post( $post_id, $post, $update ) {
193
+	public function save_post($post_id, $post, $update) {
194 194
 
195 195
 		// If it's not an entity, return.
196
-		if ( ! $this->is_entity( $post_id ) ) {
196
+		if ( ! $this->is_entity($post_id)) {
197 197
 			return;
198 198
 		}
199 199
 
200 200
 		// Get the alt labels from the request (or empty array).
201
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
201
+		$alt_labels = isset($_REQUEST['wl_alternative_label']) ? $_REQUEST['wl_alternative_label'] : array();
202 202
 
203 203
 		// Set the alternative labels.
204
-		$this->set_alternative_labels( $post_id, $alt_labels );
204
+		$this->set_alternative_labels($post_id, $alt_labels);
205 205
 
206 206
 	}
207 207
 
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
 	 * @param int $post_id The post id.
214 214
 	 * @param array $alt_labels An array of labels.
215 215
 	 */
216
-	public function set_alternative_labels( $post_id, $alt_labels ) {
216
+	public function set_alternative_labels($post_id, $alt_labels) {
217 217
 		
218 218
 		// Force $alt_labels to be an array
219
-		if( !is_array( $alt_labels ) ) {
220
-			$alt_labels = array( $alt_labels );
219
+		if ( ! is_array($alt_labels)) {
220
+			$alt_labels = array($alt_labels);
221 221
 		}
222 222
 
223
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
223
+		$this->log_service->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels)." ]");
224 224
 
225 225
 		// Delete all the existing alternate labels.
226
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
226
+		delete_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
227 227
 		
228 228
 		// Set the alternative labels.
229
-		foreach ( $alt_labels as $alt_label ) {
230
-			if ( ! empty( $alt_label ) ) {
231
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
229
+		foreach ($alt_labels as $alt_label) {
230
+			if ( ! empty($alt_label)) {
231
+				add_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label);
232 232
 			}
233 233
 		}
234 234
 
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @return mixed An array  of alternative labels.
245 245
 	 */
246
-	public function get_alternative_labels( $post_id ) {
246
+	public function get_alternative_labels($post_id) {
247 247
 
248
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
248
+		return get_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,25 +255,25 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @param WP_Post $post Post object.
257 257
 	 */
258
-	public function edit_form_before_permalink( $post ) {
258
+	public function edit_form_before_permalink($post) {
259 259
 
260 260
 		// If it's not an entity, return.
261
-		if ( ! $this->is_entity( $post->ID ) ) {
261
+		if ( ! $this->is_entity($post->ID)) {
262 262
 			return;
263 263
 		}
264 264
 
265 265
 		// Print the input template.
266
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
266
+		$this->ui_service->print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input());
267 267
 
268 268
 		// Print all the currently set alternative labels.
269
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
269
+		foreach ($this->get_alternative_labels($post->ID) as $alt_label) {
270 270
 
271
-			echo $this->get_alternative_label_input( $alt_label );
271
+			echo $this->get_alternative_label_input($alt_label);
272 272
 
273 273
 		};
274 274
 
275 275
 		// Print the button.
276
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
276
+		$this->ui_service->print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift'));
277 277
 
278 278
 	}
279 279
 
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @return string The input HTML code.
288 288
 	 */
289
-	private function get_alternative_label_input( $value = '' ) {
289
+	private function get_alternative_label_input($value = '') {
290 290
 
291
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
291
+		return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), __('Delete', 'wordlift'));
292 292
 	}
293 293
 }
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_entity_api.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * This file provides functions to get entities.
4
- *
5
- * @since 3.0.0
6
- */
3
+     * This file provides functions to get entities.
4
+     *
5
+     * @since 3.0.0
6
+     */
7 7
 
8 8
 
9 9
 /**
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
  * @return array An array of WP_Post instances.
20 20
  */
21 21
 function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true ) {
22
-	global $wpdb;
22
+    global $wpdb;
23 23
 
24
-	// Search by substring
25
-	if ( $autocomplete ) {
26
-		$title = $title . '%';
27
-	}
24
+    // Search by substring
25
+    if ( $autocomplete ) {
26
+        $title = $title . '%';
27
+    }
28 28
 
29 29
 //	// The title is a LIKE query.
30 30
 //	$query = "SELECT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug" .
@@ -37,40 +37,40 @@  discard block
 block discarded – undo
37 37
 //
38 38
 //	return $wpdb->get_results( $wpdb->prepare( $query, $title, Wordlift_Entity_Service::TYPE_NAME ) );
39 39
 
40
-	// The title is a LIKE query.
41
-	$query = "SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug"
42
-	         . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t"
43
-	         . "  WHERE p.post_type= %s"
44
-	         . "   AND p.post_title LIKE %s"
45
-	         . "   AND t.term_id = tt.term_id"
46
-	         . "   AND tt.taxonomy = %s"
47
-	         . "   AND tt.term_taxonomy_id = tr.term_taxonomy_id"
48
-	         . "   AND tr.object_id = p.ID";
40
+    // The title is a LIKE query.
41
+    $query = "SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug"
42
+                . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t"
43
+                . "  WHERE p.post_type= %s"
44
+                . "   AND p.post_title LIKE %s"
45
+                . "   AND t.term_id = tt.term_id"
46
+                . "   AND tt.taxonomy = %s"
47
+                . "   AND tt.term_taxonomy_id = tr.term_taxonomy_id"
48
+                . "   AND tr.object_id = p.ID";
49 49
 	
50
-	if( $include_alias ) {
50
+    if( $include_alias ) {
51 51
 	    
52
-		$query.= " UNION"
53
-	         . "  SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug"
54
-	         . "  FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m"
55
-	         . "   WHERE p.post_type= %s"
56
-	         . "    AND m.meta_key = %s AND m.meta_value LIKE %s"
57
-	         . "    AND m.post_id = p.ID"
58
-	         . "    AND t.term_id = tt.term_id"
59
-	         . "    AND tt.taxonomy = %s"
60
-	         . "    AND tt.term_taxonomy_id = tr.term_taxonomy_id"
61
-	         . "    AND tr.object_id = p.ID";
62
-	}
63
-
64
-	return $wpdb->get_results( $wpdb->prepare(
65
-		$query,
66
-		Wordlift_Entity_Service::TYPE_NAME,
67
-		$title,
68
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
69
-		Wordlift_Entity_Service::TYPE_NAME,
70
-		Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
71
-		$title,
72
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME
73
-	) );
52
+        $query.= " UNION"
53
+                . "  SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug"
54
+                . "  FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m"
55
+                . "   WHERE p.post_type= %s"
56
+                . "    AND m.meta_key = %s AND m.meta_value LIKE %s"
57
+                . "    AND m.post_id = p.ID"
58
+                . "    AND t.term_id = tt.term_id"
59
+                . "    AND tt.taxonomy = %s"
60
+                . "    AND tt.term_taxonomy_id = tr.term_taxonomy_id"
61
+                . "    AND tr.object_id = p.ID";
62
+    }
63
+
64
+    return $wpdb->get_results( $wpdb->prepare(
65
+        $query,
66
+        Wordlift_Entity_Service::TYPE_NAME,
67
+        $title,
68
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
69
+        Wordlift_Entity_Service::TYPE_NAME,
70
+        Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
71
+        $title,
72
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME
73
+    ) );
74 74
 }
75 75
 
76 76
 
@@ -81,30 +81,30 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function wl_entity_ajax_get_by_title() {
83 83
 
84
-	// Get the title to search.
85
-	if ( empty( $_GET['title'] ) ) {
86
-		wp_die( 'The title parameter is required.' );
87
-	}
84
+    // Get the title to search.
85
+    if ( empty( $_GET['title'] ) ) {
86
+        wp_die( 'The title parameter is required.' );
87
+    }
88 88
 
89
-	$title = $_GET['title'];
89
+    $title = $_GET['title'];
90 90
 
91
-	// Are we searching for a specific title or for a containing title?
92
-	$autocomplete = isset( $_GET['autocomplete'] );
91
+    // Are we searching for a specific title or for a containing title?
92
+    $autocomplete = isset( $_GET['autocomplete'] );
93 93
 	
94
-	// Are we searching also for the aliases?
95
-	$include_alias = isset( $_GET['alias'] );
94
+    // Are we searching also for the aliases?
95
+    $include_alias = isset( $_GET['alias'] );
96 96
 
97
-	// Get the edit link.
98
-	$post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME );
99
-	$edit_link        = $post_type_object->_edit_link . '&action=edit';
97
+    // Get the edit link.
98
+    $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME );
99
+    $edit_link        = $post_type_object->_edit_link . '&action=edit';
100 100
 
101
-	// Prepare the response with the edit link.
102
-	$response = array(
103
-		'edit_link' => $edit_link,
104
-		'results'   => wl_entity_get_by_title( $title, $autocomplete, $include_alias )
105
-	);
101
+    // Prepare the response with the edit link.
102
+    $response = array(
103
+        'edit_link' => $edit_link,
104
+        'results'   => wl_entity_get_by_title( $title, $autocomplete, $include_alias )
105
+    );
106 106
 
107
-	wl_core_send_json( $response );
107
+    wl_core_send_json( $response );
108 108
 
109 109
 }
110 110
 
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @return array An array of WP_Post instances.
20 20
  */
21
-function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true ) {
21
+function wl_entity_get_by_title($title, $autocomplete = false, $include_alias = true) {
22 22
 	global $wpdb;
23 23
 
24 24
 	// Search by substring
25
-	if ( $autocomplete ) {
26
-		$title = $title . '%';
25
+	if ($autocomplete) {
26
+		$title = $title.'%';
27 27
 	}
28 28
 
29 29
 //	// The title is a LIKE query.
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	         . "   AND tt.term_taxonomy_id = tr.term_taxonomy_id"
48 48
 	         . "   AND tr.object_id = p.ID";
49 49
 	
50
-	if( $include_alias ) {
50
+	if ($include_alias) {
51 51
 	    
52
-		$query.= " UNION"
52
+		$query .= " UNION"
53 53
 	         . "  SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug"
54 54
 	         . "  FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m"
55 55
 	         . "   WHERE p.post_type= %s"
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	         . "    AND tr.object_id = p.ID";
62 62
 	}
63 63
 
64
-	return $wpdb->get_results( $wpdb->prepare(
64
+	return $wpdb->get_results($wpdb->prepare(
65 65
 		$query,
66 66
 		Wordlift_Entity_Service::TYPE_NAME,
67 67
 		$title,
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
71 71
 		$title,
72 72
 		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME
73
-	) );
73
+	));
74 74
 }
75 75
 
76 76
 
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 function wl_entity_ajax_get_by_title() {
83 83
 
84 84
 	// Get the title to search.
85
-	if ( empty( $_GET['title'] ) ) {
86
-		wp_die( 'The title parameter is required.' );
85
+	if (empty($_GET['title'])) {
86
+		wp_die('The title parameter is required.');
87 87
 	}
88 88
 
89 89
 	$title = $_GET['title'];
90 90
 
91 91
 	// Are we searching for a specific title or for a containing title?
92
-	$autocomplete = isset( $_GET['autocomplete'] );
92
+	$autocomplete = isset($_GET['autocomplete']);
93 93
 	
94 94
 	// Are we searching also for the aliases?
95
-	$include_alias = isset( $_GET['alias'] );
95
+	$include_alias = isset($_GET['alias']);
96 96
 
97 97
 	// Get the edit link.
98
-	$post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME );
99
-	$edit_link        = $post_type_object->_edit_link . '&action=edit';
98
+	$post_type_object = get_post_type_object(Wordlift_Entity_Service::TYPE_NAME);
99
+	$edit_link        = $post_type_object->_edit_link.'&action=edit';
100 100
 
101 101
 	// Prepare the response with the edit link.
102 102
 	$response = array(
103 103
 		'edit_link' => $edit_link,
104
-		'results'   => wl_entity_get_by_title( $title, $autocomplete, $include_alias )
104
+		'results'   => wl_entity_get_by_title($title, $autocomplete, $include_alias)
105 105
 	);
106 106
 
107
-	wl_core_send_json( $response );
107
+	wl_core_send_json($response);
108 108
 
109 109
 }
110 110
 
111
-add_action( 'wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title' );
111
+add_action('wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title');
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -22,93 +22,93 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string    $plugin_name    The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string    $version    The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * Initialize the class and set its properties.
45
-	 *
46
-	 * @since    1.0.0
47
-	 * @param      string    $plugin_name       The name of this plugin.
48
-	 * @param      string    $version    The version of this plugin.
49
-	 */
50
-	public function __construct( $plugin_name, $version ) {
51
-
52
-		$this->plugin_name = $plugin_name;
53
-		$this->version = $version;
54
-
55
-	}
56
-
57
-	/**
58
-	 * Register the stylesheets for the admin area.
59
-	 *
60
-	 * @since    1.0.0
61
-	 */
62
-	public function enqueue_styles() {
63
-
64
-		/**
65
-		 * This function is provided for demonstration purposes only.
66
-		 *
67
-		 * An instance of this class should be passed to the run() function
68
-		 * defined in Wordlift_Loader as all of the hooks are defined
69
-		 * in that particular class.
70
-		 *
71
-		 * The Wordlift_Loader will then create the relationship
72
-		 * between the defined hooks and the functions defined in this
73
-		 * class.
74
-		 */
75
-
76
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Register the JavaScript for the admin area.
82
-	 *
83
-	 * @since    1.0.0
84
-	 */
85
-	public function enqueue_scripts() {
86
-
87
-		/**
88
-		 * This function is provided for demonstration purposes only.
89
-		 *
90
-		 * An instance of this class should be passed to the run() function
91
-		 * defined in Wordlift_Loader as all of the hooks are defined
92
-		 * in that particular class.
93
-		 *
94
-		 * The Wordlift_Loader will then create the relationship
95
-		 * between the defined hooks and the functions defined in this
96
-		 * class.
97
-		 */
98
-
99
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.js', array( 'jquery' ), $this->version, false );
100
-
101
-		// Add WL api endpoint to retrieve entities based on their title. We only load it on the entity edit page.
102
-		$entity_being_edited = get_post();
103
-		if (  isset( $entity_being_edited->post_type ) && $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME && is_numeric( get_the_ID() ) ) {
104
-
105
-			wp_localize_script( $this->plugin_name, 'wlEntityTitleLiveSearchParams', array(
106
-					'ajax_url' => admin_url( 'admin-ajax.php' ),
107
-					'action'   => 'entity_by_title',
108
-					'post_id'  => get_the_ID()
109
-				)
110
-			);
111
-		}
112
-	}
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string    $plugin_name    The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string    $version    The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * Initialize the class and set its properties.
45
+     *
46
+     * @since    1.0.0
47
+     * @param      string    $plugin_name       The name of this plugin.
48
+     * @param      string    $version    The version of this plugin.
49
+     */
50
+    public function __construct( $plugin_name, $version ) {
51
+
52
+        $this->plugin_name = $plugin_name;
53
+        $this->version = $version;
54
+
55
+    }
56
+
57
+    /**
58
+     * Register the stylesheets for the admin area.
59
+     *
60
+     * @since    1.0.0
61
+     */
62
+    public function enqueue_styles() {
63
+
64
+        /**
65
+         * This function is provided for demonstration purposes only.
66
+         *
67
+         * An instance of this class should be passed to the run() function
68
+         * defined in Wordlift_Loader as all of the hooks are defined
69
+         * in that particular class.
70
+         *
71
+         * The Wordlift_Loader will then create the relationship
72
+         * between the defined hooks and the functions defined in this
73
+         * class.
74
+         */
75
+
76
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
77
+
78
+    }
79
+
80
+    /**
81
+     * Register the JavaScript for the admin area.
82
+     *
83
+     * @since    1.0.0
84
+     */
85
+    public function enqueue_scripts() {
86
+
87
+        /**
88
+         * This function is provided for demonstration purposes only.
89
+         *
90
+         * An instance of this class should be passed to the run() function
91
+         * defined in Wordlift_Loader as all of the hooks are defined
92
+         * in that particular class.
93
+         *
94
+         * The Wordlift_Loader will then create the relationship
95
+         * between the defined hooks and the functions defined in this
96
+         * class.
97
+         */
98
+
99
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.js', array( 'jquery' ), $this->version, false );
100
+
101
+        // Add WL api endpoint to retrieve entities based on their title. We only load it on the entity edit page.
102
+        $entity_being_edited = get_post();
103
+        if (  isset( $entity_being_edited->post_type ) && $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME && is_numeric( get_the_ID() ) ) {
104
+
105
+            wp_localize_script( $this->plugin_name, 'wlEntityTitleLiveSearchParams', array(
106
+                    'ajax_url' => admin_url( 'admin-ajax.php' ),
107
+                    'action'   => 'entity_by_title',
108
+                    'post_id'  => get_the_ID()
109
+                )
110
+            );
111
+        }
112
+    }
113 113
 
114 114
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @param      string    $plugin_name       The name of this plugin.
48 48
 	 * @param      string    $version    The version of this plugin.
49 49
 	 */
50
-	public function __construct( $plugin_name, $version ) {
50
+	public function __construct($plugin_name, $version) {
51 51
 
52 52
 		$this->plugin_name = $plugin_name;
53 53
 		$this->version = $version;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		 * class.
74 74
 		 */
75 75
 
76
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
76
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
77 77
 
78 78
 	}
79 79
 
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 		 * class.
97 97
 		 */
98 98
 
99
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.js', array( 'jquery' ), $this->version, false );
99
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wordlift-admin.js', array('jquery'), $this->version, false);
100 100
 
101 101
 		// Add WL api endpoint to retrieve entities based on their title. We only load it on the entity edit page.
102 102
 		$entity_being_edited = get_post();
103
-		if (  isset( $entity_being_edited->post_type ) && $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME && is_numeric( get_the_ID() ) ) {
103
+		if (isset($entity_being_edited->post_type) && $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME && is_numeric(get_the_ID())) {
104 104
 
105
-			wp_localize_script( $this->plugin_name, 'wlEntityTitleLiveSearchParams', array(
106
-					'ajax_url' => admin_url( 'admin-ajax.php' ),
105
+			wp_localize_script($this->plugin_name, 'wlEntityTitleLiveSearchParams', array(
106
+					'ajax_url' => admin_url('admin-ajax.php'),
107 107
 					'action'   => 'entity_by_title',
108 108
 					'post_id'  => get_the_ID()
109 109
 				)
Please login to merge, or discard this patch.