Advertisement
verygoodplugins

Untitled

Aug 8th, 2024 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. /**
  2.  * Function to check if a specific tag was applied and update user meta with the current URL.
  3.  *
  4.  * @param int   $user_id The ID of the user.
  5.  * @param array $tags    An array of tags applied.
  6.  */
  7. function update_user_meta_with_url_on_tag_application( $user_id, $tags ) {
  8.     // Get the tag ID for "DS - Free Course Check"
  9.     $tag_id = wpf_get_tag_id( 'DS - Free Course Check' );
  10.  
  11.     // Check if the tag is in the array of applied tags
  12.     if ( in_array( $tag_id, $tags, true ) ) {
  13.         // Get the current URL's relative path from $_SERVER variables
  14.         $current_url = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );
  15.  
  16.         // Update the user meta
  17.         update_user_meta( $user_id, 'url_tag_applied', $current_url );
  18.     }
  19. }
  20. add_action( 'wpf_tags_applied', 'update_user_meta_with_url_on_tag_application', 10, 2 );
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement