Changeset 12699
- Timestamp:
- 07/03/2023 07:08:20 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/flagged.php
r12692 r12699 11 11 12 12 /** 13 * The meta key name for recording the user ID of the user who unflagged a photo. 14 * 15 * @var string 16 */ 17 const META_KEY_UNFLAGGER = 'photo_unflagger'; 18 19 /** 20 * The meta key name for recording the user ID of the user who flagged a photo. 21 * 22 * @var string 23 */ 24 const META_KEY_FLAGGER = 'photo_flagger'; 25 26 /** 13 27 * Initializer. 14 28 */ … … 42 56 // Allow Photo metabox to be shown for flagged photos. 43 57 add_filter( 'wporg_photos_post_statuses_with_photo', [ __CLASS__, 'amend_with_post_status' ] ); 58 59 // Record the fact that a flagged photo was unflagged. 60 $flagged_status = self::get_post_status(); 61 add_action( "{$flagged_status}_to_pending", [ __CLASS__, 'record_unflagging' ], 10, 3 ); 62 add_action( "pending_to_{$flagged_status}", [ __CLASS__, 'record_flagging' ], 10, 3 ); 44 63 } 45 64 … … 338 357 } 339 358 359 /** 360 * Determines if a photo post was unflagged. 361 * 362 * @param int|WP_Post $post Post object. 363 * @return bool True if the post was unflagged, else false. 364 */ 365 public static function was_unflagged( $post ) { 366 return (bool) self::get_unflagger( $post ); 367 } 368 369 /** 370 * Records the ID of the user who unflagged a post. 371 * 372 * @param int|WP_Post $post Post object. 373 * @return int|false The ID of the user who unflagged the post, else false. 374 */ 375 public static function get_unflagger( $post ) { 376 $user_id = false; 377 $post = get_post( $post ); 378 if ( $post ) { 379 $user_id = get_post_meta( $post->ID, self::META_KEY_UNFLAGGER, true ) ?? false; 380 } 381 return $user_id; 382 } 383 384 /** 385 * Records the ID of the user who unflagged a post. 386 * 387 * @param int|WP_Post $post Post object. 388 */ 389 public static function record_unflagging( $post ) { 390 if ( Registrations::get_post_type() === get_post_type( $post ) ) { 391 update_post_meta( $post->ID, self::META_KEY_UNFLAGGER, get_current_user_id() ); 392 } 393 } 394 395 /** 396 * Determines if a photo post was manually flagged. 397 * 398 * Note: A post may have been automatically flagged based on the Vision API 399 * analysis, for which this function would return false since no actual user 400 * flagged the post. Simply check the post's post status to see if it flagged. 401 * 402 * @param int|WP_Post $post Post object. 403 * @return bool True if the post was unflagged, else false. 404 */ 405 public static function was_flagged( $post ) { 406 return (bool) self::get_flagger( $post ); 407 } 408 409 /** 410 * Records the ID of the user who flagged a post. 411 * 412 * @param int|WP_Post $post Post object. 413 * @return int|false The ID of the user who unflagged the post, else false. 414 */ 415 public static function get_flagger( $post ) { 416 $user_id = false; 417 $post = get_post( $post ); 418 if ( $post ) { 419 $user_id = get_post_meta( $post->ID, self::META_KEY_FLAGGER, true ) ?? false; 420 } 421 return $user_id; 422 } 423 424 /** 425 * Records the ID of the user who flagged a post. 426 * 427 * @param int|WP_Post $post Post object. 428 */ 429 public static function record_flagging( $post ) { 430 if ( Registrations::get_post_type() === get_post_type( $post ) ) { 431 update_post_meta( $post->ID, self::META_KEY_FLAGGER, get_current_user_id() ); 432 } 433 } 434 340 435 } 341 436
Note: See TracChangeset
for help on using the changeset viewer.