Hiding buttons design - button

So I have a home page with a number of button links on, but I need certain ones to be hidden depending on who is logged in.
My initial thought was to save several different copies of my home page and then send the user to the appropriate one when they log in.
Can anyone suggest a neater way to do this?

I would not recommend to have different sites if it's only about changing some buttons and not the complete context.
Since code examples are missing i'll have some assumptions.
Let's say if your use is logged in you have set
$_SESSION['logged_in'] === true
Then just write your html like this
<!-- ... -->
<p>This is visible to everyone</p>
<?php if ( isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true ) { ?>
<p>Only logged in users see this</p>
<?php } ?>
<?php if ( !isset($_SESSION['logged_in]) ) {?>
<p>Only not logged in users see this</p>
<?php }?>
EDIT
This of course requires you to run not html but php pages. Don't forget to call session_start(); before using sessions.

Related

how can we add the functionality in button of divi theme of wordpress

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.

restrict viewing photos and article content on a wordpress site

I have a question, and i hope i am posting in the right place, if this topic belongs to another forum, please guide me where to post it.
the question is: i have a website created with WordPress and i am using the Jupiter theme, i need to hide some content (like hiding the last half of the article in a page) and disable the photos to be enlarged unless the visitor is a registered user, i need to know how to do that, and if there is a plugin to do that, i have tried "layered-popups-for-wordpress" and "optin-content-locker-layered-popups-addon" but they didn't work properly.
It might request a lot of effort for you to edit the theme on your own...You can use the_excerpt() insetead of the_content() for display info, and add a rule that only registered members can see, something like
if(is_user_logged_in()) {
the_content();
} else {
the_excerpt();
}
Do this while in the loop, of course...
These plugins might help you though
https://wordpress.org/plugins/tags/paid-content
If you're using WPMU might try this one
https://premium.wpmudev.org/project/pay-per-view/
I don't know of a plugin that does this automatically, but you can do it yourself if you are willing/able to do some minor theme development. Make a child theme of your Jupiter theme, and copy over the file content.php. There will probably be some part of the code that looks like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or something like that. The point is, the theme should already be set up to serve excerpted content for a search. You could either simply add code like this:
<?php if ( is_search() || !is_user_logged_in() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or you could customize what non logged in users are seeing like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else if (!is_user_logged_in()) : ?>
<!-- Your custom code display here -->
<?php endif; ?>
Hope that's helpful!
In order to hide certain parts of your content with just a simple shortcode you may give "Restrict Anonymous Access" plugin a try:
https://wordpress.org/plugins/restrict-anonymous-access/
Examples:
[member]My restricted content …[/member]
This shortcode can be placed wherever you need to hide something from logged-out users or even users of a certain user role can be addressed:
[member role="author"]My restricted content to users below author role …[/member]

Wordpress 3 plugin to control widget visibility

Coming from a Joomla background one of the fist things I realised is that Wordpress 3 doesn't have native support for controlling the visibility of widgets (modules in Joomla).
I've tried:
Dynamic widgets - http://wordpress.org/extend/plugins/dynamic-widgets/screenshots/ but it seems to break the admin menus.
Also tried Widget context - but it doesn't display correctly and doesn't allow granularity on the page visibility level.
Can anybody recommend a solution?
Try Widget Logic -- http://wordpress.org/extend/plugins/widget-logic/
Hope this helps!
-æ.
You can use Display Widgets. It adds checkboxes to each widget to either show or hide it on every site page: http://wordpress.org/extend/plugins/display-widgets/screenshots/
Make sure to disable other similar plugins to avoid conflict.
Example from sidebar.php:
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
Lets say you want to display this only on a page called "about-us". use is_page() function provided by wordpress.
<?php if(is_page('about-us')) { ?>
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
<?php } ?>
And as for the user level:
<?php if(current_user_can('level_10')) { // Level 10 = Administrator ?>
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
<?php } ?>
Please see Wordpress User Levels
PS: I saw the plugin provided by aendrew and I had a look at it.
Try this:
Make a backup of widget_login.php file then open it, search for line 75 and replace it with update_option("widget_logic", "is_page('" . $wl_options . "')"); This should easy up the stuff a little, when you limit a widget you have to add is_page('bla-bla') in that input that line should only require bla-bla (If the page is called Bla Bla) [not tested, but you can give it a try.]
Try this:
http://wordpress.org/extend/plugins/conditional-widgets/
Really user friendly, hope it helps
For anyone still looking for a plugin for this purpose, check out my plugin Widget Visibility.
It's user friendly (uses checkboxes) and works inside the WordPress customizer too.

How to customize User points section in user profiles

I'm using User Points module which adds an User Points tab to the users profiles.
I want to remove the link "View" from the user Points tab in User profiles, and leave only the score number.
I'm looking for the template using theme developer module:
http://dl.dropbox.com/u/72686/userpoints.png
However, the template user-profile-item.tpl.php contains only:
<dt<?php print $attributes; ?>><?php print $title; ?></dt>
<dd<?php print $attributes; ?>><?php print $value; ?></dd>
and I cannot do a lot with it.
The template contains only:
<div class="profile">
<?php print $user_profile; ?>
</div>
So, where is the template I need to modify how the User Points are displayed in user profiles ?
thanks
The user profile is a bit tricky because it's so generic. In this case you don't want to change the markup but the actual content.
You can do this by.
use hook_preprocess_user_profile where you can alter the value used
Implement hook_user yourself, and overwrite the data provided by user points module to remove the unwanted links. (They are only available if you have permission)

Drupal is allowing viewing of unpublished content

I inherited a Druapl5 site and it's showing content when published is not checked in the Publishing Options section of the Edit Content Form.
I confirmed that the status is 0 in the DB for the node. So it should be not visible.
My first guess was that I was logged in and that's why I could see it, but I logged out and I could still see it. I tried a different browser and the same thing so it's not that.
Also, the unpublished nodes are coming up in the search results which I originally thought was an out of date search cache, but may be something different.
Ever seen anything like this? Any ideas?
You mentioned in a comment that Content Access is installed on the site. This module (as well as several others, e.g. ACL) overrides the default Drupal node access mechanism in order to provide additional/more fine grained permission settings.
So my guess is that the permission configurations in that Module are configured wrong for your desired results. As far as I recall, it allows separate permission sets per content type (defined for authors and roles). You should look at your content type edit/definition pages - there should be a tab added by that module to configure the permissions. Also check the readme.txt of the module, as it might give some additional hints.
If that does not help, you should check if other node access modules are installed as well. As mentioned, there are quite a few of them, and their interactions are not easy to determine (One should aim to use only one, if possible).
Are you using Views? If so, make sure you have a filter set to show Published only.
I ran in to a similar problem with comments, which lead to some excellent spamming opportunities until I discovered it.
Rather strange. No answers, only guesses:
Try accessing admin/content/node-settings and click on Rebuild permissions.
And maybe clear the cache admin/settings/performance
Check your permissions for anonymous users. Seems like somewhere they have the wrong permisions.
All access modules override the default settings while using hook_node_access(). Most likely this is the problem. So you need to tweak those settings in the content access portion.
And this is not the best solution. But if you need something in the interim you can always put this code in the node.tpl.php file:
if(!$node->status && $user->uid != 1){
with code added:
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">
<?php print $picture ?>
<?php
if(!$node->status && $user->uid != 1){
?>
<?php if ($page == 0): ?>
<h2><?php print $title ?></h2>
<?php endif; ?>
<div class="meta">
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted ?></span>
<?php endif; ?>
<?php if ($terms): ?>
<span class="terms"><?php print $terms ?></span>
<?php endif;?>
</div>
<div class="content">
<?php print $content ?>
</div>
<?php
if ($links) {
print $links;
}
}//if for published node
?>
</div>

Resources