Plugin Directory


Ignore:
Timestamp:
09/26/2026 04:03:31 PM (3 weeks ago)
Author:
TigrouMeow
Message:

Version 0.9.3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • social-engine/trunk/classes/rest.php

    r3628743 r3714445  
    3939                                'permission_callback' => array( $this->core, 'can_access_settings' ),
    4040                                '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' )
    4146                        ) );
    4247                        register_rest_route( $this->namespace, '/add_posting_time', array(
    … …  
    241246
    242247        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) {
    257262                        return new WP_REST_Response([
    258263                                'success' => false,
    … …  
    264269        function rest_delete_all_drafts() {
    265270                try {
    266                         $this->core->delete_all_drafts_posts();
    267                 } catch (Exception $e) {
     271                        $count = $this->core->delete_all_drafts_posts();
     272                } catch (Throwable $e) {
    268273                        return new WP_REST_Response([
    269274                                'success' => false,
    … …  
    272277                }
    273278
    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 );
    275304        }
    276305
    … …  
    9871016                $use_post_enhancer = isset( $params['use_post_enhancer']) ? $params['use_post_enhancer'] : false;
    9881017                $language = isset( $params['language']) ? $params['language'] : '';
     1018                $as_draft = isset( $params['as_draft']) ? (bool) $params['as_draft'] : false;
    9891019
    9901020                if ( !$post_id || !$account_id ) {
    … …  
    10091039
    10101040                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 );
    10121042                        return new WP_REST_Response( [ 'success' => true ] );
    10131043                } catch ( Exception $e ) {
Note: See TracChangeset for help on using the changeset viewer.