Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/CriticalPath/RESTWPPost.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace WP_Rocket\Engine\CriticalPath;
4
+
5
+
use WP_Error;
6
+
7
+
/**
8
+
* Class RESTWPPost
9
+
*
10
+
* @package WP_Rocket\Engine\CriticalPath
11
+
*/
12
+
class RESTWPPost extends RESTWP {
13
+
14
+
/**
15
+
* Part of route namespace for this inherited class item type.
16
+
*
17
+
* @var string $route_namespace to be set with like post, term.
18
+
*/
19
+
protected $route_namespace = 'post';
20
+
21
+
/**
22
+
* Validate the item to be sent to generate CPCSS.
23
+
*
24
+
* @since 3.6
25
+
*
26
+
* @param int $post_id ID for this post to be validated.
27
+
*
28
+
* @return true|WP_Error
29
+
*/
30
+
protected function validate_item_for_generate( $post_id ) {
31
+
$status = get_post_status( $post_id );
32
+
33
+
if ( ! $status ) {
34
+
return new WP_Error(
35
+
'post_not_exists',
36
+
__( 'Requested post does not exist.', 'rocket' ),
37
+
[
38
+
'status' => 400,
39
+
]
40
+
);
41
+
}
42
+
43
+
if ( 'publish' !== $status ) {
44
+
return new WP_Error(
45
+
'post_not_published',
46
+
__( 'Cannot generate CPCSS for unpublished post.', 'rocket' ),
47
+
[
48
+
'status' => 400,
49
+
]
50
+
);
51
+
}
52
+
53
+
return true;
54
+
}
55
+
56
+
/**
57
+
* Validate the item to be sent to delete CPCSS.
58
+
*
59
+
* @since 3.6
60
+
*
61
+
* @param int $post_id ID for this post to be validated.
62
+
*
63
+
* @return true|WP_Error
64
+
*/
65
+
protected function validate_item_for_delete( $post_id ) {
66
+
if ( empty( get_permalink( $post_id ) ) ) {
67
+
return new WP_Error(
68
+
'post_not_exists',
69
+
__( 'Requested post does not exist.', 'rocket' ),
70
+
[
71
+
'status' => 400,
72
+
]
73
+
);
74
+
}
75
+
76
+
return true;
77
+
}
78
+
79
+
80
+
/**
81
+
* Get url for this item.
82
+
*
83
+
* @since 3.6
84
+
*
85
+
* @param int $post_id ID for this post to be validated.
86
+
*
87
+
* @return false|string
88
+
*/
89
+
protected function get_url( $post_id ) {
90
+
return get_permalink( $post_id );
91
+
}
92
+
93
+
/**
94
+
* Get CPCSS file path to save CPCSS code into.
95
+
*
96
+
* @since 3.6
97
+
*
98
+
* @param int $post_id ID for this post to be validated.
99
+
* @param bool $is_mobile Bool identifier for is_mobile CPCSS generation.
100
+
*
101
+
* @return string
102
+
*/
103
+
protected function get_path( $post_id, $is_mobile = false ) {
104
+
$post_type = get_post_type( $post_id );
105
+
106
+
return 'posts' . DIRECTORY_SEPARATOR . "{$post_type}-{$post_id}" . ( $is_mobile ? '-mobile' : '' ) . '.css';
107
+
}
108
+
}
109
+