Completed
Push — master ( a367a4...fc0246 )
by Naveen
01:03
created
src/includes/class-wordlift-publisher-service.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -18,217 +18,217 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Publisher_Service {
20 20
 
21
-	protected function __construct() {
22
-
23
-	}
24
-
25
-	private static $instance = null;
26
-
27
-	public static function get_instance() {
28
-
29
-		if ( ! isset( self::$instance ) ) {
30
-			self::$instance = new self();
31
-		}
32
-
33
-		return self::$instance;
34
-	}
35
-
36
-	/**
37
-	 * Counts the number of potential publishers.
38
-	 *
39
-	 * @return int The number of potential publishers.
40
-	 * @since 3.11.0
41
-	 *
42
-	 */
43
-	public function count() {
44
-
45
-		// Search for entities which are either a Person
46
-		// or Organization.
47
-
48
-		// Get only the ids as all we need is the count.
49
-		$entities = get_posts( array(
50
-			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
51
-			'post_status'    => 'publish',
52
-			'posts_per_page' => - 1,
53
-			'tax_query'      => array(
54
-				array(
55
-					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
56
-					'field'    => 'slug',
57
-					'terms'    => array( 'organization', 'person' ),
58
-				),
59
-			),
60
-			'fields'         => 'ids',
61
-		) );
62
-
63
-		// Finally return the count.
64
-		return count( $entities );
65
-	}
66
-
67
-	/**
68
-	 * Search SQL filter for matching against post title only.
69
-	 *
70
-	 * @link    http://wordpress.stackexchange.com/a/11826/1685
71
-	 *
72
-	 * @since   3.15.0
73
-	 *
74
-	 * @param string $search The search string.
75
-	 * @param WP_Query $wp_query The {@link WP_Query} instance.
76
-	 *
77
-	 * @return array|string An array of results.
78
-	 */
79
-	public function limit_search_to_title( $search, $wp_query ) {
80
-
81
-		// Bail out if the search or the `search_terms` haven't been set.
82
-		if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
83
-			return $search;
84
-		}
85
-
86
-		global $wpdb;
87
-
88
-		$query_vars = $wp_query->query_vars;
89
-		$percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
90
-		$search     = array();
91
-
92
-		foreach ( (array) $query_vars['search_terms'] as $term ) {
93
-			$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
94
-		}
95
-
96
-		if ( ! is_user_logged_in() ) {
97
-			$search[] = "$wpdb->posts.post_password = ''";
98
-		}
99
-
100
-		$search = ' AND ' . implode( ' AND ', $search );
101
-
102
-		return $search;
103
-	}
104
-
105
-	/**
106
-	 * Query WP for potential publishers, i.e. {@link WP_Post}s which are associated`
107
-	 * with `wl_entity_type` (taxonomy) terms of `Organization` or `Person`.
108
-	 *
109
-	 * @param string $filter The title filter.
110
-	 *
111
-	 * @return array An array of results in a select2 friendly format.
112
-	 * @since 3.11.0
113
-	 *
114
-	 */
115
-	public function query( $filter = '' ) {
116
-
117
-		// Search for the filter in the titles only.
118
-		add_filter( 'posts_search', array(
119
-			$this,
120
-			'limit_search_to_title',
121
-		), 10, 2 );
122
-
123
-		/*
21
+    protected function __construct() {
22
+
23
+    }
24
+
25
+    private static $instance = null;
26
+
27
+    public static function get_instance() {
28
+
29
+        if ( ! isset( self::$instance ) ) {
30
+            self::$instance = new self();
31
+        }
32
+
33
+        return self::$instance;
34
+    }
35
+
36
+    /**
37
+     * Counts the number of potential publishers.
38
+     *
39
+     * @return int The number of potential publishers.
40
+     * @since 3.11.0
41
+     *
42
+     */
43
+    public function count() {
44
+
45
+        // Search for entities which are either a Person
46
+        // or Organization.
47
+
48
+        // Get only the ids as all we need is the count.
49
+        $entities = get_posts( array(
50
+            'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
51
+            'post_status'    => 'publish',
52
+            'posts_per_page' => - 1,
53
+            'tax_query'      => array(
54
+                array(
55
+                    'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
56
+                    'field'    => 'slug',
57
+                    'terms'    => array( 'organization', 'person' ),
58
+                ),
59
+            ),
60
+            'fields'         => 'ids',
61
+        ) );
62
+
63
+        // Finally return the count.
64
+        return count( $entities );
65
+    }
66
+
67
+    /**
68
+     * Search SQL filter for matching against post title only.
69
+     *
70
+     * @link    http://wordpress.stackexchange.com/a/11826/1685
71
+     *
72
+     * @since   3.15.0
73
+     *
74
+     * @param string $search The search string.
75
+     * @param WP_Query $wp_query The {@link WP_Query} instance.
76
+     *
77
+     * @return array|string An array of results.
78
+     */
79
+    public function limit_search_to_title( $search, $wp_query ) {
80
+
81
+        // Bail out if the search or the `search_terms` haven't been set.
82
+        if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
83
+            return $search;
84
+        }
85
+
86
+        global $wpdb;
87
+
88
+        $query_vars = $wp_query->query_vars;
89
+        $percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
90
+        $search     = array();
91
+
92
+        foreach ( (array) $query_vars['search_terms'] as $term ) {
93
+            $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
94
+        }
95
+
96
+        if ( ! is_user_logged_in() ) {
97
+            $search[] = "$wpdb->posts.post_password = ''";
98
+        }
99
+
100
+        $search = ' AND ' . implode( ' AND ', $search );
101
+
102
+        return $search;
103
+    }
104
+
105
+    /**
106
+     * Query WP for potential publishers, i.e. {@link WP_Post}s which are associated`
107
+     * with `wl_entity_type` (taxonomy) terms of `Organization` or `Person`.
108
+     *
109
+     * @param string $filter The title filter.
110
+     *
111
+     * @return array An array of results in a select2 friendly format.
112
+     * @since 3.11.0
113
+     *
114
+     */
115
+    public function query( $filter = '' ) {
116
+
117
+        // Search for the filter in the titles only.
118
+        add_filter( 'posts_search', array(
119
+            $this,
120
+            'limit_search_to_title',
121
+        ), 10, 2 );
122
+
123
+        /*
124 124
 		 * Search for entities which are either a Person
125 125
 		 * or Organization. Sort the results by title in ascending order.
126 126
 		 */
127
-		$entities = get_posts( array(
128
-			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
129
-			'post_status'    => 'publish',
130
-			'posts_per_page' => - 1,
131
-			'tax_query'      => array(
132
-				array(
133
-					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
134
-					'field'    => 'slug',
135
-					'terms'    => array( 'organization', 'person' ),
136
-				),
137
-			),
138
-			's'              => $filter,
139
-			'orderby'        => 'title',
140
-			'order'          => 'ASC',
141
-		) );
142
-
143
-		// Remove the search filter added before the query.
144
-		remove_filter( 'posts_search', array(
145
-			$this,
146
-			'limit_search_to_title',
147
-		), 10, 2 );
148
-
149
-		// Set a reference to ourselves to pass to the closure.
150
-		$publisher_service = $this;
151
-
152
-		// Map the results in a `Select2` compatible array.
153
-		return array_map( function ( $entity ) use ( $publisher_service ) {
154
-			$type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
155
-			$thumb_id = get_post_thumbnail_id( $entity->ID );
156
-
157
-			return array(
158
-				'id'            => $entity->ID,
159
-				'text'          => wp_strip_all_tags( $entity->post_title ),
160
-				'type'          => $type[0]->name,
161
-				'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
162
-			);
163
-		}, $entities );
164
-	}
165
-
166
-	/**
167
-	 * Get the thumbnail's URL.
168
-	 *
169
-	 * @param int $attachment_id The attachment id.
170
-	 * @param string $size The attachment size (default = 'thumbnail').
171
-	 *
172
-	 * @return string|bool The image URL or false if not found.
173
-	 * @since 3.11.0
174
-	 *
175
-	 */
176
-	public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
177
-
178
-		$image = wp_get_attachment_image_src( $attachment_id, $size );
179
-
180
-		return isset( $image['0'] ) ? $image['0'] : false;
181
-	}
182
-
183
-	/**
184
-	 * Add additional instructions to featured image metabox
185
-	 * when the entity type is the publisher.
186
-	 *
187
-	 * @param string $content Current metabox content.
188
-	 *
189
-	 * @return string $content metabox content with additional instructions.
190
-	 * @since  3.19.0
191
-	 *
192
-	 */
193
-	public function add_featured_image_instruction( $content ) {
194
-		// Get the current post ID.
195
-		$post_id = get_the_ID();
196
-
197
-		// Get the publisher id.
198
-		$publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
199
-
200
-
201
-		// Bail if for some reason the post id is not set.
202
-		if (
203
-			empty( $post_id ) ||
204
-			$post_id !== (int) $publisher_id
205
-		) {
206
-			return $content;
207
-		}
208
-
209
-		$terms = wp_get_post_terms(
210
-			$post_id, // The post id.
211
-			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, // The taxonomy slug.
212
-			array(
213
-				'fields' => 'slugs',
214
-				// We don't need all fields, but only slugs.
215
-			)
216
-		);
217
-
218
-		// Check that the entity type is "Organization".
219
-		if ( in_array( 'organization', $terms, true ) ) {
220
-			// Add the featured image description when the type is "Organization".
221
-
222
-			$link    = sprintf( '<a target="_blank" href="%s">%s</a>',
223
-				esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
224
-				esc_html__( 'AMP logo guidelines', 'wordlift' ) );
225
-			$content .= sprintf( '<p>'
226
-			                     . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
227
-			                     . '</p>', $link );
228
-		}
229
-
230
-		// Finally return the content.
231
-		return $content;
232
-	}
127
+        $entities = get_posts( array(
128
+            'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
129
+            'post_status'    => 'publish',
130
+            'posts_per_page' => - 1,
131
+            'tax_query'      => array(
132
+                array(
133
+                    'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
134
+                    'field'    => 'slug',
135
+                    'terms'    => array( 'organization', 'person' ),
136
+                ),
137
+            ),
138
+            's'              => $filter,
139
+            'orderby'        => 'title',
140
+            'order'          => 'ASC',
141
+        ) );
142
+
143
+        // Remove the search filter added before the query.
144
+        remove_filter( 'posts_search', array(
145
+            $this,
146
+            'limit_search_to_title',
147
+        ), 10, 2 );
148
+
149
+        // Set a reference to ourselves to pass to the closure.
150
+        $publisher_service = $this;
151
+
152
+        // Map the results in a `Select2` compatible array.
153
+        return array_map( function ( $entity ) use ( $publisher_service ) {
154
+            $type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
155
+            $thumb_id = get_post_thumbnail_id( $entity->ID );
156
+
157
+            return array(
158
+                'id'            => $entity->ID,
159
+                'text'          => wp_strip_all_tags( $entity->post_title ),
160
+                'type'          => $type[0]->name,
161
+                'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
162
+            );
163
+        }, $entities );
164
+    }
165
+
166
+    /**
167
+     * Get the thumbnail's URL.
168
+     *
169
+     * @param int $attachment_id The attachment id.
170
+     * @param string $size The attachment size (default = 'thumbnail').
171
+     *
172
+     * @return string|bool The image URL or false if not found.
173
+     * @since 3.11.0
174
+     *
175
+     */
176
+    public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
177
+
178
+        $image = wp_get_attachment_image_src( $attachment_id, $size );
179
+
180
+        return isset( $image['0'] ) ? $image['0'] : false;
181
+    }
182
+
183
+    /**
184
+     * Add additional instructions to featured image metabox
185
+     * when the entity type is the publisher.
186
+     *
187
+     * @param string $content Current metabox content.
188
+     *
189
+     * @return string $content metabox content with additional instructions.
190
+     * @since  3.19.0
191
+     *
192
+     */
193
+    public function add_featured_image_instruction( $content ) {
194
+        // Get the current post ID.
195
+        $post_id = get_the_ID();
196
+
197
+        // Get the publisher id.
198
+        $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
199
+
200
+
201
+        // Bail if for some reason the post id is not set.
202
+        if (
203
+            empty( $post_id ) ||
204
+            $post_id !== (int) $publisher_id
205
+        ) {
206
+            return $content;
207
+        }
208
+
209
+        $terms = wp_get_post_terms(
210
+            $post_id, // The post id.
211
+            Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, // The taxonomy slug.
212
+            array(
213
+                'fields' => 'slugs',
214
+                // We don't need all fields, but only slugs.
215
+            )
216
+        );
217
+
218
+        // Check that the entity type is "Organization".
219
+        if ( in_array( 'organization', $terms, true ) ) {
220
+            // Add the featured image description when the type is "Organization".
221
+
222
+            $link    = sprintf( '<a target="_blank" href="%s">%s</a>',
223
+                esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
224
+                esc_html__( 'AMP logo guidelines', 'wordlift' ) );
225
+            $content .= sprintf( '<p>'
226
+                                    . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
227
+                                    . '</p>', $link );
228
+        }
229
+
230
+        // Finally return the content.
231
+        return $content;
232
+    }
233 233
 
234 234
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 	public static function get_instance() {
28 28
 
29
-		if ( ! isset( self::$instance ) ) {
29
+		if ( ! isset(self::$instance)) {
30 30
 			self::$instance = new self();
31 31
 		}
32 32
 
@@ -46,22 +46,22 @@  discard block
 block discarded – undo
46 46
 		// or Organization.
47 47
 
48 48
 		// Get only the ids as all we need is the count.
49
-		$entities = get_posts( array(
49
+		$entities = get_posts(array(
50 50
 			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
51 51
 			'post_status'    => 'publish',
52
-			'posts_per_page' => - 1,
52
+			'posts_per_page' => -1,
53 53
 			'tax_query'      => array(
54 54
 				array(
55 55
 					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
56 56
 					'field'    => 'slug',
57
-					'terms'    => array( 'organization', 'person' ),
57
+					'terms'    => array('organization', 'person'),
58 58
 				),
59 59
 			),
60 60
 			'fields'         => 'ids',
61
-		) );
61
+		));
62 62
 
63 63
 		// Finally return the count.
64
-		return count( $entities );
64
+		return count($entities);
65 65
 	}
66 66
 
67 67
 	/**
@@ -76,28 +76,28 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return array|string An array of results.
78 78
 	 */
79
-	public function limit_search_to_title( $search, $wp_query ) {
79
+	public function limit_search_to_title($search, $wp_query) {
80 80
 
81 81
 		// Bail out if the search or the `search_terms` haven't been set.
82
-		if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
82
+		if (empty($search) || empty($wp_query->query_vars['search_terms'])) {
83 83
 			return $search;
84 84
 		}
85 85
 
86 86
 		global $wpdb;
87 87
 
88 88
 		$query_vars = $wp_query->query_vars;
89
-		$percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
89
+		$percent    = ! empty($query_vars['exact']) ? '' : '%';
90 90
 		$search     = array();
91 91
 
92
-		foreach ( (array) $query_vars['search_terms'] as $term ) {
93
-			$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
92
+		foreach ((array) $query_vars['search_terms'] as $term) {
93
+			$search[] = $wpdb->prepare("$wpdb->posts.post_title LIKE %s", $percent.$wpdb->esc_like($term).$percent);
94 94
 		}
95 95
 
96
-		if ( ! is_user_logged_in() ) {
96
+		if ( ! is_user_logged_in()) {
97 97
 			$search[] = "$wpdb->posts.post_password = ''";
98 98
 		}
99 99
 
100
-		$search = ' AND ' . implode( ' AND ', $search );
100
+		$search = ' AND '.implode(' AND ', $search);
101 101
 
102 102
 		return $search;
103 103
 	}
@@ -112,55 +112,55 @@  discard block
 block discarded – undo
112 112
 	 * @since 3.11.0
113 113
 	 *
114 114
 	 */
115
-	public function query( $filter = '' ) {
115
+	public function query($filter = '') {
116 116
 
117 117
 		// Search for the filter in the titles only.
118
-		add_filter( 'posts_search', array(
118
+		add_filter('posts_search', array(
119 119
 			$this,
120 120
 			'limit_search_to_title',
121
-		), 10, 2 );
121
+		), 10, 2);
122 122
 
123 123
 		/*
124 124
 		 * Search for entities which are either a Person
125 125
 		 * or Organization. Sort the results by title in ascending order.
126 126
 		 */
127
-		$entities = get_posts( array(
127
+		$entities = get_posts(array(
128 128
 			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
129 129
 			'post_status'    => 'publish',
130
-			'posts_per_page' => - 1,
130
+			'posts_per_page' => -1,
131 131
 			'tax_query'      => array(
132 132
 				array(
133 133
 					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
134 134
 					'field'    => 'slug',
135
-					'terms'    => array( 'organization', 'person' ),
135
+					'terms'    => array('organization', 'person'),
136 136
 				),
137 137
 			),
138 138
 			's'              => $filter,
139 139
 			'orderby'        => 'title',
140 140
 			'order'          => 'ASC',
141
-		) );
141
+		));
142 142
 
143 143
 		// Remove the search filter added before the query.
144
-		remove_filter( 'posts_search', array(
144
+		remove_filter('posts_search', array(
145 145
 			$this,
146 146
 			'limit_search_to_title',
147
-		), 10, 2 );
147
+		), 10, 2);
148 148
 
149 149
 		// Set a reference to ourselves to pass to the closure.
150 150
 		$publisher_service = $this;
151 151
 
152 152
 		// Map the results in a `Select2` compatible array.
153
-		return array_map( function ( $entity ) use ( $publisher_service ) {
154
-			$type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
155
-			$thumb_id = get_post_thumbnail_id( $entity->ID );
153
+		return array_map(function($entity) use ($publisher_service) {
154
+			$type     = wp_get_post_terms($entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
155
+			$thumb_id = get_post_thumbnail_id($entity->ID);
156 156
 
157 157
 			return array(
158 158
 				'id'            => $entity->ID,
159
-				'text'          => wp_strip_all_tags( $entity->post_title ),
159
+				'text'          => wp_strip_all_tags($entity->post_title),
160 160
 				'type'          => $type[0]->name,
161
-				'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
161
+				'thumbnail_url' => $publisher_service->get_attachment_image_url($thumb_id),
162 162
 			);
163
-		}, $entities );
163
+		}, $entities);
164 164
 	}
165 165
 
166 166
 	/**
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 	 * @since 3.11.0
174 174
 	 *
175 175
 	 */
176
-	public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
176
+	public function get_attachment_image_url($attachment_id, $size = 'thumbnail') {
177 177
 
178
-		$image = wp_get_attachment_image_src( $attachment_id, $size );
178
+		$image = wp_get_attachment_image_src($attachment_id, $size);
179 179
 
180
-		return isset( $image['0'] ) ? $image['0'] : false;
180
+		return isset($image['0']) ? $image['0'] : false;
181 181
 	}
182 182
 
183 183
 	/**
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @since  3.19.0
191 191
 	 *
192 192
 	 */
193
-	public function add_featured_image_instruction( $content ) {
193
+	public function add_featured_image_instruction($content) {
194 194
 		// Get the current post ID.
195 195
 		$post_id = get_the_ID();
196 196
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 
201 201
 		// Bail if for some reason the post id is not set.
202 202
 		if (
203
-			empty( $post_id ) ||
203
+			empty($post_id) ||
204 204
 			$post_id !== (int) $publisher_id
205 205
 		) {
206 206
 			return $content;
@@ -216,15 +216,15 @@  discard block
 block discarded – undo
216 216
 		);
217 217
 
218 218
 		// Check that the entity type is "Organization".
219
-		if ( in_array( 'organization', $terms, true ) ) {
219
+		if (in_array('organization', $terms, true)) {
220 220
 			// Add the featured image description when the type is "Organization".
221 221
 
222
-			$link    = sprintf( '<a target="_blank" href="%s">%s</a>',
223
-				esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
224
-				esc_html__( 'AMP logo guidelines', 'wordlift' ) );
225
-			$content .= sprintf( '<p>'
226
-			                     . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
227
-			                     . '</p>', $link );
222
+			$link = sprintf('<a target="_blank" href="%s">%s</a>',
223
+				esc_attr__('https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift'),
224
+				esc_html__('AMP logo guidelines', 'wordlift'));
225
+			$content .= sprintf('<p>'
226
+			                     . esc_html_x('According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift')
227
+			                     . '</p>', $link);
228 228
 		}
229 229
 
230 230
 		// Finally return the content.
Please login to merge, or discard this patch.
src/admin/elements/class-wordlift-admin-author-element.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -19,120 +19,120 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Admin_Author_Element implements Wordlift_Admin_Element {
21 21
 
22
-	/**
23
-	 * The {@link Wordlift_Publisher_Service} instance.
24
-	 *
25
-	 * @since  3.14.0
26
-	 * @access private
27
-	 * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
28
-	 */
29
-	private $publisher_service;
30
-
31
-	/**
32
-	 * A {@link Wordlift_Admin_Select2_Element} instance.
33
-	 *
34
-	 * @since  3.14.0
35
-	 * @access private
36
-	 * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance.
37
-	 */
38
-	private $select_element;
39
-
40
-	/**
41
-	 * Create a {@link Wordlift_Admin_Person_Element} instance.
42
-	 *
43
-	 * @since 3.14.0
44
-	 *
45
-	 * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46
-	 * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance.
47
-	 */
48
-	function __construct( $publisher_service, $select_element ) {
49
-
50
-		$this->publisher_service = $publisher_service;
51
-
52
-		// Child elements.
53
-		$this->select_element = $select_element;
54
-
55
-
56
-
57
-	}
58
-
59
-	/**
60
-	 * @inheritdoc
61
-	 */
62
-	public function render( $args ) {
63
-
64
-		// Parse the arguments and merge with default values.
65
-		$params = wp_parse_args( $args, array(
66
-			'id'             => uniqid( 'wl-input-' ),
67
-			'name'           => uniqid( 'wl-input-' ),
68
-			'current_entity' => 0,
69
-		) );
70
-
71
-		$current_entity_id = $params['current_entity'];
72
-		$data              = $this->publisher_service->query();
73
-
74
-		// Set a default to show when no entity is associated and a way to unassign.
75
-		array_unshift( $data, array(
76
-			'id'            => '0',
77
-			'text'          => __( '<em>(none)</em>', 'wordlift' ),
78
-			'type'          => '',
79
-			'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
80
-		) );
81
-
82
-		// Finally do the render, passing along also the current selected entity
83
-		// id and the options data.
84
-		return $this->do_render( $params, $current_entity_id, $data );
85
-	}
86
-
87
-	/**
88
-	 * Render the `select` using the provided parameters.
89
-	 *
90
-	 * @since 3.14.0
91
-	 *
92
-	 * @param array $params The array of parameters from the `render` function.
93
-	 * @param int   $current_post_id The currently selected {@link WP_Post} `id`.
94
-	 * @param array $data An array of Select2 options.
95
-	 *
96
-	 * @return \Wordlift_Admin_Author_Element $this Return this element.
97
-	 */
98
-	protected function do_render( $params, $current_post_id, $data ) {
99
-
100
-		// Queue the script which will initialize the select and style it.
101
-		wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) );
102
-		wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' );
103
-
104
-		// Prepare the URLs for entities which don't have logos.
105
-		$person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png';
106
-		$organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png';
107
-
108
-		// Get the current post.
109
-		$current_post = $current_post_id ? get_post( $current_post_id ) : null;
110
-
111
-		// Finally render the Select.
112
-		$this->select_element->render( array(
113
-			// Id.
114
-			'id'      => $params['id'],
115
-			// Name.
116
-			'name'    => $params['name'],
117
-			// Class names.
118
-			'class'   => 'wl-select2-element',
119
-			// The selected id.
120
-			'value'   => $current_post_id,
121
-			// The selected item (must be in the options for Select2 to display it).
122
-			'options' => $current_post ? array( $current_post->ID => wp_strip_all_tags( $current_post->post_title ) ) : array(),
123
-			// Data attributes.
124
-			'data'    => array(
125
-				// The list of available options.
126
-				'wl-select2-data'               => json_encode( $data ),
127
-				// The HTML template for each option.
128
-				'wl-select2-template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
129
-				// The HTML template for the selected option.
130
-				'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
131
-			),
132
-		) );
133
-
134
-		// Finally return the element instance.
135
-		return $this;
136
-	}
22
+    /**
23
+     * The {@link Wordlift_Publisher_Service} instance.
24
+     *
25
+     * @since  3.14.0
26
+     * @access private
27
+     * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
28
+     */
29
+    private $publisher_service;
30
+
31
+    /**
32
+     * A {@link Wordlift_Admin_Select2_Element} instance.
33
+     *
34
+     * @since  3.14.0
35
+     * @access private
36
+     * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance.
37
+     */
38
+    private $select_element;
39
+
40
+    /**
41
+     * Create a {@link Wordlift_Admin_Person_Element} instance.
42
+     *
43
+     * @since 3.14.0
44
+     *
45
+     * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46
+     * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance.
47
+     */
48
+    function __construct( $publisher_service, $select_element ) {
49
+
50
+        $this->publisher_service = $publisher_service;
51
+
52
+        // Child elements.
53
+        $this->select_element = $select_element;
54
+
55
+
56
+
57
+    }
58
+
59
+    /**
60
+     * @inheritdoc
61
+     */
62
+    public function render( $args ) {
63
+
64
+        // Parse the arguments and merge with default values.
65
+        $params = wp_parse_args( $args, array(
66
+            'id'             => uniqid( 'wl-input-' ),
67
+            'name'           => uniqid( 'wl-input-' ),
68
+            'current_entity' => 0,
69
+        ) );
70
+
71
+        $current_entity_id = $params['current_entity'];
72
+        $data              = $this->publisher_service->query();
73
+
74
+        // Set a default to show when no entity is associated and a way to unassign.
75
+        array_unshift( $data, array(
76
+            'id'            => '0',
77
+            'text'          => __( '<em>(none)</em>', 'wordlift' ),
78
+            'type'          => '',
79
+            'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
80
+        ) );
81
+
82
+        // Finally do the render, passing along also the current selected entity
83
+        // id and the options data.
84
+        return $this->do_render( $params, $current_entity_id, $data );
85
+    }
86
+
87
+    /**
88
+     * Render the `select` using the provided parameters.
89
+     *
90
+     * @since 3.14.0
91
+     *
92
+     * @param array $params The array of parameters from the `render` function.
93
+     * @param int   $current_post_id The currently selected {@link WP_Post} `id`.
94
+     * @param array $data An array of Select2 options.
95
+     *
96
+     * @return \Wordlift_Admin_Author_Element $this Return this element.
97
+     */
98
+    protected function do_render( $params, $current_post_id, $data ) {
99
+
100
+        // Queue the script which will initialize the select and style it.
101
+        wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) );
102
+        wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' );
103
+
104
+        // Prepare the URLs for entities which don't have logos.
105
+        $person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png';
106
+        $organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png';
107
+
108
+        // Get the current post.
109
+        $current_post = $current_post_id ? get_post( $current_post_id ) : null;
110
+
111
+        // Finally render the Select.
112
+        $this->select_element->render( array(
113
+            // Id.
114
+            'id'      => $params['id'],
115
+            // Name.
116
+            'name'    => $params['name'],
117
+            // Class names.
118
+            'class'   => 'wl-select2-element',
119
+            // The selected id.
120
+            'value'   => $current_post_id,
121
+            // The selected item (must be in the options for Select2 to display it).
122
+            'options' => $current_post ? array( $current_post->ID => wp_strip_all_tags( $current_post->post_title ) ) : array(),
123
+            // Data attributes.
124
+            'data'    => array(
125
+                // The list of available options.
126
+                'wl-select2-data'               => json_encode( $data ),
127
+                // The HTML template for each option.
128
+                'wl-select2-template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
129
+                // The HTML template for the selected option.
130
+                'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
131
+            ),
132
+        ) );
133
+
134
+        // Finally return the element instance.
135
+        return $this;
136
+    }
137 137
 
138 138
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46 46
 	 * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance.
47 47
 	 */
48
-	function __construct( $publisher_service, $select_element ) {
48
+	function __construct($publisher_service, $select_element) {
49 49
 
50 50
 		$this->publisher_service = $publisher_service;
51 51
 
@@ -59,29 +59,29 @@  discard block
 block discarded – undo
59 59
 	/**
60 60
 	 * @inheritdoc
61 61
 	 */
62
-	public function render( $args ) {
62
+	public function render($args) {
63 63
 
64 64
 		// Parse the arguments and merge with default values.
65
-		$params = wp_parse_args( $args, array(
66
-			'id'             => uniqid( 'wl-input-' ),
67
-			'name'           => uniqid( 'wl-input-' ),
65
+		$params = wp_parse_args($args, array(
66
+			'id'             => uniqid('wl-input-'),
67
+			'name'           => uniqid('wl-input-'),
68 68
 			'current_entity' => 0,
69
-		) );
69
+		));
70 70
 
71 71
 		$current_entity_id = $params['current_entity'];
72 72
 		$data              = $this->publisher_service->query();
73 73
 
74 74
 		// Set a default to show when no entity is associated and a way to unassign.
75
-		array_unshift( $data, array(
75
+		array_unshift($data, array(
76 76
 			'id'            => '0',
77
-			'text'          => __( '<em>(none)</em>', 'wordlift' ),
77
+			'text'          => __('<em>(none)</em>', 'wordlift'),
78 78
 			'type'          => '',
79
-			'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
80
-		) );
79
+			'thumbnail_url' => plugin_dir_url(dirname(__FILE__)).'images/pixel.png',
80
+		));
81 81
 
82 82
 		// Finally do the render, passing along also the current selected entity
83 83
 		// id and the options data.
84
-		return $this->do_render( $params, $current_entity_id, $data );
84
+		return $this->do_render($params, $current_entity_id, $data);
85 85
 	}
86 86
 
87 87
 	/**
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
 	 *
96 96
 	 * @return \Wordlift_Admin_Author_Element $this Return this element.
97 97
 	 */
98
-	protected function do_render( $params, $current_post_id, $data ) {
98
+	protected function do_render($params, $current_post_id, $data) {
99 99
 
100 100
 		// Queue the script which will initialize the select and style it.
101
-		wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) );
102
-		wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' );
101
+		wp_enqueue_script('wl-author-element', plugin_dir_url(dirname(__FILE__)).'js/1/author.js', array('wordlift-select2'));
102
+		wp_enqueue_style('wl-author-element', plugin_dir_url(dirname(__FILE__)).'js/1/author.css');
103 103
 
104 104
 		// Prepare the URLs for entities which don't have logos.
105
-		$person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png';
106
-		$organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png';
105
+		$person_thumbnail_url       = plugin_dir_url(dirname(__FILE__)).'../images/person.png';
106
+		$organization_thumbnail_url = plugin_dir_url(dirname(__FILE__)).'../images/organization.png';
107 107
 
108 108
 		// Get the current post.
109
-		$current_post = $current_post_id ? get_post( $current_post_id ) : null;
109
+		$current_post = $current_post_id ? get_post($current_post_id) : null;
110 110
 
111 111
 		// Finally render the Select.
112
-		$this->select_element->render( array(
112
+		$this->select_element->render(array(
113 113
 			// Id.
114 114
 			'id'      => $params['id'],
115 115
 			// Name.
@@ -119,17 +119,17 @@  discard block
 block discarded – undo
119 119
 			// The selected id.
120 120
 			'value'   => $current_post_id,
121 121
 			// The selected item (must be in the options for Select2 to display it).
122
-			'options' => $current_post ? array( $current_post->ID => wp_strip_all_tags( $current_post->post_title ) ) : array(),
122
+			'options' => $current_post ? array($current_post->ID => wp_strip_all_tags($current_post->post_title)) : array(),
123 123
 			// Data attributes.
124 124
 			'data'    => array(
125 125
 				// The list of available options.
126
-				'wl-select2-data'               => json_encode( $data ),
126
+				'wl-select2-data'               => json_encode($data),
127 127
 				// The HTML template for each option.
128 128
 				'wl-select2-template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
129 129
 				// The HTML template for the selected option.
130 130
 				'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
131 131
 			),
132
-		) );
132
+		));
133 133
 
134 134
 		// Finally return the element instance.
135 135
 		return $this;
Please login to merge, or discard this patch.