最后一堂课WP_Post{/***帖子ID。**@自3.5.0起*@var整数*/公共$ID;/***帖子作者的ID。**出于兼容性原因,为数字字符串。**@自3.5.0起*@var字符串*/public$post_author=0;/***该帖子的本地发布时间。**@自3.5.0起*@var字符串*/public$post_date=“0000-00-00 00:00:00”;/***文章的GMT发布时间。**@自3.5.0起*@var字符串*/public$post_date_gmt=“0000-00-00 00:00:00”;/***帖子的内容。**@自3.5.0起*@var字符串*/public$post_content='';/***帖子的标题。**@自3.5.0起*@var字符串*/public$post_title=“”;/***这篇文章的摘录。**@自3.5.0起*@var字符串*/public$post_excerpt=“”;/***帖子的状态。**@自3.5.0起*@var字符串*/public$post_status='publish';/***是否允许评论。**@自3.5.0起*@var字符串*/public$comment_status=“打开”;/***是否允许ping。**@自3.5.0起*@var字符串*/public$ping_status=“打开”;/***明文形式的帖子密码。**@自3.5.0起*@var字符串*/public$post_password=“”;/***这根柱子上的子弹。**@自3.5.0起*@var字符串*/公共$post_name=“”;/***排队等待ping的URL。**@自3.5.0起*@var字符串*/public$to_ping=“”;/***已Ping的URL。**@自3.5.0起*@var字符串*/public$pinged=“”;/***帖子的本地修改时间。**@自3.5.0起*@var字符串*/public$post_modified=“0000-00-00 00:00:00”;/***帖子的GMT修改时间。**@自3.5.0起*@var字符串*/public$post_modified_gmt=“0000-00-00 00:00:00”;/***用于发布内容的实用数据库字段。**@自3.5.0起*@var字符串*/public$post_content_filtered=“”;/***帖子的父帖子的ID。**@自3.5.0起*@var整数*/公共$post_parent=0;/***文章的唯一标识符,不一定是URL,用作提要GUID。**@自3.5.0起*@var字符串*/公共$guid=“”;/***用于排序帖子的字段。**@自3.5.0起*@var整数*/公共$menu_order=0;/***帖子的类型,如帖子或页面。**@自3.5.0起*@var字符串*/public$post_type='post';/***附件的mime类型。**@自3.5.0起*@var字符串*/公共$post_time_type=“”;/***缓存的注释计数。**出于兼容性原因,为数字字符串。**@自3.5.0起*@var字符串*/public$comment_count=0;/***存储post对象的清理级别。**与数据库字段不对应。**@自3.5.0起*@var字符串*/公共$filter;/***检索WP_Post实例。**@自3.5.0起**@global wpdb$wpdb WordPress数据库抽象对象。**@param int$post_id帖子id。*@return WP_Post | false Post对象,否则为false。*/公共静态函数getinstance($post_id){全局$wpdb;$post_id=(int)$post_id;if(!$post_id){返回false;}$_post=wp_cache_get($post_id,'posts');if(!$_post){$_post=$wpdb->get_row($wpdb->prepare(“SELECT*FROM$wpdb->posts WHERE ID=%d LIMIT 1”,$post_ID);if(!$_post){返回false;}$_post=消毒post($_post,'raw');wp_cache_add($_post->ID,$_post,'帖子');}elseif(空($_post->filter)||“原始”!==$_后->过滤器){$_post=消毒post($_post,'raw');}返回新的WP_Post($_Post);}/***建造师。**@自3.5.0起**@param WP_Post | object$Post Post对象。*/公共函数__construct($post){foreach(getobject_vars($post)作为$key=>$value){$this->$key=$value;}}/***Isset-er公司。**@自3.5.0起**@param string$key要检查是否已设置的属性。*@return布尔*/公共函数__isset($key){if(“祖先”===$key){返回true;}if(“page_template”===$key){返回true;}if(“post_category”===$key){返回true;}if('tags_input'===$key){返回true;}return metadata_exists('post',$this->ID,$key);}/***格特。**@自3.5.0起**@param string$key要获取的密钥。*@返回混合*/公共函数__get($key){if(“page_template”===$key&&$this->__isset($key)){return get_post_meta($this->ID,'_wp_page_template',true);}if(“post_category”===$key){if(isobjectin_taxonomy($this->posttype,'category')){$terms=get_the_terms($this,“类别”);}if(空($terms)){返回数组();}return wp_list_pluck($terms,'term_id');}if('tags_input'===$key){if(is_object_in_taxonomy($this->post_type,'post_tag')){$terms=get_the_terms($this,'post_tag');}if(空($terms)){返回数组();}return wp_list_pluck($terms,'name');}//其余值需要过滤。if(“祖先”===$key){$value=get_post_ancestors($this);}其他{$value=get_post_meta($this->ID,$key,true);}if($this->过滤器){$value=清理post_field($key,$value,$this->ID,$this->filter);}返回$value;}/***{@缺少摘要}**@自3.5.0起**@param string$filter过滤器。*@return WP_Post*/公共函数过滤器($filter){if($this->filter===$filter){返回$this;}if(“原始”===$filter){return self::get_instance($this->ID);}return sanitize_post($this,$filter);}/***将对象转换为数组。**@自3.5.0起**@return array对象作为数组。*/公共函数to_array(){$post=获取对象变量($this);foreach(数组(“祖先”、“page_template”、“post_category”、“tags_input”)作为$key){if($this->__isset($key)){$post[$key]=$this->__get($key);}}返回$post;}}
查看所有引用 在Trac上查看 在GitHub上查看