Created
February 16, 2018 19:37
-
-
Save phoopee3/57b8c58fe5debab102be7b5c69c90017 to your computer and use it in GitHub Desktop.
I want to make an anonymous function that is based off a string i get from a database
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
// so i have two strings i get from a database, an action, and a callback function name | |
// let's say the action = 'comment_post', and the function name is 'my_comment_post' | |
// i want to add an action that is basically add_action( 'comment_post', 'my_comment_post' ); | |
// but i want to do this dynamically for any and all entries i have in the database | |
// how? | |
// in my plugin init i had this code, but it wasn't working | |
// $results->callback would be "my_comment_post" | |
// $results->hook would be 'comment_post' | |
${$results->callback} = function () { | |
// get the current user | |
$current_user = wp_get_current_user(); | |
if ( 0 == $current_user->ID ) { | |
// Not logged in. | |
return; | |
} else { | |
// add the point value to their point meta | |
update_user_meta( $current_user->ID, 'some_key', 'some_value' ); | |
} | |
}; | |
add_action( "$results->hook", "$results->callback" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my sample