I’m very new to php coding and I’ve been trying very hard to get this to work.
I’m using wedevs project management plugin with buddy press integration. There dev team doesn’t have the time to customize the plugin for me at the moment so I’m looking for a quick fix. I feel I’m so close but for some reason I’m not getting it to work.
I have a “create project” button that I would like to hide for all group members accept the Group admin. so I would like it to verify if the user is the group admin and show the “create project link”. But if it is just a group member or user, I would like the “create project link” to be hidden. Only group admins should be allowed to create projects… Here is what I have so far. But its not working. Any help or guidance would be greatly appreciated.
<?php if ( BP_Groups_Member::get_is_admin_of( $user_id )) { ?>
<style type="text/css" media="screen">
.cpm-projects nav.cpm-new-project a {visibility:visible; }
</style>
<?php } else { ?>
<style type="text/css" media="screen">
.cpm-projects nav.cpm-new-project a {visibility:hidden; }
</style>
<?php } ?>
Keep in mind that the stylesheet for the plugin has this inside the style sheet.
.cpm-projects nav.cpm-new-project a {
background: transparent url("../images/plus.png") no-repeat scroll 50% 50%;
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
height: 80px;
width: 80px;
display: block;
border-radius: 3px;
}
For some reason its still showing for all members with this code.
I’ve tried all of these calls and still nothing
if ( BP_Groups_Member::get_is_admin_of( $user_id )) {
if ( ! groups_is_user_admin( $user_id, $group_id ) ) {
if ( groups_is_user_admin( $user_id, $group_id ) ) {
if ( groups_is_user_admin( get_current_user_id(), $group_id ) ) {
Not sure if it fixes your problem, but a cleaner way is to put the CSS code as two separate classes into your custom CSS file. In other words, you hide the button with CSS for all users by default, but then create a class ".can_create_proj" to show the button for the admin.
In your PHP code, you can add the class name to the button if the current user is admin.
<nav class = "cpm-new-project">
<a clas="<?php check_is_admin( $user_id, $group_id ) ? echo "can_create_proj"; ?>">Create Project</a>
</nav>
Maybe using check_is_admin( $user_id, $group_id ) will work. Ref: https://buddypress.org/support/topic/checking-if-member-is-also-a-group-admin/
In you CSS:
nav.cpm-new-project a {
display:block;
}
.can_create_proj {
display:none;
}
Related
I have built an author page using Elementor Pro on Wordpress, and display various pieces of author metadata on the page within different sections. I would like to display a message to the author if a section doesn't contain author metadata.
In other words, if none of city, style_of_play or highest_division exist, then display profile_info_template (which is set to display: none by default)
I can get this to work when I use city only, but it stops working when I add the other 2 pieces of metadata. Any guidance on this would be much appreciated.
function nothing_to_show_display(){
global $post;
$author_id=$post->post_author;
$profile_info = get_the_author_meta('city', 'style_of_play', 'highest_division',
$author_id);
if(empty($profile_info)) : ?>
<style type="text/css">
#profile_info_template {
display: inline-block !important;
}
</style>;
<?php endif;
}
add_action( 'wp_head', 'nothing_to_show_display', 10, 1 );
The reason it stops working is because with that function you can only request one value of data at a time. https://developer.wordpress.org/reference/functions/get_the_author_meta/#div-comment-3500
My suggestion is to modify your code to only call one value at a time, then use the "OR" operator within your if statement, like this:
$author_city = get_the_author_meta('city', $author_id);
$author_style_of_play = get_the_author_meta('style_of_play', $author_id);
$author_highest_division = get_the_author_meta('highest_division', $author_id);
if(empty($author_city) || empty($author_style_of_play) || empty($author_highest_division)) : ?>
<style type="text/css">
#profile_info_template {
display: inline-block !important;
}
</style>;
<?php endif;
Also if you don't plan to use those values it is perfectly fine to simplify the code and place the functions within the if statement.
if(empty(get_the_author_meta('city', $author_id)) || empty(get_the_author_meta('style_of_play', $author_id)) || empty(get_the_author_meta('highest_division', $author_id))) : ?>
<style type="text/css">
#profile_info_template {
display: inline-block !important;
}
</style>;
<?php endif;
I have a Multisite with a main domain (www.valleysgroup.co.uk) and various sub-domains (brickslipsdirect.valleysgroup.co.uk, tradeporcelain.valleysgroup.co.uk etc).
I am wanting to share a custom top bar containing a menu that is not the primary menu of the main domain, from the main domain across all the sub-domains. This menu will be simple links to each of the sub-domains, but in the form of tabs. Tab 1 will lead to brickslipsdirect.valleysgroup.co.uk, tab 2 will lead to tradeporcelain.valleysgroup.co.uk etc.
I have spent several days trying various solutions, which I then came across the plugin: Multisite Shared Menu
This works great, apart from it will only apply the primary menu from the main domain, and no other menu's. Ideally I would like to create a new menu location named Global Top Bar on the main domain and all subs, create my menu named Global Menu on the main domain, and then pull the menu into all the subs.
I am also unsure how to implement this on the main domain and sub-domains as tabs instead of a general horizontal, dropdown or list menu.
Please see image for clarity on what I am looking for looks-wise across the main domain and the subs:
Any help would be greatly appreciated!
Unfortunately I don't have too much time to spend on this, but hopefully you or someone you know can help flesh this out more.
I've added a bunch of comments that should hopefully explain most things. You just need to plug in the IDs for each site as you find in the Multisite backend. This code will kick out an unordered list with one entry per site, and the current site having a special class. You will probably want to add some additional classes but hopefully this is enough to get you somewhere at least.
// Just the Site IDs from WordPress
$siteIds = [2, 3, 4];
// This will hold <li> tags for each
$menuItems = [];
foreach ($siteIds as $siteId) {
// Get the WordPress WP_Site object
$site = get_site($siteId);
// Sanity check that it was found and public
if (!$site || !$site->public) {
continue;
}
// Optional attributes classes on the <li>, default none
$extraAttributes = '';
// For the current site, add a class
if ($siteId === get_current_blog_id()) {
$extraAttributes = ' class="current-site"';
}
// Append an HTML node
$menuItems[] = sprintf(
'<li %3$s>%1$s</li>',
esc_html($site->blogname),
esc_attr($site->siteurl),
$extraAttributes
);
}
// Make sure the above worked
if ($menuItems) {
// Output wrapped
echo '<ul>' . implode('', $menuItems) . '</ul>';
}
I have now gone ahead and added my new menu location named Global Top Bar using the following in my main domains Child Theme > Functions.php file:
function register_new_menu_location() {
register_nav_menu('global-menu-location',__( 'Global Top Bar' ));
}
add_action( 'init', 'register_new_menu_location' );
I have also created my menu named Global Menu and marked for it to display in the newly made location.
I have then gone into my Child Theme > Header.php file and added the following which seem to work:
switch_to_blog(1);
wp_nav_menu( array(
'menu' => '16',
'container_class' => 'GlobalMenuContainerClass',
'menu_class' => 'GlobalMenuClass'
) );
restore_current_blog();
Menu '16' being my menu's ID found on my main domain. This displays the menu on all sub-domains like this:
I Added some CSS to spice it up a little and make it look more like tabs using the following CSS code:
.GlobalMenuContainerClass {
height: 45px;
padding-top: 8px;
padding-right: 100px;
padding-left: 100px;
width: 100%;
margin-right: auto;
margin-left: auto;
background: #cc2325;
}
.GlobalMenuClass {
list-style: none;
margin: 0;
padding: 0;
}
.GlobalMenuClass li a {
text-decoration: none;
float: left;
margin-right: 5px;
color: white;
border: 1px solid #777777;
padding: 5px 10px 5px 10px;
min-width: 100px;
text-align: center;
display: block;
background: #777777;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.GlobalMenuClass li a:hover:not(.active) {
background: #4e4e4e;
border: 1px solid #4e4e4e;
}
.active {
background: white;
color: black;
border: 1px solid white;
}
And here is how it now looks:
You can see there is a different hover colour for the tabs of a darker grey, but I have not yet implemented the .active tab CSS yet. Not quite sure how I am going to do this yet.
Hope this can help others in a similar situation.
I have these two buttons in the header:
Members
Register Now!
If the user is not logged in or registered, these two buttons should be shown. If logged in, these two should not be shown. How can I do that?
You can check with is_user_logged_in() for if user is logged in wp or not
if ( is_user_logged_in() ) {
// your code for logged in user
} else {
// your code for logged out user
}
Add Members and Register button for logged out user you need to used below code
if ( !is_user_logged_in() ) {
Members
Register Now!
}
There are various ways one can do this. The first one I'll mention will be leveraging a WP function, and the second one using only CSS.
Lastly, I'll end the answer with a way to display a button only to logged in users.
Option 1
WordPress has a function to determine whether a current visitor is a logged in user: is_user_logged_in() and resembles the following
function is_user_logged_in() {
$user = wp_get_current_user();
return $user->exists();
}
On can find the function in wp-includes/pluggable.php.
For your particular case, the following might do the work
<?php if ( !is_user_logged_in() ) : ?>
Members
Register Now!
<?php endif; ?>
Option 2
Adding something like the following in the Customize>Additional CSS might also do the work (it worked for me)
.logged-in .button-class {
visibility: hidden !important;
display: none !important;
}
or
.button-class {display: block;}
.logged-in .button-class {display: none;}
Additional
Alternatively, if one wants to display the buttons only when a user is logged in, using CSS, do as follows
.button-class {
visibility: hidden !important;
display: none !important;
}
.logged-in .button-class {
visibility: visible !important;
display: inline-block !important;
}
I want to add a background picture to a group of pages in wordpress.
I want to add a different background picture to another group of pages
Currently I am applying it to each individual page using PageID as in the code below. As there are over 1000 pages. Is there are a more simple way to apply to each group of pages?
.page-id-264 #header .logo a,
.page-id-272 #header .logo a {
background-image: url("http://www.richcoward.com/newcges/wp-content/uploads/2014/08/NWU-No-Frame.png") !important;
background-size: 100% !important;
background-repeat: no-repeat !important;
height: 86px !important;
width: 416px !important;
}
Thanks for your help
Here is a simple solution.
Create a custom css (say mystyle.css) file in your theme folder. Add
#header .logo a {
background-image: url("http://www.richcoward.com/newcges/wp-content/uploads/2014/08/NWU-No-Frame.png") !important;
background-size: 100% !important;
background-repeat: no-repeat !important;
height: 86px !important;
width: 416px !important;
}
into your mystyle.css. Now, open up your functions.php and enqueue your stylesheet conditionally. Use is_page() or is_page_template() conditional checks. I believe that you are talking about groups of pages, so I would imagine that you use specific page templates for specific groups, so I would tend to go for is_page_template
function enqueue_custom_style() {
if(is_page_template('page-whatever.php')) {
wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/mystyle.css' );
}
}
add_action('wp_enqueue_scripts', 'enqueue_custom_style', 999);
This should give you an idea
You could use a filter in your functions.php file to add a class to all the relevant pages. You're still going to have to rattle off each Page ID, but I guess doing it in PHP will keep your CSS smaller (and therefore load faster):
// Add specific CSS class by filter
add_filter( 'body_class', 'my_class_names' );
function my_class_names( $classes ) {
// array of Page IDs
$pageids = array(264, 272);
// if
if ( is_page( $pageids ) ) {
// add 'class-name' to the $classes array
$classes[] = 'class-name';
// return the $classes array
return $classes;
}
}
Alternatively, create page templates for each background.
I am trying to add some css to portfolio pages only on my word press site.
An example page is:
http://www.1aproductions.co.uk/portfolio/22/
The css code i am trying to add is:
.header-wrapper {
background-position:top;
background-color:transparent !important;
background-image:url('http://www.1aproductions.co.uk/wp-content/uploads/2014/06/Florence-Nightingale-smaller-no-flo.jpg') !important;
background-size: 100% auto;
}
Which would display a similar effect to the header on this page (if I could only get it to work!)
http://www.1aproductions.co.uk/work/?cat=dramas
Any Help would be greatly appreciated!
Thanks
P
It looks as though portfolio is a custom post type. So try this:
function my_custom_css() {
if ( is_singular( 'portfolio' ) ) {
echo "<style>
.header-wrapper {
background-position:top;
background-color:transparent !important;
background-image:url('http://www.1aproductions.co.uk/wp-content/uploads/2014/06/Florence-Nightingale-smaller-no-flo.jpg') !important;
background-size: 100% auto;
}
</style>";
}
}
add_action( 'wp_head', 'my_custom_css' );
See the classes of body
single single-portfolio postid-22 siteorigin-panels fixed-header no-slider dark-header --- on portfolio
page page-id-7 page-template page-template-template-portfolio-gallery-php siteorigin-panels fixed-header no-slider dark-header --- on categories.
You can add your specific background using that classes.
.single-portfolio .header wrapper{
background: xxx;
}
and
.page-id-7 .header wrapper{
background: yyy;
}