| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* UsersWP user cover widget. |
| 8 |
* |
| 9 |
* @since 1.1.2 |
| 10 |
*/ |
| 11 |
class UWP_User_Cover_Widget extends WP_Super_Duper { |
| 12 |
|
| 13 |
/** |
| 14 |
* Register the user cover widget with WordPress. |
| 15 |
* |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
|
| 19 |
|
| 20 |
$options = array( |
| 21 |
'textdomain' => 'userswp', |
| 22 |
'block-icon' => 'admin-site', |
| 23 |
'block-category'=> 'widgets', |
| 24 |
'block-keywords'=> "['userswp','profile']", |
| 25 |
'class_name' => __CLASS__, |
| 26 |
'base_id' => 'uwp_user_cover', |
| 27 |
'name' => __('UWP > User Cover Image','userswp'), |
| 28 |
//'no_wrap' => true, |
| 29 |
'block-wrap' => '', |
| 30 |
'widget_ops' => array( |
| 31 |
'classname' => 'uwp-user-cover bsui', |
| 32 |
'description' => esc_html__('Displays user cover image for user.','userswp'), |
| 33 |
), |
| 34 |
'arguments' => array( |
| 35 |
'link' => array( |
| 36 |
'title' => __("Link to profile?:", 'userswp'), |
| 37 |
'desc' => __('Link cover image to user\'s profile page.', 'userswp'), |
| 38 |
'type' => 'checkbox', |
| 39 |
'desc_tip' => true, |
| 40 |
'value' => '1', |
| 41 |
'default' => '0', |
| 42 |
'advanced' => true |
| 43 |
), |
| 44 |
'allow_change' => array( |
| 45 |
'title' => __('Allow to change cover:', 'userswp'), |
| 46 |
'desc' => __('Allow user to change cover image in profile page.', 'userswp'), |
| 47 |
'type' => 'checkbox', |
| 48 |
'desc_tip' => true, |
| 49 |
'value' => '1', |
| 50 |
'default' => 0, |
| 51 |
'advanced' => true |
| 52 |
), |
| 53 |
'user_id' => array( |
| 54 |
'title' => __('User ID:', 'userswp'), |
| 55 |
'desc' => __('Leave blank to use current user ID or use post_author for current post author ID. For profile page it will take displayed user ID. Input specific user ID for other pages.', 'userswp'), |
| 56 |
'type' => 'text', |
| 57 |
'desc_tip' => true, |
| 58 |
'default' => '', |
| 59 |
'advanced' => true |
| 60 |
), |
| 61 |
) |
| 62 |
|
| 63 |
); |
| 64 |
|
| 65 |
parent::__construct( $options ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* The Super block output function. |
| 70 |
* |
| 71 |
* @param array $args |
| 72 |
* @param array $widget_args |
| 73 |
* @param string $content |
| 74 |
* |
| 75 |
* @return mixed|string|bool |
| 76 |
*/ |
| 77 |
public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 78 |
|
| 79 |
global $post; |
| 80 |
|
| 81 |
$defaults = array( |
| 82 |
'link' => 0, |
| 83 |
'allow_change' => 0, |
| 84 |
); |
| 85 |
|
| 86 |
$args = wp_parse_args( $args, $defaults ); |
| 87 |
|
| 88 |
$args['link'] = 1 == $args['link'] ? 1 : 0; |
| 89 |
$args['allow_change'] = !empty($args['allow_change']) ? $args['allow_change'] : 0; |
| 90 |
|
| 91 |
if('post_author' == $args['user_id'] && $post instanceof WP_Post){ |
| 92 |
$user = get_userdata($post->post_author); |
| 93 |
$args['user_id'] = $post->post_author; |
| 94 |
} else if(isset($args['user_id']) && (int)$args['user_id'] > 0){ |
| 95 |
$user = get_userdata($args['user_id']); |
| 96 |
} else { |
| 97 |
$user = uwp_get_displayed_user(); |
| 98 |
} |
| 99 |
|
| 100 |
if(empty($args['user_id']) && !empty($user->ID)){ |
| 101 |
$args['user_id'] = $user->ID; |
| 102 |
} |
| 103 |
|
| 104 |
if(!$user){ |
| 105 |
return ''; |
| 106 |
} |
| 107 |
|
| 108 |
wp_enqueue_script( 'jcrop', array( 'jquery' ) ); |
| 109 |
wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); |
| 110 |
wp_enqueue_style( 'jcrop' ); |
| 111 |
wp_enqueue_style( 'jquery-ui' ); |
| 112 |
|
| 113 |
ob_start(); |
| 114 |
|
| 115 |
add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 ); |
| 116 |
$uploads = wp_upload_dir(); |
| 117 |
remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' ); |
| 118 |
$upload_url = $uploads['baseurl']; |
| 119 |
|
| 120 |
$banner = uwp_get_usermeta($user->ID, 'banner_thumb', ''); |
| 121 |
if (empty($banner)) { |
| 122 |
$banner = uwp_get_default_banner_uri(); |
| 123 |
} else { |
| 124 |
$banner = $upload_url.$banner; |
| 125 |
} |
| 126 |
|
| 127 |
$args['banner_url'] = $banner; |
| 128 |
|
| 129 |
$design_style = !empty($args['design_style']) ? esc_attr($args['design_style']) : uwp_get_option("design_style",'bootstrap'); |
| 130 |
$template = $design_style ? $design_style."/user-cover.php" : "user-cover.php"; |
| 131 |
|
| 132 |
uwp_get_template($template, $args); |
| 133 |
|
| 134 |
return ob_get_clean(); |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
} |