How to create gated content using ACF + plugin - wordpress

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>";
}
?>

Related

Redirect "dumb" URL to Author's custom post

I have created a website whereby users register and create their own templated profile pages. The profile pages are automatically created as Custom Posts upon registration, with the user being set as the Author of their specific post (profile).
(Users can only ever have one Custom Post)
I want to redirect a "dumb" URL like www.website.com/my-profile to a user's custom post when they are logged in.
For example, when John Smith visits www.website.com/my-profile he is directed to his profile page: www.website.com/users/john.smith
I have found many PHP solutions going the other way, but I can't seem to find a solution that does what I need. Any help would be greatly appreciated. Thanks!
This may not be the correct answer to the original query, but proved to be a solid workaround:
Instead of redirecting www.website.com/my-profile to www.website.com/users/john.smith every time it is entered in the URL bar, I created a shortcode that could be used when needed throughout the site.
add_shortcode('bt_redirect_user_link', 'bt_redirect_user_link');
function bt_redirect_user_link ($atts) {
// check if user is logged in
if (is_user_logged_in()) {
// get current user object
$current_user = wp_get_current_user();
// get user nickname
$user_nickname = $current_user->data->user_nicename;
// set the link href
$link_href = '/users/' . $user_nickname;
// output the link html
return $link_href;
}
}
Fortunately for me, the www.website.com/my-profile link (which needs to be redirected) is only available on buttons/icons visible to logged in users. This may not be a fully workable solution for websites that need to display the link to logged out users, and I assume IF/ELSE statements would needed to be added in those cases.

WordPress: adding or enabling user/customer registration? And making content only visible when logged in?

I currently have a very basic WordPress site with a few pages.
There are no user accounts, only my own admin account.
What I'm looking for:
A possibility for visitors to sign up i.e. register their own customer account. I don't need detailed account information, just an email address and perhaps a name and/or company name.
Restrict certain content to logged in visitors only. Preferably when someone is not logged in I would want the page to show 'this information is only accessible for customers - log in or sign up here'. And if someone is logged in, show the actual content.
Caveat: I'm dealing with a Woocommerce site and one of the things I'd like to restrict to logged in users only is the Shop page. But as I understood this is not a normal page with regular content in Wordpress. I guess its content is generated or controlled through the Woocommerce plugin. So is there a way to pull this off?
I'd assume this is a very common pattern in WordPress and this is probably very simple. But being a total WordPress newbie with zero experience, I wouldn't know how/where to start.
User Registration
Those are default WordPress behaviors. Enabling registration can be done via the admin control panel.
Settings → General → Membership, ✓ Anyone can register
Once this is done, users can registered # http://localhost/www/wordpress/wp-login.php?action=register
Conditional Tags
Conditional Tags can be used in your Template Files to alter the display of content depending on the conditions that the current page matches. They tell WordPress what code to display under specific conditions. Conditional Tags usually work with PHP if/else Conditional Statements.
Source # https://developer.wordpress.org/themes/basics/conditional-tags/
Restricting content to logged in user can be done via the is_user_logged_in() function.
Determines whether the current visitor is a logged in user.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Source # https://developer.wordpress.org/reference/functions/is_user_logged_in/
Use Case Scenario
<?php
if ( is_user_logged_in() ) {
// ... logged-in user content
} else {
// ... non-logged-in user content
};
WooCommerce Conditional Tags
You can use is_shop() to determine if the current page is a shop page.
Returns true when on the product archive page (shop).
Source # https://docs.woocommerce.com/document/conditional-tags/#section-4
Usually the shop page is built around the archive-product.php page template. the following should englobe the content from the archive-product.php page template. You don't have to specify is_shop as we're building the conditional statement on the archive-product.php page template.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
};
/**
* Basic logged-in restricted `archive-product.php` page template example.
*/
get_header();
if ( is_user_logged_in() ) {
// ... logged-in user content
} else {
// ... non-logged-in user content
};
get_footer();
Template hierarchy
As you're new to WordPress you should try to understand the basics in term of template hierarchy. You should refer to https://developer.wordpress.org/themes/basics/template-hierarchy/. WooCommerce works the same.

Wordpress E-mail before displaying content

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?

Turn advertisements off or on for members on Wordpress website?

Does anyone know how I could enable members who created an account on my WordPress website (http://developergenius.com) to be able to disable disable advertisements in the My Account (http://developergenius.com/my-account) page on my website? I want it where they could just hit a check box and then hit save and advertisements would disappear, then they could always turn them on again.
Please note that I am kind of a beginner, sorry about that!
The thing you are looking for is:
is user logged in
this is a built in wordpress function you can use.
for example:
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
echo 'Welcome, visitor!';
}
?>
you can play with it and add functions to the control panel, to the actual site and more.
if you want more options you should also see:
Roles and Capabilities
This feature gives you the power to what kind of user is logged. (admin, user, subscriber and so)

How to create a profile page in Wordpress Multisite

I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta

Resources