@@ -12,125 +12,125 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Cookie name used for the session. |
|
| 17 | - * |
|
| 18 | - * @var string cookie name |
|
| 19 | - */ |
|
| 20 | - protected $_cookie; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Stores session expiry. |
|
| 24 | - * |
|
| 25 | - * @var int session due to expire timestamp |
|
| 26 | - */ |
|
| 27 | - protected $_session_expiring; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Stores session due to expire timestamp. |
|
| 31 | - * |
|
| 32 | - * @var string session expiration timestamp |
|
| 33 | - */ |
|
| 34 | - protected $_session_expiration; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * True when the cookie exists. |
|
| 38 | - * |
|
| 39 | - * @var bool Based on whether a cookie exists. |
|
| 40 | - */ |
|
| 41 | - protected $_has_cookie = false; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Table name for session data. |
|
| 45 | - * |
|
| 46 | - * @var string Custom session table name |
|
| 47 | - */ |
|
| 48 | - protected $_table; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for the session class. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - |
|
| 55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 15 | + /** |
|
| 16 | + * Cookie name used for the session. |
|
| 17 | + * |
|
| 18 | + * @var string cookie name |
|
| 19 | + */ |
|
| 20 | + protected $_cookie; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Stores session expiry. |
|
| 24 | + * |
|
| 25 | + * @var int session due to expire timestamp |
|
| 26 | + */ |
|
| 27 | + protected $_session_expiring; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Stores session due to expire timestamp. |
|
| 31 | + * |
|
| 32 | + * @var string session expiration timestamp |
|
| 33 | + */ |
|
| 34 | + protected $_session_expiration; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * True when the cookie exists. |
|
| 38 | + * |
|
| 39 | + * @var bool Based on whether a cookie exists. |
|
| 40 | + */ |
|
| 41 | + protected $_has_cookie = false; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Table name for session data. |
|
| 45 | + * |
|
| 46 | + * @var string Custom session table name |
|
| 47 | + */ |
|
| 48 | + protected $_table; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for the session class. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + |
|
| 55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
| 57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Init hooks and session data. |
|
| 65 | - * |
|
| 66 | - * @since 3.3.0 |
|
| 67 | - */ |
|
| 68 | - public function init() { |
|
| 69 | - $this->init_session_cookie(); |
|
| 70 | - |
|
| 71 | - if ( ! is_user_logged_in() ) { |
|
| 72 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Setup cookie and customer ID. |
|
| 78 | - * |
|
| 79 | - * @since 3.6.0 |
|
| 80 | - */ |
|
| 81 | - public function init_session_cookie() { |
|
| 82 | - $cookie = $this->get_session_cookie(); |
|
| 83 | - |
|
| 84 | - if ( $cookie ) { |
|
| 85 | - $this->_customer_id = $cookie[0]; |
|
| 86 | - $this->_session_expiration = $cookie[1]; |
|
| 87 | - $this->_session_expiring = $cookie[2]; |
|
| 88 | - $this->_has_cookie = true; |
|
| 89 | - $this->_data = $this->get_session_data(); |
|
| 90 | - |
|
| 91 | - // If the user logs in, update session. |
|
| 92 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | - $this->_customer_id = get_current_user_id(); |
|
| 94 | - $this->_dirty = true; |
|
| 95 | - $this->save_data(); |
|
| 96 | - $this->set_customer_session_cookie( true ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Update session if its close to expiring. |
|
| 100 | - if ( time() > $this->_session_expiring ) { |
|
| 101 | - $this->set_session_expiration(); |
|
| 102 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $this->set_session_expiration(); |
|
| 106 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | - $this->_data = $this->get_session_data(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | - * |
|
| 114 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | - * |
|
| 116 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | - * |
|
| 118 | - * @param bool $set Should the session cookie be set. |
|
| 119 | - */ |
|
| 120 | - public function set_customer_session_cookie( $set ) { |
|
| 121 | - if ( $set ) { |
|
| 122 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | - $this->_has_cookie = true; |
|
| 126 | - |
|
| 127 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Init hooks and session data. |
|
| 65 | + * |
|
| 66 | + * @since 3.3.0 |
|
| 67 | + */ |
|
| 68 | + public function init() { |
|
| 69 | + $this->init_session_cookie(); |
|
| 70 | + |
|
| 71 | + if ( ! is_user_logged_in() ) { |
|
| 72 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Setup cookie and customer ID. |
|
| 78 | + * |
|
| 79 | + * @since 3.6.0 |
|
| 80 | + */ |
|
| 81 | + public function init_session_cookie() { |
|
| 82 | + $cookie = $this->get_session_cookie(); |
|
| 83 | + |
|
| 84 | + if ( $cookie ) { |
|
| 85 | + $this->_customer_id = $cookie[0]; |
|
| 86 | + $this->_session_expiration = $cookie[1]; |
|
| 87 | + $this->_session_expiring = $cookie[2]; |
|
| 88 | + $this->_has_cookie = true; |
|
| 89 | + $this->_data = $this->get_session_data(); |
|
| 90 | + |
|
| 91 | + // If the user logs in, update session. |
|
| 92 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | + $this->_customer_id = get_current_user_id(); |
|
| 94 | + $this->_dirty = true; |
|
| 95 | + $this->save_data(); |
|
| 96 | + $this->set_customer_session_cookie( true ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Update session if its close to expiring. |
|
| 100 | + if ( time() > $this->_session_expiring ) { |
|
| 101 | + $this->set_session_expiration(); |
|
| 102 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $this->set_session_expiration(); |
|
| 106 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | + $this->_data = $this->get_session_data(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | + * |
|
| 114 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | + * |
|
| 116 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | + * |
|
| 118 | + * @param bool $set Should the session cookie be set. |
|
| 119 | + */ |
|
| 120 | + public function set_customer_session_cookie( $set ) { |
|
| 121 | + if ( $set ) { |
|
| 122 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | + $this->_has_cookie = true; |
|
| 126 | + |
|
| 127 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 134 | 134 | if ( ! headers_sent() ) { |
| 135 | 135 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 136 | 136 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -139,86 +139,86 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Should the session cookie be secure? |
|
| 144 | - * |
|
| 145 | - * @since 3.6.0 |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function use_secure_cookie() { |
|
| 142 | + /** |
|
| 143 | + * Should the session cookie be secure? |
|
| 144 | + * |
|
| 145 | + * @since 3.6.0 |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function use_secure_cookie() { |
|
| 149 | 149 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
| 150 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | - * |
|
| 156 | - * @return bool |
|
| 157 | - */ |
|
| 158 | - public function has_session() { |
|
| 159 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Set session expiration. |
|
| 164 | - */ |
|
| 165 | - public function set_session_expiration() { |
|
| 166 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Generates session ids. |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function generate_customer_id() { |
|
| 176 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | - $hasher = new PasswordHash( 8, false ); |
|
| 178 | - return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the session cookie, if set. Otherwise return false. |
|
| 183 | - * |
|
| 184 | - * Session cookies without a customer ID are invalid. |
|
| 185 | - * |
|
| 186 | - * @return bool|array |
|
| 187 | - */ |
|
| 188 | - public function get_session_cookie() { |
|
| 189 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | - |
|
| 191 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | - |
|
| 197 | - if ( empty( $customer_id ) ) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Validate hash. |
|
| 202 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | - |
|
| 205 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Get session data. |
|
| 214 | - * |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function get_session_data() { |
|
| 218 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - public function generate_key($customer_id){ |
|
| 150 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | + * |
|
| 156 | + * @return bool |
|
| 157 | + */ |
|
| 158 | + public function has_session() { |
|
| 159 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Set session expiration. |
|
| 164 | + */ |
|
| 165 | + public function set_session_expiration() { |
|
| 166 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Generates session ids. |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function generate_customer_id() { |
|
| 176 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | + $hasher = new PasswordHash( 8, false ); |
|
| 178 | + return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the session cookie, if set. Otherwise return false. |
|
| 183 | + * |
|
| 184 | + * Session cookies without a customer ID are invalid. |
|
| 185 | + * |
|
| 186 | + * @return bool|array |
|
| 187 | + */ |
|
| 188 | + public function get_session_cookie() { |
|
| 189 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | + |
|
| 191 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | + |
|
| 197 | + if ( empty( $customer_id ) ) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Validate hash. |
|
| 202 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | + |
|
| 205 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Get session data. |
|
| 214 | + * |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function get_session_data() { |
|
| 218 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + public function generate_key($customer_id){ |
|
| 222 | 222 | if(!$customer_id){ |
| 223 | 223 | return; |
| 224 | 224 | } |
@@ -226,62 +226,62 @@ discard block |
||
| 226 | 226 | return 'wpi_trans_'.$customer_id; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Save data. |
|
| 231 | - */ |
|
| 232 | - public function save_data() { |
|
| 233 | - // Dirty if something changed - prevents saving nothing new. |
|
| 234 | - if ( $this->_dirty && $this->has_session() ) { |
|
| 229 | + /** |
|
| 230 | + * Save data. |
|
| 231 | + */ |
|
| 232 | + public function save_data() { |
|
| 233 | + // Dirty if something changed - prevents saving nothing new. |
|
| 234 | + if ( $this->_dirty && $this->has_session() ) { |
|
| 235 | 235 | |
| 236 | 236 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
| 237 | 237 | |
| 238 | - $this->_dirty = false; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Destroy all session data. |
|
| 244 | - */ |
|
| 245 | - public function destroy_session() { |
|
| 246 | - $this->delete_session( $this->_customer_id ); |
|
| 247 | - $this->forget_session(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Forget all session data without destroying it. |
|
| 252 | - */ |
|
| 253 | - public function forget_session() { |
|
| 254 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | - |
|
| 256 | - wpinv_empty_cart(); |
|
| 257 | - |
|
| 258 | - $this->_data = array(); |
|
| 259 | - $this->_dirty = false; |
|
| 260 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | - * |
|
| 266 | - * @param int $uid User ID. |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function nonce_user_logged_out( $uid ) { |
|
| 270 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Returns the session. |
|
| 275 | - * |
|
| 276 | - * @param string $customer_id Customer ID. |
|
| 277 | - * @param mixed $default Default session value. |
|
| 278 | - * @return string|array |
|
| 279 | - */ |
|
| 280 | - public function get_session( $customer_id, $default = false ) { |
|
| 281 | - |
|
| 282 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 283 | - return array(); |
|
| 284 | - } |
|
| 238 | + $this->_dirty = false; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Destroy all session data. |
|
| 244 | + */ |
|
| 245 | + public function destroy_session() { |
|
| 246 | + $this->delete_session( $this->_customer_id ); |
|
| 247 | + $this->forget_session(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Forget all session data without destroying it. |
|
| 252 | + */ |
|
| 253 | + public function forget_session() { |
|
| 254 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | + |
|
| 256 | + wpinv_empty_cart(); |
|
| 257 | + |
|
| 258 | + $this->_data = array(); |
|
| 259 | + $this->_dirty = false; |
|
| 260 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | + * |
|
| 266 | + * @param int $uid User ID. |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function nonce_user_logged_out( $uid ) { |
|
| 270 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Returns the session. |
|
| 275 | + * |
|
| 276 | + * @param string $customer_id Customer ID. |
|
| 277 | + * @param mixed $default Default session value. |
|
| 278 | + * @return string|array |
|
| 279 | + */ |
|
| 280 | + public function get_session( $customer_id, $default = false ) { |
|
| 281 | + |
|
| 282 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 283 | + return array(); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | $key = $this->generate_key($customer_id); |
| 287 | 287 | $value = get_transient($key); |
@@ -290,30 +290,30 @@ discard block |
||
| 290 | 290 | $value = $default; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - return maybe_unserialize( $value ); |
|
| 294 | - } |
|
| 293 | + return maybe_unserialize( $value ); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Delete the session from the cache and database. |
|
| 298 | - * |
|
| 299 | - * @param int $customer_id Customer ID. |
|
| 300 | - */ |
|
| 301 | - public function delete_session( $customer_id ) { |
|
| 296 | + /** |
|
| 297 | + * Delete the session from the cache and database. |
|
| 298 | + * |
|
| 299 | + * @param int $customer_id Customer ID. |
|
| 300 | + */ |
|
| 301 | + public function delete_session( $customer_id ) { |
|
| 302 | 302 | |
| 303 | 303 | $key = $this->generate_key($customer_id); |
| 304 | 304 | |
| 305 | - delete_transient($key); |
|
| 306 | - } |
|
| 305 | + delete_transient($key); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * Update the session expiry timestamp. |
|
| 310 | - * |
|
| 311 | - * @param string $customer_id Customer ID. |
|
| 312 | - * @param int $timestamp Timestamp to expire the cookie. |
|
| 313 | - */ |
|
| 314 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 308 | + /** |
|
| 309 | + * Update the session expiry timestamp. |
|
| 310 | + * |
|
| 311 | + * @param string $customer_id Customer ID. |
|
| 312 | + * @param int $timestamp Timestamp to expire the cookie. |
|
| 313 | + */ |
|
| 314 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 315 | 315 | |
| 316 | 316 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
| 317 | 317 | |
| 318 | - } |
|
| 318 | + } |
|
| 319 | 319 | } |
@@ -13,629 +13,629 @@ |
||
| 13 | 13 | |
| 14 | 14 | return array( |
| 15 | 15 | |
| 16 | - 'id' => array( |
|
| 17 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
| 18 | - 'type' => 'integer', |
|
| 19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | - 'readonly' => true, |
|
| 21 | - ), |
|
| 22 | - |
|
| 23 | - 'parent_id' => array( |
|
| 24 | - 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
| 25 | - 'type' => 'integer', |
|
| 26 | - 'minimum' => 0, |
|
| 27 | - 'default' => 0, |
|
| 28 | - 'context' => array( 'view', 'edit' ), |
|
| 29 | - ), |
|
| 30 | - |
|
| 31 | - 'key' => array( |
|
| 32 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
| 33 | - 'type' => 'string', |
|
| 34 | - 'context' => array( 'view', 'edit' ), |
|
| 35 | - 'readonly' => true, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'number' => array( |
|
| 39 | - 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
| 40 | - 'type' => 'string', |
|
| 41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | - ), |
|
| 43 | - |
|
| 44 | - 'type' => array( |
|
| 45 | - 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
| 46 | - 'type' => 'string', |
|
| 47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | - 'readonly' => true, |
|
| 49 | - ), |
|
| 50 | - |
|
| 51 | - 'post_type' => array( |
|
| 52 | - 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
| 53 | - 'type' => 'string', |
|
| 54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | - 'readonly' => true, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - 'version' => array( |
|
| 59 | - 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
| 60 | - 'type' => 'integer', |
|
| 61 | - 'context' => array( 'view', 'edit' ), |
|
| 62 | - 'readonly' => true, |
|
| 63 | - ), |
|
| 64 | - |
|
| 65 | - 'template' => array( |
|
| 66 | - 'description' => __( 'The invoice template.', 'invoicing' ), |
|
| 67 | - 'type' => 'string', |
|
| 68 | - 'default' => 'quantity', |
|
| 69 | - 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
| 70 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 71 | - ), |
|
| 72 | - |
|
| 73 | - 'status' => array( |
|
| 74 | - 'description' => __( 'Invoice status.', 'invoicing' ), |
|
| 75 | - 'type' => 'string', |
|
| 76 | - 'default' => 'wpi-pending', |
|
| 77 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
| 78 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 79 | - ), |
|
| 80 | - |
|
| 81 | - 'status_nicename' => array( |
|
| 82 | - 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
| 83 | - 'type' => 'string', |
|
| 84 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 85 | - 'readonly' => true, |
|
| 86 | - ), |
|
| 87 | - |
|
| 88 | - 'currency' => array( |
|
| 89 | - 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
| 90 | - 'type' => 'string', |
|
| 91 | - 'default' => wpinv_get_currency(), |
|
| 92 | - 'enum' => array_keys( wpinv_get_currencies() ), |
|
| 93 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 94 | - ), |
|
| 95 | - |
|
| 96 | - 'date_created' => array( |
|
| 97 | - 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
| 98 | - 'type' => 'string', |
|
| 99 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 100 | - ), |
|
| 101 | - |
|
| 102 | - 'date_created_gmt' => array( |
|
| 103 | - 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
| 104 | - 'type' => 'string', |
|
| 105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 106 | - 'readonly' => true, |
|
| 107 | - ), |
|
| 108 | - |
|
| 109 | - 'date_modified' => array( |
|
| 110 | - 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
| 111 | - 'type' => 'string', |
|
| 112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 113 | - 'readonly' => true, |
|
| 114 | - ), |
|
| 115 | - |
|
| 116 | - 'date_modified_gmt' => array( |
|
| 117 | - 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
| 118 | - 'type' => 'string', |
|
| 119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 120 | - 'readonly' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'due_date' => array( |
|
| 124 | - 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
| 125 | - 'type' => 'string', |
|
| 126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 127 | - ), |
|
| 128 | - |
|
| 129 | - 'due_date_gmt' => array( |
|
| 130 | - 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
| 131 | - 'type' => 'string', |
|
| 132 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 133 | - 'readonly' => true, |
|
| 134 | - ), |
|
| 135 | - |
|
| 136 | - 'completed_date' => array( |
|
| 137 | - 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
| 138 | - 'type' => 'string', |
|
| 139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 140 | - 'readonly' => true, |
|
| 141 | - ), |
|
| 142 | - |
|
| 143 | - 'completed_date_gmt' => array( |
|
| 144 | - 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
| 145 | - 'type' => 'string', |
|
| 146 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 147 | - 'readonly' => true, |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - 'total_discount' => array( |
|
| 151 | - 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
| 152 | - 'type' => 'number', |
|
| 153 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 154 | - 'readonly' => true, |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - 'total_tax' => array( |
|
| 158 | - 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
| 159 | - 'type' => 'number', |
|
| 160 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 161 | - 'readonly' => true, |
|
| 162 | - ), |
|
| 163 | - |
|
| 164 | - 'total_fees' => array( |
|
| 165 | - 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
| 166 | - 'type' => 'number', |
|
| 167 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 168 | - 'readonly' => true, |
|
| 169 | - ), |
|
| 170 | - |
|
| 171 | - 'subtotal' => array( |
|
| 172 | - 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
| 173 | - 'type' => 'number', |
|
| 174 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 175 | - 'readonly' => true, |
|
| 176 | - ), |
|
| 177 | - |
|
| 178 | - 'total' => array( |
|
| 179 | - 'description' => __( 'Grand total.', 'invoicing' ), |
|
| 180 | - 'type' => 'number', |
|
| 181 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 182 | - 'readonly' => true, |
|
| 183 | - ), |
|
| 184 | - |
|
| 185 | - 'initial_total' => array( |
|
| 186 | - 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
| 187 | - 'type' => 'number', |
|
| 188 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 189 | - 'readonly' => true, |
|
| 190 | - ), |
|
| 191 | - |
|
| 192 | - 'recurring_total' => array( |
|
| 193 | - 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
| 194 | - 'type' => 'number', |
|
| 195 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 196 | - 'readonly' => true, |
|
| 197 | - ), |
|
| 198 | - |
|
| 199 | - 'totals' => array( |
|
| 200 | - 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
| 201 | - 'type' => 'object', |
|
| 202 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 203 | - 'readonly' => true, |
|
| 204 | - ), |
|
| 205 | - |
|
| 206 | - 'fees' => array( |
|
| 207 | - 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
| 208 | - 'type' => 'object', |
|
| 209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 210 | - 'items' => array( |
|
| 211 | - 'type' => 'object', |
|
| 212 | - 'required' => array( 'amount' ), |
|
| 213 | - 'properties' => array( |
|
| 214 | - 'amount' => array( |
|
| 215 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 216 | - 'type' => 'string', |
|
| 217 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 218 | - ), |
|
| 219 | - 'recurring' => array( |
|
| 220 | - 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
| 221 | - 'type' => array( 'boolean', 'integer' ), |
|
| 222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - ), |
|
| 226 | - ), |
|
| 227 | - |
|
| 228 | - 'discounts' => array( |
|
| 229 | - 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
| 230 | - 'type' => 'object', |
|
| 231 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 232 | - 'items' => array( |
|
| 233 | - 'type' => 'object', |
|
| 234 | - 'required' => array( 'amount' ), |
|
| 235 | - 'properties' => array( |
|
| 236 | - 'amount' => array( |
|
| 237 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 238 | - 'type' => 'string', |
|
| 239 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 240 | - ), |
|
| 241 | - 'recurring' => array( |
|
| 242 | - 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
| 243 | - 'type' => array( 'boolean', 'integer' ), |
|
| 244 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 245 | - ), |
|
| 246 | - ), |
|
| 247 | - ), |
|
| 248 | - ), |
|
| 249 | - |
|
| 250 | - 'taxes' => array( |
|
| 251 | - 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
| 252 | - 'type' => 'object', |
|
| 253 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 254 | - 'items' => array( |
|
| 255 | - 'type' => 'object', |
|
| 256 | - 'required' => array( 'amount' ), |
|
| 257 | - 'properties' => array( |
|
| 258 | - 'amount' => array( |
|
| 259 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 260 | - 'type' => 'string', |
|
| 261 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 262 | - ), |
|
| 263 | - 'recurring' => array( |
|
| 264 | - 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
| 265 | - 'type' => array( 'boolean', 'integer' ), |
|
| 266 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 267 | - ), |
|
| 268 | - ), |
|
| 269 | - ), |
|
| 270 | - ), |
|
| 271 | - |
|
| 272 | - 'items' => array( |
|
| 273 | - 'description' => __( 'Invoice items.', 'invoicing' ), |
|
| 274 | - 'type' => 'array', |
|
| 275 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 276 | - 'items' => array( |
|
| 277 | - 'type' => 'object', |
|
| 278 | - 'required' => array( 'item_id' ), |
|
| 279 | - 'properties' => array( |
|
| 280 | - 'item_id' => array( |
|
| 281 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 282 | - 'type' => 'integer', |
|
| 283 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 284 | - ), |
|
| 285 | - 'item_name' => array( |
|
| 286 | - 'description' => __( 'Item Name.', 'invoicing' ), |
|
| 287 | - 'type' => 'string', |
|
| 288 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 289 | - ), |
|
| 290 | - 'item_description' => array( |
|
| 291 | - 'description' => __( 'Item Description.', 'invoicing' ), |
|
| 292 | - 'type' => 'string', |
|
| 293 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 294 | - ), |
|
| 295 | - 'item_price' => array( |
|
| 296 | - 'description' => __( 'Item Price.', 'invoicing' ), |
|
| 297 | - 'type' => 'number', |
|
| 298 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 299 | - ), |
|
| 300 | - 'quantity' => array( |
|
| 301 | - 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
| 302 | - 'type' => 'integer', |
|
| 303 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 304 | - ), |
|
| 305 | - 'subtotal' => array( |
|
| 306 | - 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
| 307 | - 'type' => 'number', |
|
| 308 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 309 | - 'readonly' => true, |
|
| 310 | - ), |
|
| 311 | - 'meta' => array( |
|
| 312 | - 'description' => __( 'Item Meta.', 'invoicing' ), |
|
| 313 | - 'type' => 'object', |
|
| 314 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 315 | - ), |
|
| 316 | - ), |
|
| 317 | - ), |
|
| 318 | - ), |
|
| 319 | - |
|
| 320 | - 'mode' => array( |
|
| 321 | - 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
| 322 | - 'type' => 'string', |
|
| 323 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 324 | - 'enum' => array( 'live', 'test' ), |
|
| 325 | - 'readonly' => true, |
|
| 326 | - ), |
|
| 16 | + 'id' => array( |
|
| 17 | + 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
| 18 | + 'type' => 'integer', |
|
| 19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | + 'readonly' => true, |
|
| 21 | + ), |
|
| 22 | + |
|
| 23 | + 'parent_id' => array( |
|
| 24 | + 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
| 25 | + 'type' => 'integer', |
|
| 26 | + 'minimum' => 0, |
|
| 27 | + 'default' => 0, |
|
| 28 | + 'context' => array( 'view', 'edit' ), |
|
| 29 | + ), |
|
| 30 | + |
|
| 31 | + 'key' => array( |
|
| 32 | + 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
| 33 | + 'type' => 'string', |
|
| 34 | + 'context' => array( 'view', 'edit' ), |
|
| 35 | + 'readonly' => true, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'number' => array( |
|
| 39 | + 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
| 40 | + 'type' => 'string', |
|
| 41 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | + ), |
|
| 43 | + |
|
| 44 | + 'type' => array( |
|
| 45 | + 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
| 46 | + 'type' => 'string', |
|
| 47 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | + 'readonly' => true, |
|
| 49 | + ), |
|
| 50 | + |
|
| 51 | + 'post_type' => array( |
|
| 52 | + 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
| 53 | + 'type' => 'string', |
|
| 54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | + 'readonly' => true, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + 'version' => array( |
|
| 59 | + 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
| 60 | + 'type' => 'integer', |
|
| 61 | + 'context' => array( 'view', 'edit' ), |
|
| 62 | + 'readonly' => true, |
|
| 63 | + ), |
|
| 64 | + |
|
| 65 | + 'template' => array( |
|
| 66 | + 'description' => __( 'The invoice template.', 'invoicing' ), |
|
| 67 | + 'type' => 'string', |
|
| 68 | + 'default' => 'quantity', |
|
| 69 | + 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
| 70 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 71 | + ), |
|
| 72 | + |
|
| 73 | + 'status' => array( |
|
| 74 | + 'description' => __( 'Invoice status.', 'invoicing' ), |
|
| 75 | + 'type' => 'string', |
|
| 76 | + 'default' => 'wpi-pending', |
|
| 77 | + 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
| 78 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 79 | + ), |
|
| 80 | + |
|
| 81 | + 'status_nicename' => array( |
|
| 82 | + 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
| 83 | + 'type' => 'string', |
|
| 84 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 85 | + 'readonly' => true, |
|
| 86 | + ), |
|
| 87 | + |
|
| 88 | + 'currency' => array( |
|
| 89 | + 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
| 90 | + 'type' => 'string', |
|
| 91 | + 'default' => wpinv_get_currency(), |
|
| 92 | + 'enum' => array_keys( wpinv_get_currencies() ), |
|
| 93 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 94 | + ), |
|
| 95 | + |
|
| 96 | + 'date_created' => array( |
|
| 97 | + 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
| 98 | + 'type' => 'string', |
|
| 99 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 100 | + ), |
|
| 101 | + |
|
| 102 | + 'date_created_gmt' => array( |
|
| 103 | + 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
| 104 | + 'type' => 'string', |
|
| 105 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 106 | + 'readonly' => true, |
|
| 107 | + ), |
|
| 108 | + |
|
| 109 | + 'date_modified' => array( |
|
| 110 | + 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
| 111 | + 'type' => 'string', |
|
| 112 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 113 | + 'readonly' => true, |
|
| 114 | + ), |
|
| 115 | + |
|
| 116 | + 'date_modified_gmt' => array( |
|
| 117 | + 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
| 118 | + 'type' => 'string', |
|
| 119 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 120 | + 'readonly' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'due_date' => array( |
|
| 124 | + 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
| 125 | + 'type' => 'string', |
|
| 126 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 127 | + ), |
|
| 128 | + |
|
| 129 | + 'due_date_gmt' => array( |
|
| 130 | + 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
| 131 | + 'type' => 'string', |
|
| 132 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 133 | + 'readonly' => true, |
|
| 134 | + ), |
|
| 135 | + |
|
| 136 | + 'completed_date' => array( |
|
| 137 | + 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
| 138 | + 'type' => 'string', |
|
| 139 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 140 | + 'readonly' => true, |
|
| 141 | + ), |
|
| 142 | + |
|
| 143 | + 'completed_date_gmt' => array( |
|
| 144 | + 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
| 145 | + 'type' => 'string', |
|
| 146 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 147 | + 'readonly' => true, |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + 'total_discount' => array( |
|
| 151 | + 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
| 152 | + 'type' => 'number', |
|
| 153 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 154 | + 'readonly' => true, |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + 'total_tax' => array( |
|
| 158 | + 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
| 159 | + 'type' => 'number', |
|
| 160 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 161 | + 'readonly' => true, |
|
| 162 | + ), |
|
| 163 | + |
|
| 164 | + 'total_fees' => array( |
|
| 165 | + 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
| 166 | + 'type' => 'number', |
|
| 167 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 168 | + 'readonly' => true, |
|
| 169 | + ), |
|
| 170 | + |
|
| 171 | + 'subtotal' => array( |
|
| 172 | + 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
| 173 | + 'type' => 'number', |
|
| 174 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 175 | + 'readonly' => true, |
|
| 176 | + ), |
|
| 177 | + |
|
| 178 | + 'total' => array( |
|
| 179 | + 'description' => __( 'Grand total.', 'invoicing' ), |
|
| 180 | + 'type' => 'number', |
|
| 181 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 182 | + 'readonly' => true, |
|
| 183 | + ), |
|
| 184 | + |
|
| 185 | + 'initial_total' => array( |
|
| 186 | + 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
| 187 | + 'type' => 'number', |
|
| 188 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 189 | + 'readonly' => true, |
|
| 190 | + ), |
|
| 191 | + |
|
| 192 | + 'recurring_total' => array( |
|
| 193 | + 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
| 194 | + 'type' => 'number', |
|
| 195 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 196 | + 'readonly' => true, |
|
| 197 | + ), |
|
| 198 | + |
|
| 199 | + 'totals' => array( |
|
| 200 | + 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
| 201 | + 'type' => 'object', |
|
| 202 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 203 | + 'readonly' => true, |
|
| 204 | + ), |
|
| 205 | + |
|
| 206 | + 'fees' => array( |
|
| 207 | + 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
| 208 | + 'type' => 'object', |
|
| 209 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 210 | + 'items' => array( |
|
| 211 | + 'type' => 'object', |
|
| 212 | + 'required' => array( 'amount' ), |
|
| 213 | + 'properties' => array( |
|
| 214 | + 'amount' => array( |
|
| 215 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 216 | + 'type' => 'string', |
|
| 217 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 218 | + ), |
|
| 219 | + 'recurring' => array( |
|
| 220 | + 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
| 221 | + 'type' => array( 'boolean', 'integer' ), |
|
| 222 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + ), |
|
| 226 | + ), |
|
| 227 | + |
|
| 228 | + 'discounts' => array( |
|
| 229 | + 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
| 230 | + 'type' => 'object', |
|
| 231 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 232 | + 'items' => array( |
|
| 233 | + 'type' => 'object', |
|
| 234 | + 'required' => array( 'amount' ), |
|
| 235 | + 'properties' => array( |
|
| 236 | + 'amount' => array( |
|
| 237 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 238 | + 'type' => 'string', |
|
| 239 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 240 | + ), |
|
| 241 | + 'recurring' => array( |
|
| 242 | + 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
| 243 | + 'type' => array( 'boolean', 'integer' ), |
|
| 244 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 245 | + ), |
|
| 246 | + ), |
|
| 247 | + ), |
|
| 248 | + ), |
|
| 249 | + |
|
| 250 | + 'taxes' => array( |
|
| 251 | + 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
| 252 | + 'type' => 'object', |
|
| 253 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 254 | + 'items' => array( |
|
| 255 | + 'type' => 'object', |
|
| 256 | + 'required' => array( 'amount' ), |
|
| 257 | + 'properties' => array( |
|
| 258 | + 'amount' => array( |
|
| 259 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 260 | + 'type' => 'string', |
|
| 261 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 262 | + ), |
|
| 263 | + 'recurring' => array( |
|
| 264 | + 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
| 265 | + 'type' => array( 'boolean', 'integer' ), |
|
| 266 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 267 | + ), |
|
| 268 | + ), |
|
| 269 | + ), |
|
| 270 | + ), |
|
| 271 | + |
|
| 272 | + 'items' => array( |
|
| 273 | + 'description' => __( 'Invoice items.', 'invoicing' ), |
|
| 274 | + 'type' => 'array', |
|
| 275 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 276 | + 'items' => array( |
|
| 277 | + 'type' => 'object', |
|
| 278 | + 'required' => array( 'item_id' ), |
|
| 279 | + 'properties' => array( |
|
| 280 | + 'item_id' => array( |
|
| 281 | + 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 282 | + 'type' => 'integer', |
|
| 283 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 284 | + ), |
|
| 285 | + 'item_name' => array( |
|
| 286 | + 'description' => __( 'Item Name.', 'invoicing' ), |
|
| 287 | + 'type' => 'string', |
|
| 288 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 289 | + ), |
|
| 290 | + 'item_description' => array( |
|
| 291 | + 'description' => __( 'Item Description.', 'invoicing' ), |
|
| 292 | + 'type' => 'string', |
|
| 293 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 294 | + ), |
|
| 295 | + 'item_price' => array( |
|
| 296 | + 'description' => __( 'Item Price.', 'invoicing' ), |
|
| 297 | + 'type' => 'number', |
|
| 298 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 299 | + ), |
|
| 300 | + 'quantity' => array( |
|
| 301 | + 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
| 302 | + 'type' => 'integer', |
|
| 303 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 304 | + ), |
|
| 305 | + 'subtotal' => array( |
|
| 306 | + 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
| 307 | + 'type' => 'number', |
|
| 308 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 309 | + 'readonly' => true, |
|
| 310 | + ), |
|
| 311 | + 'meta' => array( |
|
| 312 | + 'description' => __( 'Item Meta.', 'invoicing' ), |
|
| 313 | + 'type' => 'object', |
|
| 314 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 315 | + ), |
|
| 316 | + ), |
|
| 317 | + ), |
|
| 318 | + ), |
|
| 319 | + |
|
| 320 | + 'mode' => array( |
|
| 321 | + 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
| 322 | + 'type' => 'string', |
|
| 323 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 324 | + 'enum' => array( 'live', 'test' ), |
|
| 325 | + 'readonly' => true, |
|
| 326 | + ), |
|
| 327 | 327 | |
| 328 | - 'discount_code' => array( |
|
| 329 | - 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
| 330 | - 'type' => 'string', |
|
| 331 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 332 | - ), |
|
| 333 | - |
|
| 334 | - 'gateway' => array( |
|
| 335 | - 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
| 336 | - 'type' => 'string', |
|
| 337 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 338 | - ), |
|
| 339 | - |
|
| 340 | - 'gateway_title' => array( |
|
| 341 | - 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
| 342 | - 'type' => 'string', |
|
| 343 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 344 | - 'readonly' => true, |
|
| 345 | - ), |
|
| 346 | - |
|
| 347 | - 'transaction_id' => array( |
|
| 348 | - 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
| 349 | - 'type' => 'string', |
|
| 350 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 351 | - ), |
|
| 328 | + 'discount_code' => array( |
|
| 329 | + 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
| 330 | + 'type' => 'string', |
|
| 331 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 332 | + ), |
|
| 333 | + |
|
| 334 | + 'gateway' => array( |
|
| 335 | + 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
| 336 | + 'type' => 'string', |
|
| 337 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 338 | + ), |
|
| 339 | + |
|
| 340 | + 'gateway_title' => array( |
|
| 341 | + 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
| 342 | + 'type' => 'string', |
|
| 343 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 344 | + 'readonly' => true, |
|
| 345 | + ), |
|
| 346 | + |
|
| 347 | + 'transaction_id' => array( |
|
| 348 | + 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
| 349 | + 'type' => 'string', |
|
| 350 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 351 | + ), |
|
| 352 | 352 | |
| 353 | - 'disable_taxes' => array( |
|
| 354 | - 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
| 355 | - 'type' => 'boolean ', |
|
| 356 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 357 | - ), |
|
| 358 | - |
|
| 359 | - 'is_viewed' => array( |
|
| 360 | - 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
| 361 | - 'type' => 'boolean ', |
|
| 362 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 363 | - 'readonly' => true, |
|
| 364 | - ), |
|
| 365 | - |
|
| 366 | - 'email_cc' => array( |
|
| 367 | - 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
| 368 | - 'type' => 'string ', |
|
| 369 | - 'context' => array( 'view', 'edit' ), |
|
| 370 | - ), |
|
| 371 | - |
|
| 372 | - 'subscription_id' => array( |
|
| 373 | - 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
| 374 | - 'type' => 'string ', |
|
| 375 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 376 | - 'readonly' => true, |
|
| 377 | - ), |
|
| 378 | - |
|
| 379 | - 'subscription_name' => array( |
|
| 380 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 381 | - 'type' => 'string ', |
|
| 382 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 383 | - 'readonly' => true, |
|
| 384 | - ), |
|
| 385 | - |
|
| 386 | - 'subscription_name' => array( |
|
| 387 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 388 | - 'type' => 'string ', |
|
| 389 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 390 | - 'readonly' => true, |
|
| 391 | - ), |
|
| 392 | - |
|
| 393 | - 'is_parent' => array( |
|
| 394 | - 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
| 395 | - 'type' => 'boolean', |
|
| 396 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 397 | - 'readonly' => true, |
|
| 398 | - ), |
|
| 399 | - |
|
| 400 | - 'is_renewal' => array( |
|
| 401 | - 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
| 402 | - 'type' => 'boolean', |
|
| 403 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 404 | - 'readonly' => true, |
|
| 405 | - ), |
|
| 406 | - |
|
| 407 | - 'is_recurring' => array( |
|
| 408 | - 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
| 409 | - 'type' => 'boolean', |
|
| 410 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 411 | - 'readonly' => true, |
|
| 412 | - ), |
|
| 413 | - |
|
| 414 | - 'is_free' => array( |
|
| 415 | - 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
| 416 | - 'type' => 'boolean', |
|
| 417 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 418 | - 'readonly' => true, |
|
| 419 | - ), |
|
| 420 | - |
|
| 421 | - 'is_paid' => array( |
|
| 422 | - 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
| 423 | - 'type' => 'boolean', |
|
| 424 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 425 | - 'readonly' => true, |
|
| 426 | - ), |
|
| 427 | - |
|
| 428 | - 'needs_payment' => array( |
|
| 429 | - 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
| 430 | - 'type' => 'boolean', |
|
| 431 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 432 | - 'readonly' => true, |
|
| 433 | - ), |
|
| 434 | - |
|
| 435 | - 'is_refunded' => array( |
|
| 436 | - 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
| 437 | - 'type' => 'boolean', |
|
| 438 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 439 | - 'readonly' => true, |
|
| 440 | - ), |
|
| 441 | - |
|
| 442 | - 'is_due' => array( |
|
| 443 | - 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
| 444 | - 'type' => 'boolean', |
|
| 445 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 446 | - 'readonly' => true, |
|
| 447 | - ), |
|
| 448 | - |
|
| 449 | - 'is_held' => array( |
|
| 450 | - 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
| 451 | - 'type' => 'boolean', |
|
| 452 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 453 | - 'readonly' => true, |
|
| 454 | - ), |
|
| 455 | - |
|
| 456 | - 'is_draft' => array( |
|
| 457 | - 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
| 458 | - 'type' => 'boolean', |
|
| 459 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 460 | - 'readonly' => true, |
|
| 461 | - ), |
|
| 462 | - |
|
| 463 | - 'path' => array( |
|
| 464 | - 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
| 465 | - 'type' => 'string', |
|
| 466 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 467 | - 'readonly' => true, |
|
| 468 | - ), |
|
| 469 | - |
|
| 470 | - 'description' => array( |
|
| 471 | - 'description' => __( 'The invoice description.', 'invoicing' ), |
|
| 472 | - 'type' => 'string', |
|
| 473 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 474 | - ), |
|
| 475 | - |
|
| 476 | - 'payment_form' => array( |
|
| 477 | - 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
| 478 | - 'type' => 'integer', |
|
| 479 | - 'context' => array( 'view', 'edit' ), |
|
| 480 | - 'readonly' => true, |
|
| 481 | - ), |
|
| 482 | - |
|
| 483 | - 'submission_id' => array( |
|
| 484 | - 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
| 485 | - 'type' => 'string', |
|
| 486 | - 'context' => array( 'view', 'edit' ), |
|
| 487 | - 'readonly' => true, |
|
| 488 | - ), |
|
| 489 | - |
|
| 490 | - 'customer_id' => array( |
|
| 491 | - 'description' => __( 'The customer id.', 'invoicing' ), |
|
| 492 | - 'type' => 'integer', |
|
| 493 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 494 | - ), |
|
| 495 | - |
|
| 496 | - 'customer_ip' => array( |
|
| 497 | - 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
| 498 | - 'type' => 'string', |
|
| 499 | - 'format' => 'ip', |
|
| 500 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 501 | - ), |
|
| 502 | - |
|
| 503 | - 'first_name' => array( |
|
| 504 | - 'description' => __( "The customer's first name.", 'invoicing' ), |
|
| 505 | - 'type' => 'string', |
|
| 506 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 507 | - ), |
|
| 508 | - |
|
| 509 | - 'last_name' => array( |
|
| 510 | - 'description' => __( "The customer's last name.", 'invoicing' ), |
|
| 511 | - 'type' => 'string', |
|
| 512 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 513 | - ), |
|
| 353 | + 'disable_taxes' => array( |
|
| 354 | + 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
| 355 | + 'type' => 'boolean ', |
|
| 356 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 357 | + ), |
|
| 358 | + |
|
| 359 | + 'is_viewed' => array( |
|
| 360 | + 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
| 361 | + 'type' => 'boolean ', |
|
| 362 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 363 | + 'readonly' => true, |
|
| 364 | + ), |
|
| 365 | + |
|
| 366 | + 'email_cc' => array( |
|
| 367 | + 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
| 368 | + 'type' => 'string ', |
|
| 369 | + 'context' => array( 'view', 'edit' ), |
|
| 370 | + ), |
|
| 371 | + |
|
| 372 | + 'subscription_id' => array( |
|
| 373 | + 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
| 374 | + 'type' => 'string ', |
|
| 375 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 376 | + 'readonly' => true, |
|
| 377 | + ), |
|
| 378 | + |
|
| 379 | + 'subscription_name' => array( |
|
| 380 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 381 | + 'type' => 'string ', |
|
| 382 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 383 | + 'readonly' => true, |
|
| 384 | + ), |
|
| 385 | + |
|
| 386 | + 'subscription_name' => array( |
|
| 387 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 388 | + 'type' => 'string ', |
|
| 389 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 390 | + 'readonly' => true, |
|
| 391 | + ), |
|
| 392 | + |
|
| 393 | + 'is_parent' => array( |
|
| 394 | + 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
| 395 | + 'type' => 'boolean', |
|
| 396 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 397 | + 'readonly' => true, |
|
| 398 | + ), |
|
| 399 | + |
|
| 400 | + 'is_renewal' => array( |
|
| 401 | + 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
| 402 | + 'type' => 'boolean', |
|
| 403 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 404 | + 'readonly' => true, |
|
| 405 | + ), |
|
| 406 | + |
|
| 407 | + 'is_recurring' => array( |
|
| 408 | + 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
| 409 | + 'type' => 'boolean', |
|
| 410 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 411 | + 'readonly' => true, |
|
| 412 | + ), |
|
| 413 | + |
|
| 414 | + 'is_free' => array( |
|
| 415 | + 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
| 416 | + 'type' => 'boolean', |
|
| 417 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 418 | + 'readonly' => true, |
|
| 419 | + ), |
|
| 420 | + |
|
| 421 | + 'is_paid' => array( |
|
| 422 | + 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
| 423 | + 'type' => 'boolean', |
|
| 424 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 425 | + 'readonly' => true, |
|
| 426 | + ), |
|
| 427 | + |
|
| 428 | + 'needs_payment' => array( |
|
| 429 | + 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
| 430 | + 'type' => 'boolean', |
|
| 431 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 432 | + 'readonly' => true, |
|
| 433 | + ), |
|
| 434 | + |
|
| 435 | + 'is_refunded' => array( |
|
| 436 | + 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
| 437 | + 'type' => 'boolean', |
|
| 438 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 439 | + 'readonly' => true, |
|
| 440 | + ), |
|
| 441 | + |
|
| 442 | + 'is_due' => array( |
|
| 443 | + 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
| 444 | + 'type' => 'boolean', |
|
| 445 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 446 | + 'readonly' => true, |
|
| 447 | + ), |
|
| 448 | + |
|
| 449 | + 'is_held' => array( |
|
| 450 | + 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
| 451 | + 'type' => 'boolean', |
|
| 452 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 453 | + 'readonly' => true, |
|
| 454 | + ), |
|
| 455 | + |
|
| 456 | + 'is_draft' => array( |
|
| 457 | + 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
| 458 | + 'type' => 'boolean', |
|
| 459 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 460 | + 'readonly' => true, |
|
| 461 | + ), |
|
| 462 | + |
|
| 463 | + 'path' => array( |
|
| 464 | + 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
| 465 | + 'type' => 'string', |
|
| 466 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 467 | + 'readonly' => true, |
|
| 468 | + ), |
|
| 469 | + |
|
| 470 | + 'description' => array( |
|
| 471 | + 'description' => __( 'The invoice description.', 'invoicing' ), |
|
| 472 | + 'type' => 'string', |
|
| 473 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 474 | + ), |
|
| 475 | + |
|
| 476 | + 'payment_form' => array( |
|
| 477 | + 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
| 478 | + 'type' => 'integer', |
|
| 479 | + 'context' => array( 'view', 'edit' ), |
|
| 480 | + 'readonly' => true, |
|
| 481 | + ), |
|
| 482 | + |
|
| 483 | + 'submission_id' => array( |
|
| 484 | + 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
| 485 | + 'type' => 'string', |
|
| 486 | + 'context' => array( 'view', 'edit' ), |
|
| 487 | + 'readonly' => true, |
|
| 488 | + ), |
|
| 489 | + |
|
| 490 | + 'customer_id' => array( |
|
| 491 | + 'description' => __( 'The customer id.', 'invoicing' ), |
|
| 492 | + 'type' => 'integer', |
|
| 493 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 494 | + ), |
|
| 495 | + |
|
| 496 | + 'customer_ip' => array( |
|
| 497 | + 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
| 498 | + 'type' => 'string', |
|
| 499 | + 'format' => 'ip', |
|
| 500 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 501 | + ), |
|
| 502 | + |
|
| 503 | + 'first_name' => array( |
|
| 504 | + 'description' => __( "The customer's first name.", 'invoicing' ), |
|
| 505 | + 'type' => 'string', |
|
| 506 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 507 | + ), |
|
| 508 | + |
|
| 509 | + 'last_name' => array( |
|
| 510 | + 'description' => __( "The customer's last name.", 'invoicing' ), |
|
| 511 | + 'type' => 'string', |
|
| 512 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 513 | + ), |
|
| 514 | 514 | |
| 515 | - 'full_name' => array( |
|
| 516 | - 'description' => __( "The customer's full name.", 'invoicing' ), |
|
| 517 | - 'type' => 'string', |
|
| 518 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 519 | - 'readonly' => true, |
|
| 520 | - ), |
|
| 521 | - |
|
| 522 | - 'phone_number' => array( |
|
| 523 | - 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
| 524 | - 'type' => 'string', |
|
| 525 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 526 | - ), |
|
| 527 | - |
|
| 528 | - 'email_address' => array( |
|
| 529 | - 'description' => __( "The customer's email address.", 'invoicing' ), |
|
| 530 | - 'type' => 'string', |
|
| 531 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 532 | - 'readonly' => true, |
|
| 533 | - ), |
|
| 534 | - |
|
| 535 | - 'customer_country' => array( |
|
| 536 | - 'description' => __( "The customer's country.", 'invoicing' ), |
|
| 537 | - 'type' => 'string', |
|
| 538 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 539 | - 'default' => wpinv_get_default_country(), |
|
| 540 | - ), |
|
| 541 | - |
|
| 542 | - 'customer_state' => array( |
|
| 543 | - 'description' => __( "The customer's state.", 'invoicing' ), |
|
| 544 | - 'type' => 'string', |
|
| 545 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 546 | - ), |
|
| 547 | - |
|
| 548 | - 'customer_city' => array( |
|
| 549 | - 'description' => __( "The customer's city.", 'invoicing' ), |
|
| 550 | - 'type' => 'string', |
|
| 551 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 552 | - ), |
|
| 553 | - |
|
| 554 | - 'customer_zip' => array( |
|
| 555 | - 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
| 556 | - 'type' => 'string', |
|
| 557 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 558 | - ), |
|
| 559 | - |
|
| 560 | - 'customer_company' => array( |
|
| 561 | - 'description' => __( "The customer's company name.", 'invoicing' ), |
|
| 562 | - 'type' => 'string', |
|
| 563 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 564 | - ), |
|
| 565 | - |
|
| 566 | - 'vat_number' => array( |
|
| 567 | - 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
| 568 | - 'type' => 'string', |
|
| 569 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 570 | - ), |
|
| 571 | - |
|
| 572 | - 'vat_rate' => array( |
|
| 573 | - 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
| 574 | - 'type' => 'number', |
|
| 575 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 576 | - 'readonly' => true, |
|
| 577 | - ), |
|
| 578 | - |
|
| 579 | - 'customer_address' => array( |
|
| 580 | - 'description' => __( "The customer's address.", 'invoicing' ), |
|
| 581 | - 'type' => 'string', |
|
| 582 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 583 | - ), |
|
| 584 | - |
|
| 585 | - 'address_confirmed' => array( |
|
| 586 | - 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
| 587 | - 'type' => 'boolean', |
|
| 588 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 589 | - ), |
|
| 590 | - |
|
| 591 | - 'meta_data' => array( |
|
| 592 | - 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
| 593 | - 'type' => 'array', |
|
| 594 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 595 | - 'items' => array( |
|
| 596 | - 'type' => 'object', |
|
| 597 | - 'properties' => array( |
|
| 598 | - 'id' => array( |
|
| 599 | - 'description' => __( 'Meta ID.', 'invoicing' ), |
|
| 600 | - 'type' => 'string', |
|
| 601 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 602 | - ), |
|
| 603 | - 'key' => array( |
|
| 604 | - 'description' => __( 'Meta key.', 'invoicing' ), |
|
| 605 | - 'type' => 'string', |
|
| 606 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 607 | - ), |
|
| 608 | - 'value' => array( |
|
| 609 | - 'description' => __( 'Meta Value.', 'invoicing' ), |
|
| 610 | - 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
| 611 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 612 | - ), |
|
| 613 | - ), |
|
| 614 | - ), |
|
| 615 | - ), |
|
| 616 | - |
|
| 617 | - 'view_url' => array( |
|
| 618 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
| 619 | - 'type' => 'string', |
|
| 620 | - 'format' => 'uri', |
|
| 621 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 622 | - 'readonly' => true, |
|
| 623 | - ), |
|
| 624 | - |
|
| 625 | - 'checkout_payment_url' => array( |
|
| 626 | - 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
| 627 | - 'type' => 'string', |
|
| 628 | - 'format' => 'uri', |
|
| 629 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 630 | - 'readonly' => true, |
|
| 631 | - ), |
|
| 632 | - |
|
| 633 | - 'receipt_url' => array( |
|
| 634 | - 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
| 635 | - 'type' => 'string', |
|
| 636 | - 'format' => 'uri', |
|
| 637 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 638 | - 'readonly' => true, |
|
| 639 | - ), |
|
| 515 | + 'full_name' => array( |
|
| 516 | + 'description' => __( "The customer's full name.", 'invoicing' ), |
|
| 517 | + 'type' => 'string', |
|
| 518 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 519 | + 'readonly' => true, |
|
| 520 | + ), |
|
| 521 | + |
|
| 522 | + 'phone_number' => array( |
|
| 523 | + 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
| 524 | + 'type' => 'string', |
|
| 525 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 526 | + ), |
|
| 527 | + |
|
| 528 | + 'email_address' => array( |
|
| 529 | + 'description' => __( "The customer's email address.", 'invoicing' ), |
|
| 530 | + 'type' => 'string', |
|
| 531 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 532 | + 'readonly' => true, |
|
| 533 | + ), |
|
| 534 | + |
|
| 535 | + 'customer_country' => array( |
|
| 536 | + 'description' => __( "The customer's country.", 'invoicing' ), |
|
| 537 | + 'type' => 'string', |
|
| 538 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 539 | + 'default' => wpinv_get_default_country(), |
|
| 540 | + ), |
|
| 541 | + |
|
| 542 | + 'customer_state' => array( |
|
| 543 | + 'description' => __( "The customer's state.", 'invoicing' ), |
|
| 544 | + 'type' => 'string', |
|
| 545 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 546 | + ), |
|
| 547 | + |
|
| 548 | + 'customer_city' => array( |
|
| 549 | + 'description' => __( "The customer's city.", 'invoicing' ), |
|
| 550 | + 'type' => 'string', |
|
| 551 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 552 | + ), |
|
| 553 | + |
|
| 554 | + 'customer_zip' => array( |
|
| 555 | + 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
| 556 | + 'type' => 'string', |
|
| 557 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 558 | + ), |
|
| 559 | + |
|
| 560 | + 'customer_company' => array( |
|
| 561 | + 'description' => __( "The customer's company name.", 'invoicing' ), |
|
| 562 | + 'type' => 'string', |
|
| 563 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 564 | + ), |
|
| 565 | + |
|
| 566 | + 'vat_number' => array( |
|
| 567 | + 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
| 568 | + 'type' => 'string', |
|
| 569 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 570 | + ), |
|
| 571 | + |
|
| 572 | + 'vat_rate' => array( |
|
| 573 | + 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
| 574 | + 'type' => 'number', |
|
| 575 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 576 | + 'readonly' => true, |
|
| 577 | + ), |
|
| 578 | + |
|
| 579 | + 'customer_address' => array( |
|
| 580 | + 'description' => __( "The customer's address.", 'invoicing' ), |
|
| 581 | + 'type' => 'string', |
|
| 582 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 583 | + ), |
|
| 584 | + |
|
| 585 | + 'address_confirmed' => array( |
|
| 586 | + 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
| 587 | + 'type' => 'boolean', |
|
| 588 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 589 | + ), |
|
| 590 | + |
|
| 591 | + 'meta_data' => array( |
|
| 592 | + 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
| 593 | + 'type' => 'array', |
|
| 594 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 595 | + 'items' => array( |
|
| 596 | + 'type' => 'object', |
|
| 597 | + 'properties' => array( |
|
| 598 | + 'id' => array( |
|
| 599 | + 'description' => __( 'Meta ID.', 'invoicing' ), |
|
| 600 | + 'type' => 'string', |
|
| 601 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 602 | + ), |
|
| 603 | + 'key' => array( |
|
| 604 | + 'description' => __( 'Meta key.', 'invoicing' ), |
|
| 605 | + 'type' => 'string', |
|
| 606 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 607 | + ), |
|
| 608 | + 'value' => array( |
|
| 609 | + 'description' => __( 'Meta Value.', 'invoicing' ), |
|
| 610 | + 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
| 611 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 612 | + ), |
|
| 613 | + ), |
|
| 614 | + ), |
|
| 615 | + ), |
|
| 616 | + |
|
| 617 | + 'view_url' => array( |
|
| 618 | + 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
| 619 | + 'type' => 'string', |
|
| 620 | + 'format' => 'uri', |
|
| 621 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 622 | + 'readonly' => true, |
|
| 623 | + ), |
|
| 624 | + |
|
| 625 | + 'checkout_payment_url' => array( |
|
| 626 | + 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
| 627 | + 'type' => 'string', |
|
| 628 | + 'format' => 'uri', |
|
| 629 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 630 | + 'readonly' => true, |
|
| 631 | + ), |
|
| 632 | + |
|
| 633 | + 'receipt_url' => array( |
|
| 634 | + 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
| 635 | + 'type' => 'string', |
|
| 636 | + 'format' => 'uri', |
|
| 637 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 638 | + 'readonly' => true, |
|
| 639 | + ), |
|
| 640 | 640 | |
| 641 | 641 | ); |
@@ -11,166 +11,166 @@ |
||
| 11 | 11 | defined( 'ABSPATH' ) || exit; |
| 12 | 12 | |
| 13 | 13 | return array( |
| 14 | - 'AED' => 'د.إ', |
|
| 15 | - 'AFN' => '؋', |
|
| 16 | - 'ALL' => 'L', |
|
| 17 | - 'AMD' => 'AMD', |
|
| 18 | - 'ANG' => 'ƒ', |
|
| 19 | - 'AOA' => 'Kz', |
|
| 20 | - 'ARS' => '$', |
|
| 21 | - 'AUD' => '$', |
|
| 22 | - 'AWG' => 'ƒ', |
|
| 23 | - 'AZN' => 'AZN', |
|
| 24 | - 'BAM' => 'KM', |
|
| 25 | - 'BBD' => '$', |
|
| 26 | - 'BDT' => '৳', |
|
| 27 | - 'BGN' => 'лв.', |
|
| 28 | - 'BHD' => '.د.ب', |
|
| 29 | - 'BIF' => 'Fr', |
|
| 30 | - 'BMD' => '$', |
|
| 31 | - 'BND' => '$', |
|
| 32 | - 'BOB' => 'Bs.', |
|
| 33 | - 'BRL' => 'R$', |
|
| 34 | - 'BSD' => '$', |
|
| 35 | - 'BTC' => '฿', |
|
| 36 | - 'BTN' => 'Nu.', |
|
| 37 | - 'BWP' => 'P', |
|
| 38 | - 'BYN' => 'Br', |
|
| 39 | - 'BZD' => '$', |
|
| 40 | - 'CAD' => '$', |
|
| 41 | - 'CDF' => 'Fr', |
|
| 42 | - 'CHF' => 'CHF', |
|
| 43 | - 'CLP' => '$', |
|
| 44 | - 'CNY' => '¥', |
|
| 45 | - 'COP' => '$', |
|
| 46 | - 'CRC' => '₡', |
|
| 47 | - 'CUC' => '$', |
|
| 48 | - 'CUP' => '$', |
|
| 49 | - 'CVE' => '$', |
|
| 50 | - 'CZK' => 'Kč', |
|
| 51 | - 'DJF' => 'Fr', |
|
| 52 | - 'DKK' => 'DKK', |
|
| 53 | - 'DOP' => 'RD$', |
|
| 54 | - 'DZD' => 'د.ج', |
|
| 55 | - 'EGP' => 'EGP', |
|
| 56 | - 'ERN' => 'Nfk', |
|
| 57 | - 'ETB' => 'Br', |
|
| 58 | - 'EUR' => '€', |
|
| 59 | - 'FJD' => '$', |
|
| 60 | - 'FKP' => '£', |
|
| 61 | - 'GBP' => '£', |
|
| 62 | - 'GEL' => 'ლ', |
|
| 63 | - 'GGP' => '£', |
|
| 64 | - 'GHS' => '₵', |
|
| 65 | - 'GIP' => '£', |
|
| 66 | - 'GMD' => 'D', |
|
| 67 | - 'GNF' => 'Fr', |
|
| 68 | - 'GTQ' => 'Q', |
|
| 69 | - 'GYD' => '$', |
|
| 70 | - 'HKD' => '$', |
|
| 71 | - 'HNL' => 'L', |
|
| 72 | - 'HRK' => 'Kn', |
|
| 73 | - 'HTG' => 'G', |
|
| 74 | - 'HUF' => 'Ft', |
|
| 75 | - 'IDR' => 'Rp', |
|
| 76 | - 'ILS' => '₪', |
|
| 77 | - 'IMP' => '£', |
|
| 78 | - 'INR' => '₹', |
|
| 79 | - 'IQD' => 'ع.د', |
|
| 80 | - 'IRR' => '﷼', |
|
| 81 | - 'IRT' => 'تومان', |
|
| 82 | - 'ISK' => 'kr.', |
|
| 83 | - 'JEP' => '£', |
|
| 84 | - 'JMD' => '$', |
|
| 85 | - 'JOD' => 'د.ا', |
|
| 86 | - 'JPY' => '¥', |
|
| 87 | - 'KES' => 'KSh', |
|
| 88 | - 'KGS' => 'сом', |
|
| 89 | - 'KHR' => '៛', |
|
| 90 | - 'KMF' => 'Fr', |
|
| 91 | - 'KPW' => '₩', |
|
| 92 | - 'KRW' => '₩', |
|
| 93 | - 'KWD' => 'د.ك', |
|
| 94 | - 'KYD' => '$', |
|
| 95 | - 'KZT' => 'KZT', |
|
| 96 | - 'LAK' => '₭', |
|
| 97 | - 'LBP' => 'ل.ل', |
|
| 98 | - 'LKR' => 'රු', |
|
| 99 | - 'LRD' => '$', |
|
| 100 | - 'LSL' => 'L', |
|
| 101 | - 'LYD' => 'ل.د', |
|
| 102 | - 'MAD' => 'د.م.', |
|
| 103 | - 'MDL' => 'MDL', |
|
| 104 | - 'MGA' => 'Ar', |
|
| 105 | - 'MKD' => 'ден', |
|
| 106 | - 'MMK' => 'Ks', |
|
| 107 | - 'MNT' => '₮', |
|
| 108 | - 'MOP' => 'P', |
|
| 109 | - 'MRO' => 'UM', |
|
| 110 | - 'MUR' => '₨', |
|
| 111 | - 'MVR' => '.ރ', |
|
| 112 | - 'MWK' => 'MK', |
|
| 113 | - 'MXN' => '$', |
|
| 114 | - 'MYR' => 'RM', |
|
| 115 | - 'MZN' => 'MT', |
|
| 116 | - 'NAD' => '$', |
|
| 117 | - 'NGN' => '₦', |
|
| 118 | - 'NIO' => 'C$', |
|
| 119 | - 'NOK' => 'kr', |
|
| 120 | - 'NPR' => '₨', |
|
| 121 | - 'NZD' => '$', |
|
| 122 | - 'OMR' => 'ر.ع.', |
|
| 123 | - 'PAB' => 'B/.', |
|
| 124 | - 'PEN' => 'S/.', |
|
| 125 | - 'PGK' => 'K', |
|
| 126 | - 'PHP' => '₱', |
|
| 127 | - 'PKR' => '₨', |
|
| 128 | - 'PLN' => 'zł', |
|
| 129 | - 'PRB' => 'р.', |
|
| 130 | - 'PYG' => '₲', |
|
| 131 | - 'QAR' => 'ر.ق', |
|
| 132 | - 'RMB' => '¥', |
|
| 133 | - 'RON' => 'lei', |
|
| 134 | - 'RSD' => 'дин.', |
|
| 135 | - 'RUB' => '₽', |
|
| 136 | - 'RWF' => 'Fr', |
|
| 137 | - 'SAR' => 'ر.س', |
|
| 138 | - 'SBD' => '$', |
|
| 139 | - 'SCR' => '₨', |
|
| 140 | - 'SDG' => 'ج.س.', |
|
| 141 | - 'SEK' => 'kr', |
|
| 142 | - 'SGD' => '$', |
|
| 143 | - 'SHP' => '£', |
|
| 144 | - 'SLL' => 'Le', |
|
| 145 | - 'SOS' => 'Sh', |
|
| 146 | - 'SRD' => '$', |
|
| 147 | - 'SSP' => '£', |
|
| 148 | - 'STD' => 'Db', |
|
| 149 | - 'SYP' => 'ل.س', |
|
| 150 | - 'SZL' => 'L', |
|
| 151 | - 'THB' => '฿', |
|
| 152 | - 'TJS' => 'ЅМ', |
|
| 153 | - 'TMT' => 'm', |
|
| 154 | - 'TND' => 'د.ت', |
|
| 155 | - 'TOP' => 'T$', |
|
| 156 | - 'TRY' => '₺', |
|
| 157 | - 'TTD' => '$', |
|
| 158 | - 'TWD' => 'NT$', |
|
| 159 | - 'TZS' => 'Sh', |
|
| 160 | - 'UAH' => '₴', |
|
| 161 | - 'UGX' => 'UGX', |
|
| 162 | - 'USD' => '$', |
|
| 163 | - 'UYU' => '$', |
|
| 164 | - 'UZS' => 'UZS', |
|
| 165 | - 'VEF' => 'Bs.', |
|
| 166 | - 'VND' => '₫', |
|
| 167 | - 'VUV' => 'Vt', |
|
| 168 | - 'WST' => 'T', |
|
| 169 | - 'XAF' => 'Fr', |
|
| 170 | - 'XCD' => '$', |
|
| 171 | - 'XOF' => 'Fr', |
|
| 172 | - 'XPF' => 'Fr', |
|
| 173 | - 'YER' => '﷼', |
|
| 174 | - 'ZAR' => 'R', |
|
| 175 | - 'ZMW' => 'ZK', |
|
| 14 | + 'AED' => 'د.إ', |
|
| 15 | + 'AFN' => '؋', |
|
| 16 | + 'ALL' => 'L', |
|
| 17 | + 'AMD' => 'AMD', |
|
| 18 | + 'ANG' => 'ƒ', |
|
| 19 | + 'AOA' => 'Kz', |
|
| 20 | + 'ARS' => '$', |
|
| 21 | + 'AUD' => '$', |
|
| 22 | + 'AWG' => 'ƒ', |
|
| 23 | + 'AZN' => 'AZN', |
|
| 24 | + 'BAM' => 'KM', |
|
| 25 | + 'BBD' => '$', |
|
| 26 | + 'BDT' => '৳', |
|
| 27 | + 'BGN' => 'лв.', |
|
| 28 | + 'BHD' => '.د.ب', |
|
| 29 | + 'BIF' => 'Fr', |
|
| 30 | + 'BMD' => '$', |
|
| 31 | + 'BND' => '$', |
|
| 32 | + 'BOB' => 'Bs.', |
|
| 33 | + 'BRL' => 'R$', |
|
| 34 | + 'BSD' => '$', |
|
| 35 | + 'BTC' => '฿', |
|
| 36 | + 'BTN' => 'Nu.', |
|
| 37 | + 'BWP' => 'P', |
|
| 38 | + 'BYN' => 'Br', |
|
| 39 | + 'BZD' => '$', |
|
| 40 | + 'CAD' => '$', |
|
| 41 | + 'CDF' => 'Fr', |
|
| 42 | + 'CHF' => 'CHF', |
|
| 43 | + 'CLP' => '$', |
|
| 44 | + 'CNY' => '¥', |
|
| 45 | + 'COP' => '$', |
|
| 46 | + 'CRC' => '₡', |
|
| 47 | + 'CUC' => '$', |
|
| 48 | + 'CUP' => '$', |
|
| 49 | + 'CVE' => '$', |
|
| 50 | + 'CZK' => 'Kč', |
|
| 51 | + 'DJF' => 'Fr', |
|
| 52 | + 'DKK' => 'DKK', |
|
| 53 | + 'DOP' => 'RD$', |
|
| 54 | + 'DZD' => 'د.ج', |
|
| 55 | + 'EGP' => 'EGP', |
|
| 56 | + 'ERN' => 'Nfk', |
|
| 57 | + 'ETB' => 'Br', |
|
| 58 | + 'EUR' => '€', |
|
| 59 | + 'FJD' => '$', |
|
| 60 | + 'FKP' => '£', |
|
| 61 | + 'GBP' => '£', |
|
| 62 | + 'GEL' => 'ლ', |
|
| 63 | + 'GGP' => '£', |
|
| 64 | + 'GHS' => '₵', |
|
| 65 | + 'GIP' => '£', |
|
| 66 | + 'GMD' => 'D', |
|
| 67 | + 'GNF' => 'Fr', |
|
| 68 | + 'GTQ' => 'Q', |
|
| 69 | + 'GYD' => '$', |
|
| 70 | + 'HKD' => '$', |
|
| 71 | + 'HNL' => 'L', |
|
| 72 | + 'HRK' => 'Kn', |
|
| 73 | + 'HTG' => 'G', |
|
| 74 | + 'HUF' => 'Ft', |
|
| 75 | + 'IDR' => 'Rp', |
|
| 76 | + 'ILS' => '₪', |
|
| 77 | + 'IMP' => '£', |
|
| 78 | + 'INR' => '₹', |
|
| 79 | + 'IQD' => 'ع.د', |
|
| 80 | + 'IRR' => '﷼', |
|
| 81 | + 'IRT' => 'تومان', |
|
| 82 | + 'ISK' => 'kr.', |
|
| 83 | + 'JEP' => '£', |
|
| 84 | + 'JMD' => '$', |
|
| 85 | + 'JOD' => 'د.ا', |
|
| 86 | + 'JPY' => '¥', |
|
| 87 | + 'KES' => 'KSh', |
|
| 88 | + 'KGS' => 'сом', |
|
| 89 | + 'KHR' => '៛', |
|
| 90 | + 'KMF' => 'Fr', |
|
| 91 | + 'KPW' => '₩', |
|
| 92 | + 'KRW' => '₩', |
|
| 93 | + 'KWD' => 'د.ك', |
|
| 94 | + 'KYD' => '$', |
|
| 95 | + 'KZT' => 'KZT', |
|
| 96 | + 'LAK' => '₭', |
|
| 97 | + 'LBP' => 'ل.ل', |
|
| 98 | + 'LKR' => 'රු', |
|
| 99 | + 'LRD' => '$', |
|
| 100 | + 'LSL' => 'L', |
|
| 101 | + 'LYD' => 'ل.د', |
|
| 102 | + 'MAD' => 'د.م.', |
|
| 103 | + 'MDL' => 'MDL', |
|
| 104 | + 'MGA' => 'Ar', |
|
| 105 | + 'MKD' => 'ден', |
|
| 106 | + 'MMK' => 'Ks', |
|
| 107 | + 'MNT' => '₮', |
|
| 108 | + 'MOP' => 'P', |
|
| 109 | + 'MRO' => 'UM', |
|
| 110 | + 'MUR' => '₨', |
|
| 111 | + 'MVR' => '.ރ', |
|
| 112 | + 'MWK' => 'MK', |
|
| 113 | + 'MXN' => '$', |
|
| 114 | + 'MYR' => 'RM', |
|
| 115 | + 'MZN' => 'MT', |
|
| 116 | + 'NAD' => '$', |
|
| 117 | + 'NGN' => '₦', |
|
| 118 | + 'NIO' => 'C$', |
|
| 119 | + 'NOK' => 'kr', |
|
| 120 | + 'NPR' => '₨', |
|
| 121 | + 'NZD' => '$', |
|
| 122 | + 'OMR' => 'ر.ع.', |
|
| 123 | + 'PAB' => 'B/.', |
|
| 124 | + 'PEN' => 'S/.', |
|
| 125 | + 'PGK' => 'K', |
|
| 126 | + 'PHP' => '₱', |
|
| 127 | + 'PKR' => '₨', |
|
| 128 | + 'PLN' => 'zł', |
|
| 129 | + 'PRB' => 'р.', |
|
| 130 | + 'PYG' => '₲', |
|
| 131 | + 'QAR' => 'ر.ق', |
|
| 132 | + 'RMB' => '¥', |
|
| 133 | + 'RON' => 'lei', |
|
| 134 | + 'RSD' => 'дин.', |
|
| 135 | + 'RUB' => '₽', |
|
| 136 | + 'RWF' => 'Fr', |
|
| 137 | + 'SAR' => 'ر.س', |
|
| 138 | + 'SBD' => '$', |
|
| 139 | + 'SCR' => '₨', |
|
| 140 | + 'SDG' => 'ج.س.', |
|
| 141 | + 'SEK' => 'kr', |
|
| 142 | + 'SGD' => '$', |
|
| 143 | + 'SHP' => '£', |
|
| 144 | + 'SLL' => 'Le', |
|
| 145 | + 'SOS' => 'Sh', |
|
| 146 | + 'SRD' => '$', |
|
| 147 | + 'SSP' => '£', |
|
| 148 | + 'STD' => 'Db', |
|
| 149 | + 'SYP' => 'ل.س', |
|
| 150 | + 'SZL' => 'L', |
|
| 151 | + 'THB' => '฿', |
|
| 152 | + 'TJS' => 'ЅМ', |
|
| 153 | + 'TMT' => 'm', |
|
| 154 | + 'TND' => 'د.ت', |
|
| 155 | + 'TOP' => 'T$', |
|
| 156 | + 'TRY' => '₺', |
|
| 157 | + 'TTD' => '$', |
|
| 158 | + 'TWD' => 'NT$', |
|
| 159 | + 'TZS' => 'Sh', |
|
| 160 | + 'UAH' => '₴', |
|
| 161 | + 'UGX' => 'UGX', |
|
| 162 | + 'USD' => '$', |
|
| 163 | + 'UYU' => '$', |
|
| 164 | + 'UZS' => 'UZS', |
|
| 165 | + 'VEF' => 'Bs.', |
|
| 166 | + 'VND' => '₫', |
|
| 167 | + 'VUV' => 'Vt', |
|
| 168 | + 'WST' => 'T', |
|
| 169 | + 'XAF' => 'Fr', |
|
| 170 | + 'XCD' => '$', |
|
| 171 | + 'XOF' => 'Fr', |
|
| 172 | + 'XPF' => 'Fr', |
|
| 173 | + 'YER' => '﷼', |
|
| 174 | + 'ZAR' => 'R', |
|
| 175 | + 'ZMW' => 'ZK', |
|
| 176 | 176 | ); |
@@ -11,165 +11,165 @@ |
||
| 11 | 11 | defined( 'ABSPATH' ) || exit; |
| 12 | 12 | |
| 13 | 13 | return array( |
| 14 | - 'USD' => __( 'US Dollar', 'invoicing' ), |
|
| 15 | - 'EUR' => __( 'Euro', 'invoicing' ), |
|
| 16 | - 'GBP' => __( 'Pound Sterling', 'invoicing' ), |
|
| 17 | - 'AED' => __( 'United Arab Emirates', 'invoicing' ), |
|
| 18 | - 'AFN' => __( 'Afghan Afghani', 'invoicing' ), |
|
| 19 | - 'ALL' => __( 'Albanian Lek', 'invoicing' ), |
|
| 20 | - 'AMD' => __( 'Armenian Dram', 'invoicing' ), |
|
| 21 | - 'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ), |
|
| 22 | - 'AOA' => __( 'Angolan Kwanza', 'invoicing' ), |
|
| 23 | - 'ARS' => __( 'Argentine Peso', 'invoicing' ), |
|
| 24 | - 'AUD' => __( 'Australian Dollar', 'invoicing' ), |
|
| 25 | - 'AWG' => __( 'Aruban Florin', 'invoicing' ), |
|
| 26 | - 'AZN' => __( 'Azerbaijani Manat', 'invoicing' ), |
|
| 27 | - 'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ), |
|
| 28 | - 'BBD' => __( 'Barbadian Dollar', 'invoicing' ), |
|
| 29 | - 'BDT' => __( 'Bangladeshi Taka', 'invoicing' ), |
|
| 30 | - 'BGN' => __( 'Bulgarian Lev', 'invoicing' ), |
|
| 31 | - 'BHD' => __( 'Bahraini Dinar', 'invoicing' ), |
|
| 32 | - 'BIF' => __( 'Burundian Franc', 'invoicing' ), |
|
| 33 | - 'BMD' => __( 'Bermudian Dollar', 'invoicing' ), |
|
| 34 | - 'BND' => __( 'Brunei Dollar', 'invoicing' ), |
|
| 35 | - 'BOB' => __( 'Bolivian Boliviano', 'invoicing' ), |
|
| 36 | - 'BRL' => __( 'Brazilian Real', 'invoicing' ), |
|
| 37 | - 'BSD' => __( 'Bahamian Dollar', 'invoicing' ), |
|
| 38 | - 'BTC' => __( 'Bitcoin', 'invoicing' ), |
|
| 39 | - 'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ), |
|
| 40 | - 'BWP' => __( 'Botswana Pula', 'invoicing' ), |
|
| 41 | - 'BYN' => __( 'Belarusian Ruble', 'invoicing' ), |
|
| 42 | - 'BZD' => __( 'Belize Dollar', 'invoicing' ), |
|
| 43 | - 'CAD' => __( 'Canadian Dollar', 'invoicing' ), |
|
| 44 | - 'CDF' => __( 'Congolese Franc', 'invoicing' ), |
|
| 45 | - 'CHF' => __( 'Swiss Franc', 'invoicing' ), |
|
| 46 | - 'CLP' => __( 'Chilean Peso', 'invoicing' ), |
|
| 47 | - 'CNY' => __( 'Chinese Yuan', 'invoicing' ), |
|
| 48 | - 'COP' => __( 'Colombian Peso', 'invoicing' ), |
|
| 49 | - 'CRC' => __( 'Costa Rican Colon', 'invoicing' ), |
|
| 50 | - 'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ), |
|
| 51 | - 'CUP' => __( 'Cuban Peso', 'invoicing' ), |
|
| 52 | - 'CVE' => __( 'Cape Verdean escudo', 'invoicing' ), |
|
| 53 | - 'CZK' => __( 'Czech Koruna', 'invoicing' ), |
|
| 54 | - 'DJF' => __( 'Djiboutian Franc', 'invoicing' ), |
|
| 55 | - 'DKK' => __( 'Danish Krone', 'invoicing' ), |
|
| 56 | - 'DOP' => __( 'Dominican Peso', 'invoicing' ), |
|
| 57 | - 'DZD' => __( 'Algerian Dinar', 'invoicing' ), |
|
| 58 | - 'EGP' => __( 'Egyptian Pound', 'invoicing' ), |
|
| 59 | - 'ERN' => __( 'Eritrean Nakfa', 'invoicing' ), |
|
| 60 | - 'ETB' => __( 'Ethiopian Irr', 'invoicing' ), |
|
| 61 | - 'FJD' => __( 'Fijian Dollar', 'invoicing' ), |
|
| 62 | - 'FKP' => __( 'Falkland Islands Pound', 'invoicing' ), |
|
| 63 | - 'GEL' => __( 'Georgian Lari', 'invoicing' ), |
|
| 64 | - 'GGP' => __( 'Guernsey Pound', 'invoicing' ), |
|
| 65 | - 'GHS' => __( 'Ghana Cedi', 'invoicing' ), |
|
| 66 | - 'GIP' => __( 'Gibraltar Pound', 'invoicing' ), |
|
| 67 | - 'GMD' => __( 'Gambian Dalasi', 'invoicing' ), |
|
| 68 | - 'GNF' => __( 'Guinean Franc', 'invoicing' ), |
|
| 69 | - 'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ), |
|
| 70 | - 'GYD' => __( 'Guyanese Dollar', 'invoicing' ), |
|
| 71 | - 'HKD' => __( 'Hong Kong Dollar', 'invoicing' ), |
|
| 72 | - 'HNL' => __( 'Honduran Lempira', 'invoicing' ), |
|
| 73 | - 'HRK' => __( 'Croatian Kuna', 'invoicing' ), |
|
| 74 | - 'HTG' => __( 'Haitian Gourde', 'invoicing' ), |
|
| 75 | - 'HUF' => __( 'Hungarian Forint', 'invoicing' ), |
|
| 76 | - 'IDR' => __( 'Indonesian Rupiah', 'invoicing' ), |
|
| 77 | - 'ILS' => __( 'Israeli New Shekel', 'invoicing' ), |
|
| 78 | - 'IMP' => __( 'Manx Pound', 'invoicing' ), |
|
| 79 | - 'INR' => __( 'Indian Rupee', 'invoicing' ), |
|
| 80 | - 'IQD' => __( 'Iraqi Dinar', 'invoicing' ), |
|
| 81 | - 'IRR' => __( 'Iranian Rial', 'invoicing' ), |
|
| 82 | - 'IRT' => __( 'Iranian Toman', 'invoicing' ), |
|
| 83 | - 'ISK' => __( 'Icelandic Krona', 'invoicing' ), |
|
| 84 | - 'JEP' => __( 'Jersey Pound', 'invoicing' ), |
|
| 85 | - 'JMD' => __( 'Jamaican Dollar', 'invoicing' ), |
|
| 86 | - 'JOD' => __( 'Jordanian Dinar', 'invoicing' ), |
|
| 87 | - 'JPY' => __( 'Japanese Yen', 'invoicing' ), |
|
| 88 | - 'KES' => __( 'Kenyan Shilling', 'invoicing' ), |
|
| 89 | - 'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ), |
|
| 90 | - 'KHR' => __( 'Cambodian Riel', 'invoicing' ), |
|
| 91 | - 'KMF' => __( 'Comorian Franc', 'invoicing' ), |
|
| 92 | - 'KPW' => __( 'North Korean Won', 'invoicing' ), |
|
| 93 | - 'KRW' => __( 'South Korean Won', 'invoicing' ), |
|
| 94 | - 'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ), |
|
| 95 | - 'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ), |
|
| 96 | - 'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ), |
|
| 97 | - 'LAK' => __( 'Lao Kip', 'invoicing' ), |
|
| 98 | - 'LBP' => __( 'Lebanese Pound', 'invoicing' ), |
|
| 99 | - 'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ), |
|
| 100 | - 'LRD' => __( 'Liberian Dollar', 'invoicing' ), |
|
| 101 | - 'LSL' => __( 'Lesotho Loti', 'invoicing' ), |
|
| 102 | - 'LYD' => __( 'Libyan Dinar', 'invoicing' ), |
|
| 103 | - 'MAD' => __( 'Moroccan Dirham', 'invoicing' ), |
|
| 104 | - 'MDL' => __( 'Moldovan Leu', 'invoicing' ), |
|
| 105 | - 'MGA' => __( 'Malagasy Ariary', 'invoicing' ), |
|
| 106 | - 'MKD' => __( 'Macedonian Denar', 'invoicing' ), |
|
| 107 | - 'MMK' => __( 'Burmese Kyat', 'invoicing' ), |
|
| 108 | - 'MNT' => __( 'Mongolian Tughrik', 'invoicing' ), |
|
| 109 | - 'MOP' => __( 'Macanese Pataca', 'invoicing' ), |
|
| 110 | - 'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ), |
|
| 111 | - 'MUR' => __( 'Mauritian Rupee', 'invoicing' ), |
|
| 112 | - 'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ), |
|
| 113 | - 'MWK' => __( 'Malawian Kwacha', 'invoicing' ), |
|
| 114 | - 'MXN' => __( 'Mexican Peso', 'invoicing' ), |
|
| 115 | - 'MYR' => __( 'Malaysian Ringgit', 'invoicing' ), |
|
| 116 | - 'MZN' => __( 'Mozambican Metical', 'invoicing' ), |
|
| 117 | - 'NAD' => __( 'Namibian Dollar', 'invoicing' ), |
|
| 118 | - 'NGN' => __( 'Nigerian Naira', 'invoicing' ), |
|
| 119 | - 'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ), |
|
| 120 | - 'NOK' => __( 'Norwegian Krone', 'invoicing' ), |
|
| 121 | - 'NPR' => __( 'Nepalese Rupee', 'invoicing' ), |
|
| 122 | - 'NZD' => __( 'New Zealand Dollar', 'invoicing' ), |
|
| 123 | - 'OMR' => __( 'Omani Rial', 'invoicing' ), |
|
| 124 | - 'PAB' => __( 'Panamanian Balboa', 'invoicing' ), |
|
| 125 | - 'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ), |
|
| 126 | - 'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ), |
|
| 127 | - 'PHP' => __( 'Philippine Peso', 'invoicing' ), |
|
| 128 | - 'PKR' => __( 'Pakistani Rupee', 'invoicing' ), |
|
| 129 | - 'PLN' => __( 'Polish Zloty', 'invoicing' ), |
|
| 130 | - 'PRB' => __( 'Transnistrian Ruble', 'invoicing' ), |
|
| 131 | - 'PYG' => __( 'Paraguayan Guarani', 'invoicing' ), |
|
| 132 | - 'QAR' => __( 'Qatari Riyal', 'invoicing' ), |
|
| 133 | - 'RON' => __( 'Romanian Leu', 'invoicing' ), |
|
| 134 | - 'RSD' => __( 'Serbian Dinar', 'invoicing' ), |
|
| 135 | - 'RUB' => __( 'Russian Ruble', 'invoicing' ), |
|
| 136 | - 'RWF' => __( 'Rwandan Franc', 'invoicing' ), |
|
| 137 | - 'SAR' => __( 'Saudi Riyal', 'invoicing' ), |
|
| 138 | - 'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ), |
|
| 139 | - 'SCR' => __( 'Seychellois Rupee', 'invoicing' ), |
|
| 140 | - 'SDG' => __( 'Sudanese Pound', 'invoicing' ), |
|
| 141 | - 'SEK' => __( 'Swedish Krona', 'invoicing' ), |
|
| 142 | - 'SGD' => __( 'Singapore Dollar', 'invoicing' ), |
|
| 143 | - 'SHP' => __( 'Saint Helena Pound', 'invoicing' ), |
|
| 144 | - 'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ), |
|
| 145 | - 'SOS' => __( 'Somali Shilling', 'invoicing' ), |
|
| 146 | - 'SRD' => __( 'Surinamese Dollar', 'invoicing' ), |
|
| 147 | - 'SSP' => __( 'South Sudanese Pound', 'invoicing' ), |
|
| 148 | - 'STD' => __( 'Sao Tomean Dobra', 'invoicing' ), |
|
| 149 | - 'SYP' => __( 'Syrian Pound', 'invoicing' ), |
|
| 150 | - 'SZL' => __( 'Swazi Lilangeni', 'invoicing' ), |
|
| 151 | - 'THB' => __( 'Thai Baht', 'invoicing' ), |
|
| 152 | - 'TJS' => __( 'Tajikistani Somoni', 'invoicing' ), |
|
| 153 | - 'TMT' => __( 'Turkmenistan Manat', 'invoicing' ), |
|
| 154 | - 'TND' => __( 'Tunisian Dinar', 'invoicing' ), |
|
| 155 | - 'TOP' => __( 'Tongan Paʻanga', 'invoicing' ), |
|
| 156 | - 'TRY' => __( 'Turkish Lira', 'invoicing' ), |
|
| 157 | - 'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ), |
|
| 158 | - 'TWD' => __( 'New Taiwan Dollar', 'invoicing' ), |
|
| 159 | - 'TZS' => __( 'Tanzanian Shilling', 'invoicing' ), |
|
| 160 | - 'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ), |
|
| 161 | - 'UGX' => __( 'Ugandan Shilling', 'invoicing' ), |
|
| 162 | - 'UYU' => __( 'Uruguayan Peso', 'invoicing' ), |
|
| 163 | - 'UZS' => __( 'Uzbekistani Som', 'invoicing' ), |
|
| 164 | - 'VEF' => __( 'Venezuelan Bolívar', 'invoicing' ), |
|
| 165 | - 'VND' => __( 'Vietnamese Dong', 'invoicing' ), |
|
| 166 | - 'VUV' => __( 'Vanuatu Vatu', 'invoicing' ), |
|
| 167 | - 'WST' => __( 'Samoan Tala', 'invoicing' ), |
|
| 168 | - 'XAF' => __( 'Central African CFA Franc', 'invoicing' ), |
|
| 169 | - 'XCD' => __( 'East Caribbean Dollar', 'invoicing' ), |
|
| 170 | - 'XOF' => __( 'West African CFA Franc', 'invoicing' ), |
|
| 171 | - 'XPF' => __( 'CFP Franc', 'invoicing' ), |
|
| 172 | - 'YER' => __( 'Yemeni Rial', 'invoicing' ), |
|
| 173 | - 'ZAR' => __( 'South African Rand', 'invoicing' ), |
|
| 174 | - 'ZMW' => __( 'Zambian Kwacha', 'invoicing' ), |
|
| 14 | + 'USD' => __( 'US Dollar', 'invoicing' ), |
|
| 15 | + 'EUR' => __( 'Euro', 'invoicing' ), |
|
| 16 | + 'GBP' => __( 'Pound Sterling', 'invoicing' ), |
|
| 17 | + 'AED' => __( 'United Arab Emirates', 'invoicing' ), |
|
| 18 | + 'AFN' => __( 'Afghan Afghani', 'invoicing' ), |
|
| 19 | + 'ALL' => __( 'Albanian Lek', 'invoicing' ), |
|
| 20 | + 'AMD' => __( 'Armenian Dram', 'invoicing' ), |
|
| 21 | + 'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ), |
|
| 22 | + 'AOA' => __( 'Angolan Kwanza', 'invoicing' ), |
|
| 23 | + 'ARS' => __( 'Argentine Peso', 'invoicing' ), |
|
| 24 | + 'AUD' => __( 'Australian Dollar', 'invoicing' ), |
|
| 25 | + 'AWG' => __( 'Aruban Florin', 'invoicing' ), |
|
| 26 | + 'AZN' => __( 'Azerbaijani Manat', 'invoicing' ), |
|
| 27 | + 'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ), |
|
| 28 | + 'BBD' => __( 'Barbadian Dollar', 'invoicing' ), |
|
| 29 | + 'BDT' => __( 'Bangladeshi Taka', 'invoicing' ), |
|
| 30 | + 'BGN' => __( 'Bulgarian Lev', 'invoicing' ), |
|
| 31 | + 'BHD' => __( 'Bahraini Dinar', 'invoicing' ), |
|
| 32 | + 'BIF' => __( 'Burundian Franc', 'invoicing' ), |
|
| 33 | + 'BMD' => __( 'Bermudian Dollar', 'invoicing' ), |
|
| 34 | + 'BND' => __( 'Brunei Dollar', 'invoicing' ), |
|
| 35 | + 'BOB' => __( 'Bolivian Boliviano', 'invoicing' ), |
|
| 36 | + 'BRL' => __( 'Brazilian Real', 'invoicing' ), |
|
| 37 | + 'BSD' => __( 'Bahamian Dollar', 'invoicing' ), |
|
| 38 | + 'BTC' => __( 'Bitcoin', 'invoicing' ), |
|
| 39 | + 'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ), |
|
| 40 | + 'BWP' => __( 'Botswana Pula', 'invoicing' ), |
|
| 41 | + 'BYN' => __( 'Belarusian Ruble', 'invoicing' ), |
|
| 42 | + 'BZD' => __( 'Belize Dollar', 'invoicing' ), |
|
| 43 | + 'CAD' => __( 'Canadian Dollar', 'invoicing' ), |
|
| 44 | + 'CDF' => __( 'Congolese Franc', 'invoicing' ), |
|
| 45 | + 'CHF' => __( 'Swiss Franc', 'invoicing' ), |
|
| 46 | + 'CLP' => __( 'Chilean Peso', 'invoicing' ), |
|
| 47 | + 'CNY' => __( 'Chinese Yuan', 'invoicing' ), |
|
| 48 | + 'COP' => __( 'Colombian Peso', 'invoicing' ), |
|
| 49 | + 'CRC' => __( 'Costa Rican Colon', 'invoicing' ), |
|
| 50 | + 'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ), |
|
| 51 | + 'CUP' => __( 'Cuban Peso', 'invoicing' ), |
|
| 52 | + 'CVE' => __( 'Cape Verdean escudo', 'invoicing' ), |
|
| 53 | + 'CZK' => __( 'Czech Koruna', 'invoicing' ), |
|
| 54 | + 'DJF' => __( 'Djiboutian Franc', 'invoicing' ), |
|
| 55 | + 'DKK' => __( 'Danish Krone', 'invoicing' ), |
|
| 56 | + 'DOP' => __( 'Dominican Peso', 'invoicing' ), |
|
| 57 | + 'DZD' => __( 'Algerian Dinar', 'invoicing' ), |
|
| 58 | + 'EGP' => __( 'Egyptian Pound', 'invoicing' ), |
|
| 59 | + 'ERN' => __( 'Eritrean Nakfa', 'invoicing' ), |
|
| 60 | + 'ETB' => __( 'Ethiopian Irr', 'invoicing' ), |
|
| 61 | + 'FJD' => __( 'Fijian Dollar', 'invoicing' ), |
|
| 62 | + 'FKP' => __( 'Falkland Islands Pound', 'invoicing' ), |
|
| 63 | + 'GEL' => __( 'Georgian Lari', 'invoicing' ), |
|
| 64 | + 'GGP' => __( 'Guernsey Pound', 'invoicing' ), |
|
| 65 | + 'GHS' => __( 'Ghana Cedi', 'invoicing' ), |
|
| 66 | + 'GIP' => __( 'Gibraltar Pound', 'invoicing' ), |
|
| 67 | + 'GMD' => __( 'Gambian Dalasi', 'invoicing' ), |
|
| 68 | + 'GNF' => __( 'Guinean Franc', 'invoicing' ), |
|
| 69 | + 'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ), |
|
| 70 | + 'GYD' => __( 'Guyanese Dollar', 'invoicing' ), |
|
| 71 | + 'HKD' => __( 'Hong Kong Dollar', 'invoicing' ), |
|
| 72 | + 'HNL' => __( 'Honduran Lempira', 'invoicing' ), |
|
| 73 | + 'HRK' => __( 'Croatian Kuna', 'invoicing' ), |
|
| 74 | + 'HTG' => __( 'Haitian Gourde', 'invoicing' ), |
|
| 75 | + 'HUF' => __( 'Hungarian Forint', 'invoicing' ), |
|
| 76 | + 'IDR' => __( 'Indonesian Rupiah', 'invoicing' ), |
|
| 77 | + 'ILS' => __( 'Israeli New Shekel', 'invoicing' ), |
|
| 78 | + 'IMP' => __( 'Manx Pound', 'invoicing' ), |
|
| 79 | + 'INR' => __( 'Indian Rupee', 'invoicing' ), |
|
| 80 | + 'IQD' => __( 'Iraqi Dinar', 'invoicing' ), |
|
| 81 | + 'IRR' => __( 'Iranian Rial', 'invoicing' ), |
|
| 82 | + 'IRT' => __( 'Iranian Toman', 'invoicing' ), |
|
| 83 | + 'ISK' => __( 'Icelandic Krona', 'invoicing' ), |
|
| 84 | + 'JEP' => __( 'Jersey Pound', 'invoicing' ), |
|
| 85 | + 'JMD' => __( 'Jamaican Dollar', 'invoicing' ), |
|
| 86 | + 'JOD' => __( 'Jordanian Dinar', 'invoicing' ), |
|
| 87 | + 'JPY' => __( 'Japanese Yen', 'invoicing' ), |
|
| 88 | + 'KES' => __( 'Kenyan Shilling', 'invoicing' ), |
|
| 89 | + 'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ), |
|
| 90 | + 'KHR' => __( 'Cambodian Riel', 'invoicing' ), |
|
| 91 | + 'KMF' => __( 'Comorian Franc', 'invoicing' ), |
|
| 92 | + 'KPW' => __( 'North Korean Won', 'invoicing' ), |
|
| 93 | + 'KRW' => __( 'South Korean Won', 'invoicing' ), |
|
| 94 | + 'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ), |
|
| 95 | + 'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ), |
|
| 96 | + 'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ), |
|
| 97 | + 'LAK' => __( 'Lao Kip', 'invoicing' ), |
|
| 98 | + 'LBP' => __( 'Lebanese Pound', 'invoicing' ), |
|
| 99 | + 'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ), |
|
| 100 | + 'LRD' => __( 'Liberian Dollar', 'invoicing' ), |
|
| 101 | + 'LSL' => __( 'Lesotho Loti', 'invoicing' ), |
|
| 102 | + 'LYD' => __( 'Libyan Dinar', 'invoicing' ), |
|
| 103 | + 'MAD' => __( 'Moroccan Dirham', 'invoicing' ), |
|
| 104 | + 'MDL' => __( 'Moldovan Leu', 'invoicing' ), |
|
| 105 | + 'MGA' => __( 'Malagasy Ariary', 'invoicing' ), |
|
| 106 | + 'MKD' => __( 'Macedonian Denar', 'invoicing' ), |
|
| 107 | + 'MMK' => __( 'Burmese Kyat', 'invoicing' ), |
|
| 108 | + 'MNT' => __( 'Mongolian Tughrik', 'invoicing' ), |
|
| 109 | + 'MOP' => __( 'Macanese Pataca', 'invoicing' ), |
|
| 110 | + 'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ), |
|
| 111 | + 'MUR' => __( 'Mauritian Rupee', 'invoicing' ), |
|
| 112 | + 'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ), |
|
| 113 | + 'MWK' => __( 'Malawian Kwacha', 'invoicing' ), |
|
| 114 | + 'MXN' => __( 'Mexican Peso', 'invoicing' ), |
|
| 115 | + 'MYR' => __( 'Malaysian Ringgit', 'invoicing' ), |
|
| 116 | + 'MZN' => __( 'Mozambican Metical', 'invoicing' ), |
|
| 117 | + 'NAD' => __( 'Namibian Dollar', 'invoicing' ), |
|
| 118 | + 'NGN' => __( 'Nigerian Naira', 'invoicing' ), |
|
| 119 | + 'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ), |
|
| 120 | + 'NOK' => __( 'Norwegian Krone', 'invoicing' ), |
|
| 121 | + 'NPR' => __( 'Nepalese Rupee', 'invoicing' ), |
|
| 122 | + 'NZD' => __( 'New Zealand Dollar', 'invoicing' ), |
|
| 123 | + 'OMR' => __( 'Omani Rial', 'invoicing' ), |
|
| 124 | + 'PAB' => __( 'Panamanian Balboa', 'invoicing' ), |
|
| 125 | + 'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ), |
|
| 126 | + 'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ), |
|
| 127 | + 'PHP' => __( 'Philippine Peso', 'invoicing' ), |
|
| 128 | + 'PKR' => __( 'Pakistani Rupee', 'invoicing' ), |
|
| 129 | + 'PLN' => __( 'Polish Zloty', 'invoicing' ), |
|
| 130 | + 'PRB' => __( 'Transnistrian Ruble', 'invoicing' ), |
|
| 131 | + 'PYG' => __( 'Paraguayan Guarani', 'invoicing' ), |
|
| 132 | + 'QAR' => __( 'Qatari Riyal', 'invoicing' ), |
|
| 133 | + 'RON' => __( 'Romanian Leu', 'invoicing' ), |
|
| 134 | + 'RSD' => __( 'Serbian Dinar', 'invoicing' ), |
|
| 135 | + 'RUB' => __( 'Russian Ruble', 'invoicing' ), |
|
| 136 | + 'RWF' => __( 'Rwandan Franc', 'invoicing' ), |
|
| 137 | + 'SAR' => __( 'Saudi Riyal', 'invoicing' ), |
|
| 138 | + 'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ), |
|
| 139 | + 'SCR' => __( 'Seychellois Rupee', 'invoicing' ), |
|
| 140 | + 'SDG' => __( 'Sudanese Pound', 'invoicing' ), |
|
| 141 | + 'SEK' => __( 'Swedish Krona', 'invoicing' ), |
|
| 142 | + 'SGD' => __( 'Singapore Dollar', 'invoicing' ), |
|
| 143 | + 'SHP' => __( 'Saint Helena Pound', 'invoicing' ), |
|
| 144 | + 'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ), |
|
| 145 | + 'SOS' => __( 'Somali Shilling', 'invoicing' ), |
|
| 146 | + 'SRD' => __( 'Surinamese Dollar', 'invoicing' ), |
|
| 147 | + 'SSP' => __( 'South Sudanese Pound', 'invoicing' ), |
|
| 148 | + 'STD' => __( 'Sao Tomean Dobra', 'invoicing' ), |
|
| 149 | + 'SYP' => __( 'Syrian Pound', 'invoicing' ), |
|
| 150 | + 'SZL' => __( 'Swazi Lilangeni', 'invoicing' ), |
|
| 151 | + 'THB' => __( 'Thai Baht', 'invoicing' ), |
|
| 152 | + 'TJS' => __( 'Tajikistani Somoni', 'invoicing' ), |
|
| 153 | + 'TMT' => __( 'Turkmenistan Manat', 'invoicing' ), |
|
| 154 | + 'TND' => __( 'Tunisian Dinar', 'invoicing' ), |
|
| 155 | + 'TOP' => __( 'Tongan Paʻanga', 'invoicing' ), |
|
| 156 | + 'TRY' => __( 'Turkish Lira', 'invoicing' ), |
|
| 157 | + 'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ), |
|
| 158 | + 'TWD' => __( 'New Taiwan Dollar', 'invoicing' ), |
|
| 159 | + 'TZS' => __( 'Tanzanian Shilling', 'invoicing' ), |
|
| 160 | + 'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ), |
|
| 161 | + 'UGX' => __( 'Ugandan Shilling', 'invoicing' ), |
|
| 162 | + 'UYU' => __( 'Uruguayan Peso', 'invoicing' ), |
|
| 163 | + 'UZS' => __( 'Uzbekistani Som', 'invoicing' ), |
|
| 164 | + 'VEF' => __( 'Venezuelan Bolívar', 'invoicing' ), |
|
| 165 | + 'VND' => __( 'Vietnamese Dong', 'invoicing' ), |
|
| 166 | + 'VUV' => __( 'Vanuatu Vatu', 'invoicing' ), |
|
| 167 | + 'WST' => __( 'Samoan Tala', 'invoicing' ), |
|
| 168 | + 'XAF' => __( 'Central African CFA Franc', 'invoicing' ), |
|
| 169 | + 'XCD' => __( 'East Caribbean Dollar', 'invoicing' ), |
|
| 170 | + 'XOF' => __( 'West African CFA Franc', 'invoicing' ), |
|
| 171 | + 'XPF' => __( 'CFP Franc', 'invoicing' ), |
|
| 172 | + 'YER' => __( 'Yemeni Rial', 'invoicing' ), |
|
| 173 | + 'ZAR' => __( 'South African Rand', 'invoicing' ), |
|
| 174 | + 'ZMW' => __( 'Zambian Kwacha', 'invoicing' ), |
|
| 175 | 175 | ); |
@@ -15,172 +15,172 @@ |
||
| 15 | 15 | class WPInv_REST_Items_Controller extends GetPaid_REST_Posts_Controller { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Post type. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $post_type = 'wpi_item'; |
|
| 18 | + * Post type. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $post_type = 'wpi_item'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The base of this controller's route. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.13 |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $rest_base = 'items'; |
|
| 31 | - |
|
| 32 | - /** Contains this controller's class name. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $crud_class = 'WPInv_Item'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Registers the routes for the objects of the controller. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.19 |
|
| 42 | - * |
|
| 43 | - * @see register_rest_route() |
|
| 44 | - */ |
|
| 45 | - public function register_namespace_routes( $namespace ) { |
|
| 46 | - |
|
| 47 | - parent::register_namespace_routes( $namespace ); |
|
| 48 | - |
|
| 49 | - register_rest_route( |
|
| 50 | - $this->namespace, |
|
| 51 | - '/' . $this->rest_base . '/item-types', |
|
| 52 | - array( |
|
| 53 | - array( |
|
| 54 | - 'methods' => WP_REST_Server::READABLE, |
|
| 55 | - 'callback' => array( $this, 'get_item_types' ), |
|
| 56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 57 | - ), |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Handles rest requests for item types. |
|
| 65 | - * |
|
| 66 | - * @since 1.0.13 |
|
| 67 | - * |
|
| 68 | - * |
|
| 69 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 70 | - */ |
|
| 71 | - public function get_item_types() { |
|
| 72 | - return rest_ensure_response( wpinv_get_item_types() ); |
|
| 73 | - } |
|
| 24 | + /** |
|
| 25 | + * The base of this controller's route. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.13 |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $rest_base = 'items'; |
|
| 31 | + |
|
| 32 | + /** Contains this controller's class name. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $crud_class = 'WPInv_Item'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Registers the routes for the objects of the controller. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.19 |
|
| 42 | + * |
|
| 43 | + * @see register_rest_route() |
|
| 44 | + */ |
|
| 45 | + public function register_namespace_routes( $namespace ) { |
|
| 46 | + |
|
| 47 | + parent::register_namespace_routes( $namespace ); |
|
| 48 | + |
|
| 49 | + register_rest_route( |
|
| 50 | + $this->namespace, |
|
| 51 | + '/' . $this->rest_base . '/item-types', |
|
| 52 | + array( |
|
| 53 | + array( |
|
| 54 | + 'methods' => WP_REST_Server::READABLE, |
|
| 55 | + 'callback' => array( $this, 'get_item_types' ), |
|
| 56 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 57 | + ), |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Handles rest requests for item types. |
|
| 65 | + * |
|
| 66 | + * @since 1.0.13 |
|
| 67 | + * |
|
| 68 | + * |
|
| 69 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 70 | + */ |
|
| 71 | + public function get_item_types() { |
|
| 72 | + return rest_ensure_response( wpinv_get_item_types() ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Retrieves the query params for the items collection. |
|
| 77 | + * |
|
| 78 | + * @since 1.0.13 |
|
| 79 | + * |
|
| 80 | + * @return array Collection parameters. |
|
| 81 | + */ |
|
| 82 | + public function get_collection_params() { |
|
| 83 | + |
|
| 84 | + $params = array_merge( |
|
| 85 | + |
|
| 86 | + parent::get_collection_params(), |
|
| 87 | + |
|
| 88 | + array( |
|
| 89 | + |
|
| 90 | + // Item types |
|
| 91 | + 'type' => array( |
|
| 92 | + 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
| 93 | + 'type' => array( 'array', 'string' ), |
|
| 94 | + 'default' => 'any', |
|
| 95 | + 'validate_callback' => 'rest_validate_request_arg', |
|
| 96 | + 'sanitize_callback' => 'wpinv_parse_list', |
|
| 97 | + 'items' => array( |
|
| 98 | + 'enum' => array_merge( array( 'any' ), wpinv_item_types() ), |
|
| 99 | + 'type' => 'string', |
|
| 100 | + ), |
|
| 101 | + ), |
|
| 102 | + |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // Filter collection parameters for the items controller. |
|
| 107 | + return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
|
| 108 | + |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Determine the allowed query_vars for a get_items() response and |
|
| 113 | + * prepare for WP_Query. |
|
| 114 | + * |
|
| 115 | + * @param array $prepared_args Prepared arguments. |
|
| 116 | + * @param WP_REST_Request $request Request object. |
|
| 117 | + * @return array $query_args |
|
| 118 | + */ |
|
| 119 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 120 | + |
|
| 121 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
| 122 | + |
|
| 123 | + // Retrieve items by type. |
|
| 124 | + if ( ! in_array( 'any', $request['type'] ) ) { |
|
| 125 | + |
|
| 126 | + if ( empty( $query_args['meta_query'] ) ) { |
|
| 127 | + $query_args['meta_query'] = array(); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $query_args['meta_query'][] = array( |
|
| 131 | + 'key' => '_wpinv_type', |
|
| 132 | + 'value' => implode( ',', $request['type'] ), |
|
| 133 | + 'compare' => 'IN', |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Retrieves a valid list of post statuses. |
|
| 144 | + * |
|
| 145 | + * @since 1.0.15 |
|
| 146 | + * |
|
| 147 | + * @return array A list of registered item statuses. |
|
| 148 | + */ |
|
| 149 | + public function get_post_statuses() { |
|
| 150 | + return array( 'draft', 'pending', 'publish' ); |
|
| 151 | + } |
|
| 74 | 152 | |
| 75 | 153 | /** |
| 76 | - * Retrieves the query params for the items collection. |
|
| 77 | - * |
|
| 78 | - * @since 1.0.13 |
|
| 79 | - * |
|
| 80 | - * @return array Collection parameters. |
|
| 81 | - */ |
|
| 82 | - public function get_collection_params() { |
|
| 83 | - |
|
| 84 | - $params = array_merge( |
|
| 85 | - |
|
| 86 | - parent::get_collection_params(), |
|
| 87 | - |
|
| 88 | - array( |
|
| 89 | - |
|
| 90 | - // Item types |
|
| 91 | - 'type' => array( |
|
| 92 | - 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
| 93 | - 'type' => array( 'array', 'string' ), |
|
| 94 | - 'default' => 'any', |
|
| 95 | - 'validate_callback' => 'rest_validate_request_arg', |
|
| 96 | - 'sanitize_callback' => 'wpinv_parse_list', |
|
| 97 | - 'items' => array( |
|
| 98 | - 'enum' => array_merge( array( 'any' ), wpinv_item_types() ), |
|
| 99 | - 'type' => 'string', |
|
| 100 | - ), |
|
| 101 | - ), |
|
| 102 | - |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // Filter collection parameters for the items controller. |
|
| 107 | - return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
|
| 108 | - |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Determine the allowed query_vars for a get_items() response and |
|
| 113 | - * prepare for WP_Query. |
|
| 114 | - * |
|
| 115 | - * @param array $prepared_args Prepared arguments. |
|
| 116 | - * @param WP_REST_Request $request Request object. |
|
| 117 | - * @return array $query_args |
|
| 118 | - */ |
|
| 119 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 120 | - |
|
| 121 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
| 122 | - |
|
| 123 | - // Retrieve items by type. |
|
| 124 | - if ( ! in_array( 'any', $request['type'] ) ) { |
|
| 125 | - |
|
| 126 | - if ( empty( $query_args['meta_query'] ) ) { |
|
| 127 | - $query_args['meta_query'] = array(); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $query_args['meta_query'][] = array( |
|
| 131 | - 'key' => '_wpinv_type', |
|
| 132 | - 'value' => implode( ',', $request['type'] ), |
|
| 133 | - 'compare' => 'IN', |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Retrieves a valid list of post statuses. |
|
| 144 | - * |
|
| 145 | - * @since 1.0.15 |
|
| 146 | - * |
|
| 147 | - * @return array A list of registered item statuses. |
|
| 148 | - */ |
|
| 149 | - public function get_post_statuses() { |
|
| 150 | - return array( 'draft', 'pending', 'publish' ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Checks if a key should be included in a response. |
|
| 155 | - * |
|
| 156 | - * @since 1.0.19 |
|
| 157 | - * @param WPInv_Item $item Item object. |
|
| 158 | - * @param string $field_key The key to check for. |
|
| 159 | - * @return bool |
|
| 160 | - */ |
|
| 161 | - public function object_supports_field( $item, $field_key ) { |
|
| 162 | - |
|
| 163 | - if ( 'minimum_price' == $field_key && ! $item->user_can_set_their_price() ) { |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - foreach( wpinv_parse_list( 'initial_price the_initial_price recurring_price the_recurring_price recurring_period recurring_interval recurring_limit is_free_trial trial_period trial_interval first_renewal_date' ) as $key ) { |
|
| 168 | - |
|
| 169 | - if ( $key == $field_key && ! $item->is_recurring() ) { |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - foreach( wpinv_parse_list( 'trial_period trial_interval' ) as $key ) { |
|
| 176 | - |
|
| 177 | - if ( $key == $field_key && ! $item->has_free_trial() ) { |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - } |
|
| 154 | + * Checks if a key should be included in a response. |
|
| 155 | + * |
|
| 156 | + * @since 1.0.19 |
|
| 157 | + * @param WPInv_Item $item Item object. |
|
| 158 | + * @param string $field_key The key to check for. |
|
| 159 | + * @return bool |
|
| 160 | + */ |
|
| 161 | + public function object_supports_field( $item, $field_key ) { |
|
| 162 | + |
|
| 163 | + if ( 'minimum_price' == $field_key && ! $item->user_can_set_their_price() ) { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + foreach( wpinv_parse_list( 'initial_price the_initial_price recurring_price the_recurring_price recurring_period recurring_interval recurring_limit is_free_trial trial_period trial_interval first_renewal_date' ) as $key ) { |
|
| 168 | + |
|
| 169 | + if ( $key == $field_key && ! $item->is_recurring() ) { |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + foreach( wpinv_parse_list( 'trial_period trial_interval' ) as $key ) { |
|
| 176 | + |
|
| 177 | + if ( $key == $field_key && ! $item->has_free_trial() ) { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return parent::object_supports_field( $item, $field_key ); |
|
| 184 | - } |
|
| 183 | + return parent::object_supports_field( $item, $field_key ); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | } |
@@ -15,138 +15,138 @@ |
||
| 15 | 15 | class WPInv_REST_Discounts_Controller extends GetPaid_REST_Posts_Controller { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Post type. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $post_type = 'wpi_discount'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * The base of this controller's route. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.13 |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $rest_base = 'discounts'; |
|
| 31 | - |
|
| 32 | - /** Contains this controller's class name. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $crud_class = 'WPInv_Discount'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Registers the routes for the objects of the controller. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.19 |
|
| 42 | - * |
|
| 43 | - * @see register_rest_route() |
|
| 44 | - */ |
|
| 45 | - public function register_namespace_routes( $namespace ) { |
|
| 46 | - |
|
| 47 | - parent::register_namespace_routes( $namespace ); |
|
| 48 | - |
|
| 49 | - register_rest_route( |
|
| 50 | - $this->namespace, |
|
| 51 | - '/' . $this->rest_base . '/discount-types', |
|
| 52 | - array( |
|
| 53 | - array( |
|
| 54 | - 'methods' => WP_REST_Server::READABLE, |
|
| 55 | - 'callback' => array( $this, 'get_discount_types' ), |
|
| 56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 57 | - ), |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Handles rest requests for discount types. |
|
| 65 | - * |
|
| 66 | - * @since 1.0.13 |
|
| 67 | - * |
|
| 68 | - * |
|
| 69 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 70 | - */ |
|
| 71 | - public function get_discount_types() { |
|
| 72 | - return rest_ensure_response( wpinv_get_discount_types() ); |
|
| 73 | - } |
|
| 18 | + * Post type. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $post_type = 'wpi_discount'; |
|
| 74 | 23 | |
| 75 | 24 | /** |
| 76 | - * Retrieves the query params for the discount collection. |
|
| 77 | - * |
|
| 78 | - * @since 1.0.13 |
|
| 79 | - * |
|
| 80 | - * @return array Collection parameters. |
|
| 81 | - */ |
|
| 82 | - public function get_collection_params() { |
|
| 83 | - |
|
| 84 | - $params = array_merge( |
|
| 85 | - |
|
| 86 | - parent::get_collection_params(), |
|
| 87 | - |
|
| 88 | - array( |
|
| 89 | - |
|
| 90 | - // Discount types |
|
| 91 | - 'type' => array( |
|
| 92 | - 'description' => __( 'Type of discounts to fetch.', 'invoicing' ), |
|
| 93 | - 'type' => array( 'array', 'string' ), |
|
| 94 | - 'default' => 'any', |
|
| 95 | - 'validate_callback' => 'rest_validate_request_arg', |
|
| 96 | - 'sanitize_callback' => 'wpinv_parse_list', |
|
| 97 | - 'items' => array( |
|
| 98 | - 'enum' => array_merge( array( 'any' ), array_keys( wpinv_get_discount_types() ) ), |
|
| 99 | - 'type' => 'string', |
|
| 100 | - ), |
|
| 101 | - ), |
|
| 102 | - |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // Filter collection parameters for the discounts controller. |
|
| 107 | - return apply_filters( 'getpaid_rest_discounts_collection_params', $params, $this ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Determine the allowed query_vars for a get_items() response and |
|
| 112 | - * prepare for WP_Query. |
|
| 113 | - * |
|
| 114 | - * @param array $prepared_args Prepared arguments. |
|
| 115 | - * @param WP_REST_Request $request Request object. |
|
| 116 | - * @return array $query_args |
|
| 117 | - */ |
|
| 118 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 119 | - |
|
| 120 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
| 121 | - |
|
| 122 | - // Retrieve items by type. |
|
| 123 | - if ( ! in_array( 'any', $request['type'] ) ) { |
|
| 124 | - |
|
| 125 | - if ( empty( $query_args['meta_query'] ) ) { |
|
| 126 | - $query_args['meta_query'] = array(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $query_args['meta_query'][] = array( |
|
| 130 | - 'key' => '_wpi_discount_type', |
|
| 131 | - 'value' => implode( ',', $request['type'] ), |
|
| 132 | - 'compare' => 'IN', |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return apply_filters( 'getpaid_rest_discounts_prepare_items_query', $query_args, $request, $this ); |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Retrieves a valid list of post statuses. |
|
| 143 | - * |
|
| 144 | - * @since 1.0.15 |
|
| 145 | - * |
|
| 146 | - * @return array A list of registered item statuses. |
|
| 147 | - */ |
|
| 148 | - public function get_post_statuses() { |
|
| 149 | - return array( 'publish', 'pending', 'draft', 'expired' ); |
|
| 150 | - } |
|
| 25 | + * The base of this controller's route. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.13 |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $rest_base = 'discounts'; |
|
| 31 | + |
|
| 32 | + /** Contains this controller's class name. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $crud_class = 'WPInv_Discount'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Registers the routes for the objects of the controller. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.19 |
|
| 42 | + * |
|
| 43 | + * @see register_rest_route() |
|
| 44 | + */ |
|
| 45 | + public function register_namespace_routes( $namespace ) { |
|
| 46 | + |
|
| 47 | + parent::register_namespace_routes( $namespace ); |
|
| 48 | + |
|
| 49 | + register_rest_route( |
|
| 50 | + $this->namespace, |
|
| 51 | + '/' . $this->rest_base . '/discount-types', |
|
| 52 | + array( |
|
| 53 | + array( |
|
| 54 | + 'methods' => WP_REST_Server::READABLE, |
|
| 55 | + 'callback' => array( $this, 'get_discount_types' ), |
|
| 56 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 57 | + ), |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Handles rest requests for discount types. |
|
| 65 | + * |
|
| 66 | + * @since 1.0.13 |
|
| 67 | + * |
|
| 68 | + * |
|
| 69 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 70 | + */ |
|
| 71 | + public function get_discount_types() { |
|
| 72 | + return rest_ensure_response( wpinv_get_discount_types() ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Retrieves the query params for the discount collection. |
|
| 77 | + * |
|
| 78 | + * @since 1.0.13 |
|
| 79 | + * |
|
| 80 | + * @return array Collection parameters. |
|
| 81 | + */ |
|
| 82 | + public function get_collection_params() { |
|
| 83 | + |
|
| 84 | + $params = array_merge( |
|
| 85 | + |
|
| 86 | + parent::get_collection_params(), |
|
| 87 | + |
|
| 88 | + array( |
|
| 89 | + |
|
| 90 | + // Discount types |
|
| 91 | + 'type' => array( |
|
| 92 | + 'description' => __( 'Type of discounts to fetch.', 'invoicing' ), |
|
| 93 | + 'type' => array( 'array', 'string' ), |
|
| 94 | + 'default' => 'any', |
|
| 95 | + 'validate_callback' => 'rest_validate_request_arg', |
|
| 96 | + 'sanitize_callback' => 'wpinv_parse_list', |
|
| 97 | + 'items' => array( |
|
| 98 | + 'enum' => array_merge( array( 'any' ), array_keys( wpinv_get_discount_types() ) ), |
|
| 99 | + 'type' => 'string', |
|
| 100 | + ), |
|
| 101 | + ), |
|
| 102 | + |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // Filter collection parameters for the discounts controller. |
|
| 107 | + return apply_filters( 'getpaid_rest_discounts_collection_params', $params, $this ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Determine the allowed query_vars for a get_items() response and |
|
| 112 | + * prepare for WP_Query. |
|
| 113 | + * |
|
| 114 | + * @param array $prepared_args Prepared arguments. |
|
| 115 | + * @param WP_REST_Request $request Request object. |
|
| 116 | + * @return array $query_args |
|
| 117 | + */ |
|
| 118 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 119 | + |
|
| 120 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
| 121 | + |
|
| 122 | + // Retrieve items by type. |
|
| 123 | + if ( ! in_array( 'any', $request['type'] ) ) { |
|
| 124 | + |
|
| 125 | + if ( empty( $query_args['meta_query'] ) ) { |
|
| 126 | + $query_args['meta_query'] = array(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $query_args['meta_query'][] = array( |
|
| 130 | + 'key' => '_wpi_discount_type', |
|
| 131 | + 'value' => implode( ',', $request['type'] ), |
|
| 132 | + 'compare' => 'IN', |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return apply_filters( 'getpaid_rest_discounts_prepare_items_query', $query_args, $request, $this ); |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Retrieves a valid list of post statuses. |
|
| 143 | + * |
|
| 144 | + * @since 1.0.15 |
|
| 145 | + * |
|
| 146 | + * @return array A list of registered item statuses. |
|
| 147 | + */ |
|
| 148 | + public function get_post_statuses() { |
|
| 149 | + return array( 'publish', 'pending', 'draft', 'expired' ); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | } |
@@ -13,168 +13,168 @@ |
||
| 13 | 13 | |
| 14 | 14 | return array( |
| 15 | 15 | |
| 16 | - 'id' => array( |
|
| 17 | - 'description' => __( 'Unique identifier for the discount.', 'invoicing' ), |
|
| 18 | - 'type' => 'integer', |
|
| 19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | - 'readonly' => true, |
|
| 21 | - ), |
|
| 22 | - |
|
| 23 | - 'status' => array( |
|
| 24 | - 'description' => __( 'A named status for the discount.', 'invoicing' ), |
|
| 25 | - 'type' => 'string', |
|
| 26 | - 'enum' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
| 27 | - 'default' => 'draft', |
|
| 28 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 29 | - ), |
|
| 30 | - |
|
| 31 | - 'version' => array( |
|
| 32 | - 'description' => __( 'Plugin version when the discount was created.', 'invoicing' ), |
|
| 33 | - 'type' => 'string', |
|
| 34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 35 | - 'readonly' => true, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'date_created' => array( |
|
| 39 | - 'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ), |
|
| 40 | - 'type' => 'string', |
|
| 41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | - ), |
|
| 43 | - |
|
| 44 | - 'date_created_gmt' => array( |
|
| 45 | - 'description' => __( 'The GMT date the discount was created.', 'invoicing' ), |
|
| 46 | - 'type' => 'string', |
|
| 47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | - 'readonly' => true, |
|
| 49 | - ), |
|
| 50 | - |
|
| 51 | - 'date_modified' => array( |
|
| 52 | - 'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ), |
|
| 53 | - 'type' => 'string', |
|
| 54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | - 'readonly' => true, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - 'date_modified_gmt' => array( |
|
| 59 | - 'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ), |
|
| 60 | - 'type' => 'string', |
|
| 61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 62 | - 'readonly' => true, |
|
| 63 | - ), |
|
| 64 | - |
|
| 65 | - 'name' => array( |
|
| 66 | - 'description' => __( 'The discount name.', 'invoicing' ), |
|
| 67 | - 'type' => 'string', |
|
| 68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 69 | - ), |
|
| 70 | - |
|
| 71 | - 'description' => array( |
|
| 72 | - 'description' => __( 'A description of what the discount is all about.', 'invoicing' ), |
|
| 73 | - 'type' => 'string', |
|
| 74 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 75 | - ), |
|
| 76 | - |
|
| 77 | - 'code' => array( |
|
| 78 | - 'description' => __( 'The discount code.', 'invoicing' ), |
|
| 79 | - 'type' => 'string', |
|
| 80 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 81 | - 'required' => true, |
|
| 82 | - ), |
|
| 83 | - |
|
| 84 | - 'type' => array( |
|
| 85 | - 'description' => __( 'The type of discount.', 'invoicing' ), |
|
| 86 | - 'type' => 'string', |
|
| 87 | - 'enum' => array_keys( wpinv_get_discount_types() ), |
|
| 88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 89 | - 'default' => 'percent', |
|
| 90 | - ), |
|
| 91 | - |
|
| 92 | - 'amount' => array( |
|
| 93 | - 'description' => __( 'The discount value.', 'invoicing' ), |
|
| 94 | - 'type' => 'number', |
|
| 95 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 96 | - 'required' => true, |
|
| 97 | - ), |
|
| 98 | - |
|
| 99 | - 'formatted_amount' => array( |
|
| 100 | - 'description' => __( 'The formatted discount value.', 'invoicing' ), |
|
| 101 | - 'type' => 'string', |
|
| 102 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 103 | - 'readonly' => true, |
|
| 104 | - ), |
|
| 105 | - |
|
| 106 | - 'uses' => array( |
|
| 107 | - 'description' => __( 'The number of times the discount has been used.', 'invoicing' ), |
|
| 108 | - 'type' => 'integer', |
|
| 109 | - 'context' => array( 'view', 'embed' ), |
|
| 110 | - 'readonly' => true, |
|
| 111 | - ), |
|
| 112 | - |
|
| 113 | - 'max_uses' => array( |
|
| 114 | - 'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ), |
|
| 115 | - 'type' => 'integer', |
|
| 116 | - 'context' => array( 'view', 'edit' ), |
|
| 117 | - ), |
|
| 118 | - |
|
| 119 | - 'usage' => array( |
|
| 120 | - 'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ), |
|
| 121 | - 'type' => 'string', |
|
| 122 | - 'context' => array( 'view', 'embed' ), |
|
| 123 | - 'readonly' => true, |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'is_single_use' => array( |
|
| 127 | - 'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ), |
|
| 128 | - 'type' => 'boolean', |
|
| 129 | - 'context' => array( 'view', 'edit' ), |
|
| 130 | - ), |
|
| 131 | - |
|
| 132 | - 'is_recurring' => array( |
|
| 133 | - 'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ), |
|
| 134 | - 'type' => 'boolean', |
|
| 135 | - 'context' => array( 'view', 'edit' ), |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'start_date' => array( |
|
| 139 | - 'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ), |
|
| 140 | - 'type' => 'string', |
|
| 141 | - 'context' => array( 'view', 'edit' ), |
|
| 142 | - ), |
|
| 143 | - |
|
| 144 | - 'end_date' => array( |
|
| 145 | - 'description' => __( 'The expiration date for the discount.', 'invoicing' ), |
|
| 146 | - 'type' => 'string', |
|
| 147 | - 'context' => array( 'view', 'edit' ), |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - 'allowed_items' => array( |
|
| 151 | - 'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ), |
|
| 152 | - 'type' => 'array', |
|
| 153 | - 'context' => array( 'view', 'edit' ), |
|
| 154 | - 'items' => array( |
|
| 155 | - 'type' => 'integer' |
|
| 156 | - ) |
|
| 157 | - ), |
|
| 158 | - |
|
| 159 | - 'excluded_items' => array( |
|
| 160 | - 'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ), |
|
| 161 | - 'type' => 'array', |
|
| 162 | - 'context' => array( 'view', 'edit' ), |
|
| 163 | - 'items' => array( |
|
| 164 | - 'type' => 'integer' |
|
| 165 | - ) |
|
| 166 | - ), |
|
| 16 | + 'id' => array( |
|
| 17 | + 'description' => __( 'Unique identifier for the discount.', 'invoicing' ), |
|
| 18 | + 'type' => 'integer', |
|
| 19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | + 'readonly' => true, |
|
| 21 | + ), |
|
| 22 | + |
|
| 23 | + 'status' => array( |
|
| 24 | + 'description' => __( 'A named status for the discount.', 'invoicing' ), |
|
| 25 | + 'type' => 'string', |
|
| 26 | + 'enum' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
| 27 | + 'default' => 'draft', |
|
| 28 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 29 | + ), |
|
| 30 | + |
|
| 31 | + 'version' => array( |
|
| 32 | + 'description' => __( 'Plugin version when the discount was created.', 'invoicing' ), |
|
| 33 | + 'type' => 'string', |
|
| 34 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 35 | + 'readonly' => true, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'date_created' => array( |
|
| 39 | + 'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ), |
|
| 40 | + 'type' => 'string', |
|
| 41 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | + ), |
|
| 43 | + |
|
| 44 | + 'date_created_gmt' => array( |
|
| 45 | + 'description' => __( 'The GMT date the discount was created.', 'invoicing' ), |
|
| 46 | + 'type' => 'string', |
|
| 47 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | + 'readonly' => true, |
|
| 49 | + ), |
|
| 50 | + |
|
| 51 | + 'date_modified' => array( |
|
| 52 | + 'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ), |
|
| 53 | + 'type' => 'string', |
|
| 54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | + 'readonly' => true, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + 'date_modified_gmt' => array( |
|
| 59 | + 'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ), |
|
| 60 | + 'type' => 'string', |
|
| 61 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 62 | + 'readonly' => true, |
|
| 63 | + ), |
|
| 64 | + |
|
| 65 | + 'name' => array( |
|
| 66 | + 'description' => __( 'The discount name.', 'invoicing' ), |
|
| 67 | + 'type' => 'string', |
|
| 68 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 69 | + ), |
|
| 70 | + |
|
| 71 | + 'description' => array( |
|
| 72 | + 'description' => __( 'A description of what the discount is all about.', 'invoicing' ), |
|
| 73 | + 'type' => 'string', |
|
| 74 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 75 | + ), |
|
| 76 | + |
|
| 77 | + 'code' => array( |
|
| 78 | + 'description' => __( 'The discount code.', 'invoicing' ), |
|
| 79 | + 'type' => 'string', |
|
| 80 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 81 | + 'required' => true, |
|
| 82 | + ), |
|
| 83 | + |
|
| 84 | + 'type' => array( |
|
| 85 | + 'description' => __( 'The type of discount.', 'invoicing' ), |
|
| 86 | + 'type' => 'string', |
|
| 87 | + 'enum' => array_keys( wpinv_get_discount_types() ), |
|
| 88 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 89 | + 'default' => 'percent', |
|
| 90 | + ), |
|
| 91 | + |
|
| 92 | + 'amount' => array( |
|
| 93 | + 'description' => __( 'The discount value.', 'invoicing' ), |
|
| 94 | + 'type' => 'number', |
|
| 95 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 96 | + 'required' => true, |
|
| 97 | + ), |
|
| 98 | + |
|
| 99 | + 'formatted_amount' => array( |
|
| 100 | + 'description' => __( 'The formatted discount value.', 'invoicing' ), |
|
| 101 | + 'type' => 'string', |
|
| 102 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 103 | + 'readonly' => true, |
|
| 104 | + ), |
|
| 105 | + |
|
| 106 | + 'uses' => array( |
|
| 107 | + 'description' => __( 'The number of times the discount has been used.', 'invoicing' ), |
|
| 108 | + 'type' => 'integer', |
|
| 109 | + 'context' => array( 'view', 'embed' ), |
|
| 110 | + 'readonly' => true, |
|
| 111 | + ), |
|
| 112 | + |
|
| 113 | + 'max_uses' => array( |
|
| 114 | + 'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ), |
|
| 115 | + 'type' => 'integer', |
|
| 116 | + 'context' => array( 'view', 'edit' ), |
|
| 117 | + ), |
|
| 118 | + |
|
| 119 | + 'usage' => array( |
|
| 120 | + 'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ), |
|
| 121 | + 'type' => 'string', |
|
| 122 | + 'context' => array( 'view', 'embed' ), |
|
| 123 | + 'readonly' => true, |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'is_single_use' => array( |
|
| 127 | + 'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ), |
|
| 128 | + 'type' => 'boolean', |
|
| 129 | + 'context' => array( 'view', 'edit' ), |
|
| 130 | + ), |
|
| 131 | + |
|
| 132 | + 'is_recurring' => array( |
|
| 133 | + 'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ), |
|
| 134 | + 'type' => 'boolean', |
|
| 135 | + 'context' => array( 'view', 'edit' ), |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'start_date' => array( |
|
| 139 | + 'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ), |
|
| 140 | + 'type' => 'string', |
|
| 141 | + 'context' => array( 'view', 'edit' ), |
|
| 142 | + ), |
|
| 143 | + |
|
| 144 | + 'end_date' => array( |
|
| 145 | + 'description' => __( 'The expiration date for the discount.', 'invoicing' ), |
|
| 146 | + 'type' => 'string', |
|
| 147 | + 'context' => array( 'view', 'edit' ), |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + 'allowed_items' => array( |
|
| 151 | + 'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ), |
|
| 152 | + 'type' => 'array', |
|
| 153 | + 'context' => array( 'view', 'edit' ), |
|
| 154 | + 'items' => array( |
|
| 155 | + 'type' => 'integer' |
|
| 156 | + ) |
|
| 157 | + ), |
|
| 158 | + |
|
| 159 | + 'excluded_items' => array( |
|
| 160 | + 'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ), |
|
| 161 | + 'type' => 'array', |
|
| 162 | + 'context' => array( 'view', 'edit' ), |
|
| 163 | + 'items' => array( |
|
| 164 | + 'type' => 'integer' |
|
| 165 | + ) |
|
| 166 | + ), |
|
| 167 | 167 | |
| 168 | - 'minimum_total' => array( |
|
| 169 | - 'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ), |
|
| 170 | - 'type' => 'number', |
|
| 171 | - 'context' => array( 'view', 'edit' ), |
|
| 172 | - ), |
|
| 173 | - |
|
| 174 | - 'maximum_total' => array( |
|
| 175 | - 'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ), |
|
| 176 | - 'type' => 'number', |
|
| 177 | - 'context' => array( 'view', 'edit' ), |
|
| 178 | - ), |
|
| 168 | + 'minimum_total' => array( |
|
| 169 | + 'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ), |
|
| 170 | + 'type' => 'number', |
|
| 171 | + 'context' => array( 'view', 'edit' ), |
|
| 172 | + ), |
|
| 173 | + |
|
| 174 | + 'maximum_total' => array( |
|
| 175 | + 'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ), |
|
| 176 | + 'type' => 'number', |
|
| 177 | + 'context' => array( 'view', 'edit' ), |
|
| 178 | + ), |
|
| 179 | 179 | |
| 180 | 180 | ); |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 4 | - exit; |
|
| 4 | + exit; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | global $wpdb; |
@@ -21,570 +21,570 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class GetPaid_REST_Controller extends WP_REST_Controller { |
| 23 | 23 | |
| 24 | - /** |
|
| 24 | + /** |
|
| 25 | 25 | * The namespaces of this controller's route. |
| 26 | 26 | * |
| 27 | 27 | * @since 1.0.19 |
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | - protected $namespaces; |
|
| 30 | + protected $namespaces; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | + /** |
|
| 33 | 33 | * The official namespace of this controller's route. |
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.19 |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - protected $namespace = 'getpaid/v1'; |
|
| 38 | + protected $namespace = 'getpaid/v1'; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | + /** |
|
| 41 | 41 | * Cached results of get_item_schema. |
| 42 | 42 | * |
| 43 | 43 | * @since 1.0.19 |
| 44 | 44 | * @var array |
| 45 | 45 | */ |
| 46 | - protected $schema; |
|
| 46 | + protected $schema; |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Constructor. |
|
| 50 | - * |
|
| 51 | - * @since 1.0.19 |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function __construct() { |
|
| 55 | - |
|
| 56 | - // Offer several namespaces for backwards compatibility. |
|
| 57 | - $this->namespaces = apply_filters( |
|
| 58 | - 'getpaid_rest_api_namespaces', |
|
| 59 | - array( |
|
| 60 | - 'getpaid/v1', |
|
| 61 | - 'invoicing/v1', |
|
| 62 | - 'wpi/v1' |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - // Register REST routes. |
|
| 49 | + * Constructor. |
|
| 50 | + * |
|
| 51 | + * @since 1.0.19 |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function __construct() { |
|
| 55 | + |
|
| 56 | + // Offer several namespaces for backwards compatibility. |
|
| 57 | + $this->namespaces = apply_filters( |
|
| 58 | + 'getpaid_rest_api_namespaces', |
|
| 59 | + array( |
|
| 60 | + 'getpaid/v1', |
|
| 61 | + 'invoicing/v1', |
|
| 62 | + 'wpi/v1' |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + // Register REST routes. |
|
| 67 | 67 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 68 | 68 | |
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Registers routes for each namespace. |
|
| 73 | - * |
|
| 74 | - * @since 1.0.19 |
|
| 75 | - * |
|
| 76 | - */ |
|
| 77 | - public function register_routes() { |
|
| 78 | - |
|
| 79 | - foreach ( $this->namespaces as $namespace ) { |
|
| 80 | - $this->register_namespace_routes( $namespace ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Registers routes for a namespace. |
|
| 87 | - * |
|
| 88 | - * @since 1.0.19 |
|
| 89 | - * |
|
| 90 | - * @param string $namespace |
|
| 91 | - */ |
|
| 92 | - public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) { |
|
| 93 | - |
|
| 94 | - getpaid_doing_it_wrong( |
|
| 95 | - __CLASS__ . '::' .__METHOD__, |
|
| 96 | - /* translators: %s: register_namespace_routes() */ |
|
| 97 | - sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), |
|
| 98 | - '1.0.19' |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get normalized rest base. |
|
| 105 | - * |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - protected function get_normalized_rest_base() { |
|
| 109 | - return preg_replace( '/\(.*\)\//i', '', $this->rest_base ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fill batches. |
|
| 114 | - * |
|
| 115 | - * @param array array of request items. |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - protected function fill_batch_keys( $items ) { |
|
| 119 | - |
|
| 120 | - $items['create'] = empty( $items['create'] ) ? array() : $items['create']; |
|
| 121 | - $items['update'] = empty( $items['update'] ) ? array() : $items['update']; |
|
| 122 | - $items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] ); |
|
| 123 | - return $items; |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Check batch limit. |
|
| 129 | - * |
|
| 130 | - * @param array $items Request items. |
|
| 131 | - * @return bool|WP_Error |
|
| 132 | - */ |
|
| 133 | - protected function check_batch_limit( $items ) { |
|
| 134 | - $limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
|
| 135 | - $total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] ); |
|
| 136 | - |
|
| 137 | - if ( $total > $limit ) { |
|
| 138 | - /* translators: %s: items limit */ |
|
| 139 | - return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return true; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Bulk create items. |
|
| 147 | - * |
|
| 148 | - * @param array $items Array of items to create. |
|
| 149 | - * @param WP_REST_Request $request Full details about the request. |
|
| 150 | - * @param WP_REST_Server $wp_rest_server |
|
| 151 | - * @return array() |
|
| 152 | - */ |
|
| 153 | - protected function batch_create_items( $items, $request, $wp_rest_server ) { |
|
| 154 | - |
|
| 155 | - $query = $request->get_query_params(); |
|
| 156 | - $create = array(); |
|
| 157 | - |
|
| 158 | - foreach ( $items as $item ) { |
|
| 159 | - $_item = new WP_REST_Request( 'POST' ); |
|
| 160 | - |
|
| 161 | - // Default parameters. |
|
| 162 | - $defaults = array(); |
|
| 163 | - $schema = $this->get_public_item_schema(); |
|
| 164 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
| 165 | - if ( isset( $options['default'] ) ) { |
|
| 166 | - $defaults[ $arg ] = $options['default']; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - $_item->set_default_params( $defaults ); |
|
| 170 | - |
|
| 171 | - // Set request parameters. |
|
| 172 | - $_item->set_body_params( $item ); |
|
| 173 | - |
|
| 174 | - // Set query (GET) parameters. |
|
| 175 | - $_item->set_query_params( $query ); |
|
| 176 | - |
|
| 177 | - // Create the item. |
|
| 178 | - $_response = $this->create_item( $_item ); |
|
| 179 | - |
|
| 180 | - // If an error occured... |
|
| 181 | - if ( is_wp_error( $_response ) ) { |
|
| 182 | - |
|
| 183 | - $create[] = array( |
|
| 184 | - 'id' => 0, |
|
| 185 | - 'error' => array( |
|
| 186 | - 'code' => $_response->get_error_code(), |
|
| 187 | - 'message' => $_response->get_error_message(), |
|
| 188 | - 'data' => $_response->get_error_data(), |
|
| 189 | - ), |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - continue; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $create; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Registers routes for each namespace. |
|
| 73 | + * |
|
| 74 | + * @since 1.0.19 |
|
| 75 | + * |
|
| 76 | + */ |
|
| 77 | + public function register_routes() { |
|
| 78 | + |
|
| 79 | + foreach ( $this->namespaces as $namespace ) { |
|
| 80 | + $this->register_namespace_routes( $namespace ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Registers routes for a namespace. |
|
| 87 | + * |
|
| 88 | + * @since 1.0.19 |
|
| 89 | + * |
|
| 90 | + * @param string $namespace |
|
| 91 | + */ |
|
| 92 | + public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) { |
|
| 93 | + |
|
| 94 | + getpaid_doing_it_wrong( |
|
| 95 | + __CLASS__ . '::' .__METHOD__, |
|
| 96 | + /* translators: %s: register_namespace_routes() */ |
|
| 97 | + sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), |
|
| 98 | + '1.0.19' |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get normalized rest base. |
|
| 105 | + * |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + protected function get_normalized_rest_base() { |
|
| 109 | + return preg_replace( '/\(.*\)\//i', '', $this->rest_base ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fill batches. |
|
| 114 | + * |
|
| 115 | + * @param array array of request items. |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + protected function fill_batch_keys( $items ) { |
|
| 119 | + |
|
| 120 | + $items['create'] = empty( $items['create'] ) ? array() : $items['create']; |
|
| 121 | + $items['update'] = empty( $items['update'] ) ? array() : $items['update']; |
|
| 122 | + $items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] ); |
|
| 123 | + return $items; |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Check batch limit. |
|
| 129 | + * |
|
| 130 | + * @param array $items Request items. |
|
| 131 | + * @return bool|WP_Error |
|
| 132 | + */ |
|
| 133 | + protected function check_batch_limit( $items ) { |
|
| 134 | + $limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
|
| 135 | + $total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] ); |
|
| 136 | + |
|
| 137 | + if ( $total > $limit ) { |
|
| 138 | + /* translators: %s: items limit */ |
|
| 139 | + return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return true; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Bulk create items. |
|
| 147 | + * |
|
| 148 | + * @param array $items Array of items to create. |
|
| 149 | + * @param WP_REST_Request $request Full details about the request. |
|
| 150 | + * @param WP_REST_Server $wp_rest_server |
|
| 151 | + * @return array() |
|
| 152 | + */ |
|
| 153 | + protected function batch_create_items( $items, $request, $wp_rest_server ) { |
|
| 154 | + |
|
| 155 | + $query = $request->get_query_params(); |
|
| 156 | + $create = array(); |
|
| 157 | + |
|
| 158 | + foreach ( $items as $item ) { |
|
| 159 | + $_item = new WP_REST_Request( 'POST' ); |
|
| 160 | + |
|
| 161 | + // Default parameters. |
|
| 162 | + $defaults = array(); |
|
| 163 | + $schema = $this->get_public_item_schema(); |
|
| 164 | + foreach ( $schema['properties'] as $arg => $options ) { |
|
| 165 | + if ( isset( $options['default'] ) ) { |
|
| 166 | + $defaults[ $arg ] = $options['default']; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + $_item->set_default_params( $defaults ); |
|
| 170 | + |
|
| 171 | + // Set request parameters. |
|
| 172 | + $_item->set_body_params( $item ); |
|
| 173 | + |
|
| 174 | + // Set query (GET) parameters. |
|
| 175 | + $_item->set_query_params( $query ); |
|
| 176 | + |
|
| 177 | + // Create the item. |
|
| 178 | + $_response = $this->create_item( $_item ); |
|
| 179 | + |
|
| 180 | + // If an error occured... |
|
| 181 | + if ( is_wp_error( $_response ) ) { |
|
| 182 | + |
|
| 183 | + $create[] = array( |
|
| 184 | + 'id' => 0, |
|
| 185 | + 'error' => array( |
|
| 186 | + 'code' => $_response->get_error_code(), |
|
| 187 | + 'message' => $_response->get_error_message(), |
|
| 188 | + 'data' => $_response->get_error_data(), |
|
| 189 | + ), |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $create; |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Bulk update items. |
|
| 205 | + * |
|
| 206 | + * @param array $items Array of items to update. |
|
| 207 | + * @param WP_REST_Request $request Full details about the request. |
|
| 208 | + * @param WP_REST_Server $wp_rest_server |
|
| 209 | + * @return array() |
|
| 210 | + */ |
|
| 211 | + protected function batch_update_items( $items, $request, $wp_rest_server ) { |
|
| 212 | + |
|
| 213 | + $query = $request->get_query_params(); |
|
| 214 | + $update = array(); |
|
| 215 | + |
|
| 216 | + foreach ( $items as $item ) { |
|
| 217 | + |
|
| 218 | + // Create a dummy request. |
|
| 219 | + $_item = new WP_REST_Request( 'PUT' ); |
|
| 220 | + |
|
| 221 | + // Add body params. |
|
| 222 | + $_item->set_body_params( $item ); |
|
| 223 | + |
|
| 224 | + // Set query (GET) parameters. |
|
| 225 | + $_item->set_query_params( $query ); |
|
| 226 | + |
|
| 227 | + // Update the item. |
|
| 228 | + $_response = $this->update_item( $_item ); |
|
| 229 | + |
|
| 230 | + // If an error occured... |
|
| 231 | + if ( is_wp_error( $_response ) ) { |
|
| 232 | + |
|
| 233 | + $update[] = array( |
|
| 234 | + 'id' => $item['id'], |
|
| 235 | + 'error' => array( |
|
| 236 | + 'code' => $_response->get_error_code(), |
|
| 237 | + 'message' => $_response->get_error_message(), |
|
| 238 | + 'data' => $_response->get_error_data(), |
|
| 239 | + ), |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + continue; |
|
| 243 | + |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 247 | + |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $update; |
|
| 251 | + |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Bulk delete items. |
|
| 256 | + * |
|
| 257 | + * @param array $items Array of items to delete. |
|
| 258 | + * @param WP_REST_Server $wp_rest_server |
|
| 259 | + * @return array() |
|
| 260 | + */ |
|
| 261 | + protected function batch_delete_items( $items, $wp_rest_server ) { |
|
| 262 | + |
|
| 263 | + $delete = array(); |
|
| 264 | + |
|
| 265 | + foreach ( array_filter( $items ) as $id ) { |
|
| 266 | + |
|
| 267 | + // Prepare the request. |
|
| 268 | + $_item = new WP_REST_Request( 'DELETE' ); |
|
| 269 | + $_item->set_query_params( |
|
| 270 | + array( |
|
| 271 | + 'id' => $id, |
|
| 272 | + 'force' => true, |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + // Delete the item. |
|
| 277 | + $_response = $this->delete_item( $_item ); |
|
| 278 | + |
|
| 279 | + if ( is_wp_error( $_response ) ) { |
|
| 280 | + |
|
| 281 | + $delete[] = array( |
|
| 282 | + 'id' => $id, |
|
| 283 | + 'error' => array( |
|
| 284 | + 'code' => $_response->get_error_code(), |
|
| 285 | + 'message' => $_response->get_error_message(), |
|
| 286 | + 'data' => $_response->get_error_data(), |
|
| 287 | + ), |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + continue; |
|
| 291 | + } |
|
| 200 | 292 | |
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Bulk update items. |
|
| 205 | - * |
|
| 206 | - * @param array $items Array of items to update. |
|
| 207 | - * @param WP_REST_Request $request Full details about the request. |
|
| 208 | - * @param WP_REST_Server $wp_rest_server |
|
| 209 | - * @return array() |
|
| 210 | - */ |
|
| 211 | - protected function batch_update_items( $items, $request, $wp_rest_server ) { |
|
| 212 | - |
|
| 213 | - $query = $request->get_query_params(); |
|
| 214 | - $update = array(); |
|
| 215 | - |
|
| 216 | - foreach ( $items as $item ) { |
|
| 217 | - |
|
| 218 | - // Create a dummy request. |
|
| 219 | - $_item = new WP_REST_Request( 'PUT' ); |
|
| 220 | - |
|
| 221 | - // Add body params. |
|
| 222 | - $_item->set_body_params( $item ); |
|
| 223 | - |
|
| 224 | - // Set query (GET) parameters. |
|
| 225 | - $_item->set_query_params( $query ); |
|
| 226 | - |
|
| 227 | - // Update the item. |
|
| 228 | - $_response = $this->update_item( $_item ); |
|
| 229 | - |
|
| 230 | - // If an error occured... |
|
| 231 | - if ( is_wp_error( $_response ) ) { |
|
| 232 | - |
|
| 233 | - $update[] = array( |
|
| 234 | - 'id' => $item['id'], |
|
| 235 | - 'error' => array( |
|
| 236 | - 'code' => $_response->get_error_code(), |
|
| 237 | - 'message' => $_response->get_error_message(), |
|
| 238 | - 'data' => $_response->get_error_data(), |
|
| 239 | - ), |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - continue; |
|
| 243 | - |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 247 | - |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $update; |
|
| 251 | - |
|
| 252 | - } |
|
| 293 | + $delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 253 | 294 | |
| 254 | - /** |
|
| 255 | - * Bulk delete items. |
|
| 256 | - * |
|
| 257 | - * @param array $items Array of items to delete. |
|
| 258 | - * @param WP_REST_Server $wp_rest_server |
|
| 259 | - * @return array() |
|
| 260 | - */ |
|
| 261 | - protected function batch_delete_items( $items, $wp_rest_server ) { |
|
| 262 | - |
|
| 263 | - $delete = array(); |
|
| 264 | - |
|
| 265 | - foreach ( array_filter( $items ) as $id ) { |
|
| 266 | - |
|
| 267 | - // Prepare the request. |
|
| 268 | - $_item = new WP_REST_Request( 'DELETE' ); |
|
| 269 | - $_item->set_query_params( |
|
| 270 | - array( |
|
| 271 | - 'id' => $id, |
|
| 272 | - 'force' => true, |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - // Delete the item. |
|
| 277 | - $_response = $this->delete_item( $_item ); |
|
| 278 | - |
|
| 279 | - if ( is_wp_error( $_response ) ) { |
|
| 280 | - |
|
| 281 | - $delete[] = array( |
|
| 282 | - 'id' => $id, |
|
| 283 | - 'error' => array( |
|
| 284 | - 'code' => $_response->get_error_code(), |
|
| 285 | - 'message' => $_response->get_error_message(), |
|
| 286 | - 'data' => $_response->get_error_data(), |
|
| 287 | - ), |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - continue; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false ); |
|
| 294 | - |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return $delete; |
|
| 298 | - |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Bulk create, update and delete items. |
|
| 303 | - * |
|
| 304 | - * @param WP_REST_Request $request Full details about the request. |
|
| 305 | - * @return WP_Error|array. |
|
| 306 | - */ |
|
| 307 | - public function batch_items( $request ) { |
|
| 308 | - global $wp_rest_server; |
|
| 309 | - |
|
| 310 | - // Prepare the batch items. |
|
| 311 | - $items = $this->fill_batch_keys( array_filter( $request->get_params() ) ); |
|
| 312 | - |
|
| 313 | - // Ensure that the batch has not exceeded the limit to prevent abuse. |
|
| 314 | - $limit = $this->check_batch_limit( $items ); |
|
| 315 | - if ( is_wp_error( $limit ) ) { |
|
| 316 | - return $limit; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Process the items. |
|
| 320 | - return array( |
|
| 321 | - 'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ), |
|
| 322 | - 'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ), |
|
| 323 | - 'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ), |
|
| 324 | - ); |
|
| 325 | - |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Add meta query. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param array $args Query args. |
|
| 333 | - * @param array $meta_query Meta query. |
|
| 334 | - * @return array |
|
| 335 | - */ |
|
| 336 | - protected function add_meta_query( $args, $meta_query ) { |
|
| 337 | - if ( empty( $args['meta_query'] ) ) { |
|
| 338 | - $args['meta_query'] = array(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - $args['meta_query'][] = $meta_query; |
|
| 342 | - |
|
| 343 | - return $args['meta_query']; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Get the batch schema, conforming to JSON Schema. |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - public function get_public_batch_schema() { |
|
| 352 | - |
|
| 353 | - return array( |
|
| 354 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 355 | - 'title' => 'batch', |
|
| 356 | - 'type' => 'object', |
|
| 357 | - 'properties' => array( |
|
| 358 | - 'create' => array( |
|
| 359 | - 'description' => __( 'List of created resources.', 'invoicing' ), |
|
| 360 | - 'type' => 'array', |
|
| 361 | - 'context' => array( 'view', 'edit' ), |
|
| 362 | - 'items' => array( |
|
| 363 | - 'type' => 'object', |
|
| 364 | - ), |
|
| 365 | - ), |
|
| 366 | - 'update' => array( |
|
| 367 | - 'description' => __( 'List of updated resources.', 'invoicing' ), |
|
| 368 | - 'type' => 'array', |
|
| 369 | - 'context' => array( 'view', 'edit' ), |
|
| 370 | - 'items' => array( |
|
| 371 | - 'type' => 'object', |
|
| 372 | - ), |
|
| 373 | - ), |
|
| 374 | - 'delete' => array( |
|
| 375 | - 'description' => __( 'List of deleted resources.', 'invoicing' ), |
|
| 376 | - 'type' => 'array', |
|
| 377 | - 'context' => array( 'view', 'edit' ), |
|
| 378 | - 'items' => array( |
|
| 379 | - 'type' => 'integer', |
|
| 380 | - ), |
|
| 381 | - ), |
|
| 382 | - ), |
|
| 383 | - ); |
|
| 384 | - |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Returns the value of schema['properties'] |
|
| 389 | - * |
|
| 390 | - * i.e Schema fields. |
|
| 391 | - * |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - * @return array |
|
| 394 | - */ |
|
| 395 | - protected function get_schema_properties() { |
|
| 396 | - |
|
| 397 | - $schema = $this->get_item_schema(); |
|
| 398 | - $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
| 399 | - |
|
| 400 | - // For back-compat, include any field with an empty schema |
|
| 401 | - // because it won't be present in $this->get_item_schema(). |
|
| 402 | - foreach ( $this->get_additional_fields() as $field_name => $field_options ) { |
|
| 403 | - if ( is_null( $field_options['schema'] ) ) { |
|
| 404 | - $properties[ $field_name ] = $field_options; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - return $properties; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Filters fields by context. |
|
| 413 | - * |
|
| 414 | - * @param array $fields Array of fields |
|
| 415 | - * @param string|null context view, edit or embed |
|
| 416 | - * @since 1.0.19 |
|
| 417 | - * @return array |
|
| 418 | - */ |
|
| 419 | - protected function filter_response_fields_by_context( $fields, $context ) { |
|
| 420 | - |
|
| 421 | - if ( empty( $context ) ) { |
|
| 422 | - return $fields; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - foreach ( $fields as $name => $options ) { |
|
| 426 | - if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
| 427 | - unset( $fields[ $name ] ); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return $fields; |
|
| 432 | - |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Filters fields by an array of requested fields. |
|
| 437 | - * |
|
| 438 | - * @param array $fields Array of available fields |
|
| 439 | - * @param array $requested array of requested fields. |
|
| 440 | - * @since 1.0.19 |
|
| 441 | - * @return array |
|
| 442 | - */ |
|
| 443 | - protected function filter_response_fields_by_array( $fields, $requested ) { |
|
| 444 | - |
|
| 445 | - // Trim off any whitespace from the list array. |
|
| 446 | - $requested = array_map( 'trim', $requested ); |
|
| 447 | - |
|
| 448 | - // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
|
| 449 | - if ( in_array( 'id', $fields, true ) ) { |
|
| 450 | - $requested[] = 'id'; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Get rid of duplicate fields. |
|
| 454 | - $requested = array_unique( $requested ); |
|
| 455 | - |
|
| 456 | - // Return the list of all included fields which are available. |
|
| 457 | - return array_reduce( |
|
| 458 | - $requested, |
|
| 459 | - function( $response_fields, $field ) use ( $fields ) { |
|
| 460 | - |
|
| 461 | - if ( in_array( $field, $fields, true ) ) { |
|
| 462 | - $response_fields[] = $field; |
|
| 463 | - return $response_fields; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // Check for nested fields if $field is not a direct match. |
|
| 467 | - $nested_fields = explode( '.', $field ); |
|
| 468 | - |
|
| 469 | - // A nested field is included so long as its top-level property is |
|
| 470 | - // present in the schema. |
|
| 471 | - if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
| 472 | - $response_fields[] = $field; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - return $response_fields; |
|
| 476 | - }, |
|
| 477 | - array() |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Gets an array of fields to be included on the response. |
|
| 484 | - * |
|
| 485 | - * Included fields are based on item schema and `_fields=` request argument. |
|
| 486 | - * Copied from WordPress 5.3 to support old versions. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - * @param WP_REST_Request $request Full details about the request. |
|
| 490 | - * @return array Fields to be included in the response. |
|
| 491 | - */ |
|
| 492 | - public function get_fields_for_response( $request ) { |
|
| 493 | - |
|
| 494 | - // Retrieve fields in the schema. |
|
| 495 | - $properties = $this->get_schema_properties(); |
|
| 496 | - |
|
| 497 | - // Exclude fields that specify a different context than the request context. |
|
| 498 | - $properties = $this->filter_response_fields_by_context( $properties, $request['context'] ); |
|
| 499 | - |
|
| 500 | - // We only need the field keys. |
|
| 501 | - $fields = array_keys( $properties ); |
|
| 502 | - |
|
| 503 | - // Is the user filtering the response fields?? |
|
| 504 | - if ( empty( $request['_fields'] ) ) { |
|
| 505 | - return $fields; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) ); |
|
| 509 | - |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Limits an object to the requested fields. |
|
| 514 | - * |
|
| 515 | - * Included fields are based on the `_fields` request argument. |
|
| 516 | - * |
|
| 517 | - * @since 1.0.19 |
|
| 518 | - * @param array $data Fields to include in the response. |
|
| 519 | - * @param array $fields Requested fields. |
|
| 520 | - * @return array Fields to be included in the response. |
|
| 521 | - */ |
|
| 522 | - public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) { |
|
| 523 | - |
|
| 524 | - // Is the user filtering the response fields?? |
|
| 525 | - if ( empty( $fields ) ) { |
|
| 526 | - return $data; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - foreach ( $data as $key => $value ) { |
|
| 530 | - |
|
| 531 | - // Numeric arrays. |
|
| 532 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 533 | - $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix ); |
|
| 534 | - continue; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - // Generate a new prefix. |
|
| 538 | - $new_prefix = empty( $prefix ) ? $key : "$prefix.$key"; |
|
| 539 | - |
|
| 540 | - // Check if it was requested. |
|
| 541 | - if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) { |
|
| 542 | - unset( $data[ $key ] ); |
|
| 543 | - continue; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if ( $key != 'meta_data' && is_array( $value ) ) { |
|
| 547 | - $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix ); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $data; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Given an array of fields to include in a response, some of which may be |
|
| 557 | - * `nested.fields`, determine whether the provided field should be included |
|
| 558 | - * in the response body. |
|
| 559 | - * |
|
| 560 | - * Copied from WordPress 5.3 to support old versions. |
|
| 561 | - * |
|
| 562 | - * @since 1.0.19 |
|
| 563 | - * |
|
| 564 | - * @param string $field A field to test for inclusion in the response body. |
|
| 565 | - * @param array $fields An array of string fields supported by the endpoint. |
|
| 566 | - * @return bool Whether to include the field or not. |
|
| 567 | - * @see rest_is_field_included() |
|
| 568 | - */ |
|
| 569 | - public function is_field_included( $field, $fields ) { |
|
| 570 | - if ( in_array( $field, $fields, true ) ) { |
|
| 571 | - return true; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - foreach ( $fields as $accepted_field ) { |
|
| 575 | - // Check to see if $field is the parent of any item in $fields. |
|
| 576 | - // A field "parent" should be accepted if "parent.child" is accepted. |
|
| 577 | - if ( strpos( $accepted_field, "$field." ) === 0 ) { |
|
| 578 | - return true; |
|
| 579 | - } |
|
| 580 | - // Conversely, if "parent" is accepted, all "parent.child" fields |
|
| 581 | - // should also be accepted. |
|
| 582 | - if ( strpos( $field, "$accepted_field." ) === 0 ) { |
|
| 583 | - return true; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return $delete; |
|
| 298 | + |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Bulk create, update and delete items. |
|
| 303 | + * |
|
| 304 | + * @param WP_REST_Request $request Full details about the request. |
|
| 305 | + * @return WP_Error|array. |
|
| 306 | + */ |
|
| 307 | + public function batch_items( $request ) { |
|
| 308 | + global $wp_rest_server; |
|
| 309 | + |
|
| 310 | + // Prepare the batch items. |
|
| 311 | + $items = $this->fill_batch_keys( array_filter( $request->get_params() ) ); |
|
| 312 | + |
|
| 313 | + // Ensure that the batch has not exceeded the limit to prevent abuse. |
|
| 314 | + $limit = $this->check_batch_limit( $items ); |
|
| 315 | + if ( is_wp_error( $limit ) ) { |
|
| 316 | + return $limit; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Process the items. |
|
| 320 | + return array( |
|
| 321 | + 'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ), |
|
| 322 | + 'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ), |
|
| 323 | + 'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ), |
|
| 324 | + ); |
|
| 325 | + |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Add meta query. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param array $args Query args. |
|
| 333 | + * @param array $meta_query Meta query. |
|
| 334 | + * @return array |
|
| 335 | + */ |
|
| 336 | + protected function add_meta_query( $args, $meta_query ) { |
|
| 337 | + if ( empty( $args['meta_query'] ) ) { |
|
| 338 | + $args['meta_query'] = array(); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + $args['meta_query'][] = $meta_query; |
|
| 342 | + |
|
| 343 | + return $args['meta_query']; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Get the batch schema, conforming to JSON Schema. |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + public function get_public_batch_schema() { |
|
| 352 | + |
|
| 353 | + return array( |
|
| 354 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 355 | + 'title' => 'batch', |
|
| 356 | + 'type' => 'object', |
|
| 357 | + 'properties' => array( |
|
| 358 | + 'create' => array( |
|
| 359 | + 'description' => __( 'List of created resources.', 'invoicing' ), |
|
| 360 | + 'type' => 'array', |
|
| 361 | + 'context' => array( 'view', 'edit' ), |
|
| 362 | + 'items' => array( |
|
| 363 | + 'type' => 'object', |
|
| 364 | + ), |
|
| 365 | + ), |
|
| 366 | + 'update' => array( |
|
| 367 | + 'description' => __( 'List of updated resources.', 'invoicing' ), |
|
| 368 | + 'type' => 'array', |
|
| 369 | + 'context' => array( 'view', 'edit' ), |
|
| 370 | + 'items' => array( |
|
| 371 | + 'type' => 'object', |
|
| 372 | + ), |
|
| 373 | + ), |
|
| 374 | + 'delete' => array( |
|
| 375 | + 'description' => __( 'List of deleted resources.', 'invoicing' ), |
|
| 376 | + 'type' => 'array', |
|
| 377 | + 'context' => array( 'view', 'edit' ), |
|
| 378 | + 'items' => array( |
|
| 379 | + 'type' => 'integer', |
|
| 380 | + ), |
|
| 381 | + ), |
|
| 382 | + ), |
|
| 383 | + ); |
|
| 384 | + |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Returns the value of schema['properties'] |
|
| 389 | + * |
|
| 390 | + * i.e Schema fields. |
|
| 391 | + * |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + * @return array |
|
| 394 | + */ |
|
| 395 | + protected function get_schema_properties() { |
|
| 396 | + |
|
| 397 | + $schema = $this->get_item_schema(); |
|
| 398 | + $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
| 399 | + |
|
| 400 | + // For back-compat, include any field with an empty schema |
|
| 401 | + // because it won't be present in $this->get_item_schema(). |
|
| 402 | + foreach ( $this->get_additional_fields() as $field_name => $field_options ) { |
|
| 403 | + if ( is_null( $field_options['schema'] ) ) { |
|
| 404 | + $properties[ $field_name ] = $field_options; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + return $properties; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Filters fields by context. |
|
| 413 | + * |
|
| 414 | + * @param array $fields Array of fields |
|
| 415 | + * @param string|null context view, edit or embed |
|
| 416 | + * @since 1.0.19 |
|
| 417 | + * @return array |
|
| 418 | + */ |
|
| 419 | + protected function filter_response_fields_by_context( $fields, $context ) { |
|
| 420 | + |
|
| 421 | + if ( empty( $context ) ) { |
|
| 422 | + return $fields; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + foreach ( $fields as $name => $options ) { |
|
| 426 | + if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
| 427 | + unset( $fields[ $name ] ); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return $fields; |
|
| 432 | + |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Filters fields by an array of requested fields. |
|
| 437 | + * |
|
| 438 | + * @param array $fields Array of available fields |
|
| 439 | + * @param array $requested array of requested fields. |
|
| 440 | + * @since 1.0.19 |
|
| 441 | + * @return array |
|
| 442 | + */ |
|
| 443 | + protected function filter_response_fields_by_array( $fields, $requested ) { |
|
| 444 | + |
|
| 445 | + // Trim off any whitespace from the list array. |
|
| 446 | + $requested = array_map( 'trim', $requested ); |
|
| 447 | + |
|
| 448 | + // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
|
| 449 | + if ( in_array( 'id', $fields, true ) ) { |
|
| 450 | + $requested[] = 'id'; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Get rid of duplicate fields. |
|
| 454 | + $requested = array_unique( $requested ); |
|
| 455 | + |
|
| 456 | + // Return the list of all included fields which are available. |
|
| 457 | + return array_reduce( |
|
| 458 | + $requested, |
|
| 459 | + function( $response_fields, $field ) use ( $fields ) { |
|
| 460 | + |
|
| 461 | + if ( in_array( $field, $fields, true ) ) { |
|
| 462 | + $response_fields[] = $field; |
|
| 463 | + return $response_fields; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // Check for nested fields if $field is not a direct match. |
|
| 467 | + $nested_fields = explode( '.', $field ); |
|
| 468 | + |
|
| 469 | + // A nested field is included so long as its top-level property is |
|
| 470 | + // present in the schema. |
|
| 471 | + if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
| 472 | + $response_fields[] = $field; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + return $response_fields; |
|
| 476 | + }, |
|
| 477 | + array() |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Gets an array of fields to be included on the response. |
|
| 484 | + * |
|
| 485 | + * Included fields are based on item schema and `_fields=` request argument. |
|
| 486 | + * Copied from WordPress 5.3 to support old versions. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + * @param WP_REST_Request $request Full details about the request. |
|
| 490 | + * @return array Fields to be included in the response. |
|
| 491 | + */ |
|
| 492 | + public function get_fields_for_response( $request ) { |
|
| 493 | + |
|
| 494 | + // Retrieve fields in the schema. |
|
| 495 | + $properties = $this->get_schema_properties(); |
|
| 496 | + |
|
| 497 | + // Exclude fields that specify a different context than the request context. |
|
| 498 | + $properties = $this->filter_response_fields_by_context( $properties, $request['context'] ); |
|
| 499 | + |
|
| 500 | + // We only need the field keys. |
|
| 501 | + $fields = array_keys( $properties ); |
|
| 502 | + |
|
| 503 | + // Is the user filtering the response fields?? |
|
| 504 | + if ( empty( $request['_fields'] ) ) { |
|
| 505 | + return $fields; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) ); |
|
| 509 | + |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Limits an object to the requested fields. |
|
| 514 | + * |
|
| 515 | + * Included fields are based on the `_fields` request argument. |
|
| 516 | + * |
|
| 517 | + * @since 1.0.19 |
|
| 518 | + * @param array $data Fields to include in the response. |
|
| 519 | + * @param array $fields Requested fields. |
|
| 520 | + * @return array Fields to be included in the response. |
|
| 521 | + */ |
|
| 522 | + public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) { |
|
| 523 | + |
|
| 524 | + // Is the user filtering the response fields?? |
|
| 525 | + if ( empty( $fields ) ) { |
|
| 526 | + return $data; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + foreach ( $data as $key => $value ) { |
|
| 530 | + |
|
| 531 | + // Numeric arrays. |
|
| 532 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 533 | + $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix ); |
|
| 534 | + continue; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + // Generate a new prefix. |
|
| 538 | + $new_prefix = empty( $prefix ) ? $key : "$prefix.$key"; |
|
| 539 | + |
|
| 540 | + // Check if it was requested. |
|
| 541 | + if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) { |
|
| 542 | + unset( $data[ $key ] ); |
|
| 543 | + continue; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if ( $key != 'meta_data' && is_array( $value ) ) { |
|
| 547 | + $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix ); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $data; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Given an array of fields to include in a response, some of which may be |
|
| 557 | + * `nested.fields`, determine whether the provided field should be included |
|
| 558 | + * in the response body. |
|
| 559 | + * |
|
| 560 | + * Copied from WordPress 5.3 to support old versions. |
|
| 561 | + * |
|
| 562 | + * @since 1.0.19 |
|
| 563 | + * |
|
| 564 | + * @param string $field A field to test for inclusion in the response body. |
|
| 565 | + * @param array $fields An array of string fields supported by the endpoint. |
|
| 566 | + * @return bool Whether to include the field or not. |
|
| 567 | + * @see rest_is_field_included() |
|
| 568 | + */ |
|
| 569 | + public function is_field_included( $field, $fields ) { |
|
| 570 | + if ( in_array( $field, $fields, true ) ) { |
|
| 571 | + return true; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + foreach ( $fields as $accepted_field ) { |
|
| 575 | + // Check to see if $field is the parent of any item in $fields. |
|
| 576 | + // A field "parent" should be accepted if "parent.child" is accepted. |
|
| 577 | + if ( strpos( $accepted_field, "$field." ) === 0 ) { |
|
| 578 | + return true; |
|
| 579 | + } |
|
| 580 | + // Conversely, if "parent" is accepted, all "parent.child" fields |
|
| 581 | + // should also be accepted. |
|
| 582 | + if ( strpos( $field, "$accepted_field." ) === 0 ) { |
|
| 583 | + return true; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | 590 | } |