| 1 |
<?php |
| 2 |
if ( ! class_exists( 'LP_Admin_Dashboard' ) ) { |
| 3 |
/** |
| 4 |
* Class LP_Admin_Dashboard |
| 5 |
* |
| 6 |
* Displays widgets in admin. |
| 7 |
*/ |
| 8 |
class LP_Admin_Dashboard { |
| 9 |
|
| 10 |
/** |
| 11 |
* LP_Admin_Dashboard constructor. |
| 12 |
*/ |
| 13 |
public function __construct() { |
| 14 |
add_action( 'wp_dashboard_setup', array( $this, 'register' ) ); |
| 15 |
} |
| 16 |
|
| 17 |
public function register() { |
| 18 |
if ( current_user_can( 'manage_options' ) || current_user_can( 'publish_lp_orders' ) ) { |
| 19 |
wp_add_dashboard_widget( |
| 20 |
'learn_press_dashboard_order_statuses', |
| 21 |
esc_html__( 'LearnPress order status', 'learnpress' ), |
| 22 |
array( |
| 23 |
$this, |
| 24 |
'order_statuses', |
| 25 |
) |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
wp_add_dashboard_widget( |
| 30 |
'learn_press_dashboard_plugin_status', |
| 31 |
esc_html__( 'LearnPress status', 'learnpress' ), |
| 32 |
array( |
| 33 |
$this, |
| 34 |
'plugin_status', |
| 35 |
) |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Order status widget |
| 41 |
*/ |
| 42 |
public function order_statuses() { |
| 43 |
?> |
| 44 |
<ul class="lp-order-statuses lp_append_data"> |
| 45 |
<?php lp_skeleton_animation_html( 4, 100, 'height: 30px;border-radius:4px;' ); ?> |
| 46 |
</ul> |
| 47 |
<ul class="lp-order-statuses"> |
| 48 |
<?php |
| 49 |
$eduma_data = $this->_get_theme_info( 14058034 ); |
| 50 |
|
| 51 |
if ( function_exists( 'learn_press_get_item_referral' ) ) { |
| 52 |
$eduma_data['url'] = learn_press_get_item_referral( 14058034 ); |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! empty( $eduma_data ) ) { |
| 56 |
?> |
| 57 |
|
| 58 |
<li class="clear"></li> |
| 59 |
<li class="featured-theme"> |
| 60 |
<?php if ( isset( $eduma_data['name'] ) && isset( $eduma_data['price_cents'] ) ) : ?> |
| 61 |
<p> |
| 62 |
<a href="<?php echo esc_url_raw( $eduma_data['url'] ); ?>"> |
| 63 |
<?php echo esc_html( $eduma_data['name'] ); ?> |
| 64 |
</a> - <?php printf( '%s%s', '$', $eduma_data['price_cents'] / 100 ); ?> |
| 65 |
</p> |
| 66 |
<?php endif; ?> |
| 67 |
|
| 68 |
<?php if ( isset( $eduma_data['rating']['count'] ) && isset( $eduma_data['rating']['rating'] ) ) : ?> |
| 69 |
<div> |
| 70 |
<?php |
| 71 |
wp_star_rating( |
| 72 |
array( |
| 73 |
'rating' => $eduma_data['rating']['rating'], |
| 74 |
'type' => 'rating', |
| 75 |
'number' => $eduma_data['rating']['count'], |
| 76 |
) |
| 77 |
); |
| 78 |
?> |
| 79 |
|
| 80 |
<span class="count-rating">(<?php echo esc_html( $eduma_data['rating']['count'] ); ?>)</span> |
| 81 |
<span> |
| 82 |
- <?php echo sprintf( '%d %s', esc_html( $eduma_data['number_of_sales'] ), esc_html__( ' sales', 'learnpress' ) ); ?> |
| 83 |
</span> |
| 84 |
</div> |
| 85 |
<?php endif; ?> |
| 86 |
|
| 87 |
<?php if ( isset( $eduma_data['author_username'] ) ) : ?> |
| 88 |
<p> |
| 89 |
<?php esc_html_e( 'Created by: ', 'learnpress' ); ?> |
| 90 |
<a href="https://thimpress.com/" class="author"><?php echo esc_html( $eduma_data['author_username'] ); ?></a> |
| 91 |
</p> |
| 92 |
<?php endif; ?> |
| 93 |
</li> |
| 94 |
<?php } ?> |
| 95 |
</ul> |
| 96 |
<?php |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Get total value of LP orders has completed. |
| 101 |
* |
| 102 |
* @return int|string |
| 103 |
*/ |
| 104 |
private function _get_order_total_raised() { |
| 105 |
$orders = learn_press_get_orders( array( 'post_status' => 'lp-completed' ) ); |
| 106 |
$total = 0; |
| 107 |
|
| 108 |
if ( $orders ) { |
| 109 |
foreach ( $orders as $order ) { |
| 110 |
$order = learn_press_get_order( $order->ID ); |
| 111 |
$total = $total + floatval( $order->order_total ); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return learn_press_format_price( $total, true ); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* @param String $item_id - The ID of an Envato Marketplace item |
| 120 |
* |
| 121 |
* @returns mixed |
| 122 |
*/ |
| 123 |
private function _get_theme_info( $item_id ) { |
| 124 |
$alls = LP_Plugins_Helper::get_related_themes(); |
| 125 |
|
| 126 |
if ( ! $alls ) { |
| 127 |
return false; |
| 128 |
} |
| 129 |
|
| 130 |
foreach ( $alls as $k => $types ) { |
| 131 |
if ( isset( $types[ $item_id ] ) ) { |
| 132 |
return $types[ $item_id ]; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Get data from wordpress.org |
| 141 |
* |
| 142 |
* @since 2.0 |
| 143 |
*/ |
| 144 |
private function _get_data() { |
| 145 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 146 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 147 |
|
| 148 |
$api = get_transient( 'lp_plugin_status' ); |
| 149 |
|
| 150 |
if ( false === $api || is_wp_error( $api ) ) { |
| 151 |
$api = plugins_api( |
| 152 |
'plugin_information', |
| 153 |
array( |
| 154 |
'slug' => 'learnpress', |
| 155 |
'fields' => array( |
| 156 |
'active_installs' => true, |
| 157 |
'short_description' => true, |
| 158 |
'description' => true, |
| 159 |
'ratings' => true, |
| 160 |
'downloaded' => true, |
| 161 |
), |
| 162 |
) |
| 163 |
); |
| 164 |
|
| 165 |
if ( ! is_wp_error( $api ) ) { |
| 166 |
set_transient( 'lp_plugin_status', $api, 12 * HOUR_IN_SECONDS ); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return $api; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Plugin status widget |
| 175 |
*/ |
| 176 |
public function plugin_status() { |
| 177 |
$plugin_data = $this->_get_data(); |
| 178 |
|
| 179 |
if ( ! $plugin_data || is_wp_error( $plugin_data ) ) { |
| 180 |
learn_press_admin_view( 'dashboard/plugin-status/html-no-data' ); |
| 181 |
} else { |
| 182 |
learn_press_admin_view( 'dashboard/plugin-status/html-results', array( 'plugin_data' => $plugin_data ) ); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
new LP_Admin_Dashboard(); |
| 188 |
|