PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
← All changes | includes/features/frmx-inline-edit.php +50 -9 2.4.4 → 2.5.1 View file →
@@ -30,8 +30,45 @@
30 30 add_action( 'wp_ajax_forumax_save_reply_edit', array( $this, 'save_reply_edit' ) );
31 31 }
32 32
33 33 /**
34 + * Revision created by the current wp_update_post() call.
35 + *
36 + * @var int
37 + */
38 + private $revision_id = 0;
39 +
40 + /**
41 + * Start recording the revision wp_update_post() creates.
42 + *
43 + * @return void
44 + */
45 + private function watch_revisions() {
46 + $this->revision_id = 0;
47 + add_action( '_wp_put_post_revision', array( $this, 'record_revision' ) );
48 + }
49 +
50 + /**
51 + * Stop recording and return the recorded revision ID.
52 + *
53 + * @return int
54 + */
55 + private function stop_watching_revisions() {
56 + remove_action( '_wp_put_post_revision', array( $this, 'record_revision' ) );
57 + return (int) $this->revision_id;
58 + }
59 +
60 + /**
61 + * Remember a freshly stored revision.
62 + *
63 + * @param int $revision_id Revision ID.
64 + * @return void
65 + */
66 + public function record_revision( $revision_id ) {
67 + $this->revision_id = (int) $revision_id;
68 + }
69 +
70 + /**
34 71 * AJAX handler: Get raw topic content for editing.
35 72 *
36 73 * Returns the topic title and raw content for the inline editor.
37 74 */
@@ -97,21 +134,24 @@
97 134 if ( empty( $new_content ) ) {
98 135 wp_send_json_error( array( 'message' => esc_html__( 'Content cannot be empty.', 'forumax' ) ) );
99 136 }
100 137
101 - // Update the topic.
102 - $updated = wp_update_post( array(
138 + // Update the topic. wp_update_post() expects slashed data; passing
139 + // unslashed values stripped every backslash from the content.
140 + $this->watch_revisions();
141 + $updated = wp_update_post( wp_slash( array(
103 142 'ID' => $topic_id,
104 143 'post_title' => $new_title,
105 144 'post_content' => $new_content,
106 - ), true );
145 + ) ), true );
107 146
108 147 if ( is_wp_error( $updated ) ) {
109 148 wp_send_json_error( array( 'message' => $updated->get_error_message() ) );
110 149 }
111 150
112 - // Log the revision (bbPress tracks edits).
113 - $revision_id = wp_save_post_revision( $topic_id );
151 + // Log the revision (bbPress tracks edits). wp_update_post() already
152 + // stored it, so a second wp_save_post_revision() call returns nothing.
153 + $revision_id = $this->stop_watching_revisions() ?: wp_save_post_revision( $topic_id );
114 154 if ( $revision_id ) {
115 155 bbp_update_topic_revision_log( array(
116 156 'topic_id' => $topic_id,
117 157 'revision_id' => $revision_id,
@@ -191,13 +231,14 @@
191 231 if ( empty( $new_content ) ) {
192 232 wp_send_json_error( array( 'message' => esc_html__( 'Content cannot be empty.', 'forumax' ) ) );
193 233 }
194 234
195 - // Update the reply.
196 - $updated = wp_update_post( array(
235 + // Update the reply (slashed, see save_topic_edit()).
236 + $this->watch_revisions();
237 + $updated = wp_update_post( wp_slash( array(
197 238 'ID' => $reply_id,
198 239 'post_content' => $new_content,
199 - ), true );
240 + ) ), true );
200 241
201 242 if ( is_wp_error( $updated ) ) {
202 243 wp_send_json_error( array( 'message' => $updated->get_error_message() ) );
203 244 }
@@ -202,9 +243,9 @@
202 243 wp_send_json_error( array( 'message' => $updated->get_error_message() ) );
203 244 }
204 245
205 246 // Log the revision (bbPress tracks edits).
206 - $revision_id = wp_save_post_revision( $reply_id );
247 + $revision_id = $this->stop_watching_revisions() ?: wp_save_post_revision( $reply_id );
207 248 if ( $revision_id ) {
208 249 bbp_update_reply_revision_log( array(
209 250 'reply_id' => $reply_id,
210 251 'revision_id' => $revision_id,