Changeset 10858
- Timestamp:
- 06/01/2016 09:00:21 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 5 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 -
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r10853 r10858 135 135 136 136 /** 137 * Error holder. 138 * 139 * @since 2.6.0 140 * 141 * @var WP_Error 142 */ 143 public $errors; 144 145 /** 146 * Error type to return. Either 'bool' or 'wp_error'. 147 * 148 * @since 2.6.0 149 * 150 * @var string 151 */ 152 public $error_type = 'bool'; 153 154 /** 137 155 * Constructor method. 138 156 * … … 142 160 */ 143 161 public function __construct( $id = false ) { 162 // Instantiate errors object. 163 $this->errors = new WP_Error; 164 144 165 if ( !empty( $id ) ) { 145 166 $this->id = (int) $id; … … 236 257 do_action_ref_array( 'bp_activity_before_save', array( &$this ) ); 237 258 259 if ( 'wp_error' === $this->error_type && $this->errors->get_error_code() ) { 260 return $this->errors; 261 } 262 238 263 if ( empty( $this->component ) || empty( $this->type ) ) { 239 return false; 264 if ( 'bool' === $this->error_type ) { 265 return false; 266 } else { 267 if ( empty( $this->component ) ) { 268 $this->errors->add( 'bp_activity_missing_component' ); 269 } else { 270 $this->errors->add( 'bp_activity_missing_type' ); 271 } 272 273 return $this->errors; 274 } 240 275 } 241 276 -
trunk/src/bp-groups/bp-groups-activity.php
r10454 r10858 380 380 'secondary_item_id' => false, 381 381 'recorded_time' => bp_core_current_time(), 382 'hide_sitewide' => $hide_sitewide 382 'hide_sitewide' => $hide_sitewide, 383 'error_type' => 'bool' 383 384 ) ); 384 385 -
trunk/src/bp-groups/bp-groups-functions.php
r10819 r10858 1150 1150 * 1151 1151 * @since 1.2.0 1152 * @since 2.6.0 Added 'error_type' parameter to $args. 1152 1153 * 1153 1154 * @param array|string $args { … … 1169 1170 1170 1171 $defaults = array( 1171 'content' => false, 1172 'user_id' => bp_loggedin_user_id(), 1173 'group_id' => 0 1172 'content' => false, 1173 'user_id' => bp_loggedin_user_id(), 1174 'group_id' => 0, 1175 'error_type' => 'bool' 1174 1176 ); 1175 1177 … … 1212 1214 1213 1215 $activity_id = groups_record_activity( array( 1214 'user_id' => $user_id, 1215 'action' => $action, 1216 'content' => $content_filtered, 1217 'type' => 'activity_update', 1218 'item_id' => $group_id 1216 'user_id' => $user_id, 1217 'action' => $action, 1218 'content' => $content_filtered, 1219 'type' => 'activity_update', 1220 'item_id' => $group_id, 1221 'error_type' => $error_type 1219 1222 ) ); 1220 1223 -
trunk/src/bp-templates/bp-legacy/buddypress-functions.php
r10825 r10858 920 920 921 921 if ( ! $object && bp_is_active( 'activity' ) ) { 922 $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );922 $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) ); 923 923 924 924 } elseif ( 'groups' === $object ) { 925 925 if ( $item_id && bp_is_active( 'groups' ) ) 926 $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id ) );926 $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) ); 927 927 928 928 } else { … … 932 932 } 933 933 934 if ( empty( $activity_id ) )934 if ( false === $activity_id ) { 935 935 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' ); 936 } elseif ( is_wp_error( $activity_id ) && $activity_id->get_error_code() ) { 937 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' ); 938 } 936 939 937 940 $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0; … … 998 1001 'content' => $_POST['content'], 999 1002 'parent_id' => $_POST['comment_id'], 1003 'error_type' => 'wp_error' 1000 1004 ) ); 1001 1005 1002 if ( ! $comment_id ) { 1003 if ( ! empty( $bp->activity->errors['new_comment'] ) && is_wp_error( $bp->activity->errors['new_comment'] ) ) { 1004 $feedback = $bp->activity->errors['new_comment']->get_error_message(); 1005 unset( $bp->activity->errors['new_comment'] ); 1006 } 1007 1008 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' ); 1006 if ( is_wp_error( $comment_id ) ) { 1007 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' ); 1009 1008 } 1010 1009
Note: See TracChangeset
for help on using the changeset viewer.