| 1 |
<?php // phpcs:ignore |
| 2 |
// Prevent direct file access. |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
die( 'No direct access' ); |
| 5 |
} |
| 6 |
/** |
| 7 |
* Gutenberg class for Metronet Profile Picture |
| 8 |
* |
| 9 |
* Gutenberg class for Metronet Profile Picture |
| 10 |
* |
| 11 |
* @category Metronet Metronet Profile Picture |
| 12 |
* @package Metronet Metronet Profile Picture |
| 13 |
* @author Ronald Huereca <[email protected]> |
| 14 |
* @license GPL-2.0+ |
| 15 |
* @link https://github.com/ronalfy/user-profile-picture |
| 16 |
* |
| 17 |
* @since 2.0.0 |
| 18 |
*/ |
| 19 |
class User_Profile_Picture_Gutenberg { |
| 20 |
/** |
| 21 |
* Class constructor. |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
add_action( 'init', array( $this, 'register_block' ) ); |
| 29 |
add_action( 'enqueue_block_assets', array( $this, 'add_gutenberg_styles' ) ); |
| 30 |
add_action( 'enqueue_block_editor_assets', array( $this, 'add_gutenberg_scripts' ) ); |
| 31 |
add_action( 'admin_footer', array( $this, 'load_gutenblock_svgs' ) ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Register the main User Profile Picture block. |
| 36 |
*/ |
| 37 |
public function register_block() { |
| 38 |
register_block_type( |
| 39 |
'mpp/user-profile', |
| 40 |
array( |
| 41 |
'attributes' => array(), |
| 42 |
) |
| 43 |
); |
| 44 |
register_block_type( |
| 45 |
'mpp/user-profile-enhanced', |
| 46 |
array( |
| 47 |
'attributes' => array( |
| 48 |
'profileName' => array( |
| 49 |
'type' => 'string', |
| 50 |
'default' => '', |
| 51 |
), |
| 52 |
'theme' => array( |
| 53 |
'type' => 'string', |
| 54 |
'default' => 'regular', |
| 55 |
), |
| 56 |
'profileTitle' => array( |
| 57 |
'type' => 'string', |
| 58 |
'default' => '', |
| 59 |
), |
| 60 |
'profileContent' => array( |
| 61 |
'type' => 'string', |
| 62 |
'default' => '', |
| 63 |
), |
| 64 |
'profileViewPosts' => array( |
| 65 |
'type' => 'string', |
| 66 |
'default' => __( 'View Posts', 'profile-builder' ), |
| 67 |
), |
| 68 |
'profileViewWebsite' => array( |
| 69 |
'type' => 'string', |
| 70 |
'default' => __( 'View Website', 'profile-builder' ), |
| 71 |
), |
| 72 |
'profileAlignment' => array( |
| 73 |
'type' => 'string', |
| 74 |
'default' => '', |
| 75 |
), |
| 76 |
'profileImgURL' => array( |
| 77 |
'type' => 'string', |
| 78 |
'default' => '', |
| 79 |
), |
| 80 |
'profileImgID' => array( |
| 81 |
'type' => 'number', |
| 82 |
'default' => '', |
| 83 |
), |
| 84 |
'profileURL' => array( |
| 85 |
'type' => 'string', |
| 86 |
'default' => '', |
| 87 |
), |
| 88 |
'padding' => array( |
| 89 |
'type' => 'number', |
| 90 |
'default' => 0, |
| 91 |
), |
| 92 |
'border' => array( |
| 93 |
'type' => 'number', |
| 94 |
'default' => 0, |
| 95 |
), |
| 96 |
'borderRounded' => array( |
| 97 |
'type' => 'number', |
| 98 |
'default' => 0, |
| 99 |
), |
| 100 |
'borderColor' => array( |
| 101 |
'type' => 'string', |
| 102 |
'default' => '#f2f2f2', |
| 103 |
), |
| 104 |
'profileBackgroundColor' => array( |
| 105 |
'type' => 'string', |
| 106 |
'default' => '#f2f2f2', |
| 107 |
), |
| 108 |
'profileTextColor' => array( |
| 109 |
'type' => 'string', |
| 110 |
'default' => '#32373c', |
| 111 |
), |
| 112 |
'profileViewPostsBackgroundColor' => array( |
| 113 |
'type' => 'string', |
| 114 |
'default' => '#cf6d38', |
| 115 |
), |
| 116 |
'profileViewPostsTextColor' => array( |
| 117 |
'type' => 'string', |
| 118 |
'default' => '#FFFFFF', |
| 119 |
), |
| 120 |
'profileWebsiteBackgroundColor' => array( |
| 121 |
'type' => 'string', |
| 122 |
'default' => '#000000', |
| 123 |
), |
| 124 |
'profileWebsiteTextColor' => array( |
| 125 |
'type' => 'string', |
| 126 |
'default' => '#FFFFFF', |
| 127 |
), |
| 128 |
'profileLinkColor' => array( |
| 129 |
'type' => 'string', |
| 130 |
'default' => 'inherit', |
| 131 |
), |
| 132 |
'headerFontSize' => array( |
| 133 |
'type' => 'number', |
| 134 |
'default' => 24, |
| 135 |
), |
| 136 |
'buttonFontSize' => array( |
| 137 |
'type' => 'number', |
| 138 |
'default' => 16, |
| 139 |
), |
| 140 |
'profileFontSize' => array( |
| 141 |
'type' => 'number', |
| 142 |
'default' => 18, |
| 143 |
), |
| 144 |
'profileAvatarShape' => array( |
| 145 |
'type' => 'string', |
| 146 |
'default' => 'square', |
| 147 |
), |
| 148 |
'showName' => array( |
| 149 |
'type' => 'boolean', |
| 150 |
'default' => true, |
| 151 |
), |
| 152 |
'showTitle' => array( |
| 153 |
'type' => 'boolean', |
| 154 |
'default' => true, |
| 155 |
), |
| 156 |
'showDescription' => array( |
| 157 |
'type' => 'boolean', |
| 158 |
'default' => true, |
| 159 |
), |
| 160 |
'showViewPosts' => array( |
| 161 |
'type' => 'boolean', |
| 162 |
'default' => true, |
| 163 |
), |
| 164 |
'showWebsite' => array( |
| 165 |
'type' => 'boolean', |
| 166 |
'default' => true, |
| 167 |
), |
| 168 |
'user_id' => array( |
| 169 |
'type' => 'number', |
| 170 |
'default' => 0, |
| 171 |
), |
| 172 |
'socialFacebook' => array( |
| 173 |
'type' => 'string', |
| 174 |
'default' => '', |
| 175 |
), |
| 176 |
'socialTwitter' => array( |
| 177 |
'type' => 'string', |
| 178 |
'default' => '', |
| 179 |
), |
| 180 |
'socialYouTube' => array( |
| 181 |
'type' => 'string', |
| 182 |
'default' => '', |
| 183 |
), |
| 184 |
'socialLinkedIn' => array( |
| 185 |
'type' => 'string', |
| 186 |
'default' => '', |
| 187 |
), |
| 188 |
'socialWordPress' => array( |
| 189 |
'type' => 'string', |
| 190 |
'default' => '', |
| 191 |
), |
| 192 |
'socialGitHub' => array( |
| 193 |
'type' => 'string', |
| 194 |
'default' => '', |
| 195 |
), |
| 196 |
'socialPinterest' => array( |
| 197 |
'type' => 'string', |
| 198 |
'default' => '', |
| 199 |
), |
| 200 |
'socialInstagram' => array( |
| 201 |
'type' => 'string', |
| 202 |
'default' => '', |
| 203 |
), |
| 204 |
'website' => array( |
| 205 |
'type' => 'string', |
| 206 |
'default' => '', |
| 207 |
), |
| 208 |
'socialMediaOptions' => array( |
| 209 |
'type' => 'string', |
| 210 |
'default' => 'colors', |
| 211 |
), |
| 212 |
'socialMediaColors' => array( |
| 213 |
'type' => 'string', |
| 214 |
'default' => '#000000', |
| 215 |
), |
| 216 |
'tabbedAuthorProfile' => array( |
| 217 |
'type' => 'string', |
| 218 |
'default' => __( 'Author Details', 'profile-builder' ), |
| 219 |
), |
| 220 |
'tabbedAuthorProfileHeading' => array( |
| 221 |
'type' => 'string', |
| 222 |
'default' => __( 'Author Details', 'profile-builder' ), |
| 223 |
), |
| 224 |
'tabbedAuthorLatestPosts' => array( |
| 225 |
'type' => 'string', |
| 226 |
'default' => __( 'Latest Posts', 'profile-builder' ), |
| 227 |
), |
| 228 |
'tabbedAuthorSubHeading' => array( |
| 229 |
'type' => 'string', |
| 230 |
'default' => '', |
| 231 |
), |
| 232 |
'tabbedAuthorProfileTitle' => array( |
| 233 |
'type' => 'string', |
| 234 |
'default' => '', |
| 235 |
), |
| 236 |
'profileTabHeadlineColor' => array( |
| 237 |
'type' => 'string', |
| 238 |
'default' => '#42737b', |
| 239 |
), |
| 240 |
'profileTabColor' => array( |
| 241 |
'type' => 'string', |
| 242 |
'default' => '#42737b', |
| 243 |
), |
| 244 |
'profileTabPostsColor' => array( |
| 245 |
'type' => 'string', |
| 246 |
'default' => '#30424b', |
| 247 |
), |
| 248 |
'profileTabHeadlineTextColor' => array( |
| 249 |
'type' => 'string', |
| 250 |
'default' => '#FFFFFF', |
| 251 |
), |
| 252 |
'profileTabTextColor' => array( |
| 253 |
'type' => 'string', |
| 254 |
'default' => '#FFFFFF', |
| 255 |
), |
| 256 |
'profileTabPostsTextColor' => array( |
| 257 |
'type' => 'string', |
| 258 |
'default' => '#FFFFFF', |
| 259 |
), |
| 260 |
'profileLatestPostsOptionsValue' => array( |
| 261 |
'type' => 'string', |
| 262 |
'default' => 'light', |
| 263 |
), |
| 264 |
'profileCompactAlignment' => array( |
| 265 |
'type' => 'string', |
| 266 |
'default' => 'center', |
| 267 |
), |
| 268 |
'showPostsWidth' => array( |
| 269 |
'type' => 'string', |
| 270 |
'default' => '', |
| 271 |
), |
| 272 |
'showSocialMedia' => array( |
| 273 |
'type' => 'boolean', |
| 274 |
'default' => true, |
| 275 |
), |
| 276 |
'profileName' => array( |
| 277 |
'type' => 'string', |
| 278 |
'default' => '', |
| 279 |
), |
| 280 |
|
| 281 |
), |
| 282 |
'render_callback' => array( $this, 'display_frontend' ), |
| 283 |
'editor_script' => 'mpp_gutenberg', |
| 284 |
) |
| 285 |
); |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Display the front-end for the Gutenberg block. |
| 290 |
* |
| 291 |
* @param array $attributes Array of block attributes. |
| 292 |
*/ |
| 293 |
public function display_frontend( $attributes ) { |
| 294 |
if ( is_admin() ) { |
| 295 |
return; |
| 296 |
} |
| 297 |
ob_start(); |
| 298 |
if ( empty( $attributes['profileImgURL'] ) ) { |
| 299 |
$attributes['profileImgURL'] = wp_get_attachment_image_url( $attributes['profileImgID'], 'thumbnail', false, '' ); |
| 300 |
} |
| 301 |
?> |
| 302 |
<?php if ( 'regular' === $attributes['theme'] || 'compact' === $attributes['theme'] || 'profile' === $attributes['theme'] ) : ?> |
| 303 |
<div class="mpp-enhanced-profile-wrap mpp-block-profile <?php echo 'compact' === $attributes['theme'] ? esc_attr( $attributes['profileCompactAlignment'] ) : ''; ?> <?php echo esc_attr( $attributes['theme'] ); ?> <?php echo esc_attr( $attributes['profileAvatarShape'] ); ?>" style="<?php echo $attributes['padding'] > 0 ? 'padding: ' . esc_attr( $attributes['padding'] ) . 'px;' : ''; ?><?php echo $attributes['border'] > 0 ? 'border:' . esc_attr( $attributes['border'] ) . 'px solid ' . esc_attr( $attributes['borderColor'] ) . ';' : ''; ?><?php echo $attributes['borderRounded'] > 0 ? 'border-radius:' . esc_attr( $attributes['borderRounded'] ) . 'px;' : ''; ?>background-color: <?php echo esc_attr( $attributes['profileBackgroundColor'] ) . ';'; ?> color: <?php echo esc_attr( $attributes['profileTextColor'] ) . ';'; ?>"> |
| 304 |
<div class="mpp-profile-gutenberg-wrap mt-font-size-<?php echo esc_attr( $attributes['profileFontSize'] ); ?>"> |
| 305 |
<?php if ( 'regular' === $attributes['theme'] ) : ?> |
| 306 |
<div class="mpp-profile-image-wrapper"> |
| 307 |
<div class="mpp-profile-image-square"> |
| 308 |
<img class="profile-avatar" alt="avatar" src="<?php echo esc_url( $attributes['profileImgURL'] ); ?>" /> |
| 309 |
</div> |
| 310 |
</div> |
| 311 |
<div class="mpp-content-wrap"> |
| 312 |
<?php if ( $attributes['showName'] ) : ?> |
| 313 |
<h2 style="color:<?php echo esc_attr( $attributes['profileTextColor'] ); ?>; font-size: <?php echo esc_attr( $attributes['headerFontSize'] ) . 'px;'; ?>"><?php echo wp_kses_post( $attributes['profileName'] ); ?></h2> |
| 314 |
<?php endif; ?> |
| 315 |
<?php if ( $attributes['showTitle'] ) : ?> |
| 316 |
<p style="color:<?php echo esc_attr( $attributes['profileTextColor'] ); ?>"><?php echo wp_kses_post( $attributes['profileTitle'] ); ?></p> |
| 317 |
<?php endif; ?> |
| 318 |
<?php if ( $attributes['showDescription'] ) : ?> |
| 319 |
<div><?php echo wp_kses_post( $attributes['profileContent'] ); ?></div> |
| 320 |
<?php endif; ?> |
| 321 |
<?php if ( isset( $attributes['profileURL'] ) && strlen( $attributes['profileURL'] ) > 0 ) : ?> |
| 322 |
<div class="mpp-gutenberg-view-posts"> |
| 323 |
<?php if ( $attributes['showViewPosts'] ) : ?> |
| 324 |
<div class="mpp-profile-view-posts" style="background-color: <?php echo esc_attr( $attributes['profileViewPostsBackgroundColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileViewPostsTextColor'] ); ?>; width: <?php echo esc_attr( $attributes['showPostsWidth'] ); ?>; font-size: <?php echo esc_attr( $attributes['buttonFontSize'] ); ?>px;"> |
| 325 |
<a href="<?php echo esc_url( $attributes['profileURL'] ); ?>" style="background: <?php echo esc_attr( $attributes['profileViewPostsBackgroundColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileViewPostsTextColor'] ); ?>"> |
| 326 |
<?php |
| 327 |
if ( isset( $attributes['profileViewPosts'] ) ) { |
| 328 |
echo esc_html( $attributes['profileViewPosts'] ); |
| 329 |
} else { |
| 330 |
esc_html_e( 'View Posts', 'profile-builder' ); |
| 331 |
} |
| 332 |
?> |
| 333 |
</a> |
| 334 |
</div><!-- .mpp-profile-view-posts --> |
| 335 |
<?php endif; ?> |
| 336 |
<?php if ( '' !== $attributes['website'] && $attributes['showWebsite'] ) : ?> |
| 337 |
<div class="mpp-profile-view-website" style="background: <?php echo esc_attr( $attributes['profileWebsiteBackgroundColor'] ); ?>;color: <?php echo esc_attr( $attributes['profileWebsiteTextColor'] ); ?>; font-size: <?php echo esc_attr( $attributes['buttonFontSize'] ); ?>px;"> |
| 338 |
<a href="<?php echo esc_url( $attributes['website'] ); ?>" style="background: <?php echo esc_attr( $attributes['profileWebsiteBackgroundColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileWebsiteTextColor'] ); ?>;"> |
| 339 |
<?php |
| 340 |
if ( isset( $attributes['profileViewWebsite'] ) ) { |
| 341 |
echo esc_html( $attributes['profileViewWebsite'] ); |
| 342 |
} else { |
| 343 |
esc_html_e( 'View Website', 'profile-builder' ); |
| 344 |
} |
| 345 |
?> |
| 346 |
</a> |
| 347 |
</div><!-- .mpp-profile-view-website --> |
| 348 |
<?php endif; ?> |
| 349 |
</div><!-- .mpp-gutenberg-view-posts --> |
| 350 |
<?php endif; ?> |
| 351 |
</div><!-- .mpp-content-wrap --> |
| 352 |
<?php endif; /* End Regular Theme */ ?> |
| 353 |
<?php if ( 'profile' === $attributes['theme'] ) : ?> |
| 354 |
<?php if ( $attributes['showName'] ) : ?> |
| 355 |
<h2 style="color: <?php echo esc_attr( $attributes['profileTextColor'] ); ?>; font-size: <?php echo esc_attr( $attributes['headerFontSize'] ) . 'px'; ?>"><?php echo wp_kses_post( $attributes['profileName'] ); ?></h2> |
| 356 |
<?php endif; ?> |
| 357 |
<div class="mpp-profile-image-wrapper"> |
| 358 |
<div class="mpp-profile-image-square"> |
| 359 |
<img src="<?php echo esc_url( $attributes['profileImgURL'] ); ?>" alt="avatar" class="profile-avatar" /> |
| 360 |
</div> |
| 361 |
</div><!-- .mpp-profile-image-wrapper --> |
| 362 |
<?php if ( $attributes['showDescription'] ) : ?> |
| 363 |
<div class="mpp-profile-text"> |
| 364 |
<?php echo wp_kses_post( $attributes['profileContent'] ); ?> |
| 365 |
</div><!-- .mpp-profile-text --> |
| 366 |
<?php endif; ?> |
| 367 |
<?php |
| 368 |
$font_size = isset( $attributes['fontSize'] ) ? $attributes['fontSize'] : false; |
| 369 |
$font_size_style = ''; |
| 370 |
if ( $font_size ) { |
| 371 |
$font_size_style = 'font-size: ' . $font_size . 'px'; |
| 372 |
} |
| 373 |
?> |
| 374 |
<div class="mpp-profile-meta" style="<?php echo esc_attr( $font_size_style ); ?>"> |
| 375 |
<?php if ( $attributes['showViewPosts'] ) : ?> |
| 376 |
<div class="mpp-profile-link alignleft"> |
| 377 |
<a href="<?php echo esc_url( $attributes['profileURL'] ); ?>" style="color: <?php echo esc_attr( $attributes['profileLinkColor'] ); ?>;"><?php esc_html_e( 'View all posts by', 'profile-builder' ); ?> <?php echo esc_html( $attributes['profileName'] ); ?></a> |
| 378 |
</div><!-- .mpp-profile-link --> |
| 379 |
<div class="mpp-profile-link alignright"> |
| 380 |
<a href="<?php echo esc_url( $attributes['website'] ); ?>" style="color: <?php echo esc_attr( $attributes['profileLinkColor'] ); ?>"> |
| 381 |
<?php esc_html_e( 'Website', 'profile-builder' ); ?> |
| 382 |
</a> |
| 383 |
</div><!-- .mpp-profile-link --> |
| 384 |
<?php endif; ?> |
| 385 |
</div><!-- .mpp-profile-meta --> |
| 386 |
<?php endif; /* End of profile theme */ ?> |
| 387 |
<?php if ( 'compact' === $attributes['theme'] ) : ?> |
| 388 |
<?php if ( $attributes['showName'] ) : ?> |
| 389 |
<h2 style="color: <?php echo esc_attr( $attributes['profileTextColor'] ); ?>; font-size: <?php echo esc_attr( $attributes['headerFontSize'] ) . 'px'; ?>"><?php echo wp_kses_post( $attributes['profileName'] ); ?></h2> |
| 390 |
<?php endif; ?> |
| 391 |
<div class="mpp-profile-image-wrapper"> |
| 392 |
<div class="mpp-profile-image-square"> |
| 393 |
<img src="<?php echo esc_url( $attributes['profileImgURL'] ); ?>" alt="avatar" class="profile-avatar" /> |
| 394 |
</div> |
| 395 |
</div><!-- .mpp-profile-image-wrapper --> |
| 396 |
<?php if ( $attributes['showDescription'] ) : ?> |
| 397 |
<div class="mpp-profile-text"> |
| 398 |
<?php echo wp_kses_post( $attributes['profileContent'] ); ?> |
| 399 |
</div><!-- .mpp-profile-text --> |
| 400 |
<?php endif; ?> |
| 401 |
<div class="mpp-compact-meta"> |
| 402 |
<?php if ( $attributes['showViewPosts'] ) : ?> |
| 403 |
<div class="mpp-profile-view-posts" style="background: <?php echo esc_attr( $attributes['profileViewPostsBackgroundColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileViewPostsTextColor'] ); ?>; width: 90%; margin: 0 auto 10px auto; font-size: <?php echo esc_attr( $attributes['buttonFontSize'] ); ?>px;"> |
| 404 |
<a href="<?php echo esc_url( $attributes['profileURL'] ); ?>" style="color: <?php echo esc_attr( $attributes['profileViewPostsTextColor'] ); ?>; background: <?php echo esc_attr( $attributes['profileViewPostsBackgroundColor'] ); ?>;"><?php esc_html_e( 'View Posts', 'profile-builder' ); ?></a> |
| 405 |
</div><!-- .mpp-profile-view-posts --> |
| 406 |
<?php endif; ?> |
| 407 |
<?php if ( '' !== $attributes['website'] && $attributes['showWebsite'] ) : ?> |
| 408 |
<div class="mpp-profile-view-website" style="background: <?php echo esc_attr( $attributes['profileWebsiteBackgroundColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileWebsiteTextColor'] ); ?>; width: 90%; margin: 0 auto 0 auto; font-size: <?php echo esc_attr( $attributes['buttonFontSize'] ); ?>px;"> |
| 409 |
<a href="<?php echo esc_url( $attributes['website'] ); ?>" style="color: <?php echo esc_attr( $attributes['profileWebsiteTextColor'] ); ?>; background: <?php echo esc_attr( $attributes['profileWebsiteBackgroundColor'] ); ?>;"><?php esc_html_e( 'View Website', 'profile-builder' ); ?></a> |
| 410 |
</div><!-- .mpp-profile-view-posts --> |
| 411 |
<?php endif; ?> |
| 412 |
|
| 413 |
</div> |
| 414 |
<?php endif; /* Compact theme end */ ?> |
| 415 |
<?php if ( true === $attributes['showSocialMedia'] && ( 'regular' === $attributes['theme'] || 'compact' === $attributes['theme'] || 'profile' === $attributes['theme'] ) ) : ?> |
| 416 |
<?php echo $this->get_social_icons( $attributes ); // phpcs:ignore ?> |
| 417 |
<?php endif; ?> |
| 418 |
</div><!-- .mpp-profile-gutenberg-wrap --> |
| 419 |
</div><!-- .mpp-profile-wrap --> |
| 420 |
<?php endif; ?> |
| 421 |
<?php if ( 'tabbed' === $attributes['theme'] ) : ?> |
| 422 |
<style> |
| 423 |
.mpp-author-tabbed ul.mpp-author-tabs li.active:after { |
| 424 |
border-top: 10px solid <?php echo esc_attr( $attributes['profileTabColor'] ); ?>; |
| 425 |
border-top-color: <?php echo esc_attr( $attributes['profileTabColor'] ); ?>; |
| 426 |
} |
| 427 |
.mpp-author-tabbed ul.mpp-author-tabs li.mpp-tab-posts.active:after { |
| 428 |
border-top: 10px solid <?php echo esc_attr( $attributes['profileTabPostsColor'] ); ?>; |
| 429 |
border-top-color: <?php echo esc_attr( $attributes['profileTabPostsColor'] ); ?>; |
| 430 |
} |
| 431 |
</style> |
| 432 |
<div class="mpp-author-tabbed tabbed <?php echo esc_attr( $attributes['profileAvatarShape'] ); ?> mpp-block-profile"> |
| 433 |
<ul class="mpp-author-tabs"> |
| 434 |
<li class="mpp-tab-profile active mpp-gutenberg-tab" data-tab="mpp-profile-tab" style="background: <?php echo esc_attr( $attributes['profileTabColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileTabTextColor'] ); ?>;"> |
| 435 |
<?php echo wp_kses_post( $attributes['tabbedAuthorProfile'] ); ?> |
| 436 |
</li> |
| 437 |
<li class="mpp-tab-posts mpp-gutenberg-tab" data-tab="mpp-latestposts-tab" style="background: <?php echo esc_attr( $attributes['profileTabPostsColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileTabPostsTextColor'] ); ?>;"> |
| 438 |
<?php echo wp_kses_post( $attributes['tabbedAuthorLatestPosts'] ); ?> |
| 439 |
</li> |
| 440 |
</ul> |
| 441 |
<div class="mpp-tab-wrapper" style="<?php echo $attributes['padding'] > 0 ? 'padding: ' . esc_attr( $attributes['padding'] ) . 'px;' : ''; ?><?php echo $attributes['border'] > 0 ? 'border:' . esc_attr( $attributes['border'] ) . 'px solid ' . esc_attr( $attributes['borderColor'] ) . ';' : ''; ?><?php echo $attributes['borderRounded'] > 0 ? 'border-radius:' . esc_attr( $attributes['borderRounded'] ) . 'px;' : ''; ?>background-color: <?php echo esc_attr( $attributes['profileBackgroundColor'] ) . ';'; ?> color: <?php echo esc_attr( $attributes['profileTextColor'] ) . ';'; ?>"> |
| 442 |
<div class="mpp-tab-active mpp-profile-tab mpp-tab"> |
| 443 |
<div class="mpp-author-social-wrapper"> |
| 444 |
<div class="mpp-author-heading"> |
| 445 |
<div class="mpp-author-profile-heading" style="background: <?php echo esc_attr( $attributes['profileTabHeadlineColor'] ); ?>; color: <?php echo esc_attr( $attributes['profileTabHeadlineTextColor'] ); ?>;"> |
| 446 |
<?php echo wp_kses_post( $attributes['tabbedAuthorProfileHeading'] ); ?> |
| 447 |
</div><!-- .mpp-author-heading --> |
| 448 |
</div><!-- .mpp-author-social-wrapper --> |
| 449 |
<?php if ( $attributes['showSocialMedia'] ) : ?> |
| 450 |
<div class="mpp-author-social"> |
| 451 |
<?php echo $this->get_social_icons( $attributes ); // phpcs:ignore ?> |
| 452 |
</div> |
| 453 |
<?php endif; ?> |
| 454 |
</div><!-- .mpp-author-social-wrapper --> |
| 455 |
<div class="mpp-profile-image-wrapper"> |
| 456 |
<div class="mpp-profile-image-square"> |
| 457 |
<img class="profile-avatar" alt="avatar" src="<?php echo esc_url( $attributes['profileImgURL'] ); ?>"> |
| 458 |
<div class="mpp-author-profile-sub-heading"> |
| 459 |
<?php echo wp_kses_post( $attributes['tabbedAuthorSubHeading'] ); ?> |
| 460 |
</div> |
| 461 |
</div><!-- .mpp-profile-image-square --> |
| 462 |
</div><!-- .mpp-profile-image-wrapper --> |
| 463 |
<div class="mpp-tabbed-profile-information"> |
| 464 |
<?php if ( $attributes['showTitle'] || '' !== $attributes['tabbedAuthorProfileTitle'] ) : ?> |
| 465 |
<?php echo '<div>' . wp_kses_post( $attributes['tabbedAuthorProfileTitle'] ) . '</div>'; ?> |
| 466 |
<?php endif; ?> |
| 467 |
<?php if ( $attributes['showName'] ) : ?> |
| 468 |
<h2 style="color: <?php echo esc_attr( $attributes['profileTextColor'] ); ?>; font-size: <?php echo esc_attr( $attributes['headerFontSize'] ) . 'px;'; ?>"><?php echo wp_kses_post( $attributes['profileName'] ); ?></h2> |
| 469 |
<?php endif; ?> |
| 470 |
<?php if ( $attributes['showDescription'] ) : ?> |
| 471 |
<div class="mpp-profile-text mt-font-size-<?php echo esc_attr( $attributes['profileFontSize'] ); ?>"> |
| 472 |
<?php echo wp_kses_post( $attributes['profileContent'] ); ?> |
| 473 |
</div> |
| 474 |
<?php endif; ?> |
| 475 |
</div><!-- .mpp-tabbed-profile-information --> |
| 476 |
</div><!-- first profile tab --> |
| 477 |
<div class="mpp-tabbed-latest-posts mpp-latestposts-tab mpp-tab"> |
| 478 |
<?php |
| 479 |
$user_id = $attributes['user_id']; |
| 480 |
$args = array( |
| 481 |
'post_type' => 'post', |
| 482 |
'post_status' => 'publish', |
| 483 |
'author' => $user_id, |
| 484 |
'orderby' => 'date', |
| 485 |
'order' => 'DESC', |
| 486 |
'posts_per_page' => 5, |
| 487 |
); |
| 488 |
$posts = get_posts( $args ); |
| 489 |
?> |
| 490 |
<ul class="mpp-author-tab-content <?php echo esc_attr( $attributes['profileLatestPostsOptionsValue'] ); ?>"> |
| 491 |
<?php |
| 492 |
foreach ( $posts as $post ) { |
| 493 |
printf( "<li><a href='%s'>%s</a></li>", esc_url( get_permalink( $post->ID ) ), esc_html( $post->post_title ) ); |
| 494 |
} |
| 495 |
?> |
| 496 |
</ul> |
| 497 |
</div><!-- .mpp-tabbed-latest-posts --> |
| 498 |
</div><!-- mpp-tab-wrapper --> |
| 499 |
</div><!-- .mpp-author-tabbed --> |
| 500 |
|
| 501 |
<?php endif; ?> |
| 502 |
<?php |
| 503 |
$this->load_gutenblock_svgs(); |
| 504 |
return ob_get_clean(); |
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Get the social icons for the block. |
| 509 |
* |
| 510 |
* @param array $attributes Gutenberg attributes. |
| 511 |
*/ |
| 512 |
public function get_social_icons( $attributes ) { |
| 513 |
ob_start(); |
| 514 |
?> |
| 515 |
<div class="mpp-social"> |
| 516 |
<?php if ( ! empty( $attributes['socialFacebook'] ) ) : ?> |
| 517 |
<a href="<?php echo esc_url( $attributes['socialFacebook'] ); ?>"> |
| 518 |
<svg class="icon icon-facebook" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 519 |
<use href="#facebook"></use> |
| 520 |
</svg> |
| 521 |
</a> |
| 522 |
<?php endif; ?> |
| 523 |
<?php if ( ! empty( $attributes['socialTwitter'] ) ) : ?> |
| 524 |
<a href="<?php echo esc_url( $attributes['socialTwitter'] ); ?>"> |
| 525 |
<svg class="icon icon-twitter" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 526 |
<use href="#twitter"></use> |
| 527 |
</svg> |
| 528 |
</a> |
| 529 |
<?php endif; ?> |
| 530 |
<?php if ( ! empty( $attributes['socialInstagram'] ) ) : ?> |
| 531 |
<a href="<?php echo esc_url( $attributes['socialInstagram'] ); ?>"> |
| 532 |
<svg class="icon icon-instagram" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 533 |
<use href="#instagram"></use> |
| 534 |
</svg> |
| 535 |
</a> |
| 536 |
<?php endif; ?> |
| 537 |
<?php if ( ! empty( $attributes['socialPinterest'] ) ) : ?> |
| 538 |
<a href="<?php echo esc_url( $attributes['socialPinterest'] ); ?>"> |
| 539 |
<svg class="icon icon-pinterest" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 540 |
<use href="#pinterest"></use> |
| 541 |
</svg> |
| 542 |
</a> |
| 543 |
<?php endif; ?> |
| 544 |
<?php if ( ! empty( $attributes['socialLinkedIn'] ) ) : ?> |
| 545 |
<a href="<?php echo esc_url( $attributes['socialLinkedIn'] ); ?>"> |
| 546 |
<svg class="icon icon-linkedin" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 547 |
<use href="#linkedin"></use> |
| 548 |
</svg> |
| 549 |
</a> |
| 550 |
<?php endif; ?> |
| 551 |
<?php if ( ! empty( $attributes['socialYouTube'] ) ) : ?> |
| 552 |
<a href="<?php echo esc_url( $attributes['socialYouTube'] ); ?>"> |
| 553 |
<svg class="icon icon-youtube" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 554 |
<use href="#youtube"></use> |
| 555 |
</svg> |
| 556 |
</a> |
| 557 |
<?php endif; ?> |
| 558 |
<?php if ( ! empty( $attributes['socialGitHub'] ) ) : ?> |
| 559 |
<a href="<?php echo esc_url( $attributes['socialGitHub'] ); ?>"> |
| 560 |
<svg class="icon icon-github" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 561 |
<use href="#github"></use> |
| 562 |
</svg> |
| 563 |
</a> |
| 564 |
<?php endif; ?> |
| 565 |
<?php if ( ! empty( $attributes['socialWordPress'] ) ) : ?> |
| 566 |
<a href="<?php echo esc_url( $attributes['socialWordPress'] ); ?>"> |
| 567 |
<svg class="icon icon-wordpress" role="img" style="<?php echo 'custom' === $attributes['socialMediaOptions'] ? 'fill:' . esc_attr( $attributes['socialMediaColors'] ) . ';' : ''; ?>"> |
| 568 |
<use href="#wordpress"></use><?php // phpcs:ignore ?> |
| 569 |
</svg> |
| 570 |
</a> |
| 571 |
<?php endif; ?> |
| 572 |
</div><!-- .mpp-social --> |
| 573 |
<?php |
| 574 |
return ob_get_clean(); |
| 575 |
} |
| 576 |
|
| 577 |
/** |
| 578 |
* Add SVGs for the social icons in the block. |
| 579 |
*/ |
| 580 |
public function load_gutenblock_svgs() { |
| 581 |
if ( '' !== get_post_type() ) { |
| 582 |
// Define SVG sprite file. |
| 583 |
$path = '/img/social-logos.svg'; |
| 584 |
$svg_icons = rtrim( dirname( plugin_dir_path( __FILE__ ) ), '/' ); |
| 585 |
if ( ! empty( $path ) && is_string( $path ) ) { |
| 586 |
$svg_icons .= '/' . ltrim( $path, '/' ); |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* Filter Social Icons Sprite. |
| 591 |
* |
| 592 |
* @since 2.1.0 |
| 593 |
* |
| 594 |
* @param string Absolute directory path to SVG sprite |
| 595 |
*/ |
| 596 |
$svg_icons = apply_filters( 'mpp_icons_sprite', $svg_icons ); |
| 597 |
// If it exists, include it. |
| 598 |
if ( file_exists( $svg_icons ) ) { |
| 599 |
echo '<div style="position: absolute; height: 0; width: 0; overflow: hidden;">'; |
| 600 |
require $svg_icons; |
| 601 |
echo '</div>'; |
| 602 |
} |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
/** |
| 607 |
* Add Gutenberg scripts. |
| 608 |
*/ |
| 609 |
public function add_gutenberg_scripts() { |
| 610 |
|
| 611 |
wp_enqueue_script( 'mpp_gutenberg', User_Profile_Picture::get_plugin_url( 'dist/blocks.build.js' ), array( 'wp-blocks', 'wp-element' ), USER_PROFILE_PICTURE_VERSION, true ); |
| 612 |
|
| 613 |
/* For the Gutenberg plugin */ |
| 614 |
if ( function_exists( 'wp_set_script_translations' ) ) { |
| 615 |
wp_set_script_translations( 'mpp_gutenberg', 'profile-builder' ); |
| 616 |
} elseif ( function_exists( 'gutenberg_get_jed_locale_data' ) ) { |
| 617 |
$locale = gutenberg_get_jed_locale_data( 'profile-builder' ); |
| 618 |
$content = 'wp.i18n.setLocaleData( ' . wp_json_encode( $locale ) . ', "post-type-archive-mapping" );'; |
| 619 |
wp_script_add_data( 'mpp_gutenberg', 'data', $content ); |
| 620 |
} elseif ( function_exists( 'wp_get_jed_locale_data' ) ) { |
| 621 |
/* for 5.0 */ |
| 622 |
$locale = wp_get_jed_locale_data( 'profile-builder' ); |
| 623 |
$content = 'wp.i18n.setLocaleData( ' . $locale . ', "metronet-profile-picture" );'; |
| 624 |
wp_script_add_data( 'mpp_gutenberg', 'data', $content ); |
| 625 |
} |
| 626 |
|
| 627 |
// Pass in REST URL. |
| 628 |
wp_localize_script( |
| 629 |
'mpp_gutenberg', |
| 630 |
'mpp_gutenberg', |
| 631 |
array( |
| 632 |
'rest_url' => esc_url( rest_url( 'mpp/v2' ) ), |
| 633 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 634 |
'mystery_man' => User_Profile_Picture::get_plugin_url( 'img/mystery.png' ), |
| 635 |
) |
| 636 |
); |
| 637 |
|
| 638 |
wp_enqueue_style( 'mpp_gutenberg', User_Profile_Picture::get_plugin_url( '/dist/blocks.editor.build.css' ), array(), USER_PROFILE_PICTURE_VERSION, 'all' ); |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* Add Gutenberg styles. |
| 643 |
*/ |
| 644 |
public function add_gutenberg_styles() { |
| 645 |
if ( is_admin() ) { |
| 646 |
return; |
| 647 |
} |
| 648 |
// Ensure script debug allows non-minified scripts. |
| 649 |
wp_enqueue_style( 'mpp_gutenberg', User_Profile_Picture::get_plugin_url( '/dist/blocks.style.build.css' ), array(), USER_PROFILE_PICTURE_VERSION, 'all' ); |
| 650 |
wp_enqueue_script( 'mpp_gutenberg_tabs', User_Profile_Picture::get_plugin_url( 'js/mpp-frontend.js' ), array( 'jquery' ), USER_PROFILE_PICTURE_VERSION, true ); |
| 651 |
|
| 652 |
} |
| 653 |
} |
| 654 |
|