Pass WordPress user email to calendly widget - wordpress

I would like to pass my logged in WP user email and user first/last names to my calendly widget. The calendly documentation explains how to do so with parameters but I'd like to do it without parameters, directly taking those from WP.
I haven't been able to find the solution and lack PHP skills.
This is what I have:
<!-- Calendly inline widget begin -->
<div class="calendly-inline-widget" style="min-width:320px;height:580px;" data-auto- load="false">
<script type="text/javascript"
src="https://assets.calendly.com/assets/external/widget.js"></script>
<script>
Calendly.initInlineWidget({
url: 'https://calendly.com/fabiennewintle/chat',
prefill: {
name: first_name,
email: user_email,
}
});
</script>
</div>
<!-- Calendly inline widget end -->
The problem is with the prefill, I imagine I would have to use the wp_get_current_user() { function but I don't know how to use it and how to connect it to this iframe from my child functions.php.
If anyone had any advice I'd very much appreciate it.

Related

Is there any way to show a specific Service Category in Amelia Booking Plugin Wordpress

I am creating a booking website, I am showing some products to user on a page which he wants to appoint for. On clicking one product, the user is redirected to the booking page of Amelia plugin. The problem is that there are many products and I don't want to show all the service Categories of Amelia on a single page, and also don't want to create a separate booking page for every product.
Is there any Solution for this?
"JUST SOLVED IT"
So I was looking for a solution that targets all the services in a single page, but only show the service that user clicks on the previous page.
The solution I came through was some custom HTML code (Paste this code on the page you are trying to show services):
<div id="show"> [ameliacatalog category=7] </div>
// Some more services like this
<style>
#show{
display:none;
}
// Hide services by their IDs
</style>
<script>
var id = window.location.hash;
id = id.substring(1);
myFunction(id);
function myFunction(id){
document.getElementById(id).style.display = "block";
}
</script>
And Now you can redirect links on your products or images like this
https://example.com/page#show
Thank me later ;)

Create a Dynamic Site Address in a Wordpress Menu

I'm doing some work on an existing site that is based on the Wordpress theme, but uses about 15 plugins (Including Buddypress). One in particular is the WP Sliding Login|Dashboard plugin, which has a link to the user's activity feed. I found the code that creates that link in the wp-sliding-login-dashboard.php file:
<?php
if ( is_user_logged_in() ) {
global $current_user;
$username = $current_user->user_login;
echo ' <li>Activity Feed</li>';
}
?>
I want to use this code to send the user to the same location, but using the a link at the top of the home page. Unfortunately, the home page links are all created using Wordpress menus, which as far as I can tell, only allow for the use of static links attached to existing pages.
Do I create a dummy page to link to that exits only to execute the above code? Is that even possible? Picture a five-year-old trying to read Shakespeare, and you have an idea of my ability as a coder, so feel free to engage me as such - i.e. if you say, "oh just create a scoping function instead of creating a global function", i would stare at you drooling and confused.
Images for clarity: The sliding login menu (WP-Sliding Login|Dashboard Plugin), showing the target URL in the status bar as www.ferrignofit.com/members/FerrignoFit/activity/ (the current logged in user is FerrignoFit):
http://i.imgur.com/NPvmCXU.jpg
The main page Wordpress-based menu, which i want to go to the above URL, but is currently going to www.ferrignofit.com/activity/, a different page:
http://i.imgur.com/dIiFpDC.jpg
So here's a jQuery solution for this specific issue. From seeing the images you have, what you want to do is target a specific anchor in your dynamic WordPress menu.
As you may be aware, you can create custom links for the WordPress menu function... it simply lets you set a label and a URL. You should create such item and just give it a hash for the URL for now.
Now set a class for that specific menu item so you can have a nice handle for jQuery to target it (otherwise you can use the dynamic class that WordPress creates for each specific menu-item).
One you have a class set or you know what you need to target then you can add this block of code before your menu.
<?php if (is_user_logged_in()){ ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
var userName = '<?php $current_user = wp_get_current_user(); echo $current_user->display_name;?>';
var userUrl = 'http://www.mywebsitename.com/members/'+ userName +'/activity/';
targetNav.attr('href',userUrl);
});
</script>
<?php } else { ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
targetNav.attr('href','http://www.stackoverflow.com');
});
</script>
<?php } ?>
Please not that I am using PHP to get the current username in WordPress, after I get the username and I store it in the userName variable I use it in the userUrl to set it with the path that I want.
On another note, I'm using is_user_logged_in() so you have the option of making the link something else if the user is in fact not logged in. So with this if statement one of the two blocks of code will be output by PHP.
As soon as my two variables are set, I simply target my menu item with jQuery and modify the href attribute to replace the hash with the path and dynamic username.
Though this is not very good practice to mix JS and PHP, I'd like to learn myself here what other solutions someone can suggest so I'm posting this as a solution for your very specific issue.
I tested this code with my own WordPress site and it works, just remember that this code NEEDS to be in a PHP file otherwise the PHP used in the <script> tags won't mean anything to the server if it's in a .js file.

Wordpress - Erase "Roles" on Profile Page

I'm new at Wordpress plugin creation and still trying to get the concept of action hook or filter hook.
I've created a custom role for "moderator". What I want for this role:
- in charge of users with specific role, e.g. subscribers.
- able to change users password.
- NOT able to change other users roles.
the problem is this: to be able to change other users password the moderators will need to have access to user profile page. But, on the user profile page, the moderators can change the other user role. I'm able to hide it by changing the wp-admin/user-edit.php but I think it's better done by plugin. So, how to hide / modify the "roles" selection with a plugin?
Thanks for the help.
To make it more clear, I'm attaching a picture for it.
There are no hooks to remove that. It has to be solved with CSS and/or jQuery.
Here, both CSS and jQuery do almost the same, you can choose one or another, or use both.
The current_user_can has to be adjusted to your roles/capabilities setup.
Note that the hook admin_head can have a suffix, so it'll only run in that specific /wp-admin/WP-PAGE.php address.
add_action( 'admin_head-user-edit.php', 'so_13598192_remove_roles_dropbox' );
function so_13598192_remove_roles_dropbox()
{
// Admins can edit that, exit without printing scripts
if ( current_user_can( 'administrator' ) )
return;
?>
<style>
label[for=role], #role
{
display:none;
}
</style>
<script>
jQuery(document).ready(function($)
{
$('label[for=role]').parent().parent().remove();
});
</script>
<?php
}

How to pass data between wordpress pages

I am new to wordpress and i want to transfer data from one page to another in wordpress. I used php to post my form data to a wordpress page. My code is:
<form method='post' action='http://www.example.com/www/create_website/'>
.....
<input type ='submit' value = 'OK'/>
</form>
But every time i clicked the submit button i got error page not found. Why it is so because link is loading the page in browser but not working for form post. How can i solve the issue???
Having spent about a day figuring out how to do this, I thought it might be helpful to others in the stackoverflow community.
GOAL: To take the results from a form field and use it on another page.
In this example, my client wanted users to be able to fill in any amount in a text field to make a Paypal payment. I'm using S2Member plugin to create buttons and hook up the Paypal payments, but they did not offer this functionality --only buttons with hard wired amounts.
You can see this in action here:
http://virginiabloom.com/?page_id=250 . But it is LIVE. If you start a paypal payment, it WILL deduct money from your account. Which will make Virginia very happy.
HOW I SOLVED IT:
First, I created a form just for this field.
Enter Other Payment Amount $
Next, I found a very simple plugin on stackoverflow and adapted it to my needs:
<?php
/*
Plugin name: redirect on post
Desciption:
http://stackoverflow.com/questions/13686245/how-to-create-a-custom-url-based-on-dropdown-in-wordpress-form-submission
I-changed-dropdown-to-field-input
*/
function redirect_on_submit() {
// check if the post is set
if (isset($_POST['amount']) && ! empty ($_POST['amount']))
{
header( "Location: yourUrl.com/?
page_id=542&amount=" . $_POST['amount'] );
}
}
add_action('init', redirect_on_submit);
NOTE: Change the page URL and ID information in the header to point to the Wordpress page you want to send the information to.
If you don't know how to manually install a plugin, its very simple.
Save the snippet as a .php file. Open up your hosting account and find the plugins folder (its in the wp-content folder) Copy the file into the folder.
Go back to Wordpress and look at your plugins. You should see it there. If its not activated, the activate it.
I installed another plugin:
Allow PHP in Posts and Pages (Version 3.0.4)
After installing it, the plugin will appear on the Wordpress menu.
Open it and you can use their snippet maker that will put php into your post inside a short code.
Configuration:
Show the snippet not found message: yes (for debugging)
Use the old (pre.2.2 code: no
Use the advanced filter method: yes
Remove all plugin data on install: no
You should see the code snippet box appear at the bottom of the page.
My snippet was simple. I just wanted to echo the "amount" parameter from the page url. So it looked like this:
echo $_GET['amount']?>
Note that you have to put the ending php tag, but not the beginning tag.
Now, you just use the shortcode [php function=1] on the page wherever you want to get this parameter.
Here's what it looks like on MY results page.
<h2>Payment of $ [php function=1]</h2>
<strong><em>Click Paypal button to start payment or cancel.</em></strong>
[s2Member-PayPal-Button sp="1" ids="xxx" exp="24" desc="Payment" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="yoururl.com"
ra="[php function=1]" image="default" output="button" /]
To make sure that users can only enter in decimal numbers, I used jQuery validation on the form. There are other ways to do it, but this was very simple. Just put this code on the page with the form which I've included below.
<form id="myform" action="http://virginiabloom.com/?page_id=542" method="post"><span style="font-size:1.5em;">Enter Other Payment Amount $</span><input id="amount" class="left" name="amount" type="text" /><input type="submit" value="Submit" /></form>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
$( "#myform" ).validate({
rules: {
amount: {
required: false,
number: true
}
}
});
</script>
That's it! I hope this helps somebody.
If you need to go to one of your WordPress page, please don't put the direct link in action.
Instead of that put the below php code.
<form method='post' action='<?php bloginfo('url'); ?>/your-page-name/' >
If you wants to go to a particular file inside your template directory put the below code
<form method='post' action='<?php bloginfo('template_url'); ?>/your-page.php' >
Check this WordPress codex page for more about bloginfo.
<?php bloginfo('url'); ?>
will generate the base site url.

Make WordPress User Name the Email Address

Is it possible to make WordPress user name the Email Address?
So unername could be hidden or not required and is replaced with email address.
I know there are plugins that can allow users to use their email as the log in, but they still have to enter the username when they register. I want to try and do away with the username.
I know this thread is over a year old now, but I just tested creating an account where the username is an email address and it works. In theory, you could create a front-end signup form that saves the email variable to both the username and email fields in the database.
WordPress allows usernames with some special characters, so this is a completely valid way to sign people up: http://codex.wordpress.org/Function_Reference/sanitize_user
Yes it is possible. Even you can configure WordPress to Login, Register and Retrieve Password using Email only.
You can put the code below in your theme's functions.php file.
Step-1: Remove Username textfield
add_action('login_head', function(){
?>
<style>
#registerform > p:first-child{
display:none;
}
</style>
<script type="text/javascript" src="<?php echo site_url('/wp-includes/js/jquery/jquery.js'); ?>"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#registerform > p:first-child').css('display', 'none');
});
</script>
<?php
});
Step-2: Remove Username error
//Remove error for username, only show error for email only.
add_filter('registration_errors', function($wp_error, $sanitized_user_login, $user_email){
if(isset($wp_error->errors['empty_username'])){
unset($wp_error->errors['empty_username']);
}
if(isset($wp_error->errors['username_exists'])){
unset($wp_error->errors['username_exists']);
}
return $wp_error;
}, 10, 3);
Step-3: Manipulate Background Registration Functionality.
add_action('login_form_register', function(){
if(isset($_POST['user_login']) && isset($_POST['user_email']) && !empty($_POST['user_email'])){
$_POST['user_login'] = $_POST['user_email'];
}
});
There is also a plugin to achieve this functionality.
Plugin: https://wordpress.org/plugins/smart-wp-login/
The username is a core entity in the WordPress DB and philosophy and it can't be bypassed like that. Now if you want to let users login with their emails, use this plugin: http://wordpress.org/extend/plugins/wp-email-login/ It allows you to login with either email/pass or username/pass. Found it like a month ago, works like a charm.
Even plugins that use alternative means for registration and login (facebook, twitter and Google) create a username (for instance, one plugins I've tried creates usernames like fbX where X is the facebook ID. Unfortunately it is not something we can work around.
Hope this helps! :)

Resources