| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* UpStream_Client Class |
| 10 |
* |
| 11 |
* @since 1.0 |
| 12 |
*/ |
| 13 |
class UpStream_Client |
| 14 |
{ |
| 15 |
|
| 16 |
/** |
| 17 |
* The client ID |
| 18 |
* |
| 19 |
* @since 1.0 |
| 20 |
*/ |
| 21 |
public $ID = 0; |
| 22 |
|
| 23 |
public $meta_prefix = '_upstream_client_'; |
| 24 |
|
| 25 |
public $meta = [ |
| 26 |
'logo', |
| 27 |
'logo_id', |
| 28 |
'address', |
| 29 |
'phone', |
| 30 |
'website', |
| 31 |
'users', |
| 32 |
]; |
| 33 |
|
| 34 |
/** |
| 35 |
* Declare the default properties in WP_Post as we can't extend it |
| 36 |
* Anything we've declared above has been removed. |
| 37 |
*/ |
| 38 |
public $post_author = 0; |
| 39 |
public $post_date = '0000-00-00 00:00:00'; |
| 40 |
public $post_date_gmt = '0000-00-00 00:00:00'; |
| 41 |
public $post_content = ''; |
| 42 |
public $post_title = ''; |
| 43 |
public $post_excerpt = ''; |
| 44 |
public $post_status = 'publish'; |
| 45 |
public $comment_status = 'open'; |
| 46 |
public $ping_status = 'open'; |
| 47 |
public $post_password = ''; |
| 48 |
public $post_name = ''; |
| 49 |
public $to_ping = ''; |
| 50 |
public $pinged = ''; |
| 51 |
public $post_modified = '0000-00-00 00:00:00'; |
| 52 |
public $post_modified_gmt = '0000-00-00 00:00:00'; |
| 53 |
public $post_content_filtered = ''; |
| 54 |
public $post_parent = 0; |
| 55 |
public $guid = ''; |
| 56 |
public $menu_order = 0; |
| 57 |
public $post_mime_type = ''; |
| 58 |
public $comment_count = 0; |
| 59 |
public $filter; |
| 60 |
|
| 61 |
/** |
| 62 |
* Get things going |
| 63 |
* |
| 64 |
* @since 1.0 |
| 65 |
*/ |
| 66 |
public function __construct($_id = false, $_args = []) |
| 67 |
{ |
| 68 |
|
| 69 |
// if no id is sent, then go through the varous ways of getting the id |
| 70 |
// may need to check the order more closely to ensure we get it right |
| 71 |
if ( ! $_id) { |
| 72 |
$user_id = upstream_current_user_id(); |
| 73 |
$_id = upstream_get_users_client_id($user_id); |
| 74 |
} |
| 75 |
|
| 76 |
if ( ! $_id) { |
| 77 |
$_id = upstream_project_client_id(); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
$client = WP_Post::get_instance($_id); |
| 82 |
|
| 83 |
return $this->setup_client($client); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Given the client data, let's set the variables |
| 88 |
* |
| 89 |
* @since 2.3.6 |
| 90 |
* |
| 91 |
* @param object $client The Client Object |
| 92 |
* |
| 93 |
* @return bool If the setup was successful or not |
| 94 |
*/ |
| 95 |
private function setup_client($client) |
| 96 |
{ |
| 97 |
if ( ! is_object($client)) { |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
if ( ! is_a($client, 'WP_Post')) { |
| 102 |
return false; |
| 103 |
} |
| 104 |
|
| 105 |
if ('client' !== $client->post_type) { |
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
// sets the value of each key |
| 110 |
foreach ($client as $key => $value) { |
| 111 |
switch ($key) { |
| 112 |
default: |
| 113 |
$this->$key = $value; |
| 114 |
break; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
public function init() |
| 122 |
{ |
| 123 |
add_action('init', [$this, 'hooks']); |
| 124 |
} |
| 125 |
|
| 126 |
public function hooks() |
| 127 |
{ |
| 128 |
//add_action( 'wp_insert_post', array( $this, 'update_project_meta_admin' ), 1, 3 ); |
| 129 |
//add_action( "cmb2_post_process_fields__upstream_project_bugs", array( $this, 'bug_changes' ), 10, 2 ); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* Get a meta value |
| 135 |
* |
| 136 |
* @since 1.0.0 |
| 137 |
* |
| 138 |
* @param string $meta the meta field (without prefix) |
| 139 |
* |
| 140 |
* @return mixed |
| 141 |
*/ |
| 142 |
public function get_meta($meta) |
| 143 |
{ |
| 144 |
$result = get_post_meta($this->ID, $this->meta_prefix . $meta, true); |
| 145 |
if ( ! $result) { |
| 146 |
$result = null; |
| 147 |
} |
| 148 |
|
| 149 |
return $result; |
| 150 |
} |
| 151 |
} |
| 152 |
|