fix: Address issues with all 4 features
1. Admin Store Link - Add to WP admin bar (Menu.php) with proper option check 2. Activity Log - Fix Loading text to show correct state after data loads 3. Avatar Upload - Use correct option key woonoow_allow_custom_avatar 4. Downloadable Files - Connect to WooCommerce native: - Add downloads array to format_product_full - Add downloads/download_limit/download_expiry handling in update_product - Add downloads handling in create_product
This commit is contained in:
@@ -111,6 +111,21 @@ class Menu {
|
||||
'title' => __( 'WooNooW Standalone Admin', 'woonoow' ),
|
||||
],
|
||||
] );
|
||||
|
||||
// Add Store link if customer SPA is not disabled
|
||||
$customer_spa_enabled = get_option( 'woonoow_customer_spa_enabled', true );
|
||||
if ( $customer_spa_enabled ) {
|
||||
$store_url = home_url( '/store/' );
|
||||
$wp_admin_bar->add_node( [
|
||||
'id' => 'woonoow-store',
|
||||
'title' => '<span class="ab-icon dashicons-cart"></span><span class="ab-label">' . __( 'Store', 'woonoow' ) . '</span>',
|
||||
'href' => $store_url,
|
||||
'meta' => [
|
||||
'title' => __( 'View Customer Store', 'woonoow' ),
|
||||
'target' => '_blank',
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -475,6 +475,29 @@ class ProductsController {
|
||||
$product->set_featured((bool) $data['featured']);
|
||||
}
|
||||
|
||||
// Downloadable files
|
||||
if (isset($data['downloads']) && is_array($data['downloads'])) {
|
||||
$wc_downloads = [];
|
||||
foreach ($data['downloads'] as $download) {
|
||||
if (!empty($download['file'])) {
|
||||
$wc_downloads[] = [
|
||||
'id' => $download['id'] ?? md5($download['file']),
|
||||
'name' => self::sanitize_text($download['name'] ?? ''),
|
||||
'file' => esc_url_raw($download['file']),
|
||||
];
|
||||
}
|
||||
}
|
||||
$product->set_downloads($wc_downloads);
|
||||
}
|
||||
if (isset($data['download_limit'])) {
|
||||
$limit = $data['download_limit'] === '' ? -1 : (int) $data['download_limit'];
|
||||
$product->set_download_limit($limit);
|
||||
}
|
||||
if (isset($data['download_expiry'])) {
|
||||
$expiry = $data['download_expiry'] === '' ? -1 : (int) $data['download_expiry'];
|
||||
$product->set_download_expiry($expiry);
|
||||
}
|
||||
|
||||
// Categories
|
||||
if (isset($data['categories'])) {
|
||||
$product->set_category_ids($data['categories']);
|
||||
@@ -700,6 +723,21 @@ class ProductsController {
|
||||
$data['downloadable'] = $product->is_downloadable();
|
||||
$data['featured'] = $product->is_featured();
|
||||
|
||||
// Downloadable files
|
||||
if ($product->is_downloadable()) {
|
||||
$downloads = [];
|
||||
foreach ($product->get_downloads() as $download_id => $download) {
|
||||
$downloads[] = [
|
||||
'id' => $download_id,
|
||||
'name' => $download->get_name(),
|
||||
'file' => $download->get_file(),
|
||||
];
|
||||
}
|
||||
$data['downloads'] = $downloads;
|
||||
$data['download_limit'] = $product->get_download_limit() !== -1 ? (string) $product->get_download_limit() : '';
|
||||
$data['download_expiry'] = $product->get_download_expiry() !== -1 ? (string) $product->get_download_expiry() : '';
|
||||
}
|
||||
|
||||
// Images array (URLs) for frontend - featured + gallery
|
||||
$images = [];
|
||||
$featured_image_id = $product->get_image_id();
|
||||
|
||||
@@ -234,9 +234,8 @@ class AccountController {
|
||||
* Upload customer avatar
|
||||
*/
|
||||
public static function upload_avatar(WP_REST_Request $request) {
|
||||
// Check if custom avatars are enabled
|
||||
$settings = get_option('woonoow_customer_settings', []);
|
||||
$allow_custom_avatar = $settings['allow_custom_avatar'] ?? false;
|
||||
// Check if custom avatars are enabled (stored as 'yes' or 'no')
|
||||
$allow_custom_avatar = get_option('woonoow_allow_custom_avatar', 'no') === 'yes';
|
||||
|
||||
if (!$allow_custom_avatar) {
|
||||
return new WP_Error('avatar_disabled', 'Custom avatars are not enabled', ['status' => 403]);
|
||||
@@ -358,10 +357,11 @@ class AccountController {
|
||||
*/
|
||||
public static function get_avatar_settings(WP_REST_Request $request) {
|
||||
$user_id = get_current_user_id();
|
||||
$settings = get_option('woonoow_customer_settings', []);
|
||||
// Use correct option key (stored as 'yes' or 'no')
|
||||
$allow_custom_avatar = get_option('woonoow_allow_custom_avatar', 'no') === 'yes';
|
||||
|
||||
return new WP_REST_Response([
|
||||
'allow_custom_avatar' => $settings['allow_custom_avatar'] ?? false,
|
||||
'allow_custom_avatar' => $allow_custom_avatar,
|
||||
'current_avatar' => get_user_meta($user_id, 'woonoow_custom_avatar', true) ?: null,
|
||||
'gravatar_url' => get_avatar_url($user_id),
|
||||
], 200);
|
||||
|
||||
Reference in New Issue
Block a user