PluginProbe
Parse.ly / 3.20.3
Parse.ly v3.20.3
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / Metadata / class-post-builder.php

class-post-builder.php in Parse.ly 3.20.3, at src/Metadata/class-post-builder.php

85 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Page Metadata Builder class
4 *
5 * @package Parsely
6 * @since 3.4.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\Metadata;
12
13 use Parsely\Parsely;
14 use WP_Post;
15
16 /**
17 * Implements abstract Metadata Builder class to generate the metadata array
18 * for a post page.
19 *
20 * @since 3.4.0
21 */
22 class Post_Builder extends Metadata_Builder {
23 /**
24 * Post object to generate the metadata for.
25 *
26 * @var WP_Post
27 */
28 private $post;
29
30 /**
31 * Constructor.
32 *
33 * @param Parsely $parsely Instance of Parsely class.
34 * @param WP_Post $post Post object to generate the metadata for.
35 */
36 public function __construct( Parsely $parsely, WP_Post $post ) {
37 parent::__construct( $parsely );
38 $this->post = $post;
39 }
40
41 /**
42 * Generates the metadata object by calling the build_* methods and
43 * returns the value.
44 *
45 * @since 3.4.0
46 *
47 * @return array<string, mixed>
48 */
49 public function get_metadata(): array {
50 $this->build_basic();
51 $this->build_headline();
52 $this->build_url();
53
54 $this->build_type( $this->post, 'post' );
55 $this->build_main_entity( 'post' );
56 $this->build_thumbnail_url( $this->post );
57 $this->build_image( $this->post );
58 $this->build_article_section( $this->post );
59 $this->build_author( $this->post );
60 $this->build_publisher();
61 $this->build_keywords( $this->post );
62 $this->build_metadata_post_times( $this->post );
63
64 return $this->metadata;
65 }
66
67 /**
68 * Populates the headline field in the metadata object.
69 *
70 * @since 3.4.0
71 */
72 private function build_headline(): void {
73 $this->metadata['headline'] = $this->clean_value( get_the_title( $this->post ) );
74 }
75
76 /**
77 * Populates the url field in the metadata object by getting the current page's URL.
78 *
79 * @since 3.4.0
80 */
81 protected function build_url(): void {
82 $this->metadata['url'] = $this->get_current_url( 'post', $this->post->ID );
83 }
84 }
85