Changeset 3714445 for social-engine/trunk/classes/core.php
- Timestamp:
- 09/26/2026 04:03:31 PM (3 weeks ago)
- File:
-
- 1 edited
-
social-engine/trunk/classes/core.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
social-engine/trunk/classes/core.php
r3651508 r3714445 489 489 $post_content, 490 490 $post_thumbnail_ids, 491 $post_id 491 $post_id, 492 $status = 'future' 492 493 ) { 493 494 foreach ( $times as $time ) { … … 501 502 'date' => $post_date, 502 503 'content' => $post_content, 503 'status' => 'future',504 'status' => $status, 504 505 'thumbnail_ids' => $post_thumbnail_ids, 505 506 'service_id' => $account['serviceId'], … … 584 585 } 585 586 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 ) 587 588 { 588 589 $all_defaults = $this->get_option( 'defaults', [] ); … … 600 601 $post = get_post( $post_id ); 601 602 $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 ); 603 604 } 604 605 … … 609 610 } 610 611 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 ) 612 613 { 613 614 … … 682 683 $draft_enabled = $this->get_option( 'draft_enabled', false ); 683 684 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 684 689 $schedule_post_date = new DateTime( $post->post_date ); 685 690 if ( $auto_schedule_posts ) { … … 774 779 $schedule_post_content, 775 780 $schedule_post_thumbnail_ids, 776 $post->ID 781 $post->ID, 782 $new_post_status 777 783 ); 778 784 … … 784 790 $this->log( 'Post scheduled successfully with ID: ' . $id ); 785 791 if ( $auto_schedule_posts == 1 ) { 786 if ( !$draft_enabled ) {792 if ( !$draft_enabled && !$as_draft ) { 787 793 $this->log( 'No draft, no defaults, immediate schedule, posting Post ID: ' . $id ); 788 794 $this->post( $id ); 789 795 } 790 796 791 if ( $draft_enabled ) {797 if ( $draft_enabled || $as_draft ) { 792 798 $this->log( 'Draft enabled, no defaults, immediate schedule, posting Post ID: ' . $id ); 793 799 wp_update_post( [ … … 841 847 $schedule_post_content, 842 848 $schedule_post_thumbnail_ids, 843 $post->ID 849 $post->ID, 850 $new_post_status 844 851 ); 845 852 … … 1003 1010 } 1004 1011 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 ) 1006 1014 { 1007 1015 foreach ( $ids as $id ) { 1008 1016 $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 ); 1010 1018 if ( !$result ) { 1011 throw new E rror( 'Failed to delete the social post.' );1019 throw new Exception( 'Failed to delete the social post.' ); 1012 1020 } 1013 1021 foreach ( $thumbnail_ids as $thumbnail_id ) { … … 1458 1466 function delete_all_drafts_posts( ) 1459 1467 { 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( [ 1461 1482 'post_type' => $this->get_social_post_type( ), 1462 'post_status' => ['draft'],1483 'post_status' => $statuses, 1463 1484 '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 ); 1469 1494 } 1470 1495
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)