modify BuddyPress adminbar only in admin pages - wordpress

I have modified the buddypress admin bar by creating the following plugin which adds a simple text link to the bar:
function bp_adminbar_currentsite_menu() {
global $bp;
?>
<li>
<!-- Insert your link url or relative url, and your link text below -->
EXAMPLE LINK TEXT
</li>
<?php
}
// Call The Function Above
add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);
However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a php_self check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here.
How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area?
Thanks

using is_admin() is the answer. It is a wordpress function that checks to see if you are looking at admin pages or not.

Related

Can Shortcodes be used in a Static WordPress Homepage?

I have a Static page set as the home page of my wordpress website. It has a custom shortcode to show a woocommerce catalog based on my own meta query.
When I add valid products, it does not show up immediately or even after a while. However, if I publish the static page, then it shows up magically, thus leading to my question.
What are my alternatives, if I want to show my shortcode on a static home page?
I think this is my problem and nothing else, because I tried disabling all plugins and clearing the cache, but still it did not show the latest added products.
You can edit the template of your theme adding the do_shortcode() function where you want the shortcode to be displayed, for example:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>

Hide Wordpress dashboard?

I'm new to wordpress and a bit confused with something. I'm trying to build a classified marketplace type of website for myself. I am NOT building this for a "client". I will probably be using a hack of several different plugins as my coding skills are not up to par. Eventually I will hopefully have lots of users who will be composed of buyers & sellers.
My question pertains to the WP dashboard. When buyers/sellers sign up for my site, will they be able to see the backend WP dashboard? I would prefer that they NOT be able to access a backend dashboard at all let alone a WP branded one. Is this possible? If so any clue as to how this might be accomplished?
thank you Brian
Normal users do not actually see the 'backend' WP dashboard. What they are seeing is a 'profile' type page meant for the original functionality of wordpres; being a blog.
If you do not want users to go to this page when they log-in, you can use a couple of hooks. Here is some code that redirects to the front page after logging-in and logging-out. This goes in your functions.php file.
add_action('login_form', 'ang_redirect_to_front_page');
add_action('wp_logout', 'go_home');
function ang_redirect_to_front_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
function go_home(){
wp_redirect( home_url() );
exit();
}
And, if your theme is still displaying the menu at the top of the screen that allows the users to go to this 'profile' area, you can go into your footer.php file and remove this:
<?php wp_footer();?>
However, if you do this, then you will not see it as the admin either.
WordPress is might not be the thing to use for that kind of website, even with a bunch of plugins. Read up on other content management systems just incase.
This link might answer your question:
http://buddypress.org/support/topic/how-to-prevent-non-admins-from-accessing-wp-admin-dashboard/
You can also add this to your theme's function.php file:
// DISABLE ADMIN BAR FOR ALL USERS
show_admin_bar( false );
If you are not too used to wordpress, use WOOCOMMERCE plugin. Its completely free and well documented

How to highlight comments in WordPress admin panel?

I want to highlight author comments in admin panel of WordPress engine. I have many comments on my blog every day, and it's hard sometimes in admin panel to find my own comment.
This can be achieved with a targeted action hook and a bit of CSS:
add_action( 'admin_head-edit-comments.php', 'colored_comments_so_15232115' );
function colored_comments_so_15232115()
{
?>
<style>.comment-author-USER_LOGIN { background-color: #DFDB83 }</style>
<?php
}
Replace USER_LOGIN with your login name. And surely, you could add as many users/background-colors as needed.
This CSS is only printed in the Comments page (/wp-admin/edit-comments.php) by using the hook admin_head-$hook_suffix.
You can also use a plugin: Comment Moderation Highlights
note: I'm the plugin developer.
Set it so that it looks for your email addresss, pick a color and save. All your comments will be Highlighted within the comments admin.

Wordpress user dashboard custom left menu example code help needed

I need help to show the left menu item on other role users dashboard. I am using the code at plugin to add the custom admin menu items .
add_action('admin_menu', 'wp_hotlel_admin_menu');
function wp_hotlel_admin_menu() {
add_menu_page('Page Title', 'Menu Title', 10,'unique-slug','ChainForm_page');
function ChainForm_page() {
echo "test";
}
The menu is being displayed and working at admin dashboard. But not being displayed at other users dashboard. I am being logged in through Wordpress basic users login section.
I have added the line below,
global $wp_roles;
$wp_roles->add_cap('Subscriber','wp-wall');
Subscriber is my user type. The menu item is not being displayed still at general users custom menu.
Please help me to fix this.
Thanks in advance.
The add_cap has been deprecated since version 2.8 I believe. You could use something like:
<?php
if( current_user_can( 'edit-posts' ) ){
//YOUR CODE HERE
}
?>
See the Codex Pages for Roles and Capabilities:
http://codex.wordpress.org/Roles_and_Capabilities
And a simplified version:
http://web-profile.com.ua/wordpress/dev/user-capabilities/
Your value 10 (the third argument) should be replaced with a capability (e.g. 'edit_pages'). User levels are deprecated. Here is a list of all available capabilities and their associated roles.

why is the <?php wp_head ?> tag creating a top margin at the top of my theme header

Hey people, I've been coming here for a while but just decided to join.
I'm new to php and I'm trying to make a website with WordPress as the CMS.
Anyway, I'm basically making my own theme because I don't want my website to look like a blog, and it's going pretty smoothly so far but theres this huge top margin gap in the browser even when I set margins to 0px.
I tried trial and error and found out that it's being caused by: <?php wp_head(); ?>
It's two different things.
1. wp_head() function
wp_head() is a template tag to print whatever plugin / theme specific function used by wordpress action. Read codex for more detail about it.
2. The admin bar
The top margin, is generated by wordpress's admin bar.
To fix this for logged in users you can do a couple of things:
Disable admin bar from the admin:
Go to admin panel
Users >> User Profile
Uncheck 'when viewing
site' on 'Show Admin Bar'
Remove the admin bar from your theme entirely:
Open your functions.php
Add this to it:
function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Remove only the code which creates the css:
Open your functions.php
Add this to it:
function my_filter_head() { remove_action('wp_head', '_admin_bar_bump_cb'); }
add_action('get_header', 'my_filter_head');
Note: Extensive updates are from #hitautodestruct
you neeed to call wp_footer() in your footer
just insert this line <?php wp_footer();?> into your footer.php file
If you have updated your wordpress install to the latest version.. there seems to be some bug with the admin bar...
were it would produce an inline stylesheet appended to the top of your pages.. causing the margin-top:28px
see here
1 recomendation is to put a new function into your functions.php file located in your theme folder.. this will completly remove the bar, so no users of your theme will have any of the same issues!
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Not sure if this will help.. but worth a shot.. also turning off the admin bar while viewing the front end of the site under your profile page..

Resources