Changeset 3714445 for social-engine/trunk/classes/rest.php
- Timestamp:
- 09/26/2026 04:03:31 PM (3 weeks ago)
- File:
-
- 1 edited
-
social-engine/trunk/classes/rest.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
social-engine/trunk/classes/rest.php
r3628743 r3714445 39 39 'permission_callback' => array( $this->core, 'can_access_settings' ), 40 40 'callback' => array( $this, 'rest_delete_all_drafts' ) 41 ) ); 42 register_rest_route( $this->namespace, '/delete_all_social_posts', array( 43 'methods' => 'POST', 44 'permission_callback' => array( $this->core, 'can_access_settings' ), 45 'callback' => array( $this, 'rest_delete_all_social_posts' ) 41 46 ) ); 42 47 register_rest_route( $this->namespace, '/add_posting_time', array( … … 241 246 242 247 function rest_reset_all_data() { 243 delete_option( Meow_SCLEGN_Core::get_plugin_option_name() );244 $args =[245 'post_type' => $this->core->get_social_post_type(),246 'numberposts' => -1,247 'post_status' => 'any',248 ];249 $posts = get_posts( $args);250 try{251 foreach ($posts as $post) {252 $this->core->delete_social_post($post->ID);253 }254 return new WP_REST_Response([ 'success' => true ], 200 );255 } 256 catch ( Exception$e) {248 try { 249 $post_ids = get_posts( [ 250 'post_type' => $this->core->get_social_post_type(), 251 'numberposts' => -1, 252 'post_status' => 'any', 253 'fields' => 'ids', 254 ] ); 255 if ( !empty( $post_ids ) ) { 256 $this->core->delete_social_posts( $post_ids, true ); 257 } 258 delete_option( Meow_SCLEGN_Core::get_plugin_option_name() ); 259 return new WP_REST_Response([ 'success' => true, 'count' => count( $post_ids ) ], 200 ); 260 } 261 catch (Throwable $e) { 257 262 return new WP_REST_Response([ 258 263 'success' => false, … … 264 269 function rest_delete_all_drafts() { 265 270 try { 266 $ this->core->delete_all_drafts_posts();267 } catch ( Exception$e) {271 $count = $this->core->delete_all_drafts_posts(); 272 } catch (Throwable $e) { 268 273 return new WP_REST_Response([ 269 274 'success' => false, … … 272 277 } 273 278 274 return new WP_REST_Response([ 'success' => true ], 200 ); 279 return new WP_REST_Response([ 'success' => true, 'count' => $count ], 200 ); 280 } 281 282 // Delete every social post with the given statuses ('draft', 'future', 'publish'). 283 function rest_delete_all_social_posts( $request ) { 284 $params = $request->get_json_params(); 285 $statuses = isset( $params['statuses'] ) ? (array) $params['statuses'] : []; 286 287 if ( empty( $statuses ) ) { 288 return new WP_REST_Response([ 289 'success' => false, 290 'message' => 'The statuses to delete are missing.', 291 ], 400 ); 292 } 293 294 try { 295 $count = $this->core->delete_all_social_posts_by_status( $statuses ); 296 } catch (Throwable $e) { 297 return new WP_REST_Response([ 298 'success' => false, 299 'message' => $e->getMessage(), 300 ], 500 ); 301 } 302 303 return new WP_REST_Response([ 'success' => true, 'count' => $count ], 200 ); 275 304 } 276 305 … … 987 1016 $use_post_enhancer = isset( $params['use_post_enhancer']) ? $params['use_post_enhancer'] : false; 988 1017 $language = isset( $params['language']) ? $params['language'] : ''; 1018 $as_draft = isset( $params['as_draft']) ? (bool) $params['as_draft'] : false; 989 1019 990 1020 if ( !$post_id || !$account_id ) { … … 1009 1039 1010 1040 try { 1011 $this->core->revive_as_social_post( $post_id, $account_id, $use_post_enhancer );1041 $this->core->revive_as_social_post( $post_id, $account_id, $use_post_enhancer, $as_draft ); 1012 1042 return new WP_REST_Response( [ 'success' => true ] ); 1013 1043 } catch ( Exception $e ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)