Last active
November 22, 2023 11:41
-
-
Save alicolville/af3e216ae8dd1dd82b250b511e4ac252 to your computer and use it in GitHub Desktop.
Example User ID lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set the user that you wish to load to one passed via qs, if not, default to logged in user id | |
$user_id = ( false === isset( $_GET[ 'user-id' ] ) ) ? (int) $_GET[ 'user-id' ] : get_current_user_id(); | |
// Worth checking that the user we're trying to view exists | |
if ( false === get_userdata( $user_id ) ) { | |
// display error saying user doesn't exist | |
} | |
if ( false === does_user_have_permission_to_view( $user_id, get_current_user_id() ) { | |
// display error saying this person can't view that person's data | |
} | |
bmi_component_gravity_view( $user_id ); | |
bmi_component_wt_start_weight( $user_id ); | |
function bmi_component_wt_start_weight( $user_id = NULL ) { | |
if ( true === empty( $user_id ) ) { | |
$user_id = get_current_user_id(); | |
} | |
// Where possible, call PHP functions directly over the do_shortcode() method, e.g. | |
// note: if doing this, worth doing a function_exists() call to ensure the relevant plugin is still enabled. | |
echo ws_ls_shortcode_start_weight( $user_id ); | |
} | |
function bmi_component_gravity_view( $user_id = NULL ) { | |
if ( true === empty( $user_id ) ) { | |
$user_id = get_current_user_id(); | |
} | |
$shortcode = sprintf( '[gravityview id="9201" searchfield="user_id" search_value="%d"]', $user_id ); | |
do_shortcode( $shortcode ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment