Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active October 20, 2020 02:01
Show Gist options
  • Save KaineLabs/3900bca20c1ec77bf87b954ee81174a1 to your computer and use it in GitHub Desktop.
Save KaineLabs/3900bca20c1ec77bf87b954ee81174a1 to your computer and use it in GitHub Desktop.
Add Optional Fields Widget
<?php
/**
* Add Optional Fields Widget.
*/
function yzc_add_profile_completeness_optinal_widget() {
if ( ! bp_is_my_profile() && ! current_user_can( 'administrator' ) ) {
return;
}
if ( ! function_exists( 'yzpc_get_user_unfilled_fields' ) ) {
return;
}
$user_id = bp_displayed_user_id();
// Get Required Fields.
$optional_fields = yzpc_get_user_unfilled_fields( 'optional', $user_id );
if ( empty( $optional_fields ) ) {
return;
}
// Get Fields By type.
$fields = yzpc_get_fields_sorted_by_types( $optional_fields );
?>
<style type="text/css">
.yzpc-optional-fields-widget .yzpc-parent-fields-content {
display: none;
}
.yzpc-optional-fields-widget .yz-widget-content {
overflow: hidden;
padding: 12px 12px 0;
background-color: #eee;
}
.yzpc-optional-fields-widget .yzpc-fields-parent-item {
color: #fff;
display: block;
cursor: pointer;
font-size: 14px;
font-weight: 600;
border-radius: 3px;
padding: 15px 15px;
margin-bottom: 12px;
background-color: #03A9F4;
}
.yzpc-optional-fields-widget i.fa-chevron-down {
float: right;
}
.yzpc-optional-fields-widget .yzpc-field-item i,
.yzpc-optional-fields-widget .yzpc-fields-parent-item i {
width: 30px;
margin-right: 8px;
text-align: center;
}
.yzpc-optional-fields-widget .yzpc-field-item {
display: block;
color: #898989;
font-size: 13px;
font-weight: 600;
margin-bottom: 12px;
border-radius: 3px;
padding: 12px 15px;
background-color: #fff;
}
.yz-widget.yzpc-optional-fields-widget p {
padding: 12px;
display: block;
font-size: 14px;
background: #fff;
margin-bottom: 12px;
border-radius: 3px;
}
</style>
<div class="yz-widget yzpc-optional-fields-widget yz_effect yz-white-bg yz-wg-title-icon-bg" data-effect="fadeInUp">
<div class="yz-widget-main-content">
<div class="yz-widget-head">
<h2 class="yz-widget-title"><i class="fas fa-info"></i><?php _e( 'Important Fields !', 'youzer' ); ?></h2>
</div>
<div class="yz-widget-content">
<p><?php _e( 'Please consider filling the following fields !', 'youzer' ); ?></p>
<?php
if ( isset( $fields['images'] ) && ! empty( $fields['images'] ) ) {
echo '<div class="yzpc-fields yzpc-profile-images-fields"><div class="yzpc-fields-content">';
foreach ( $fields['images'] as $element => $title ) {
if ( $element == 'change-avatar' ) {
// Get Group Url.
$field_url = yz_get_profile_settings_url( 'change-avatar' );
echo '<a class="yzpc-fields-parent-item" href="' . $field_url . '"><i class="fas fa-user-circle"></i>' . $title . '</a>';
}
if ( $element == 'change-cover-image' ) {
// Get Group Url.
$field_url = yz_get_profile_settings_url( 'change-cover-image' );
echo '<a class="yzpc-fields-parent-item" href="' . $field_url . '"><i class="fas fa-image"></i>' . $title . '</a>';
}
}
echo '</div></div>';
}
if ( isset( $fields['xprofile'] ) && ! empty( $fields['xprofile'] ) ) {
echo '<div class="yzpc-fields yzpc-profile-info-fields"><div class="yzpc-fields-content">';
foreach ( $fields['xprofile'] as $group_id => $field ) {
// Get Fields Group.
$group = new BP_XProfile_Group( $group_id );
// Get Group Icon.
$group_icon = yz_get_xprofile_group_icon( $group_id );
// Get Group Url.
$field_url = yz_get_profile_settings_url( 'edit/group/' . $group_id, $user_id );
echo '<div class="yzpc-fields-parent-item"><i class="' . $group_icon . '"></i>' . $group->name . '<i class="fas fa-chevron-down"></i></div>';
echo '<div class="yzpc-parent-fields-content">';
foreach ( $field as $field_key => $field_title ) {
echo '<a class="yzpc-field-item" href="' . $field_url . '/#yz_field_' . $field_key . '"><i class="far fa-edit"></i>' . $field_title . '</a>';
}
echo '</div>';
}
echo '</div></div>';
}
?>
<?php
global $Youzer;
if ( ! empty( $fields['widgets'] ) ) {
echo '<div class="yzpc-fields yzpc-profile-widgets-fields"><div class="yzpc-fields-content">';
foreach ( $fields['widgets'] as $widget_name => $field ) {
// Get Youzer Widgets.
$youzer_widgets = yz_user_widgets_fields();
// Get Widget Settings Url.
$field_url = yz_get_widgets_settings_url( $widget_name, $user_id );
if ( 'social_networks' == $widget_name ) {
$field_url = yz_get_profile_settings_url( 'social-networks' );
}
// Get Widget Data.
$widget_data = $Youzer->widgets->{$widget_name}->args();
$widget_title = apply_filters( 'yzpc_profile_widget_name', $widget_data['widget_title'] );
if ( isset( $youzer_widgets[ $widget_name ]['id'] ) ) {
echo '<a class="yzpc-fields-parent-item" href="' . $field_url . '"><i class="' . $widget_data['widget_icon'] . '"></i>' . $widget_title . '<i class="fas fa-chevron-down"></i></a>';
} else {
echo '<div class="yzpc-fields-parent-item"><i class="' . $widget_data['widget_icon'] . '"></i>' . $widget_title . '<i class="fas fa-chevron-down"></i></div>';
echo '<div class="yzpc-parent-fields-content">';
foreach ( $field as $field_key => $field_title ) {
echo '<a class="yzpc-field-item" href="' . $field_url . '"><i class="far fa-edit"></i>' . sprintf( __( '%1s - %2s', 'youzer-profile-completeness' ), $widget_title, $field_title ) . '</a>';
}
echo '</div>';
}
}
echo '</div></div>';
}
?>
</div>
</div>
</div>
<?php
}
add_action( 'yz_profile_sidebar', 'yzc_add_profile_completeness_optinal_widget' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment