Changeset 10858 for trunk/src/bp-activity/bp-activity-functions.php
- Timestamp:
- 06/01/2016 09:00:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-functions.php
r10853 r10858 1783 1783 * 1784 1784 * @since 1.1.0 1785 * @since 2.6.0 Added 'error_type' parameter to $args. 1785 1786 * 1786 1787 * @param array|string $args { … … 1814 1815 * Default: false. 1815 1816 * @type bool $is_spam Should the item be marked as spam? Default: false. 1817 * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. 1816 1818 * } 1817 1819 * @return int|bool The ID of the activity on success. False on error. … … 1832 1834 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream? 1833 1835 'is_spam' => false, // Is this activity item to be marked as spam? 1836 'error_type' => 'bool' 1834 1837 ), 'activity_add' ); 1835 1838 … … 1855 1858 $activity->hide_sitewide = $r['hide_sitewide']; 1856 1859 $activity->is_spam = $r['is_spam']; 1860 $activity->error_type = $r['error_type']; 1857 1861 $activity->action = ! empty( $r['action'] ) 1858 ? $r['action'] 1859 : bp_activity_generate_action_string( $activity ); 1860 1861 if ( ! $activity->save() ) { 1862 ? $r['action'] 1863 : bp_activity_generate_action_string( $activity ); 1864 1865 $save = $activity->save(); 1866 1867 if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) { 1868 return $save; 1869 } elseif ('bool' === $r['error_type'] && false === $save ) { 1862 1870 return false; 1863 1871 } … … 1899 1907 1900 1908 $r = wp_parse_args( $args, array( 1901 'content' => false, 1902 'user_id' => bp_loggedin_user_id() 1909 'content' => false, 1910 'user_id' => bp_loggedin_user_id(), 1911 'error_type' => 'bool', 1903 1912 ) ); 1904 1913 … … 1940 1949 'component' => buddypress()->activity->id, 1941 1950 'type' => 'activity_update', 1951 'error_type' => $r['error_type'] 1942 1952 ) ); 1953 1954 if ( is_wp_error( $activity_id ) ) { 1955 return $activity_id; 1956 } 1943 1957 1944 1958 /** … … 2492 2506 * @since 2.5.0 Add a new possible parameter $skip_notification for the array of arguments. 2493 2507 * Add the $primary_link parameter for the array of arguments. 2508 * @since 2.6.0 Added 'error_type' parameter to $args. 2494 2509 * 2495 2510 * @param array|string $args { … … 2508 2523 * @type bool $skip_notification Optional. false to send a comment notification, false otherwise. 2509 2524 * Defaults to false. 2525 * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. 2510 2526 * } 2511 2527 * @return int|bool The ID of the comment on success, otherwise false. 2512 2528 */ 2513 2529 function bp_activity_new_comment( $args = '' ) { 2514 $bp = buddypress(); 2515 $errors = new WP_Error(); 2516 $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' ); 2517 2518 if ( empty( $bp->activity->errors ) ) { 2519 $bp->activity->errors = array(); 2520 } 2530 $bp = buddypress(); 2521 2531 2522 2532 $r = wp_parse_args( $args, array( … … 2528 2538 'primary_link' => '', 2529 2539 'skip_notification' => false, 2540 'error_type' => 'bool' 2530 2541 ) ); 2542 2543 // Error type is boolean; need to initialize some variables for backpat. 2544 if ( 'bool' === $r['error_type'] ) { 2545 if ( empty( $bp->activity->errors ) ) { 2546 $bp->activity->errors = array(); 2547 } 2548 } 2549 2550 // Default error message. 2551 $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' ); 2531 2552 2532 2553 // Bail if missing necessary data. 2533 2554 if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) { 2534 $errors->add( 'missing_data', $feedback ); 2535 $bp->activity->errors['new_comment'] = $errors; 2536 2537 return false; 2555 $error = new WP_Error( 'missing_data', $feedback ); 2556 2557 if ( 'wp_error' === $r['error_type'] ) { 2558 return $error; 2559 2560 // Backpat. 2561 } else { 2562 $bp->activity->errors['new_comment'] = $error; 2563 return false; 2564 } 2538 2565 } 2539 2566 … … 2550 2577 // Bail if the parent activity does not exist. 2551 2578 if ( empty( $activity->date_recorded ) ) { 2552 $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) ); 2553 $bp->activity->errors['new_comment'] = $errors; 2554 2555 return false; 2579 $error = new WP_Error( 'missing_activity', __( 'The item you were replying to no longer exists.', 'buddypress' ) ); 2580 2581 if ( 'wp_error' === $r['error_type'] ) { 2582 return $error; 2583 2584 // Backpat. 2585 } else { 2586 $bp->activity->errors['new_comment'] = $error; 2587 return false; 2588 } 2589 2556 2590 } 2557 2591 … … 2578 2612 'item_id' => $activity_id, 2579 2613 'secondary_item_id' => $r['parent_id'], 2580 'hide_sitewide' => $is_hidden 2614 'hide_sitewide' => $is_hidden, 2615 'error_type' => $r['error_type'] 2581 2616 ) ); 2617 2618 // Return WP Error. 2619 if ( is_wp_error( $comment_id ) && 'wp_error' === $r['error_type'] ) { 2620 return $comment_id; 2621 } 2582 2622 2583 2623 // Comment caches are stored only with the top-level item. … … 2620 2660 2621 2661 if ( empty( $comment_id ) ) { 2622 $errors->add( 'comment_failed', $feedback ); 2623 $bp->activity->errors['new_comment'] = $errors; 2662 $error = new WP_Error( 'comment_failed', $feedback ); 2663 2664 if ( 'wp_error' === $r['error_type'] ) { 2665 return $error; 2666 2667 // Backpat. 2668 } else { 2669 $bp->activity->errors['new_comment'] = $error; 2670 } 2624 2671 } 2625 2672
Note: See TracChangeset
for help on using the changeset viewer.