|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Main class responsible for saving the post object |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.0 |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace lasso\process; |
|
8
|
|
|
|
|
9
|
|
|
use lasso\internal_api\api_action; |
|
10
|
|
|
|
|
11
|
|
|
class save implements api_action { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Process the post save |
|
15
|
|
|
* |
|
16
|
|
|
* @since 0.9.2 |
|
17
|
|
|
* |
|
18
|
|
|
* @param array $data Sanitized data to use for saving. |
|
19
|
|
|
* |
|
20
|
|
|
* @return bool Always returns true. |
|
21
|
|
|
*/ |
|
22
|
|
View Code Duplication |
public function content( $data ) { |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$save_to_post_disabled = $this->save_to_post_disables(); |
|
25
|
|
|
|
|
26
|
|
|
$postid = (int) $data[ 'post_id' ]; |
|
27
|
|
|
$content = $this->replace_rendered_shortcodes( $data[ 'content' ] ); |
|
28
|
|
|
|
|
29
|
|
|
if ( 'off' == $save_to_post_disabled || empty( $save_to_post_disabled ) ) { |
|
30
|
|
|
|
|
31
|
|
|
$args = array( |
|
32
|
|
|
'ID' => (int) $postid, |
|
33
|
|
|
'post_content' => $content |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
wp_update_post( apply_filters( 'lasso_object_save_args', $args ) ); |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// run save action |
|
41
|
|
|
do_action( 'lasso_post_saved', $postid, $content, get_current_user_ID() ); |
|
42
|
|
|
|
|
43
|
|
|
return true; |
|
44
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Process the post save |
|
49
|
|
|
* |
|
50
|
|
|
* @since 0.9.2 |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $data Sanitized data to use for saving. |
|
53
|
|
|
* |
|
54
|
|
|
* @return bool Always returns true. |
|
55
|
|
|
*/ |
|
56
|
|
View Code Duplication |
public function publish_content( $data ) { |
|
|
|
|
|
|
57
|
|
|
$save_to_post_disabled = $this->save_to_post_disables(); |
|
58
|
|
|
|
|
59
|
|
|
$postid = (int) $data[ 'post_id' ]; |
|
60
|
|
|
$content = $this->replace_rendered_shortcodes( $data[ 'content' ] ); |
|
61
|
|
|
|
|
62
|
|
|
if ( 'off' == $save_to_post_disabled || empty( $save_to_post_disabled ) ) { |
|
63
|
|
|
|
|
64
|
|
|
$args = array ( |
|
65
|
|
|
'ID' => $postid, |
|
66
|
|
|
'post_content' => $content, |
|
67
|
|
|
'post_status' => 'publish' |
|
68
|
|
|
); |
|
69
|
|
|
wp_update_post( apply_filters( 'lasso_object_publish_args', $args ) ); |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
do_action( 'lasso_post_published', $postid, $content, get_current_user_ID() ); |
|
74
|
|
|
|
|
75
|
|
|
return true; |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* The keys required for the actions of this class. |
|
81
|
|
|
* |
|
82
|
|
|
* @since 0.9.2 |
|
83
|
|
|
* |
|
84
|
|
|
* @return array Array of keys to pull from $_POST per action and their sanitization callback |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function params(){ |
|
87
|
|
|
$params[ 'process_save_content' ] = array( |
|
|
|
|
|
|
88
|
|
|
'post_id' => 'absint', |
|
89
|
|
|
'content' => 'wp_kses_post' |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$params[ 'process_save_publish_content' ] = array( |
|
93
|
|
|
'post_id' => 'absint', |
|
94
|
|
|
'content' => 'wp_kses_post' |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
return $params; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Additional auth callbacks to check. |
|
102
|
|
|
* |
|
103
|
|
|
* @since 0.9.2 |
|
104
|
|
|
* |
|
105
|
|
|
* @return array Array of additional functions to use to authorize action. |
|
106
|
|
|
*/ |
|
107
|
|
|
public static function auth_callbacks() { |
|
108
|
|
|
$params[ 'process_save_content' ] = array( |
|
|
|
|
|
|
109
|
|
|
'lasso_user_can' |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
$params[ 'process_save_publish_content' ] = array(); |
|
113
|
|
|
|
|
114
|
|
|
return $params; |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Check if saving post is disabled. |
|
120
|
|
|
* |
|
121
|
|
|
* @since 0.9.2 |
|
122
|
|
|
* |
|
123
|
|
|
* @access protected |
|
124
|
|
|
* |
|
125
|
|
|
* @return bool |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function save_to_post_disables() { |
|
128
|
|
|
$save_to_post_disabled = lasso_editor_get_option( 'post_save_disabled', 'lasso_editor' ); |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
return $save_to_post_disabled; |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Replace shortcodes from other plugins with shortcode tags. |
|
136
|
|
|
* |
|
137
|
|
|
* @since 0.9.9 |
|
138
|
|
|
* |
|
139
|
|
|
* @access protected |
|
140
|
|
|
* |
|
141
|
|
|
* @param string $content |
|
142
|
|
|
* |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
protected function replace_rendered_shortcodes( $content ) { |
|
146
|
|
|
if ( false === strpos( $content, '<!--EDITUS_OTHER_SHORTCODE_START|' ) ) { |
|
147
|
|
|
return $content; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$content = preg_replace( |
|
151
|
|
|
'/<!--EDITUS_OTHER_SHORTCODE_START\|\[(.*?)\]-->(.*?)<!--EDITUS_OTHER_SHORTCODE_END-->/s', |
|
152
|
|
|
'$1', |
|
153
|
|
|
$content |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
return $content; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.