EditProfileBuilder.php
5 years ago
FieldsShortcodeCallback.php
5 years ago
FrontendProfileBuilder.php
5 years ago
GlobalShortcodes.php
5 years ago
LoginFormBuilder.php
5 years ago
PasswordResetBuilder.php
5 years ago
RegistrationFormBuilder.php
5 years ago
builder-preview.php
5 years ago
index.php
5 years ago
FrontendProfileBuilder.php
697 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\ShortcodeParser\Builder; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager as EM; |
| 6 | |
| 7 | class FrontendProfileBuilder |
| 8 | { |
| 9 | /** @var \WP_User user_data */ |
| 10 | static private $user_data; |
| 11 | |
| 12 | /** |
| 13 | * Define all front-end profile sub-shortcode. |
| 14 | * |
| 15 | * @param $user |
| 16 | */ |
| 17 | public function __construct($user) |
| 18 | { |
| 19 | self::$user_data = $user; |
| 20 | |
| 21 | add_shortcode('profile-username', array($this, 'profile_username')); |
| 22 | |
| 23 | add_shortcode('profile-email', array($this, 'profile_email')); |
| 24 | |
| 25 | add_shortcode('profile-website', array($this, 'profile_website')); |
| 26 | |
| 27 | add_shortcode('profile-nickname', array($this, 'profile_nickname')); |
| 28 | |
| 29 | add_shortcode('profile-display-name', array($this, 'profile_display_name')); |
| 30 | |
| 31 | add_shortcode('profile-first-name', array($this, 'profile_first_name')); |
| 32 | |
| 33 | add_shortcode('profile-last-name', array($this, 'profile_last_name')); |
| 34 | |
| 35 | add_shortcode('profile-bio', array($this, 'profile_bio')); |
| 36 | |
| 37 | add_shortcode('profile-cpf', array($this, 'profile_custom_profile_field')); |
| 38 | |
| 39 | add_shortcode('profile-file', array($this, 'profile_user_uploaded_file')); |
| 40 | |
| 41 | add_shortcode('profile-cover-image-url', array($this, 'cover_image_url')); |
| 42 | |
| 43 | add_shortcode('profile-avatar-url', array($this, 'user_avatar_url')); |
| 44 | // backward compat |
| 45 | add_shortcode('user-avatar-url', array($this, 'user_avatar_url')); |
| 46 | |
| 47 | add_shortcode('profile-hide-empty-data', array($this, 'hide_empty_data')); |
| 48 | |
| 49 | add_shortcode('post-count', array($this, 'post_count')); |
| 50 | add_shortcode('profile-post-count', array($this, 'post_count')); |
| 51 | |
| 52 | add_shortcode('comment-count', array($this, 'get_comment_count')); |
| 53 | add_shortcode('profile-comment-count', array($this, 'get_comment_count')); |
| 54 | |
| 55 | add_shortcode('profile-post-list', array($this, 'author_post_list')); |
| 56 | add_shortcode('profile-comment-list', array($this, 'author_comment_list')); |
| 57 | |
| 58 | add_shortcode('profile-author-posts-url', array($this, 'author_post_url')); |
| 59 | |
| 60 | add_shortcode('profile-date-registered', array($this, 'date_user_registered')); |
| 61 | |
| 62 | add_shortcode('jcarousel-author-posts', array($this, 'pp_jcarousel_author_posts')); |
| 63 | |
| 64 | /** |
| 65 | * @param object $user WP_User object |
| 66 | */ |
| 67 | do_action('ppress_register_profile_shortcode', $user); |
| 68 | } |
| 69 | |
| 70 | public function date_user_registered() |
| 71 | { |
| 72 | return date('F jS, Y', strtotime(self::$user_data->user_registered)); |
| 73 | } |
| 74 | |
| 75 | public function author_post_url() |
| 76 | { |
| 77 | return get_author_posts_url(self::$user_data->ID); |
| 78 | } |
| 79 | |
| 80 | public function author_post_list($attributes) |
| 81 | { |
| 82 | $attributes = shortcode_atts(array('limit' => 10), $attributes); |
| 83 | |
| 84 | $user_id = self::$user_data->ID; |
| 85 | $limit = absint($attributes['limit']); |
| 86 | |
| 87 | $cache_key = "pp_profile_post_list_{$user_id}_{$limit}"; |
| 88 | $output = get_transient($cache_key); |
| 89 | |
| 90 | if ($output === false) { |
| 91 | |
| 92 | $posts = get_posts(array( |
| 93 | 'author' => $user_id, |
| 94 | 'posts_per_page' => $limit, |
| 95 | 'offset' => 0 |
| 96 | )); |
| 97 | |
| 98 | $output = ''; |
| 99 | |
| 100 | if ( ! empty($posts)) { |
| 101 | |
| 102 | $output .= "<ul class='pp-user-post-list'>"; |
| 103 | /** @var \WP_Post $post */ |
| 104 | foreach ($posts as $post) { |
| 105 | $output .= sprintf('<li class="pp-user-post-item"><a href="%s"><h3 class="pp-post-item-head">%s</h3></a></li>', get_permalink($post->ID), $post->post_title); |
| 106 | } |
| 107 | |
| 108 | $output .= "</ul>"; |
| 109 | |
| 110 | set_transient($cache_key, $output, HOUR_IN_SECONDS); |
| 111 | } else { |
| 112 | |
| 113 | $note = esc_html__('This user has not created any post.', 'wp-user-avatar'); |
| 114 | |
| 115 | if (self::$user_data->ID == get_current_user_id()) { |
| 116 | $note = esc_html__('You have not created any post.', 'wp-user-avatar'); |
| 117 | } |
| 118 | |
| 119 | $output .= sprintf('<div class="pp-user-comment-no-item"><span>%s</span></div>', $note); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return $output; |
| 124 | } |
| 125 | |
| 126 | public function author_comment_list($attributes) |
| 127 | { |
| 128 | $attributes = shortcode_atts(array('limit' => 10), $attributes); |
| 129 | |
| 130 | $user_id = self::$user_data->ID; |
| 131 | |
| 132 | $limit = absint($attributes['limit']); |
| 133 | |
| 134 | $cache_key = "pp_profile_comments_list_{$user_id}_{$limit}"; |
| 135 | |
| 136 | $output = get_transient($cache_key); |
| 137 | |
| 138 | if ($output === false) { |
| 139 | |
| 140 | $comments = get_comments([ |
| 141 | 'number' => $limit, |
| 142 | 'user_id' => $user_id, |
| 143 | 'post_status' => ['publish'], |
| 144 | 'status' => 'approve' |
| 145 | ]); |
| 146 | |
| 147 | $output = ''; |
| 148 | |
| 149 | if ( ! empty($comments)) { |
| 150 | |
| 151 | $output .= '<div class="pp-user-comment-list">'; |
| 152 | /** @var \WP_Comment $comment */ |
| 153 | foreach ($comments as $comment) { |
| 154 | $output .= '<div class="pp-user-comment-item">'; |
| 155 | $output .= '<div class="pp-user-comment-item-link">'; |
| 156 | $output .= sprintf( |
| 157 | '<a href="%s">%s</a>', |
| 158 | esc_url(get_comment_link($comment->comment_ID)), |
| 159 | get_comment_excerpt($comment->comment_ID) |
| 160 | ); |
| 161 | $output .= '</div>'; |
| 162 | $output .= '<div class="pp-user-comment-item-meta">'; |
| 163 | $output .= sprintf('On <a href="%s">%s</a>', get_permalink($comment->comment_post_ID), get_the_title($comment->comment_post_ID)); |
| 164 | $output .= '</div>'; |
| 165 | $output .= '</div>'; |
| 166 | } |
| 167 | |
| 168 | $output .= "</div>"; |
| 169 | |
| 170 | set_transient($cache_key, $output, HOUR_IN_SECONDS); |
| 171 | |
| 172 | } else { |
| 173 | |
| 174 | $note = esc_html__('This user has not made any comment.', 'wp-user-avatar'); |
| 175 | |
| 176 | if (self::$user_data->ID == get_current_user_id()) { |
| 177 | $note = esc_html__('You have not made any comment.', 'wp-user-avatar'); |
| 178 | } |
| 179 | |
| 180 | $output .= sprintf('<div class="pp-user-comment-no-item"><span>%s</span></div>', $note); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return $output; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Profile username |
| 189 | * |
| 190 | * @return mixed |
| 191 | */ |
| 192 | public function profile_username() |
| 193 | { |
| 194 | $capitalization = apply_filters('ppress_capitalize_username', true); |
| 195 | |
| 196 | $username = self::$user_data->user_login; |
| 197 | |
| 198 | $username = $capitalization ? ucwords($username) : $username; |
| 199 | |
| 200 | return apply_filters('ppress_profile_username', $username, self::$user_data); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * User email |
| 206 | * |
| 207 | * @return mixed |
| 208 | */ |
| 209 | public function profile_email() |
| 210 | { |
| 211 | return apply_filters('ppress_profile_email', self::$user_data->user_email, self::$user_data); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Return user avatar image url |
| 216 | * |
| 217 | * @param array $atts shortcode attributes |
| 218 | * |
| 219 | * @return string image url |
| 220 | */ |
| 221 | public function user_avatar_url($atts) |
| 222 | { |
| 223 | $atts = shortcode_atts( |
| 224 | array( |
| 225 | 'size' => '400', |
| 226 | 'url' => '', |
| 227 | ), |
| 228 | $atts |
| 229 | ); |
| 230 | |
| 231 | $user_id = self::$user_data->ID; |
| 232 | |
| 233 | return apply_filters('ppress_profile_avatar_url', get_avatar_url($user_id, ['size' => $atts['size']]), self::$user_data); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Return user cover image url |
| 238 | * |
| 239 | * @return string image url |
| 240 | */ |
| 241 | public function cover_image_url() |
| 242 | { |
| 243 | $user_id = self::$user_data->ID; |
| 244 | |
| 245 | return apply_filters('ppress_profile_avatar_url', ppress_get_cover_image_url($user_id), self::$user_data); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * User website URL |
| 250 | * |
| 251 | * @return mixed |
| 252 | */ |
| 253 | public function profile_website() |
| 254 | { |
| 255 | return apply_filters('ppress_profile_website', self::$user_data->user_url, self::$user_data); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Nickname of user |
| 260 | * |
| 261 | * @return mixed |
| 262 | */ |
| 263 | public function profile_nickname() |
| 264 | { |
| 265 | return apply_filters('ppress_profile_nickname', ucwords(self::$user_data->nickname), self::$user_data); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Display name of profile |
| 270 | * |
| 271 | * @return mixed |
| 272 | */ |
| 273 | public function profile_display_name($atts = false) |
| 274 | { |
| 275 | $display_name = self::$user_data->display_name; |
| 276 | |
| 277 | if ( ! empty($atts['format']) && ! empty(self::$user_data->first_name) && ! empty(self::$user_data->last_name)) { |
| 278 | |
| 279 | switch ($atts['format']) { |
| 280 | case 'first_last_names': |
| 281 | $display_name = self::$user_data->first_name . ' ' . self::$user_data->last_name; |
| 282 | break; |
| 283 | case 'last_first_names': |
| 284 | $display_name = self::$user_data->last_name . ' ' . self::$user_data->first_name; |
| 285 | break; |
| 286 | case 'first_name_initial_l': |
| 287 | $display_name = self::$user_data->first_name . ' ' . self::$user_data->last_name[0]; |
| 288 | break; |
| 289 | case 'f_initial_last_name': |
| 290 | $display_name = self::$user_data->first_name[0] . ' ' . self::$user_data->last_name; |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return apply_filters('ppress_profile_display_name', ucwords($display_name), self::$user_data); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Profile first name |
| 300 | * |
| 301 | * @return mixed |
| 302 | */ |
| 303 | public function profile_first_name() |
| 304 | { |
| 305 | return apply_filters('ppress_profile_first_name', ucwords(self::$user_data->first_name), self::$user_data); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | /** |
| 310 | * Last name of user. |
| 311 | * |
| 312 | * @return mixed |
| 313 | */ |
| 314 | public function profile_last_name() |
| 315 | { |
| 316 | return apply_filters('ppress_profile_last_name', ucwords(self::$user_data->last_name), self::$user_data); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Description/bio of user. |
| 321 | * |
| 322 | * @return mixed |
| 323 | */ |
| 324 | public function profile_bio() |
| 325 | { |
| 326 | return apply_filters('ppress_profile_bio', make_clickable(wpautop(wp_kses_post(html_entity_decode(self::$user_data->description)))), self::$user_data); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Custom profile data of user. |
| 331 | * |
| 332 | * @param $atts array shortcode attributes |
| 333 | * |
| 334 | * @return string |
| 335 | */ |
| 336 | public function profile_custom_profile_field($atts) |
| 337 | { |
| 338 | if ( ! EM::is_enabled(EM::CUSTOM_FIELDS)) return ''; |
| 339 | |
| 340 | $atts = shortcode_atts( |
| 341 | array( |
| 342 | 'key' => '', |
| 343 | ), |
| 344 | $atts |
| 345 | ); |
| 346 | |
| 347 | $key = $atts['key']; |
| 348 | |
| 349 | if (empty($key)) return esc_html__('Field key is missing', 'wp-user-avatar'); |
| 350 | |
| 351 | $data = self::$user_data->{$key}; |
| 352 | |
| 353 | if (is_array($data)) { |
| 354 | $data = implode(', ', |
| 355 | array_filter($data, function ($val) { |
| 356 | return ! empty($val); |
| 357 | }) |
| 358 | ); |
| 359 | } |
| 360 | |
| 361 | return apply_filters('ppress_profile_cpf', $data, self::$user_data); |
| 362 | } |
| 363 | |
| 364 | public function profile_user_uploaded_file($atts) |
| 365 | { |
| 366 | $atts = ppress_normalize_attributes($atts); |
| 367 | |
| 368 | $atts = shortcode_atts( |
| 369 | array( |
| 370 | 'key' => '', |
| 371 | 'raw' => false, |
| 372 | ), |
| 373 | $atts |
| 374 | ); |
| 375 | |
| 376 | $key = $atts['key']; |
| 377 | |
| 378 | $user_upload_data = get_user_meta(self::$user_data->ID, 'pp_uploaded_files', true); |
| 379 | |
| 380 | if (empty($user_upload_data)) return ''; |
| 381 | |
| 382 | $filename = $user_upload_data[$key]; |
| 383 | |
| 384 | if (empty($filename)) return ''; |
| 385 | |
| 386 | $link = PPRESS_FILE_UPLOAD_URL . $filename; |
| 387 | |
| 388 | if ( ! empty($atts['raw']) && ($atts['raw'] === true || $atts['raw'] == 'true')) { |
| 389 | $return = $link; |
| 390 | } else { |
| 391 | $return = "<a href='$link'>$filename</a>"; |
| 392 | } |
| 393 | |
| 394 | return apply_filters('ppress_profile_file', $return, self::$user_data); |
| 395 | |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Return number of post written by a user |
| 400 | * |
| 401 | * @return int |
| 402 | */ |
| 403 | public function post_count() |
| 404 | { |
| 405 | return apply_filters('ppress_profile_post_count', count_user_posts(self::$user_data->ID), self::$user_data, true); |
| 406 | } |
| 407 | |
| 408 | public function hide_empty_data($atts, $content) |
| 409 | { |
| 410 | $atts = shortcode_atts( |
| 411 | array( |
| 412 | 'field' => '', |
| 413 | ), |
| 414 | $atts |
| 415 | ); |
| 416 | |
| 417 | $key = ! empty($atts['field']) ? strip_tags($atts['field']) : ''; |
| 418 | |
| 419 | switch ($key) { |
| 420 | case 'username': |
| 421 | $key = 'user_login'; |
| 422 | break; |
| 423 | case 'email': |
| 424 | $key = 'user_email'; |
| 425 | break; |
| 426 | case 'website': |
| 427 | $key = 'user_url'; |
| 428 | break; |
| 429 | case 'nickname': |
| 430 | $key = 'nickname'; |
| 431 | break; |
| 432 | case 'display_name': |
| 433 | $key = 'display_name'; |
| 434 | break; |
| 435 | case 'first_name': |
| 436 | $key = 'first_name'; |
| 437 | break; |
| 438 | case 'last_name': |
| 439 | $key = 'last_name'; |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | if ( ! empty($key) && ! empty(self::$user_data->$key)) { |
| 444 | return do_shortcode($content); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Return the total comment count made by a user |
| 450 | */ |
| 451 | public function get_comment_count() |
| 452 | { |
| 453 | global $wpdb; |
| 454 | $userId = self::$user_data->ID; |
| 455 | |
| 456 | $count = $wpdb->get_var(' |
| 457 | SELECT COUNT(comment_ID) |
| 458 | FROM ' . $wpdb->comments . ' |
| 459 | WHERE user_id = "' . $userId . '" AND comment_type = "" AND comment_approved = 1'); |
| 460 | |
| 461 | return apply_filters('ppress_profile_comment_count', $count, self::$user_data); |
| 462 | } |
| 463 | |
| 464 | protected function jcarousel_css() |
| 465 | { |
| 466 | ob_start(); |
| 467 | ?> |
| 468 | <style type="text/css"> |
| 469 | /* jcarousel responsive */ |
| 470 | a.jcarousel-control-next, a.jcarousel-control-prev { |
| 471 | text-decoration: none !important; |
| 472 | } |
| 473 | |
| 474 | .pp-jcarousel-wrapper ul li a { |
| 475 | color: #5B5B5B; |
| 476 | text-decoration: none |
| 477 | } |
| 478 | |
| 479 | .pp-jcarousel-wrapper { |
| 480 | color: #5B5B5B; |
| 481 | background-color: #F5F5F5; |
| 482 | margin: 20px auto; |
| 483 | position: relative; |
| 484 | border: 10px solid #fff; |
| 485 | -webkit-border-radius: 5px; |
| 486 | -moz-border-radius: 5px; |
| 487 | border-radius: 5px; |
| 488 | -webkit-box-shadow: 0 0 2px #999; |
| 489 | -moz-box-shadow: 0 0 2px #999; |
| 490 | box-shadow: 0 0 2px #999; |
| 491 | } |
| 492 | |
| 493 | /** Carousel **/ |
| 494 | .ppjcarousel { |
| 495 | position: relative; |
| 496 | overflow: hidden; |
| 497 | width: 100%; |
| 498 | } |
| 499 | |
| 500 | .ppjcarousel ul { |
| 501 | width: 20000em; |
| 502 | position: relative; |
| 503 | list-style: none; |
| 504 | margin: 0; |
| 505 | padding: 0; |
| 506 | } |
| 507 | |
| 508 | .ppjcarousel li { |
| 509 | width: 200px; |
| 510 | float: left; |
| 511 | margin: 1px 3px 1px 0; |
| 512 | -moz-box-sizing: border-box; |
| 513 | -webkit-box-sizing: border-box; |
| 514 | box-sizing: border-box; |
| 515 | } |
| 516 | |
| 517 | .ppjcarousel img { |
| 518 | display: block; |
| 519 | width: 100%; |
| 520 | height: 100px !important; |
| 521 | } |
| 522 | |
| 523 | .jc-no-post { |
| 524 | font-family: inherit; |
| 525 | font-size: 15px; |
| 526 | padding: 5px; |
| 527 | text-align: center; |
| 528 | } |
| 529 | |
| 530 | .jc-title { |
| 531 | font-family: inherit; |
| 532 | font-size: 15px; |
| 533 | word-wrap: break-word; |
| 534 | padding: 5px; |
| 535 | margin: 0 4px; |
| 536 | text-align: center; |
| 537 | } |
| 538 | |
| 539 | /** Carousel Controls **/ |
| 540 | .jcarousel-control-prev, .jcarousel-control-next { |
| 541 | position: absolute; |
| 542 | top: 50%; |
| 543 | margin-top: -15px; |
| 544 | width: 30px; |
| 545 | height: 30px; |
| 546 | text-align: center; |
| 547 | background: #4E443C; |
| 548 | color: #fff; |
| 549 | text-decoration: none; |
| 550 | text-shadow: 0 0 1px #000; |
| 551 | font: 24px/27px Arial, sans-serif; |
| 552 | -webkit-border-radius: 30px; |
| 553 | -moz-border-radius: 30px; |
| 554 | border-radius: 30px; |
| 555 | -webkit-box-shadow: 0 0 4px #F0EFE7; |
| 556 | -moz-box-shadow: 0 0 4px #F0EFE7; |
| 557 | box-shadow: 0 0 4px #F0EFE7; |
| 558 | } |
| 559 | |
| 560 | .jcarousel-control-prev { |
| 561 | left: 15px; |
| 562 | } |
| 563 | |
| 564 | .jcarousel-control-next { |
| 565 | right: 15px; |
| 566 | } |
| 567 | |
| 568 | /** Carousel Pagination **/ |
| 569 | .jcarousel-pagination { |
| 570 | position: absolute; |
| 571 | bottom: -40px; |
| 572 | left: 50%; |
| 573 | -webkit-transform: translate(-50%, 0); |
| 574 | -ms-transform: translate(-50%, 0); |
| 575 | -moz-transform: translate(-50%, 0); |
| 576 | transform: translate(-50%, 0); |
| 577 | margin: 0; |
| 578 | } |
| 579 | |
| 580 | .jcarousel-pagination a { |
| 581 | text-decoration: none; |
| 582 | display: inline-block; |
| 583 | font-size: 11px; |
| 584 | height: 10px; |
| 585 | width: 10px; |
| 586 | line-height: 10px; |
| 587 | background: #fff; |
| 588 | color: #4E443C; |
| 589 | border-radius: 10px; |
| 590 | text-indent: -9999px; |
| 591 | margin-right: 7px; |
| 592 | -webkit-box-shadow: 0 0 2px #4E443C; |
| 593 | -moz-box-shadow: 0 0 2px #4E443C; |
| 594 | box-shadow: 0 0 2px #4E443C; |
| 595 | } |
| 596 | |
| 597 | .jcarousel-pagination a.active { |
| 598 | background: #4E443C; |
| 599 | color: #fff; |
| 600 | opacity: 1; |
| 601 | -webkit-box-shadow: 0 0 2px #F0EFE7; |
| 602 | -moz-box-shadow: 0 0 2px #F0EFE7; |
| 603 | box-shadow: 0 0 2px #F0EFE7; |
| 604 | } |
| 605 | </style> |
| 606 | <?php |
| 607 | return ppress_minify_css(ob_get_clean()); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * jCarousel author latest post slider |
| 612 | * |
| 613 | * @param $atts |
| 614 | * |
| 615 | * @return string |
| 616 | */ |
| 617 | public function pp_jcarousel_author_posts($atts) |
| 618 | { |
| 619 | wp_enqueue_script('pp-jcarousel', PPRESS_ASSETS_URL . '/js/jcarousel.min.js', array('jquery'), PPRESS_VERSION_NUMBER, true); |
| 620 | |
| 621 | $atts = shortcode_atts( |
| 622 | array( |
| 623 | 'count' => 10, |
| 624 | 'default' => PPRESS_ASSETS_URL . '/images/frontend/jc_dft_img.jpg', |
| 625 | 'width' => '', |
| 626 | ), |
| 627 | $atts |
| 628 | ); |
| 629 | |
| 630 | $posts = get_posts( |
| 631 | array( |
| 632 | 'post_type' => 'post', |
| 633 | 'posts_per_page' => (int)$atts['count'], |
| 634 | 'author' => self::$user_data->ID, |
| 635 | ) |
| 636 | ); |
| 637 | |
| 638 | $default_img = $atts['default']; |
| 639 | $width = ! empty($atts['width']) ? ' style="width: ' . $atts['width'] . ';"' : null; |
| 640 | |
| 641 | ob_start(); |
| 642 | echo $this->jcarousel_css(); |
| 643 | ?> |
| 644 | <div class="pp-jcarousel-wrapper"<?php echo $width; ?>> |
| 645 | <div class="ppjcarousel"> |
| 646 | <?php |
| 647 | if (empty($posts)) { |
| 648 | echo '<div class="jc-no-post">' . apply_filters('jcarousel_no_post', esc_html__('No post written yet.', 'wp-user-avatar')) . '</div>'; |
| 649 | } else { |
| 650 | |
| 651 | echo '<ul>'; |
| 652 | foreach ($posts as $post) { |
| 653 | $feature_img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium', false); |
| 654 | |
| 655 | $feature_img = isset($feature_img[0]) ? $feature_img[0] : false; |
| 656 | |
| 657 | if ( ! $feature_img) { |
| 658 | $feature_img = $default_img; |
| 659 | } |
| 660 | ?> |
| 661 | <li> |
| 662 | <a href="<?php echo get_permalink($post->ID); ?>"> |
| 663 | <img src="<?php echo $feature_img; ?>" alt="<?php echo $post->post_title; ?>"> |
| 664 | |
| 665 | <div class="jc-title"><?php echo $post->post_title; ?></div> |
| 666 | </a> |
| 667 | </li> |
| 668 | <?php |
| 669 | } |
| 670 | echo '</ul>'; |
| 671 | } |
| 672 | ?> |
| 673 | </div> |
| 674 | |
| 675 | <?php |
| 676 | // hide jcarousel nav link if no post is found |
| 677 | if ( ! empty($posts)) { ?> |
| 678 | <a href="#" class="jcarousel-control-prev">‹</a> |
| 679 | <a href="#" class="jcarousel-control-next">›</a> |
| 680 | <p class="jcarousel-pagination"></p> |
| 681 | <?php } ?> |
| 682 | </div> |
| 683 | <?php |
| 684 | return apply_filters('ppress_jcarousel_author_posts', ob_get_clean(), self::$user_data); |
| 685 | } |
| 686 | |
| 687 | public static function get_instance($user = '') |
| 688 | { |
| 689 | static $instance = false; |
| 690 | $user = isset($user) && ! empty($user) ? $user : wp_get_current_user(); |
| 691 | if ( ! $instance) { |
| 692 | $instance = new self($user); |
| 693 | } |
| 694 | |
| 695 | return $instance; |
| 696 | } |
| 697 | } |