template-sab.php
234 lines
| 1 | <?php |
| 2 | |
| 3 | if ( isset($sabox_options['sab_colored']) && '1' == $sabox_options['sab_colored'] ) { |
| 4 | $sabox_color = 'sabox-colored'; |
| 5 | } else { |
| 6 | $sabox_color = ''; |
| 7 | } |
| 8 | |
| 9 | if ( isset($sabox_options['sab_web_position'] ) && '0' != $sabox_options['sab_web_position'] ) { |
| 10 | $sab_web_align = 'sab-web-position'; |
| 11 | } else { |
| 12 | $sab_web_align = ''; |
| 13 | } |
| 14 | |
| 15 | if ( isset($sabox_options['sab_web_target']) && '1' == $sabox_options['sab_web_target'] ) { |
| 16 | $sab_web_target = '_blank'; |
| 17 | } else { |
| 18 | $sab_web_target = '_self'; |
| 19 | } |
| 20 | |
| 21 | if ( isset($sabox_options['sab_web_rel'] ) && '1' == $sabox_options['sab_web_rel'] ) { |
| 22 | $sab_web_rel = 'rel="nofollow"'; |
| 23 | } else { |
| 24 | $sab_web_rel = ''; |
| 25 | } |
| 26 | |
| 27 | $sab_author_link = sprintf( '<a href="%s" class="vcard author" rel="author" itemprop="url"><span class="fn" itemprop="name">%s</span></a>', esc_url( get_author_posts_url( $sabox_author_id ) ), esc_html( get_the_author_meta( 'display_name', $sabox_author_id ) ) ); |
| 28 | |
| 29 | $author_description = apply_filters( 'sab_user_description', get_the_author_meta( 'description' ,$sabox_author_id), $sabox_author_id ); |
| 30 | |
| 31 | if ( '' != $author_description || isset($sabox_options['sab_no_description'] ) && '0' == $sabox_options['sab_no_description'] ) { // hide the author box if no description is provided |
| 32 | |
| 33 | $show_guest_only = ( get_post_meta( get_the_ID(), '_disable_sab_author_here', true ) ) ? get_post_meta( get_the_ID(), '_disable_sab_author_here', true ) : "false"; |
| 34 | |
| 35 | if ( $show_guest_only != "on" ) { |
| 36 | |
| 37 | echo '<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author">'; // start saboxplugin-wrap div |
| 38 | |
| 39 | if(!isset($sabox_options['sab_show_latest_posts'])){ |
| 40 | $sabox_options['sab_show_latest_posts'] = false; |
| 41 | } |
| 42 | |
| 43 | if(!isset($sabox_options['sab_show_custom_html'])){ |
| 44 | $sabox_options['sab_show_custom_html'] = false; |
| 45 | } |
| 46 | |
| 47 | if ('1' == $sabox_options['sab_show_latest_posts'] || '1' == $sabox_options['sab_show_custom_html']) { |
| 48 | echo '<div class="saboxplugin-tabs-wrapper">'; |
| 49 | echo '<ul>'; |
| 50 | echo '<li class="active" data-tab="about">About the Author</li>'; |
| 51 | if ('1' == $sabox_options['sab_show_latest_posts']) { |
| 52 | echo '<li data-tab="latest_posts">Latest posts</li>'; |
| 53 | } |
| 54 | if ('1' == $sabox_options['sab_show_custom_html']) { |
| 55 | echo '<li data-tab="other">Other</li>'; |
| 56 | } |
| 57 | echo '</div>'; |
| 58 | } |
| 59 | |
| 60 | echo '<div class="saboxplugin-tab saboxplugin-tab-about">'; |
| 61 | |
| 62 | // author box gravatar |
| 63 | echo '<div class="saboxplugin-gravatar">'; |
| 64 | $custom_profile_image = get_the_author_meta( 'sabox-profile-image', $sabox_author_id ); |
| 65 | if ( '' != $custom_profile_image ) { |
| 66 | $mediaid = attachment_url_to_postid( $custom_profile_image ); |
| 67 | $alt = $mediaid ? get_post_meta( $mediaid, '_wp_attachment_image_alt', true ) : ''; |
| 68 | |
| 69 | |
| 70 | $link = null; |
| 71 | $nofollow = ''; |
| 72 | if ( isset( $sabox_options['sab_author_link'] ) ) { |
| 73 | if ( 'author-page' == $sabox_options['sab_author_link'] ) { |
| 74 | |
| 75 | $link = get_user_meta( $sabox_author_id, 'sab_box_link', true ); |
| 76 | if(empty($link)) |
| 77 | $link = get_author_posts_url( $sabox_author_id ); |
| 78 | |
| 79 | } elseif ( 'author-website' == $sabox_options['sab_author_link'] ) { |
| 80 | if ( isset( $sabox_options['sab_author_link_noffolow'] ) && '1' == $sabox_options['sab_author_link_noffolow'] ) { |
| 81 | $nofollow = ' rel="nofollow"'; |
| 82 | } |
| 83 | |
| 84 | $link = get_the_author_meta( 'user_url', $sabox_author_id ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if($link != null) |
| 89 | echo "<a $nofollow href='".$link."'>"; |
| 90 | |
| 91 | echo '<img src="' . esc_url( $custom_profile_image ) . '" width="' . $sabox_options['sab_avatar_size'] . '" height="' . $sabox_options['sab_avatar_size'] . '" alt="' . esc_attr( $alt ) . '" itemprop="image">'; |
| 92 | |
| 93 | if($link != null) |
| 94 | echo "</a>"; |
| 95 | |
| 96 | } else { |
| 97 | echo get_avatar( get_the_author_meta( 'user_email', $sabox_author_id ), $sabox_options['sab_avatar_size'], '', '', array('extra_attr' => 'itemprop="image"') ); |
| 98 | } |
| 99 | |
| 100 | echo '</div>'; |
| 101 | |
| 102 | // author box name |
| 103 | echo '<div class="saboxplugin-authorname">'; |
| 104 | echo apply_filters( 'sabox_author_html', $sab_author_link, $sabox_options, $sabox_author_id ); |
| 105 | if ( is_user_logged_in() && get_current_user_id() == $sabox_author_id ) { |
| 106 | echo '<a class="sab-profile-edit" target="_blank" href="' . get_edit_user_link() . '"> ' . esc_html__( 'Edit profile', 'simple-author-box' ) . '</a>'; |
| 107 | } |
| 108 | echo '</div>'; |
| 109 | |
| 110 | // author box description |
| 111 | echo '<div class="saboxplugin-desc">'; |
| 112 | echo '<div itemprop="description">'; |
| 113 | |
| 114 | $author_description = wptexturize( $author_description ); |
| 115 | $author_description = wpautop( $author_description ); |
| 116 | echo wp_kses_post( $author_description ); |
| 117 | if ( '' == $author_description && is_user_logged_in() && $sabox_author_id == get_current_user_id() ) { |
| 118 | echo '<a target="_blank" href="' . admin_url() . 'profile.php?#wp-description-wrap">' . esc_html__( 'Add Biographical Info', 'simple-author-box' ) . '</a>'; |
| 119 | } |
| 120 | echo '</div>'; |
| 121 | echo '</div>'; |
| 122 | |
| 123 | if ( is_single() || is_page() ) { |
| 124 | if ( get_the_author_meta( 'user_url' ) != '' && '1' == $sabox_options['sab_web'] ) { // author website on single |
| 125 | echo '<div class="saboxplugin-web ' . esc_attr( $sab_web_align ) . '">'; |
| 126 | echo '<a href="' . esc_url( get_the_author_meta( 'user_url', $sabox_author_id ) ) . '" target="' . esc_attr( $sab_web_target ) . '" ' . $sab_web_rel . '>' . esc_html( Simple_Author_Box_Helper::strip_prot(get_the_author_meta( 'user_url', $sabox_author_id )) ) . '</a>'; |
| 127 | echo '</div>'; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | if ( is_author() || is_archive() ) { |
| 133 | if ( get_the_author_meta( 'user_url' ) != '' ) { // force show author website on author.php or archive.php |
| 134 | echo '<div class="saboxplugin-web ' . esc_attr( $sab_web_align ) . '">'; |
| 135 | echo '<a href="' . esc_url( get_the_author_meta( 'user_url', $sabox_author_id ) ) . '" target="' . esc_attr( $sab_web_target ) . '" ' . $sab_web_rel . '>' . esc_html( Simple_Author_Box_Helper::strip_prot(get_the_author_meta( 'user_url', $sabox_author_id )) ) . '</a>'; |
| 136 | echo '</div>'; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // author box clearfix |
| 141 | echo '<div class="clearfix"></div>'; |
| 142 | |
| 143 | // author box social icons |
| 144 | $author = get_userdata( $sabox_author_id ); |
| 145 | $show_social_icons = apply_filters( 'sabox_hide_social_icons', true, $author ); |
| 146 | |
| 147 | |
| 148 | if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { |
| 149 | echo '<div class="sab-edit-settings">'; |
| 150 | echo '<a target="_blank" href="' . admin_url() . 'themes.php?page=simple-author-box">' . esc_html__( 'Settings', 'simple-author-box' ) . '<i class="dashicons dashicons-admin-settings"></i></a>'; |
| 151 | echo '</div>'; |
| 152 | } |
| 153 | |
| 154 | $show_email = isset($sabox_options['sab_email'] ) && '0' == $sabox_options['sab_email'] ? false : true; |
| 155 | $social_links = Simple_Author_Box_Helper::get_user_social_links( $sabox_author_id, $show_email ); |
| 156 | |
| 157 | if ( empty( $social_links ) && is_user_logged_in() && $sabox_author_id == get_current_user_id() ) { |
| 158 | echo '<a target="_blank" href="' . admin_url() . 'profile.php?#sabox-social-table">' . esc_html__( 'Add Social Links', 'simple-author-box' ) . '</a>'; |
| 159 | } |
| 160 | |
| 161 | if ( isset($sabox_options['sab_hide_socials']) && '0' == $sabox_options['sab_hide_socials'] && $show_social_icons && ! empty( $social_links ) ) { // hide social icons div option |
| 162 | echo '<div class="saboxplugin-socials ' . esc_attr( $sabox_color ) . '">'; |
| 163 | |
| 164 | foreach ( $social_links as $social_platform => $social_link ) { |
| 165 | |
| 166 | if ( 'user_email' == $social_platform ) { |
| 167 | $social_link = 'mailto:' . antispambot( $social_link ); |
| 168 | } |
| 169 | |
| 170 | if ( 'whatsapp' == $social_platform ) { |
| 171 | $social_link = 'https://wa.me/' . $social_link; |
| 172 | } |
| 173 | |
| 174 | if ( 'phone' == $social_platform ) { |
| 175 | $social_link = 'tel:' . $social_link; |
| 176 | } |
| 177 | |
| 178 | if ( 'telegram' == $social_platform ) { |
| 179 | $social_link = 'https://t.me/' . $social_link; |
| 180 | } |
| 181 | |
| 182 | if ( 'skype' == $social_platform ) { |
| 183 | $social_link = 'skype:' . $social_link.'?call'; |
| 184 | } |
| 185 | |
| 186 | if ( ! empty( $social_link ) ) { |
| 187 | echo Simple_Author_Box_Helper::get_sabox_social_icon( $social_link, $social_platform ); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | echo '</div>'; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | echo '</div>'; // about tab |
| 198 | |
| 199 | echo '<div class="saboxplugin-tab saboxplugin-tab-latest_posts" style="display:none">'; |
| 200 | $latest_posts = get_posts(array( |
| 201 | 'author' => $sabox_author_id, |
| 202 | 'orderby' => 'post_date', |
| 203 | 'order' => 'DESC', |
| 204 | 'posts_per_page' => 3 |
| 205 | )); |
| 206 | if (!empty($latest_posts)) { |
| 207 | echo '<ul>'; |
| 208 | foreach ($latest_posts as $latest_post) { |
| 209 | echo '<li><a href="' . get_permalink($latest_post->ID) . '">' . $latest_post->post_title . '</a></li>'; |
| 210 | } |
| 211 | echo '</ul>'; |
| 212 | } else { |
| 213 | echo 'You do not have any posts.'; |
| 214 | } |
| 215 | echo '</div>'; |
| 216 | |
| 217 | echo '<div class="saboxplugin-tab saboxplugin-tab-other" style="display:none">'; |
| 218 | |
| 219 | $author_html = get_user_meta($sabox_author_id, 'sab_box_author_html', true); |
| 220 | if(!empty($sabox_options['sab_tab_custom_html_body'])){ |
| 221 | echo str_ireplace('%%author_html%%', $author_html, $sabox_options['sab_tab_custom_html_body']); |
| 222 | } else if (false != $author_html) { |
| 223 | echo $author_html; |
| 224 | } else { |
| 225 | echo '<i>Set your Author Custom HTML Tab Content on your <a href="' . admin_url('profile.php') . '#sabox-custom-profile-image" target="_blank" class="clickable">Profile page</a></i>'; |
| 226 | } |
| 227 | echo '</div>'; |
| 228 | |
| 229 | } // end of social icons |
| 230 | echo '</div>'; // end of saboxplugin-wrap div |
| 231 | |
| 232 | } |
| 233 | |
| 234 |