wp-optimize
/
vendor
/
team-updraft
/
common-libs
/
src
/
updraft-tasks
/
class-updraft-task-meta.php
class-updraft-task-meta.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.4.2, at vendor/team-updraft/common-libs/src/updraft-tasks/class-updraft-task-meta.php
| 1 | <?php |
| 2 | /** |
| 3 | * The DB handle class for the options framework |
| 4 | */ |
| 5 | |
| 6 | if (!defined('ABSPATH')) die('Access denied.'); |
| 7 | |
| 8 | if (!class_exists('Updraft_Task_Meta')) : |
| 9 | |
| 10 | class Updraft_Task_Meta { |
| 11 | |
| 12 | /** |
| 13 | * This method gets data from the task meta table in the WordPress database |
| 14 | * |
| 15 | * @param int $id the instance id of the task |
| 16 | * @param String $key the key to get |
| 17 | * |
| 18 | * @return Mixed The option from the database |
| 19 | */ |
| 20 | public static function get_task_meta($id, $key) { |
| 21 | global $wpdb; |
| 22 | |
| 23 | $id = (int) $id; |
| 24 | if (!$id) return false; |
| 25 | |
| 26 | $sql = $wpdb->prepare("SELECT meta_value FROM {$wpdb->base_prefix}tm_taskmeta WHERE task_id = %d AND meta_key = %s LIMIT 1", $id, $key); |
| 27 | |
| 28 | $meta = $wpdb->get_var($sql); |
| 29 | |
| 30 | if ($meta) |
| 31 | return maybe_unserialize($meta); |
| 32 | else return false; |
| 33 | } |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * This method is used to update data stored in the WordPress database |
| 38 | * |
| 39 | * @param int $id the instance id of the task |
| 40 | * @param String $key the key of the data to update |
| 41 | * @param Mixed $value the value to save to the option |
| 42 | * |
| 43 | * @return Mixed the status of the update operation |
| 44 | */ |
| 45 | public static function update_task_meta($id, $key, $value) { |
| 46 | global $wpdb; |
| 47 | |
| 48 | $id = (int) $id; |
| 49 | if (!$id) return false; |
| 50 | |
| 51 | $value = maybe_serialize($value); |
| 52 | |
| 53 | if (false !== self::get_task_meta($id, $key)) { |
| 54 | $sql = $wpdb->prepare("UPDATE {$wpdb->base_prefix}tm_taskmeta SET meta_value = %s WHERE meta_key = %s AND task_id = %d", $value, $key, $id); |
| 55 | } else { |
| 56 | $sql = $wpdb->prepare("INSERT INTO {$wpdb->base_prefix}tm_taskmeta (task_id, meta_key, meta_value) VALUES (%d, %s, %s)", $id, $key, $value); |
| 57 | } |
| 58 | |
| 59 | return $wpdb->query($sql); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * This method is used to delete task data stored in the WordPress database |
| 64 | * |
| 65 | * @param int $id the instance id of the task |
| 66 | * @param String $key the key to delete |
| 67 | * |
| 68 | * @return Mixed the status of the delete operation |
| 69 | */ |
| 70 | public static function delete_task_meta($id, $key) { |
| 71 | global $wpdb; |
| 72 | |
| 73 | $id = (int) $id; |
| 74 | if (!$id) return false; |
| 75 | |
| 76 | $sql = $wpdb->prepare("DELETE FROM {$wpdb->base_prefix}tm_taskmeta WHERE task_id = %d AND meta_key = %s LIMIT 1", $id, $key); |
| 77 | return $wpdb->query($sql); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Bulk delete task |
| 82 | * |
| 83 | * @param int $id the instance id of the task |
| 84 | */ |
| 85 | public static function bulk_delete_task_meta($id) { |
| 86 | global $wpdb; |
| 87 | |
| 88 | $id = (int) $id; |
| 89 | if (!$id) return false; |
| 90 | |
| 91 | $sql = $wpdb->prepare("DELETE FROM {$wpdb->base_prefix}tm_taskmeta WHERE task_id = %d", $id); |
| 92 | return $wpdb->query($sql); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | endif; |
| 97 |