|
@@ -68,28 +68,26 @@ class Studiou_WC_Product_Cat_Manage_DB {
|
|
|
$display_type = 'default';
|
|
$display_type = 'default';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Get protected category data if available
|
|
|
|
|
|
|
+ // Get protected category data using direct DB access
|
|
|
$visibility = 'public';
|
|
$visibility = 'public';
|
|
|
$protected_passwords = '';
|
|
$protected_passwords = '';
|
|
|
|
|
|
|
|
- if (class_exists('WC_Protected_Categories')) {
|
|
|
|
|
- // Get visibility
|
|
|
|
|
- $visibility = get_term_meta($category->term_id, 'visibility', true);
|
|
|
|
|
- if (empty($visibility)) {
|
|
|
|
|
- $visibility = 'public';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Get password protection
|
|
|
|
|
- if ($visibility === 'protected') {
|
|
|
|
|
- // Use the Util::get_term_passwords method pattern which the plugin uses
|
|
|
|
|
- $passwords = get_term_meta($category->term_id, 'password', false);
|
|
|
|
|
-
|
|
|
|
|
- // Back-compat - for passwords stored as separate meta items
|
|
|
|
|
- if ($passwords && !empty($passwords[0]) && is_array($passwords[0])) {
|
|
|
|
|
|
|
+ // Get visibility directly from term meta
|
|
|
|
|
+ $visibility_meta = get_term_meta($category->term_id, 'visibility', true);
|
|
|
|
|
+ if (!empty($visibility_meta)) {
|
|
|
|
|
+ $visibility = $visibility_meta;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // If protected, get passwords directly from term meta
|
|
|
|
|
+ if ($visibility === 'protected') {
|
|
|
|
|
+ $passwords = get_term_meta($category->term_id, 'password', false);
|
|
|
|
|
+ if (!empty($passwords)) {
|
|
|
|
|
+ // Handle different password storage formats
|
|
|
|
|
+ if (is_array($passwords[0])) {
|
|
|
$passwords = $passwords[0];
|
|
$passwords = $passwords[0];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!empty($passwords) && is_array($passwords)) {
|
|
|
|
|
|
|
+ if (!empty($passwords)) {
|
|
|
$protected_passwords = implode('|', $passwords);
|
|
$protected_passwords = implode('|', $passwords);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -186,28 +184,8 @@ class Studiou_WC_Product_Cat_Manage_DB {
|
|
|
// Set display type
|
|
// Set display type
|
|
|
update_term_meta($term_id, 'display_type', $category_data['display-type']);
|
|
update_term_meta($term_id, 'display_type', $category_data['display-type']);
|
|
|
|
|
|
|
|
- // Set visibility and password protection if WC Protected Categories is active
|
|
|
|
|
- if (class_exists('WC_Protected_Categories')) {
|
|
|
|
|
- // Set visibility
|
|
|
|
|
- update_term_meta($term_id, 'visibility', $category_data['visibility']);
|
|
|
|
|
-
|
|
|
|
|
- // Set password protection if visibility is protected and passwords are provided
|
|
|
|
|
- if ($category_data['visibility'] === 'protected' && !empty($category_data['protected-passwords'])) {
|
|
|
|
|
- $passwords = explode('|', $category_data['protected-passwords']);
|
|
|
|
|
- // Filter out empty passwords
|
|
|
|
|
- $passwords = array_filter($passwords);
|
|
|
|
|
-
|
|
|
|
|
- if (empty($passwords)) {
|
|
|
|
|
- // If no valid passwords after filtering, set a default one as the plugin does
|
|
|
|
|
- $passwords = ['password123'];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Store each password as a separate meta entry
|
|
|
|
|
- foreach ($passwords as $password) {
|
|
|
|
|
- add_term_meta($term_id, 'password', $password);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Set visibility and password protection using direct DB access
|
|
|
|
|
+ $this->set_category_protection($term_id, $category_data);
|
|
|
|
|
|
|
|
return array(
|
|
return array(
|
|
|
'status' => 'created',
|
|
'status' => 'created',
|
|
@@ -273,33 +251,8 @@ class Studiou_WC_Product_Cat_Manage_DB {
|
|
|
// Set display type
|
|
// Set display type
|
|
|
update_term_meta($existing->term_id, 'display_type', $category_data['display-type']);
|
|
update_term_meta($existing->term_id, 'display_type', $category_data['display-type']);
|
|
|
|
|
|
|
|
- // Set visibility and password protection if WC Protected Categories is active
|
|
|
|
|
- if (class_exists('WC_Protected_Categories')) {
|
|
|
|
|
- // First remove existing protection meta
|
|
|
|
|
- delete_term_meta($existing->term_id, 'password');
|
|
|
|
|
- delete_term_meta($existing->term_id, 'user_roles');
|
|
|
|
|
- delete_term_meta($existing->term_id, 'users');
|
|
|
|
|
-
|
|
|
|
|
- // Set visibility
|
|
|
|
|
- update_term_meta($existing->term_id, 'visibility', $category_data['visibility']);
|
|
|
|
|
-
|
|
|
|
|
- // Set password protection if visibility is protected and passwords are provided
|
|
|
|
|
- if ($category_data['visibility'] === 'protected' && !empty($category_data['protected-passwords'])) {
|
|
|
|
|
- $passwords = explode('|', $category_data['protected-passwords']);
|
|
|
|
|
- // Filter out empty passwords
|
|
|
|
|
- $passwords = array_filter($passwords);
|
|
|
|
|
-
|
|
|
|
|
- if (empty($passwords)) {
|
|
|
|
|
- // If no valid passwords after filtering, set a default one as the plugin does
|
|
|
|
|
- $passwords = ['password123'];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Note: The plugin stores each password as a separate meta entry with the same key
|
|
|
|
|
- foreach ($passwords as $password) {
|
|
|
|
|
- add_term_meta($existing->term_id, 'password', $password);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Set visibility and password protection using direct DB access
|
|
|
|
|
+ $this->set_category_protection($existing->term_id, $category_data);
|
|
|
|
|
|
|
|
return array(
|
|
return array(
|
|
|
'status' => 'updated',
|
|
'status' => 'updated',
|
|
@@ -347,4 +300,34 @@ class Studiou_WC_Product_Cat_Manage_DB {
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Set category protection settings
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $term_id Term ID
|
|
|
|
|
+ * @param array $category_data Category data
|
|
|
|
|
+ */
|
|
|
|
|
+ private function set_category_protection($term_id, $category_data) {
|
|
|
|
|
+ // First remove existing protection meta to avoid duplicates
|
|
|
|
|
+ delete_term_meta($term_id, 'password');
|
|
|
|
|
+ delete_term_meta($term_id, 'visibility');
|
|
|
|
|
+
|
|
|
|
|
+ // Set visibility
|
|
|
|
|
+ update_term_meta($term_id, 'visibility', $category_data['visibility']);
|
|
|
|
|
+
|
|
|
|
|
+ // Set password protection if visibility is protected and passwords are provided
|
|
|
|
|
+ if ($category_data['visibility'] === 'protected' && !empty($category_data['protected-passwords'])) {
|
|
|
|
|
+ $passwords = explode('|', $category_data['protected-passwords']);
|
|
|
|
|
+ // Filter out empty passwords
|
|
|
|
|
+ $passwords = array_filter($passwords);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($passwords)) {
|
|
|
|
|
+ // If no valid passwords after filtering, set a default one
|
|
|
|
|
+ $passwords = ['password123'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Store the passwords array as a single meta entry
|
|
|
|
|
+ add_term_meta($term_id, 'password', $passwords);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|