芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/popup-maker/classes/Abstract/Model/Post.php
setup( $post ); } /** * Given the post data, let's set the variables * * @param WP_Post $post */ protected function setup( $post ) { if ( ! is_a( $post, 'WP_Post' ) || ! $this->is_required_post_type( $post ) ) { $this->valid = false; return; } $this->post = $post; foreach ( get_object_vars( $post ) as $key => $value ) { $this->$key = $value; } } /** * @param WP_Post $post * * @return bool */ protected function is_required_post_type( $post ) { if ( $this->required_post_type ) { if ( is_array( $this->required_post_type ) && ! in_array( $post->post_type, $this->required_post_type ) ) { return false; } elseif ( is_string( $this->required_post_type ) && $this->required_post_type !== $post->post_type ) { return false; } } return true; } /** * is triggered when invoking inaccessible methods in an object context. * * @param $name string * @param $arguments array * * @return mixed * @link http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods */ public function __call( $name, $arguments ) { if ( method_exists( $this, 'get_' . $name ) ) { return call_user_func_array( [ $this, 'get_' . $name ], $arguments ); } } /** * Magic __get function to dispatch a call to retrieve a private property * * @param $key * * @return mixed|WP_Error */ public function __get( $key ) { if ( method_exists( $this, 'get_' . $key ) ) { return call_user_func( [ $this, 'get_' . $key ] ); } else { $meta = $this->get_meta( $key ); if ( $meta ) { return $meta; } return new WP_Error( 'post-invalid-property', sprintf( __( 'Can\'t get property %s' ), $key ) ); } } /** * Is object valid. * * @return bool. */ public function is_valid() { return $this->valid; } /** * @param $key * @param bool $single * * @return mixed|false */ public function get_meta( $key, $single = true ) { /** * Checks for remapped meta values. This allows easily adding compatibility layers in the object meta. */ if ( false !== $remapped_value = $this->remapped_meta( $key ) ) { return $remapped_value; } return get_post_meta( $this->ID, $key, $single ); } /** * @param string $key * @param mixed $value * @param bool $unique * * @return bool|int */ public function add_meta( $key, $value, $unique = false ) { return add_post_meta( $this->ID, $key, $value, $unique ); } /** * @param string $key * @param mixed $value * * @return bool|int */ public function update_meta( $key, $value ) { return update_post_meta( $this->ID, $key, $value ); } /** * @param string $key * * @return bool */ public function delete_meta( $key ) { return delete_post_meta( $this->ID, $key ); } /** * Allows for easy backward compatibility layer management in each child class. * * @param string $key * * @return bool */ public function remapped_meta( $key = '' ) { return false; } /** * @return int */ public function author_id() { return (int) $this->post_author; } /** * Convert object to array. * * @return array Object as array. */ public function to_array() { $post = get_object_vars( $this ); return $post; } /** * @return bool */ public function is_trash() { return get_post_status( $this->ID ) === 'trash'; } /** * @return bool */ public function is_published() { return get_post_status( $this->ID ) === 'publish'; } /** * @return bool */ public function is_draft() { return get_post_status( $this->ID ) === 'draft'; } /** * @return bool */ public function is_private() { return get_post_status( $this->ID ) === 'private'; } /** * @return bool */ public function is_pending() { return get_post_status( $this->ID ) === 'pending'; } }