-
Notifications
You must be signed in to change notification settings - Fork 877
/
post-site-information.php
118 lines (100 loc) · 3.52 KB
/
post-site-information.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\Editors\Framework\Site;
/**
* The Post_Site_Information class.
*/
class Post_Site_Information extends Base_Site_Information {
/**
* The permalink.
*
* @var string $permalink
*/
private $permalink;
/**
* Sets the permalink.
*
* @param string $permalink The permalink.
*
* @return void
*/
public function set_permalink( string $permalink ): void {
$this->permalink = $permalink;
}
/**
* Returns post specific site information together with the generic site information.
*
* @return array<string|string,string[]>
*/
public function get_legacy_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();
$data = [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',
'metabox' => [
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
'base_url' => $this->base_url_for_js(),
],
];
return \array_merge_recursive( $data, parent::get_legacy_site_information() );
}
/**
* Returns post specific site information together with the generic site information.
*
* @return array<string|string,string[]>
*/
public function get_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();
$data = [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
'base_url' => $this->base_url_for_js(),
];
return \array_merge( $data, parent::get_site_information() );
}
/**
* Returns the url to search for keyword for the post.
*
* @return string
*/
private function search_url(): string {
return \admin_url( 'edit.php?seo_kw_filter={keyword}' );
}
/**
* Returns the url to edit the taxonomy.
*
* @return string
*/
private function edit_url(): string {
return \admin_url( 'post.php?post={id}&action=edit' );
}
/**
* Returns a base URL for use in the JS, takes permalink structure into account.
*
* @return string
*/
private function base_url_for_js(): string {
global $pagenow;
// The default base is the home_url.
$base_url = \home_url( '/', null );
if ( $pagenow === 'post-new.php' ) {
return $base_url;
}
// If %postname% is the last tag, just strip it and use that as a base.
if ( \preg_match( '#%postname%/?$#', $this->permalink ) === 1 ) {
$base_url = \preg_replace( '#%postname%/?$#', '', $this->permalink );
}
// If %pagename% is the last tag, just strip it and use that as a base.
if ( \preg_match( '#%pagename%/?$#', $this->permalink ) === 1 ) {
$base_url = \preg_replace( '#%pagename%/?$#', '', $this->permalink );
}
return $base_url;
}
}