| 1 |
<?php |
| 2 |
/** |
| 3 |
* Store CPT |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Data_Store; |
| 8 |
|
| 9 |
use WPFunnels\Exception\Wpfnl_Data_Exception; |
| 10 |
|
| 11 |
abstract class Wpfnl_Abstract_Store_data implements Wpfnl_Data_Store |
| 12 |
{ |
| 13 |
protected $id; |
| 14 |
|
| 15 |
abstract public function set_data(\WP_Post $post); |
| 16 |
|
| 17 |
public function set_id($id) |
| 18 |
{ |
| 19 |
$this->id = $id; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_id() |
| 23 |
{ |
| 24 |
return $this->id; |
| 25 |
} |
| 26 |
|
| 27 |
public function delete($id) |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
public function get_meta($id, $key) |
| 32 |
{ |
| 33 |
return get_post_meta($id, $key, true); |
| 34 |
} |
| 35 |
|
| 36 |
public function update_meta($id, $key, $value) |
| 37 |
{ |
| 38 |
if(is_array($value)) { |
| 39 |
if(count($value)) { |
| 40 |
update_post_meta($id, $key, $value); |
| 41 |
}else { |
| 42 |
delete_post_meta( $id, $key ); |
| 43 |
} |
| 44 |
} elseif (!empty($value)) { |
| 45 |
update_post_meta($id, $key, $value); |
| 46 |
} else { |
| 47 |
delete_post_meta( $id, $key ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
public function delete_meta() |
| 52 |
{ |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
public function read($id) |
| 58 |
{ |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* When invalid data is found exception will |
| 65 |
* be thrown without reading from DB |
| 66 |
* |
| 67 |
* @param $code |
| 68 |
* @param $message |
| 69 |
* @param int $http_status_code |
| 70 |
* @param array $data |
| 71 |
* |
| 72 |
* @throws Wpfnl_Data_Exception |
| 73 |
* @since 1.0.0 |
| 74 |
*/ |
| 75 |
protected function error($code, $message, $http_status_code = 400, $data = []) |
| 76 |
{ |
| 77 |
throw new Wpfnl_Data_Exception($code, $message, $http_status_code, $data); |
| 78 |
} |
| 79 |
} |
| 80 |
|