Wordpress-Restricting parts of a post to specific users - wordpress

I have a site that is going to be used by Real estate agents, Brokers, and apt. hunters to locate and lease apartments. I need the brokers to be able to add showing instructions to their listing that agents can view but not edit and the public cannot view.
I am using a "real estate" theme that has gotten me 2/3 of the way there but this added functionality that I require doesn't seem to be able to be plugged into the theme with... a plug in. I've tried Advanced custom fields, members, and numerous other role, and custom field plug ins. I was convinced that this project would or could be supported by some existing plugin or widget but am now not so sure.
If anyone has experience with this please throw me a bone. I dont expect code examples but just a pointer in the right direction.
Thanks in advance!

Assuming the theme uses custom roles for brokers/agents etc, why not add a custom field to the listing editor screen, then use an if current_user_can capability check in the template to display it.
e.g
<?php if( current_user_can( ' edit_listing ' ) : ?>
<?php echo get_field( ' instructions ' ); ?>
<?php endif; ?>

Related

Using wordpress Api for wordpress features

I am building an external website for a client using the bootstrap 4 framework. and they have a Wordpress with all of their data linked, music and videos, etc stored in it. The Wordpress acts as just a management system for their content. I will be building a separate webpage/site for them to present to their users that will allow users to sign up and subscribe for the mailing list and updates etc.... SO having to never use an API ever. I was wondering what do I need to place in the index.php file to call upon the wordpress api from https://wp.example.com. Does it need to go into the head section or right before the closing body tag?
I would like to use the WordPress Api to GET or echo the current user's avatar and username. to include inside the bootstrap header navbar.
<?php
global $current_user;
get_currentuserinfo();
echo get_avatar( $current_user->ID, 64 );
?>
<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) {
echo 'Welcome Back, ' . $current_user->user_login . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; }
else { wp_loginout(); } ?>
and finally last but not least I would like to use the wordpress api to check if a user is logged in/out to display/hide a bootstrap button the will contain an exclusive menu. I'm pretty new to this but I think its something like this
<?php global
if ( is_user_logged_in() ) {
// <button type="button" class="btn btn-outline-primary">Menu</button>
} else {
<button type="button" class="btn btn-outline-primary">SignUp/Login</button>
}
?>
BUt I Dont know exactly how to call or request, head or include or whatever it is that is required to use the api from the https://wp.example.com installation in the html or where to place it ie. , , to make these functions work. Please Help
Definitely follow cabrerahector's advice and look at the documentation for the WordPress API...that is the best place to start.
To answer your question...the only reason to use the WP REST API is when you do not want to use WordPress for handling the front-end of your website.
So... you will not be using your 'Theme' folder except for index.php, functions.php and style.css.
You will also probably want to put your WordPress install in a sub-domain and run your front-end from the primary domain.
I put the following code in my theme's index.php
<script type="text/javascript">window.location = 'http://admin.example.com/wp-admin/';</script>
check out this article Using WordPress as a Headless CMS
Also, the WP REST API is limited...I have had to add several custom endpoints because some data is not included out-of-the-box.
You can get 'user' data by using the following endpoint
GET /wp/v2/users/<id>
REST API Handbook/users

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.

UPME (User Profiles Made Easy) Profile Fields in Template

I am looking to display only certain fields from the User Profiles Made Easy Plugin on my page. The users 'Display Name' for example, I don't need the full profile, just the display name. Can anyone point me in the right direction on how to do this?
I have looked at the docs, posted on the plugin forum and trawled the Internet for help but I can't find any.
Currently I can only get the whole profile to display, even when I pass the display_name in.
<?php echo do_shortcode("[upme view=display_name]"); ?>
Any help would be appreciated.
Thanks.
I managed to accomplish this using the following code:
<?php
$display_name = get_user_meta($user_ID, 'display_name');
$description = get_user_meta($user_ID, 'description');
?>
Then I pulled the value from the array using:
<?php echo $display_name[0]; ?>
I am no php expert so I am not sure if this is efficient (or even correct), but it seemed to work for me.

How Create Responsive One Page WordPress Theme with scrollable effects?

Where can I find a soucre that learn to create a Responsive One Page WordPress Theme so when I click on the menu item it scroll down.
Here is an example of what I want http://thememints.com/templates/?theme=Cingle%20WP.
I have had exactly the same question and after searching around found this post.
I was rather shocked to see the responses to this question. It seem to me like people are quick to answer questions without properly reading the question.
All the contributors have given solutions to responsive and parallax scrolling websites but not one has answered the real question.
It is not too broad, and it is not vague. All he is asking is how you go about creating a Single page theme in WORDPRESS.... no one gave any direction as to how to accomplish this.
Not sure why these answers got rated as usefull .
So after digging around with trial and error I found the following to answer the question as to how you go about to create a single page WORDPRESS theme.
One of the major aspect to understand is the Wordpress query-post function which allows you to post multiple page content such as home , about, service and content onto a single page.
To create the the menu structure to scroll to the different sections I found this tutorial to be usefull - create-a-single-page-wordpress-website
I hope this helps
As William Patton said this is a broad question but as far I can understand this may help :
http://www.designerledger.com/parallax-scrolling-tutorials/ for the one page theme.
and a basic start for wordpress development theme :
http://codex.wordpress.org/Theme_Development
Update : I found this awesome plugin that helps you create full screen pages
https://github.com/alvarotrigo/fullPage.js
EDIT 2016
Due to the many up votes at user3263807 answer I made a small/basic one page guide for wordpress. For css/js there are plenty good tutorials and plugins over the internet. Also I assume you are familiar with WordPress Themes.
First of all you should create a template file for your one page. Let's call it template-one-page.php. The template name, commented inside the file, is the name that will appear in Page Attributes -> Template when you creating a page inside admin panel. After that create a page, ie Home, and assign as template your template. If you want your page to appear as front page (when you enter mydomain.com this page will be shown) go to Setting->Reading->Front page displays->A static page and set as front page your page.
// File Security Check
defined('ABSPATH') OR exit;
/*
Template Name: One Page
*/
?>
Normally a one page has sections. So we want to decide what type of sections we want. It could be pages, child pages, posts, custom fields (like a repeater from ACF) etc.
<?php
$id = get_the_ID(); // The page id
$sections = get_posts(array('post_type' => 'page', 'post_parent' => $id)); // get all child pages
foreach ($sections as $key => $section):
?>
<section id="page-<?php $section->ID; ?>" <?php post_class('', $section->ID); ?>>
<h1><?php echo get_the_title($section->ID); ?></h1>
</section>
<?php endforeach; ?>
Or with a Loop
<?php
$id = get_the_ID(); // The page id
$query = new WP_Query( array('post_type' => 'page', 'post_parent' => $id) ); // get all child pages
if($query->have_posts()):
while ( $query->have_posts() ) : $query->the_post();
?>
<section id="page-<?php the_ID() ?>" <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
</section>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
You can query what ever you want depending the need of your site.
you should take look at below link:
[1] http://www.1stwebdesigner.com/css/responsive-website-tutorial/
[2] http://www.1stwebdesigner.com/css/create-a-responsive-website-video-tutorial/
[3] http://readwrite.com/2013/04/16/10-developer-tips-to-build-a-responsive-website-infographic#awesm=~okrhufNGLHp1mh (Best one to keep points in mind while creating )
Thanks.
Here is full detailed video tutorial that deals with setting a one-page scrolling Wordpress website from any theme you want. Need to join - there is a free trial. This allows you to "peek under the hood" and understand the principle of how the other one page themes and plugins were created.
http://www.lynda.com/WordPress-tutorials/WordPress-Building-One-Page-Style-Site/169876-2.html
I have looked into several ready-made themes, such as Onesie and OneEngine, and found them a nightmare to manage on the back end, very user unfriendly. The content of the long home page with several sections in both themes is managed not through the Pages section, like one would assume, but through a different admin section in the Appearance folder, with none of the usual Wordpress interface controls. The tutorial above deals with it properly, with the real Wordpress Pages assembled by a custom loop on the front page and menus working in the same way as built-in Wordpress menus.
I used localscroll and scrollTo jquery plugin in my one page theme, it's working fine.
The plugins link:http://flesler.blogspot.com
After you imported the jquery and plugins files into your page, just call the function like below, then if you click a anchor link, the page will scroll up or down smoothly.
$.localScroll({
target:'body',
duration:1000,
queue:true,
hash:true,
easing:'easeInOutExpo',
offset: {left: 0, top: -55}
});

Wordpress adding thumbnails to category

How to take on a problem in WordPress admin editing.
I'd like to edit an edit-category admin panel to add a featured image to it (just like in posts), but I'm a bit indecisive since a lot of people use a custom field with static path to a photo, but I'm wondering is there a way to do it better(enable some wp hook and such).
Can someone point me in the right direction?
Thanks for the plugin it seems good, but i have one additional problem. It seems i have a lack of knowledge on how to query an object [category] so i can apply filters, hope im making some sense. This is done on my home.php. all dumps are null
<?php get_header();
$listcat = get_categories('hide_empty=0');
foreach($listcat as $x){
$img = apply_filters( 'taxonomy-images-queried-term-image', '');
var_dump($img);
}
get_footer(); ?>
The same code works with no problems if i stick it in category.php. Any ideas? :)
i've used several times the plugin "Taxonomy Images". it works with multi-language wp installs too.
link with instruction: http://wordpress.mfields.org/plugins/taxonomy-images/

Resources