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/core.php

    r3651508 r3714445  
    489489                $post_content,
    490490                $post_thumbnail_ids,
    491                 $post_id
     491                $post_id,
     492                $status = 'future'
    492493         ) {
    493494                foreach ( $times as $time ) {
    … …  
    501502                                        'date'          => $post_date,
    502503                                        'content'       => $post_content,
    503                                         'status'        => 'future',
     504                                        'status'        => $status,
    504505                                        'thumbnail_ids' => $post_thumbnail_ids,
    505506                                        'service_id'    => $account['serviceId'],
    … …  
    584585        }
    585586
    586         public function revive_as_social_post( $post_id, $account_id, $use_post_enhancer = false )
     587        public function revive_as_social_post( $post_id, $account_id, $use_post_enhancer = false, $as_draft = false )
    587588        {
    588589                $all_defaults = $this->get_option( 'defaults', [] );
    … …  
    600601                $post = get_post( $post_id );
    601602                $auto_schedule_posts = $this->get_option( 'auto_schedule_posts', null );
    602                 $this->create_social_post_by_post( $post, $auto_schedule_posts, $defaults, $account_id, $use_post_enhancer );
     603                $this->create_social_post_by_post( $post, $auto_schedule_posts, $defaults, $account_id, $use_post_enhancer, null, null, $as_draft );
    603604        }
    604605
    … …  
    609610        }
    610611
    611         protected function create_social_post_by_post( $post, $auto_schedule_posts, $defaults, $specific_account_id = null, $use_post_enhancer = false, $allowed_services = null, $card_id = null )
     612        protected function create_social_post_by_post( $post, $auto_schedule_posts, $defaults, $specific_account_id = null, $use_post_enhancer = false, $allowed_services = null, $card_id = null, $as_draft = false )
    612613        {
    613614
    … …  
    682683                $draft_enabled = $this->get_option( 'draft_enabled', false );
    683684
     685                // When drafts are requested (Revive with "Create as Drafts"), the social posts are
     686                // created as drafts so they can be reviewed before anything goes out.
     687                $new_post_status = $as_draft ? 'draft' : 'future';
     688
    684689                $schedule_post_date = new DateTime( $post->post_date );
    685690                if ( $auto_schedule_posts ) {
    … …  
    774779                                                        $schedule_post_content,
    775780                                                        $schedule_post_thumbnail_ids,
    776                                                         $post->ID
     781                                                        $post->ID,
     782                                                        $new_post_status
    777783                                                 );
    778784
    … …  
    784790                                                        $this->log( 'Post scheduled successfully with ID: ' . $id );
    785791                                                        if ( $auto_schedule_posts == 1 ) {
    786                                                                 if ( !$draft_enabled ) {
     792                                                                if ( !$draft_enabled && !$as_draft ) {
    787793                                                                        $this->log( 'No draft, no defaults, immediate schedule, posting Post ID: ' . $id );
    788794                                                                        $this->post( $id );
    789795                                                                }
    790796
    791                                                                 if ( $draft_enabled ) {
     797                                                                if ( $draft_enabled || $as_draft ) {
    792798                                                                        $this->log( 'Draft enabled, no defaults, immediate schedule, posting Post ID: ' . $id );
    793799                                                                        wp_update_post( [
    … …  
    841847                                                        $schedule_post_content,
    842848                                                        $schedule_post_thumbnail_ids,
    843                                                         $post->ID
     849                                                        $post->ID,
     850                                                        $new_post_status
    844851                                                 );
    845852
    … …  
    10031010        }
    10041011
    1005         public function delete_social_posts( $ids )
     1012        // $force_delete bypasses the trash, which is what the bulk Maintenance tools do.
     1013        public function delete_social_posts( $ids, $force_delete = false )
    10061014        {
    10071015                foreach ( $ids as $id ) {
    10081016                        $thumbnail_ids = json_decode( $this->get_post_meta_with_default_value( $id, 'sclegn_thumbnails', true, '[]' ) );
    1009                         $result = wp_delete_post( $id );
     1017                        $result = wp_delete_post( $id, $force_delete );
    10101018                        if ( !$result ) {
    1011                                 throw new Error( 'Failed to delete the social post.' );
     1019                                throw new Exception( 'Failed to delete the social post.' );
    10121020                        }
    10131021                        foreach ( $thumbnail_ids as $thumbnail_id ) {
    … …  
    14581466        function delete_all_drafts_posts(  )
    14591467        {
    1460                 $args = [
     1468                return $this->delete_all_social_posts_by_status( ['draft'] );
     1469        }
     1470
     1471        // Delete every social post matching the given statuses. Returns the number of
     1472        // deleted posts. Used by the Maintenance tools to clean up the queue in one go.
     1473        function delete_all_social_posts_by_status( $statuses )
     1474        {
     1475                $allowed_statuses = ['draft', 'future', 'publish'];
     1476                $statuses = array_values( array_intersect( (array) $statuses, $allowed_statuses ) );
     1477                if ( empty( $statuses ) ) {
     1478                        return 0;
     1479                }
     1480
     1481                $post_ids = get_posts( [
    14611482                        'post_type' => $this->get_social_post_type(  ),
    1462                         'post_status' => ['draft'],
     1483                        'post_status' => $statuses,
    14631484                        'numberposts' => -1,
    1464                 ];
    1465                 $posts = get_posts( $args );
    1466                 foreach ( $posts as $post ) {
    1467                         wp_delete_post( $post->ID, true );
    1468                 }
     1485                        'fields' => 'ids',
     1486                ] );
     1487
     1488                if ( empty( $post_ids ) ) {
     1489                        return 0;
     1490                }
     1491
     1492                $this->delete_social_posts( $post_ids, true );
     1493                return count( $post_ids );
    14691494        }
    14701495
Note: See TracChangeset for help on using the changeset viewer.