You didn’t provide any information on how you’re getting the script on the page to begin with. Assuming that this is something you have hardcoded into your template, here is a way you could approach it.
First, you need to check if the user is logged in, because if they are not, there’s no point in outputting anything since you wouldn’t have any data.
Next, use wp_get_current_user()
to get the current user’s info in a standard WP user object. The user’s email address will be in that object as $user->user_email
.
Here’s what that looks like in practice:
<?php
// Is the user logged in?
if ( is_user_logged_in() ) {
// Get the current user.
$user = wp_get_current_user();
// Output your script.
?><script>
rewardful('convert', { email: '<?php echo $user->user_email; ?>' })
</script><?php
} ?>
Related Posts:
- How to Add Image to WordPress RSS-Feed with no Plug-in?
- Childs PHP files not overwriting Parent’s PHP files
- Is it safe to use $_SERVER[‘REQUEST_URI’]?
- Namespacing WordPress project according to FIG standards
- Redirect to Page after Post Submit
- How will php 7 affect WordPress?
- How to add active class to custom menu using while loop and wp_list_pages
- Get list of WP Updates Across Sites
- automated tests as a user?
- WordPress Wysiwyg Content not being displayed
- Problems with function on function.php
- Want to create Child theme, but already edited Parent theme css files and some php files
- Switching between custom templates in a post type of the admin menu
- How to add a custom id to each post URL in wordpress
- How do I display the function the_content in this loop?
- Set WP_MAX_MEMORY_LIMIT higher than PHP.ini memory_limit
- Custom category code not showing all posts
- Custom Plugin For Converting CSV To MySQL
- Correct folder permissions?
- Link posts to pages for breadcrumbs
- WordPress add post format support not working
- Can I install/embed WordPress on a ‘single page’?
- Why WordPress won’t update via VPN?
- Create custom permalinks to show Custom Post Type’s relationship?
- conditional logic for front-end custom field edits
- Custom posts in different columns style
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- php syntax : [ && ] between commands [closed]
- Add user ID to woocommerce customer dashboard
- How to do a code in php and have text before it? [closed]
- Which PHP page is the Default Posts Page
- Need to put a script above tag in header.php – WP 5.7.1
- Code Executing Too Late?
- New walker for walker_nav_menu to change inside container data
- Add data-id attribute to child page links
- Isotope Drop Down Categories Filter Function
- Getting users with a specific meta data and then querying their posts?
- Making your own custom post views count
- How to remap one of the TinyMCE Advanced Editor button to open the wordpress media library?
- How to allow download url redirection only if user logged in WordPress site?
- trying to get wp_get_attachment_url to output clickable link
- Conditional multidimensional arrays and array_map
- A $_POST should occur when submit form but is not?
- Argument for if term-> have child?
- Select through customizer the template part to be viewed
- difference between sanitize_email ,FILTER_VALIDATE_EMAIL and input email type in html5
- Concatenate string to the_field()
- get users search not working with array
- Conditional featured image with youtube thumbnail
- How to change thumbnail src attribute?
- Get wp_current_user_id using PHP and MySQL
- get_page_templates only return templates with “home” in the filename
- Show different website layout if no sidebar added
- Showing Subcategory Name/Link Instead of Parent Category
- Get URI from PodPress using PHP
- How to pass hook variable to function?
- What does $2$3 mean? [closed]
- Writing a link cloaking plugin
- How to use wp_send_json() and output the value with ajax?
- How do you remove header sitewide from mobile only?
- Let current user know pending posts counts using wp_query
- How do I get pagination for get_posts() in WordPress or do I have to rewrite the whole code?
- How to setup the Email piping in WordPress plugin?
- Use wp_head hook on template page
- Gutenberg block don’t save rich text content
- how to remove a query arguments from all site urls?
- how to separate an array into different arrays and save them into db?
- How to enable HTML tags in category description without breaking the category page
- Remove duplicates from echo output in PHP [closed]
- I can’t separate the array by commas
- Trying to get pagination working on WP_Query() post grid
- How to add locations input to user profile?
- Get original value in save_post action hooka
- WordPress database error only while loading page for 1st time
- Multiple WordPress sites with different theme and plugin sharing the same content
- how to print total post count with 2 custom fields (date-range)
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- make an array in wordpress cusmization api?
- Code works on page-example.php by not category-example.php
- A custom RSS feed link, how do I modify the XML structure?
- Gravity Forms Marketo Plugin Feed [closed]
- Limit Search Queries per IP per Day
- How to correctly add the featured immage (thumbnails) support in a WP theme? Why I can’t add a featured immage?
- I am trying to call external database recieving error
- How can I order metaboxes in my posts in WordPress?
- How to call the_author_meta and make it work?
- wordpress taxonomy in regular posts
- Correct Syntax for uploading files to custom directory in WordPress
- Running self host server on Ubuntu, can’t increase upload limit past 2MB, tried all the solutions
- send meta box input data without publish button
- How to replace wp-admin login page to another location?
- How to find the value of the user password in wordpress and send it to another server via rest api
- Please help to know why single.php crashes after I add this code [closed]
- Please help! Parse error: syntax error, unexpected ‘
- use wpdb object on other file
- Field validation strlen works in php7.4 fails 8.1 [closed]
- How do I get a function to work in single.php
- Limit a search box by CPT + taxonomies, in only one page
- How to edit a widget code?
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?