I have a problem with usersultra plugin for wordpress.
I have created a template page for search, but i only want to display it for the client who is logged in, how can i use usersultra for this case.
Secondly when i check 'Only Logged in Users' checkbox in page settings it displays the content of my page and form of registration at the same time.
Please how can i resolve this problem.
EDIT :
this is what am trying but it doesn't work
<?php echo do_shortcode("[usersultra_protect_content display_rule='logged_in_based' custom_message_loggedin='Only Logged in users can see the content']
<b>myfield :</b><?php the_field('myfield');?>
[/usersultra_protect_content]"); ?>
it only shows the text not the value.
EDIT 2 :
it worked with the code Ahmed provided
<?php echo do_shortcode("[usersultra_protect_content display_rule='logged_in_based' custom_message_loggedin='Only Logged in users can see the content']
<b>myfield :</b>".the_field('myfield')."
[/usersultra_protect_content]"); ?>
You can do that via this shortcode,
<?php echo do_shortcode("[usersultra_protect_content display_rule='logged_in_based' custom_message_loggedin='Only Logged in users can see the content']Your private content here [/usersultra_protect_content]"); ?>
The shortcode is listed here on documentation page : https://usersultra.com/userultra/
Related
I am using divi theme in wordpress for my site. and i add one header using page builder. I want that only logged in user can clicked on shop now button and if they are not logged in then they will redirect to login page
You are asking about quite basic functionality of the WordPress API:
boolean is_user_logged_in()
If you are modifying the theme directly or have enabled a plugin that lets you use PHP-code on your pages and posts, you can use this Wordpress-/PHP-function in combination with a PHP if-statement to check whether the current user is logged in and, in case he or she is, add really anythingto your page. Ok, except for a living unicorn.
<?php if ( is_user_logged_in() ) : ?>
Shop Now
<?php endif; ?>
You said if the current user of your web-page is not logged in, he or she is supposed to be redirected to the login-page. The else-statement is probably what you are looking for. And, if you are brave enough, try not to hard-code the login link here by making use of the WordPress API-function wp_login_url():
<?php if ( is_user_logged_in() ) : ?>
Shop Now
<?php else: ?>
Log In to shop
<?php endif; ?>
Remember, if you want to use this code on your wordpress pages, articles, widgets, whatever..., you have to install a plugin that lets you use PHP there. Also, this code is not completly free of avoidable repetitions for the sake of making the examples easy to understand. It should be easy to figure out how to optimize the code.
I have experience in HMTL/PHP but I cannot understand how someone could implement this basic functionality in Wordpress. I could not find an article or web page on their website or by searching through the internet.
I want to create a basic html form, pass some data as select queries in a database and visualize back the results paginated.
In traditional PHP we are using "action" in order to send the form data through POST or GET to the action page and then with some PHP code we can fetch the data and visualize it with tables etc.
I cannot understand how to do such a thing in a wordpress page. Where the action parameter should point to? How could I implement this basic functionality in WordPress?
Please could someone help?
This is the mode to develop a separated .php file which uses your wordpress theme and can access to almost all wordpress functions:
<?php include(’wp-blog-header.php’); ?>
<?php get_header(); ?>
<!– Your code here –>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Then you can use all WordPress functions cited here: http://codex.wordpress.org/Function_Reference
You can save this file anywhere, but be sure to insert correct path to wp-blog-header and there must not be any prohibiting .htaccess
This is the way to insert php code into a wordpress post:
You have to use this plugin http://wordpress.org/plugins/allow-php-in-posts-and-pages/
Then create a post and use [php] [/php] to insert your php code and open it. Look at the address bar. This it the URL to access this post. Use it as action parameter in your form. Then control $_REQUEST[] in your php code to extract parameters received from your form.
Now you can control this post as any other normal wordpress post from the wordpress admin panel.
You need to create custom wordpress templates for pages in your theme. Here i use templates
1.form-page.php --- with template name "Form-page-template" and
2.form-page-action.php ---with template name "Form-page-action-template"
form-page.php
<?php
/*
Template Name: Form-page-template
*/
?>
<?php get_header(); ?>
<form method="post" action="http://yourdomain.com/form-page-action/" name="input-form"/>
<!-- form contents -->
</form>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You just save this template inside your theme : location => like wp-contents/themes/your-theme/form-page.php . and this will add Form-page-template in your theme .Now create a page inside from wordpress dashboard through pages->addnew ,here i give page name "form-page" and select template for page from right pannel,here we need to select "Form-page-template" that we created early.
Now we have the page url :: http://yourdomain.com/form-page/ where we can see our form,now create form-action-page.
2.form-page-action.php
<?php
/*
Template Name: Form-page-action-template
*/
?>
<?php get_header(); ?>
<!-- Your action page contents goes here -->
<?php
//getting input etc.. you need to do
$input = $post['input'];
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Now you need to save this template inside your theme as above, Create a new page for this template as said above here i creating a page "form-page-action" with template "Form-page-action-template" so here i get a page url for our
action page like :: http://yourdomain.com/form-page-action/ , and you need to use this url as the action url in your form page.and this way you can add your form action page inside wordpress theme.
You can edit the contents of these page inside from wordpress like=> Appreance -> Editor , select the templates to edit.
I have the following code to generate the link to the author on a category.php page:
<?php while ( have_posts() ) : the_post(); ?>
....
<?php the_author_meta( 'display_name' ); ?>
....
<?php endwhile; ?>
Unfortunately, the link get an empty href attribute. The display name is populated properly. I am using the latest WordPress.
That won't point to the author archive. It'll point to the author's URL as specified in their profile settings under the WP admin dashboard. So if a user hasn't provided a URL then it will be empty.
It is because the USER haven't provided his URL (this is author url) according to the code.
Check in Wordpress Admin > Users > All Users > choose the user and edit the URL for the particular user and check.
It will show up.
Hope this helps you.
Is there an easy way to password protect an archive and single posts of a custom post type?
I found this article on password protecting single posts, but am still lost on the archive loop. I would want it only display the password box until the user has logged in.
https://wordpress.stackexchange.com/questions/4952/forcing-all-posts-associated-with-a-custom-post-type-to-be-private
Thanks,
The only way I've found to quickly password-protect the archive is by creating a template that retrieves the custom post type data and associating it with a page that can be password protected.
http://codex.wordpress.org/Page_Templates
Once that page is password protected, you find the post ID to apply it to the single-{your_custom_post_type}.php like so:
<?php
if ( !post_password_required('{protected_post_id}') ) : ?>
//protected content here
<?php else:
//show the password form of the protected page
echo get_the_password_form('{protected_post_id}');
endif; ?>
This saves you from having to password-protect every post under your custom post type.
For single pages you could just edit single.php and add something along the lines of:
<?php
if ( is_user_logged_in() ) {
// Show Post to Logged in User
}
else {
//Show password field
}
?>
If like you mentioned you are using a custom post type or an archive template you could apply the same method as above to single-[custom-post-type-name].php or archive.php
I've a site and I would create a simply "Members only" page.
I would add a protection to a page content so only editors and administrators can access.
This page should be visible to all users, but when a guest click on it, the page content is protected by username/password. When user fill these fields, the page automatically redirect to protect content.
Is there a plugin, or method, that I can consider?
There probely is some plugin for this kind of stuff, i mostly build my own themes, and implement it there.
if its just one page you want to protect, you could make a own template file for that page.
if the page name is "secrets", you could in the teames folder copy the page.php (or index.php) to page-secrets.php, and add some php code to protect that page.
a relly simple version could be:
<?php
get_header();
if($_POST['password'] == 'the password')
{
...
}
else
{
echo "<h2>This page is password protected</h2>";
echo "<form action='?' method='post'>";
echo "<label><span>Password</span>";
echo "<input type='password' name='password' /></label>";
echo "<input type='submit' name='Authenticate' />";
echo "</form>";
}
get_footer();
?>
where ... is the copied content from page.php (or index.php) between the get_header(); and get_footer(); rows
Wordpress has builtin "password-protect page" feature. If you are using some kind of a standard theme, all you need is to set a password inside a "publish" box at the page editor page (password field is hidden behind some link).
I advice you to use the "members" plugin
http://wordpress.org/extend/plugins/members/
it allows to protect page with role. If you protect page with 'subscriber', user must be logged.