Display a text if element not shown in PHP - php

I have a code in PHP that displays icons of social medias. But when the user didn't fill them, they don't show up. Which is great but I would like to encourage them to fill it up with a text/link.
Here is the code :
<?php
add_filter( "buddyboss_get_user_social_array", "buddyboss_user_social_remove_disabled" ); //remove disabled.
//Allow users to display their social media links in their profiles.
$profile_social_media_links_switch = boss_get_option( 'profile_social_media_links_switch' );
if ( ! empty( $profile_social_media_links_switch ) ):
$social_profiles = (array)boss_get_option( 'profile_social_media_links' );
foreach ( $social_profiles as $social ):
if ( empty( $social['title'] ) ) {
continue;
}
$social_key = sanitize_title( $social['title'] );
$background_image_style = '';
$icon_url = $social['thumb'];
$url = buddyboss_get_user_social( bp_displayed_user_id(), $social_key ); //Get user social link
//Set profile icon
if ( ! empty ( $icon_url) ) {
$background_image_style = "background-image: url($icon_url); background-size: cover;";
}
?>
<?php if ( !empty( $url ) ): ?>
<a class="btn" href="<?php echo $url; ?>" title="<?php echo esc_attr( $social['title'] ); ?>" target="_blank"><i style="<?php echo $background_image_style ?>" class="alt-social-icon alt-<?php echo empty( $background_image_style ) ? $social_key : ''; ?>"></i> </a>
<?php endif; ?>
<?php endforeach;
endif;
?>
</div>
How to add this text : Display your Social Profiles here...

If I caught the main goal, it is necessary to display the text Display your Social Profiles here... in case of no social_profiles.
I check on empty both $profile_social_media_links_switch and $social_profiles. If any of them is empty then show your desired text
Try this code:
<?php
add_filter( "buddyboss_get_user_social_array", "buddyboss_user_social_remove_disabled" ); //remove disabled.
//Allow users to display their social media links in their profiles.
$profile_social_media_links_switch = boss_get_option( 'profile_social_media_links_switch' );
if ( ! empty( $profile_social_media_links_switch ) ) {
$social_profiles = (array)boss_get_option('profile_social_media_links');
if (!empty($social_profiles)) {
foreach ($social_profiles as $social) {
if (empty($social['title'])) {
continue;
}
$social_key = sanitize_title($social['title']);
$background_image_style = '';
$icon_url = $social['thumb'];
$url = buddyboss_get_user_social(bp_displayed_user_id(), $social_key); //Get user social link
//Set profile icon
if (!empty ($icon_url)) {
$background_image_style = "background-image: url($icon_url); background-size: cover;";
}
if (!empty($url)) { ?>
<a class="btn" href="<?php echo $url; ?>" title="<?php echo esc_attr($social['title']); ?>"
target="_blank"><i
style="<?php echo $background_image_style ?>"
class="alt-social-icon alt-<?php echo empty($background_image_style) ? $social_key : ''; ?>"></i>
</a>
<?php
}
}
} else {
echo 'Display your Social Profiles here...';
}
} else {
echo 'Display your Social Profiles here...';
}
?>
</div>

Related

Make clicakble username when user is logged in

I want to have on my woocommerce shop clickable username instead of dropdown list ( as it is in original )
I mean this should be clicakable - moving to my-account
There is code
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_render_attribute('wrapper', 'class', 'site-header-account');
?>
<div <?php echo organey_get_render_attribute_string(
"wrapper",
$this
); ?>>
<?php
$link_url = "https://mytestshop.pl/my-account/";
$html_attr =
"data-toggle=button-side data-target=.site-account-side";
if (!is_user_logged_in()) {
add_action("wp_footer", "organey_header_account_side");
if (!empty($settings["link"]["url"])) {
$link_url = $settings["link"]["url"];
}
}
?>
<a <?php echo is_user_logged_in()
? 'class="my-account-icon"'
: esc_attr($html_attr); ?> href="<?php echo $link_url; ?>">
<span class="account-user">
<?php if (!is_user_logged_in()) {
if (!empty($settings["account_icon"])) {
\Elementor\Icons_Manager::render_icon(
$settings["account_icon"],
["aria-hidden" => "true"]
);
}
} else {
$user_id = get_current_user_id();
echo get_avatar($user_id, 32);
} ?>
</span>
<span class="account-content">
<?php if (!is_user_logged_in()) {
echo esc_html__("Login", "organey");
} else {
$user = wp_get_current_user(); ?>
<?php echo esc_html($user->display_name); ?>
<?php
} ?>
</span>
</a>
<?php if (is_user_logged_in()) { ?>
<?php } ?>
</div>
It should be clickable but it works only when i use - open in new tab.
When I just click on it nothing happens.

Formatting lost when link added to an image

I am customizing the wordpress woocommerce product category page. I successfully added an image inline with the product name. My issue arises when I try to make the images linkable. The formatting of the image gets lost as they display bigger, not inline with the product name and with a border. More details below, can anyone help?
This is the current code:
global $product;
$link = get_field('product_fiche');
$label = get_field('energy_label');
$full = get_field('full_energy_label');
?>
<div class="price-wrapper <?php if($link || $label) { echo 'has-col'; } ?>">
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
<?php if(is_product_category() && $link || $label) : ?>
<span class="product-action">
<?php if($link) { echo '<a class="link" href="'.$link.'" target="_blank">Product Fiche</a>'; } ?>
<?php if($label) { echo '<img class="energy-label" src="'.$label.'" alt="energy label" />'; } ?>
</span>
<?php endif; ?>
</div>
This is how the category pages appear: (please note how the icons appear inline with the product name)
enter image description here
This is the updated code, I formatted the addition in bold.
global $product;
$link = get_field('product_fiche');
$label = get_field('energy_label');
$full = get_field('full_energy_label');
?>
<div class="price-wrapper <?php if($link || $label) { echo 'has-col'; } ?>">
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
<?php if(is_product_category() && $link || $label) : ?>
<span class="product-action">
<?php if($link) { echo '<a class="link" href="'.$link.'" target="_blank">Product Fiche</a>'; } ?>
<?php if($label) { echo '****<img class="energy-label" src="'.$label.'" alt="energy label" />****'; } ?>
</span>
<?php endif; ?>
</div>
The above code leads to the below:
enter image description here

Change the profile cover image dynamically

does someone know how to change an image header dynamically depends by specific categories,
ex: image1 for red category, image2 for blue category, image3 for green category?
Im using ultimate member plugin but don't well php coding
I have found the original code
function um_profile_header_cover_area( $args ) {
global $ultimatemember;
if ( $args['cover_enabled'] == 1 ) {
$default_cover = um_get_option('default_cover');
$overlay = '<span class="um-cover-overlay">
<span class="um-cover-overlay-s">
<ins>
<i class="um-faicon-picture-o"></i>
<span class="um-cover-overlay-t">'.__('Change your cover photo', 'ultimatemember').'</span>
</ins>
</span>
</span>';
?>
<div class="um-cover <?php if ( um_profile('cover_photo') || ( $default_cover && $default_cover['url'] ) ) echo 'has-cover'; ?>" data-user_id="<?php echo um_profile_id(); ?>" data-ratio="<?php echo $args['cover_ratio']; ?>">
<?php do_action('um_cover_area_content', um_profile_id() ); ?>
<?php
if ( $ultimatemember->fields->editing ) {
$items = array(
''.__('Change cover photo', 'ultimatemember').'',
''.__('Remove', 'ultimatemember').'',
''.__('Cancel', 'ultimatemember').'',
);
echo $ultimatemember->menu->new_ui( 'bc', 'div.um-cover', 'click', $items );
}
?>
<?php $ultimatemember->fields->add_hidden_field( 'cover_photo' ); ?>
<?php echo $overlay; ?>
<div class="um-cover-e">
<?php if ( um_profile('cover_photo') ) { ?>
<?php
if( $ultimatemember->mobile->isMobile() ) {
if ( $ultimatemember->mobile->isTablet() ) {
echo um_user('cover_photo', 1000);
echo um_user('cover_photo', 300);
}
} else {
echo um_user('cover_photo', 1000);
}
?>
<?php } elseif ( $default_cover && $default_cover['url'] ) {
$default_cover = $default_cover['url'];
echo '<img src="'. $default_cover . '" alt="" />';
} else {
if ( !isset( $ultimatemember->user->cannot_edit ) ) { ?>
<span class="um-cover-add-i"><i class="um-icon-plus um-tip-n" title="<?php _e('Upload a cover photo', 'ultimatemember'); ?>"></i></span>
<?php }
} ?>
</div></div>
<?php
}}
Thanks in advance

upload categorie to woocommerce

hello I am new to programing. I am creating a simple RSS feed plugin for wordpress to upload some products to WooCommerce and need to upload the category to wordpress . In plugin the category is visible but they are not showing like the url link. I need the category to show like checkbox. Can anybody have any idea ?
File number 1
* Init feed with information from DB
private function load()
{
if ($this->id) {
$post = get_post( $this->id );
if (!$post) {
$this->id = null;
return;
}
$this->title = $post->post_title;
$this->id = $post->ID;
$meta = get_post_meta($post->ID);
foreach ($meta as $key=>$item) {
$newKey = substr($key, 1);
$this->properties[$newKey] = $item[0];
if ($newKey == 'post_category') {
$this->properties[$newKey] = unserialize($item[0]);
}
}
}
}
..................
$fields = array( 'post_category');
..................
// Create post
$post = array('post_category' => $this->post_category);
And the file number 2 have this
<div class="postbox">
<div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
<h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Categories', 'rss-autopilot'); ?></span></h3>
<div class="inside">
<ul class="rssap-categories-list">
<?php wp_category_checklist( 0, 0, $feed->post_category, false, null, true ); ?>
</ul>
<div class="clear"></div>
</div>
</div>
Here is your code.
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats">';
foreach ( $terms as $term ) {
echo '<li class="category">';
echo '<h2>';
echo '<input name="product_category[]" type="checkbox" value="'. $term->term_id.'"';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
echo '</ul>';
}

Wordpress Magnifying function using images from custom filed "et_gallery"

The goal effect is: When clicked on the magnifying icon, it uses the "Fancybox" plugin to display big size images (mutiple images separated by commas) in the custom filed "et_gallery".
Right now the magnifying isn't working at all.
http://heidixu.com/#!/?page_id=4
It was working fine once. And then I accidently replaced the final code with an earlier version. So the version I currently have is pretty close but something is not right or missing and I can't figure out what because I'm not an expert in php...
This is the page: http://heidixu.com/#!/?page_id=4 and every other pages with thumbnails work the same.
This is my current version of php code that was edited:
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php
$et_ptemplate_settings = array();
$et_ptemplate_settings = maybe_unserialize( get_post_meta($post->ID,'et_ptemplate_settings',true) );
$fullwidth = true;
$et_ptemplate_showtitle = isset( $et_ptemplate_settings['et_ptemplate_showtitle'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_showtitle'] : false;
$et_ptemplate_showdesc = isset( $et_ptemplate_settings['et_ptemplate_showdesc'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_showdesc'] : false;
$et_ptemplate_detect_portrait = isset( $et_ptemplate_settings['et_ptemplate_detect_portrait'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_detect_portrait'] : false;
$gallery_cats = isset( $et_ptemplate_settings['et_ptemplate_gallerycats'] ) ? (array) $et_ptemplate_settings['et_ptemplate_gallerycats'] : array();
$et_ptemplate_gallery_perpage = isset( $et_ptemplate_settings['et_ptemplate_gallery_perpage'] ) ? (int) $et_ptemplate_settings['et_ptemplate_gallery_perpage'] : 12;
$et_ptemplate_portfolio_size = isset( $et_ptemplate_settings['et_ptemplate_imagesize'] ) ? (int) $et_ptemplate_settings['et_ptemplate_imagesize'] : 2;
$et_ptemplate_portfolio_class = '';
if ( $et_ptemplate_portfolio_size == 1 ) $et_ptemplate_portfolio_class = ' et_portfolio_small';
if ( $et_ptemplate_portfolio_size == 3 ) $et_ptemplate_portfolio_class = ' et_portfolio_large';
?>
<?php get_header(); ?>
<div class="single_container et_shadow">
<div class="single_content">
<div class="entry post clearfix">
<?php get_template_part('loop','page'); ?>
<div id="et_pt_portfolio_gallery" class="clearfix<?php echo $et_ptemplate_portfolio_class; ?>">
<?php $gallery_query = '';
$portfolio_count = 1;
$et_open_row = false;
if ( !empty($gallery_cats) ) $gallery_query = '&cat=' . implode(",", $gallery_cats);
else echo '<!-- gallery category is not selected -->'; ?>
<?php
$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
?>
<?php query_posts("showposts=$et_ptemplate_gallery_perpage&paged=" . $et_paged . $gallery_query); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $width = 260;
$height = 170;
if ( $et_ptemplate_portfolio_size == 1 ) {
$width = 140;
$height = 94;
$et_portrait_height = 170;
}
if ( $et_ptemplate_portfolio_size == 2 ) $et_portrait_height = 315;
if ( $et_ptemplate_portfolio_size == 3 ) {
$width = 430;
$height = 283;
$et_portrait_height = 860;
}
$et_auto_image_detection = false;
if ( has_post_thumbnail( $post->ID ) && $et_ptemplate_detect_portrait ) {
$wordpress_thumbnail = get_post( get_post_thumbnail_id($post->ID) );
$wordpress_thumbnail_url = $wordpress_thumbnail->guid;
if ( et_is_portrait($wordpress_thumbnail_url) ) $height = $et_portrait_height;
}
$titletext = get_the_title();
$et_portfolio_title = get_post_meta($post->ID,'et_portfolio_title',true) ? get_post_meta($post->ID,'et_portfolio_title',true) : get_the_title();
$et_videolink = get_post_meta($post->ID,'et_videolink',true) ? get_post_meta($post->ID,'et_videolink',true) : '';
$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,true,'et_portfolio');
$thumb = $thumbnail["thumb"];
if ( $et_ptemplate_detect_portrait && $thumbnail["use_timthumb"] && et_is_portrait($thumb) ) {
$height = $et_portrait_height;
} ?>
<?php if ( $portfolio_count == 1 || ( $et_ptemplate_portfolio_size == 2 && (!$fullwidth && ($portfolio_count+1) % 2 == 0) ) || ( $et_ptemplate_portfolio_size == 3 && (($portfolio_count+1) % 2 == 0) ) ) {
$et_open_row = true; ?>
<div class="et_pt_portfolio_row clearfix">
<?php } ?>
<div class="et_pt_portfolio_item">
<?php if ($et_ptemplate_showtitle) { ?>
<h2 class="et_pt_portfolio_title"><?php echo $et_portfolio_title; ?></h2>
<?php } ?>
<div class="et_pt_portfolio_entry<?php if ( $height == $et_portrait_height ) echo ' et_portrait_layout'; ?>">
<div class="et_pt_portfolio_image<?php if ($et_videolink <> '') echo ' et_video'; ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
<?php $gallery = explode(',', get_post_meta($post->ID, 'et_gallery', true));
foreach ($gallery as $item) { ?>
<a class="fancybox" href="<?php echo $item; ?>" style="display: none;" rel="gallery[<?php echo $post->ID; ?>]" title="<?php the_title(); ?>"></a>
<?php } ?>
<span class="et_pt_portfolio_overlay"></span>
<a class="et_portfolio_zoom_icon <?php if ($et_videolink <> '') echo 'et_video_lightbox'; else echo('fancybox'); ?>" title="<?php the_title(); ?>"<?php if ($et_videolink == '') echo ' rel="gallery[' . $post->ID . '"]'; ?> href="<?php if ($et_videolink <> '') echo $et_videolink; else echo($thumbnail['fullpath']); ?>"><?php esc_html_e('Zoom in','Sky'); ?></a>
<a class="et_portfolio_more_icon" href="<?php the_permalink(); ?>"><?php esc_html_e('Read more','Sky'); ?></a>
</div> <!-- end .et_pt_portfolio_image -->
</div> <!-- end .et_pt_portfolio_entry -->
<?php if ($et_ptemplate_showdesc) { ?>
<p><?php truncate_post(90); ?></p>
<?php } ?>
</div> <!-- end .et_pt_portfolio_item -->
<?php if ( ($et_ptemplate_portfolio_size == 2 && !$fullwidth && $portfolio_count % 2 == 0) || ( $et_ptemplate_portfolio_size == 3 && ($portfolio_count % 2 == 0) ) ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<?php if ( ($et_ptemplate_portfolio_size == 2 && $fullwidth && $portfolio_count % 3 == 0) || ($et_ptemplate_portfolio_size == 1 && !$fullwidth && $portfolio_count % 3 == 0) || ($et_ptemplate_portfolio_size == 1 && $fullwidth && $portfolio_count % 5 == 0) ) { ?>
</div> <!-- end .et_pt_portfolio_row -->
<div class="et_pt_portfolio_row clearfix">
<?php $et_open_row = true; ?>
<?php } ?>
<?php $portfolio_count++;
endwhile; ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<div class="page-nav clearfix">
<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation'); ?>
<?php } ?>
</div> <!-- end .entry -->
<?php else : ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<?php get_template_part('includes/no-results'); ?>
<?php endif; wp_reset_query(); ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
</div> <!-- end #et_pt_portfolio_gallery -->
</div> <!-- end .entry -->
</div> <!-- end .single_content -->
<div class="content-bottom"></div>
</div> <!-- end .single_container -->
<?php if (get_option('sky_show_pagescomments') == 'on') comments_template('', true); ?>
Could any php experts please take a look. Thank you so much.
-Heidi
So far, when you click on the magnifying icon, it produces this error:
Error: a is undefined
Source File: http://heidixu.com/wp-content/themes/Sky/epanel/page_templates/js/fancybox/jquery.fancybox-1.3.4.pack.js?ver=1.3.4
Line: 19
It looks like the link (the <a> tag) is not bound to fancybox regardless it has the specified class.
I want to believe that your generated code is not well formed; you have this html:
Zoom in
and wonder if this part specifically
... ]="" rel="gallery[ ....
...is creating the error. I cannot find what part of your php code generates those (misplaced?) brackets.

Categories