Skip to content

Instantly share code, notes, and snippets.

@alicolville
Last active November 22, 2023 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alicolville/af3e216ae8dd1dd82b250b511e4ac252 to your computer and use it in GitHub Desktop.
Save alicolville/af3e216ae8dd1dd82b250b511e4ac252 to your computer and use it in GitHub Desktop.
Example User ID lookup
<?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