SeedProd.php
2.73 KB
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
119
120
121
122
123
<?php
namespace AIOSEO\Plugin\Common\Standalone\PageBuilders;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Integrate our SEO Panel with SeedProd Page Builder.
*
* @since 4.1.7
*/
class SeedProd extends Base {
/**
* The plugin files.
*
* @since 4.1.7
*
* @var array
*/
public $plugins = [
'coming-soon/coming-soon.php',
'seedprod-coming-soon-pro-5/seedprod-coming-soon-pro-5.php',
];
/**
* The integration slug.
*
* @since 4.1.7
*
* @var string
*/
public $integrationSlug = 'seedprod';
/**
* Init the integration.
*
* @since 4.1.7
*
* @return void
*/
public function init() {
$postType = get_post_type( $this->getPostId() );
if ( ! aioseo()->postSettings->canAddPostSettingsMetabox( $postType ) ) {
return;
}
// SeedProd de-enqueues and de-register scripts/styles on priority PHP_INT_MAX.
// Thus, we need to enqueue our scripts at the same priority for more compatibility.
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ], PHP_INT_MAX );
add_filter( 'style_loader_tag', [ $this, 'replaceStyleTag' ], 10, 2 );
}
/**
* Enqueue the scripts and styles.
*
* @since 4.1.7
*
* @return void
*/
public function enqueue() {
if ( ! $this->isBuilderScreen() ) {
return;
}
parent::enqueue();
}
/**
* Check whether or not is builder screen.
*
* @since 4.1.7
*
* @return boolean Whether or not is builder screen.
*/
public function isBuilderScreen() {
$currentScreen = aioseo()->helpers->getCurrentScreen();
return $currentScreen && preg_match( '/seedprod.*?_builder$/i', $currentScreen->base );
}
/**
* Replace original tag to prevent being removed by SeedProd.
*
* @param string $tag The <link> tag for the enqueued style.
* @param string $handle The style's registered handle.
* @return string The tag.
*/
public function replaceStyleTag( $tag, $handle ) {
if ( ! $this->isBuilderScreen() ) {
return $tag;
}
$aioseoCommonHandle = 'aioseo-' . $this->integrationSlug . '-common';
if ( $aioseoCommonHandle === $handle ) {
// All the *common.css links are removed from SeedProd.
// https://github.com/awesomemotive/seedprod-plugins/blob/32854442979bfa068aadf9b8a8a929e5f9f353e5/seedprod-pro/resources/views/builder.php#L406
$tag = str_ireplace( 'href=', 'data-href=', $tag );
}
return $tag;
}
/**
* Returns whether or not the given Post ID was built with SeedProd.
*
* @since 4.1.7
*
* @param int $postId The Post ID.
* @return boolean Whether or not the Post was built with SeedProd.
*/
public function isBuiltWith( $postId ) {
$isSeedProd = get_post_meta( $postId, '_seedprod_page', true );
if ( ! empty( $isSeedProd ) ) {
return true;
}
return false;
}
}