Wordpress E-mail before displaying content - wordpress

So, I have a lot of posts with custom content. Some of this content is hidden, for example prices. I want the prices to be visible after the user submits an e-mailaddress. But it has to be remembered via cookies.
I first tried to make user registrations with e-mailaddress only, but that's not what I want and is not very safe.
Then I wanted to try Email Before Download plugin, but that's not gonna work either. That gives me 1 link or 1 text per contactform (it uses contactform 7).
Is there a plugin for this?
Edit Maybe it's a better idea to use Sessions. I now have:
<input type="email" placeholder="E-mailadres" name="email" />
Then I made a session:
<?php
if(isset($_POST['email'])){
$_SESSION['user_email_set'] = true;
}
if(isset($_SESSION['user_email_set']) && $_SESSION['user_email_set']){
echo "Sessions made :)";
}
?>
But, when I refresh the page or go to another page, the sessions is lost. What did I do wrong?

Related

How to create gated content using ACF + plugin

I'm looking to create gated content using some sort of plugin with ACF.
Do any of you have experience with this?
The Gated content should be hidden from people that are not signed in.
I would like to create the user accounts myself and send the account information to the users - the users should not be able to register themselves.
I would also like to hide specific content on the page, rather than a full page.
Just like if you read an online newspaper and are prompted with a payment wall.
However, I don't need a subscription or payments for this solution - I simply need to hide content for regular users and show it if the users are signed in.
Any help is much appreciated.
Thank you.
Within the template of the block you can use logic like this:
<p>content for everyone</p>
<?php
if (is_user_logged_in()) {
echo "<p>hello, logged in user</p>";
} else {
echo "<p>hello, guest</p>";
}
?>

Issue with Wordpress Contact Form 7 Plugin - Dynamic Text Extension

I use the Contact Form 7 plugin for contact forms on our site. I am using this on a WP installation with multiple sites. We have employment application forms on each site, and to identify the site when we do a REST call to our webapp, I would like to include the site_id (or blog_id, I'm unclear on which is the right name) so it can be used to reference the WP site in the other app. I installed the Dynamic Text Extension for this particular task, and this is my first attempt, based on the help docs, to add a hidden field with the blog_id:
[dynamichidden blog_id id:blog_id "CF7_bloginfo value='blog_id'"]
and end up with this:
<input name="dynamichidden-927" value="Elite Trade Painting Calgary" size="40" class="wpcf7-form-control wpcf7dtx-dynamictext wpcf7-dynamichidden" id="blog_id" aria-invalid="false" data-hasqtip="true" type="hidden">
I should note that no matter what I put in the tag, the same value comes up. I know I am editing the right form because if I delete the tag, it disappears completely – but no matter what I change, it always has the wrong value.
https://elitetradepainting.com/calgary/employment-opportunities/
My mistake was looking at the wrong page and thinking that bloginfo() returns the blog id - it doesn't. The DTX developer answered my question in WP forums and advised me to use a shortcode, so I wrote a callback that uses get_current_blog_id:
in functions.php:
function get_blog_id_callback() {
return get_current_blog_id();
}
add_shortcode('get_blog_id', 'get_blog_id_callback');
Then the snippet for the control in the Edit Contact Form page is as simple as:
[dynamichidden blog_id "get_blog_id"]

I'm trying to integrate PayPal Payment with Contact Form 7 in WordPress, and my Redirect isn't working

I'm working on a Charity site where we want to accept membership payments and donations via paypal.
I am having a problem with Contact Form 7 and redirection to PayPal with a variable payment amount. I'm really hoping that someone can assist or shed some insight on this problem for me.
I read This Post, which made it sound quite easy but, while my email is being sent, the form isn't redirecting to PayPal, in fact it's not doing anything at all, not even giving me the "thank you your form has been submitted" notice.
my form has this line: £[text* AmountPaying 6/ id:PayingThis]
And under "Additional Settings" I have inserted this:
<script>
function my_redirect() {
var price = document.getElementById("PayingThis").value;
var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=#####&currency_code=GBP&amount="+price+"&return=http://www.example.org/join-or-renew-your-membership-online/";
window.location = url;
}
</script>
on_sent_ok: "my_redirect();"
does anybody have any experience with this ?
Thanks for the comments !
With some help troubleshooting from a friend I have figured out how to make this happen with contactForm7 - in fact, I believe you could extend this solution, and submit a lot of dynamic information directly to PayPalmy problem.
This is what I did - and it's essentially the same as this guy does here
BUT, instead of putting that code in the "ADDITIONAL SETTINGS" Area of the CF7 Form page - I added this:
<script>
function my_redirect() {
var price = document.getElementById("PayingThis").value;
var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=#######&currency_code=GBP&amount="+price+"&return=http://www.example.org/join-or-renew-your-membership-online/";
window.location = url;
}
</script>
up at the top, with the rest of the Form building html and tags, just before the code for the form itself:
Your Name (required): [text* your-name]
etc.
and then in the Additional settings box.. I only called the function
on_sent_ok: "my_redirect();"
and it worked! it takes the value the user enters in the "How much do you want to give us" box, and submits it to paypal
I hope others can benefit from this
thanks again for taking the time to view and help
-5tratus
Contact Form 7 is a great plugin but creating a form for PayPal gets a little tricky. Gravity Forms would be a great options but you would need the developers license that cost $200.
My recommendation is to look up the PayPal form API and create the form yourself, from scratch and integrate it OR you should have a look at the Advanced Custom Fields plugin, and the PayPal Field Add-on for Advanced Custom Fields! It's all free.
It enables you to set a form on any post/page/etc with a paypal button. All you have to do is add the <?php the_field('NAME_OF_YOUR_FIELD'); ?> to your template, wherever you want to display it.
http://wordpress.org/plugins/advanced-custom-fields/
http://wordpress.org/plugins/advanced-custom-fields-paypal-field/
Thanks 5tratus. Works.
An old support thread (https://wordpress.org/support/topic/contact-form-7-paypal-integration-1) was getting as far as redirecting to PayPal, but then PayPal was giving an "Page Not Found" "You have requested an outdated version of PayPal" message.
I didn't need price or any extra variables, so I cleaned it up to just redirect to the product page. Here's what I used and it works:
<script>
function my_redirect() {
var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=[PUT YOUR BUTTON ID HERE]";
window.location = url;
}</script>
As 5tratus says, put the above code in at the bottom of the form code itself, then put
on_sent_ok: "my_redirect();"
in the "additional settings" part.
Refer this useful plugin - https://wordpress.org/plugins/contact-form-7-paypal-extension/

Wordpress admin: set category from variable instead of checkbox

The only way to set a category to a new post seems to be to select the appropriate one via a check-box before submitting it.
At best, you can set a default category as an option in case no box has been checked by the user.
This is really a problem for me as my admin menus are and have to be the categories themselves.
As I mentioned, in my WordPress admin I have a custom menu listing category names. Clicking on one leads directly to the generic "add a new post" page.
What makes it less generic is that I have inserted the category ID within this link, like this: "wp-admin/post-new.php?cat=5".
At this point,I would like not to check a category from a box before submitting the new post. Instead, I want WordPress to use the variable provided in the URL and submit the category ID accordingly when my new post is ready to be published.
Is it possible?
Which file would I have to edit in order to achieve this?
Any other idea that would lead to the same result?
You can use an extension that you will develop. It is better than trying to modify Wordpress core files.
I did something that may help you in one of mine. Using this :
if(is_admin()){
add_action('post_submitbox_misc_actions', 'plugin_add_custom_box');
}
function plugin_add_custom_box(){
?>
<div class="al2fb_post_submit">
<div class="misc-pub-section">
<?php
echo '<input type="checkbox" id="plugin" name="plugin_action" value="1"/>';
echo '<label for="plugin">';
_e("Label", 'myplugin_textdomain');
echo '</label> ';
?>
</div>
</div>
<?php
}
This add a custom checkbox. Using the same name for the checkbox here than checkboxes already displayed by Wordpress and checking it analysing your URL, you will probably be able to store the category you want without modifying core files.

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.

Resources