WordPressを読む 38-3 /blog/wp-includes/post.php 3
2014/12/24
目次
- 1 /blog/wp-includes/post.php 3
- 2 関数 get_post_ancestors()
- 3 関数 get_post_field()
- 4 関数 get_post_mime_type()
- 5 関数 get_post_status()
- 6 関数 get_post_statuses()
- 7 関数 get_page_statuses()
- 8 関数 register_post_status()
- 9 関数 get_post_status_object()
- 10 関数 get_post_stati()
- 11 関数 is_post_type_hierarchical()
- 12 関数 post_type_exists()
- 13 関数 get_post_type()
- 14 関数 get_post_type_object()
- 15 関数 get_post_types()
/blog/wp-includes/post.php 3
関数 get_post_ancestors()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /** * Retrieve ancestors of a post. * * @since 2.5.0 * * @param int|WP_Post $post Post ID or post object. * @return array Ancestor IDs or empty array if none are found. */ function get_post_ancestors( $post ) { $post = get_post( $post ); if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) return array(); $ancestors = array(); $id = $ancestors[] = $post->post_parent; while ( $ancestor = get_post( $id ) ) { // Loop detection: If the ancestor has been seen before, break. if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) break; $id = $ancestors[] = $ancestor->post_parent; } return $ancestors; } |
関数 get_post_field()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /** * Retrieve data from a post field based on Post ID. * * Examples of the post field will be, 'post_type', 'post_status', 'post_content', * etc and based off of the post object property or key names. * * The context values are based off of the taxonomy filter functions and * supported values are found within those functions. * * @since 2.3.0 * * @see sanitize_post_field() * * @param string $field Post field name. * @param int|WP_Post $post Post ID or post object. * @param string $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db', * or 'display'. Default 'display'. * @return string The value of the post field on success, empty string on failure. */ function get_post_field( $field, $post, $context = 'display' ) { $post = get_post( $post ); if ( !$post ) return ''; if ( !isset($post->$field) ) return ''; return sanitize_post_field($field, $post->$field, $post->ID, $context); } |
関数 get_post_mime_type()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Retrieve the mime type of an attachment based on the ID. * * This function can be used with any post type, but it makes more sense with * attachments. * * @since 2.0.0 * * @param int|WP_Post $ID Optional. Post ID or post object. Default empty. * @return string|bool The mime type on success, false on failure. */ function get_post_mime_type( $ID = '' ) { $post = get_post($ID); if ( is_object($post) ) return $post->post_mime_type; return false; } |
関数 get_post_status()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /** * Retrieve the post status based on the Post ID. * * If the post ID is of an attachment, then the parent post status will be given * instead. * * @since 2.0.0 * * @param int|WP_Post $ID Optional. Post ID or post object. Default empty. * @return string|bool Post status on success, false on failure. */ function get_post_status( $ID = '' ) { $post = get_post($ID); if ( !is_object($post) ) return false; if ( 'attachment' == $post->post_type ) { if ( 'private' == $post->post_status ) return 'private'; // Unattached attachments are assumed to be published. if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) return 'publish'; // Inherit status from the parent. if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) { $parent_post_status = get_post_status( $post->post_parent ); if ( 'trash' == $parent_post_status ) { return get_post_meta( $post->post_parent, '_wp_trash_meta_status', true ); } else { return $parent_post_status; } } } return $post->post_status; } |
関数 get_post_statuses()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Retrieve all of the WordPress supported post statuses. * * Posts have a limited set of valid status values, this provides the * post_status values and descriptions. * * @since 2.5.0 * * @return array List of post statuses. */ function get_post_statuses() { $status = array( 'draft' => __( 'Draft' ), 'pending' => __( 'Pending Review' ), 'private' => __( 'Private' ), 'publish' => __( 'Published' ) ); return $status; } |
関数 get_page_statuses()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Retrieve all of the WordPress support page statuses. * * Pages have a limited set of valid status values, this provides the * post_status values and descriptions. * * @since 2.5.0 * * @return array List of page statuses. */ function get_page_statuses() { $status = array( 'draft' => __( 'Draft' ), 'private' => __( 'Private' ), 'publish' => __( 'Published' ) ); return $status; } |
関数 register_post_status()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | /** * Register a post status. Do not use before init. * * A simple function for creating or modifying a post status based on the * parameters given. The function will accept an array (second optional * parameter), along with a string for the post status name. * * Arguments prefixed with an _underscore shouldn't be used by plugins and themes. * * @since 3.0.0 * @uses $wp_post_statuses Inserts new post status object into the list * * @param string $post_status Name of the post status. * @param array|string $args { * Optional. Array or string of post status arguments. * * @type bool|string $label A descriptive name for the post status marked * for translation. Defaults to value of $post_status. * @type bool|array $label_count Descriptive text to use for nooped plurals. * Default array of $label, twice * @type bool $exclude_from_search Whether to exclude posts with this post status * from search results. Default is value of $internal. * @type bool $_builtin Whether the status is built-in. Core-use only. * Default false. * @type bool $public Whether posts of this status should be shown * in the front end of the site. Default true. * @type bool $internal Whether the status is for internal use only. * Default false. * @type bool $protected Whether posts with this status should be protected. * Default false. * @type bool $private Whether posts with this status should be private. * Default false. * @type bool $publicly_queryable Whether posts with this status should be publicly- * queryable. Default is value of $public. * @type bool $show_in_admin_all_list Whether to include posts in the edit listing for * their post type. Default is value of $internal. * @type bool $show_in_admin_status_list Show in the list of statuses with post counts at * the top of the edit listings, * e.g. All (12) | Published (9) | My Custom Status (2) * Default is value of $internal. * } */ function register_post_status( $post_status, $args = array() ) { global $wp_post_statuses; if (!is_array($wp_post_statuses)) $wp_post_statuses = array(); // Args prefixed with an underscore are reserved for internal use. $defaults = array( 'label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, ); $args = wp_parse_args($args, $defaults); $args = (object) $args; $post_status = sanitize_key($post_status); $args->name = $post_status; // Set various defaults. if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) $args->internal = true; if ( null === $args->public ) $args->public = false; if ( null === $args->private ) $args->private = false; if ( null === $args->protected ) $args->protected = false; if ( null === $args->internal ) $args->internal = false; if ( null === $args->publicly_queryable ) $args->publicly_queryable = $args->public; if ( null === $args->exclude_from_search ) $args->exclude_from_search = $args->internal; if ( null === $args->show_in_admin_all_list ) $args->show_in_admin_all_list = !$args->internal; if ( null === $args->show_in_admin_status_list ) $args->show_in_admin_status_list = !$args->internal; if ( false === $args->label ) $args->label = $post_status; if ( false === $args->label_count ) $args->label_count = array( $args->label, $args->label ); $wp_post_statuses[$post_status] = $args; return $args; } |
関数 get_post_status_object()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Retrieve a post status object by name. * * @since 3.0.0 * * @global array $wp_post_statuses List of post statuses. * * @see register_post_status() * * @param string $post_status The name of a registered post status. * @return object A post status object. */ function get_post_status_object( $post_status ) { global $wp_post_statuses; if ( empty($wp_post_statuses[$post_status]) ) return null; return $wp_post_statuses[$post_status]; } |
関数 get_post_stati()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** * Get a list of all registered post status objects. * * @since 3.0.0 * * @global array $wp_post_statuses List of post statuses. * * @see register_post_status() * * @param array|string $args Optional. Array or string of post status arguments. Default array. * @param string $output Optional. The type of output to return. Accepts post status 'names' * or 'objects'. Default 'names'. * @param string $operator Optional. The logical operation to perform. 'or' means only one element * from the array needs to match; 'and' means all elements must match. * Default 'and'. * @return array A list of post status names or objects. */ function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { global $wp_post_statuses; $field = ('names' == $output) ? 'name' : false; return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); } |
関数 is_post_type_hierarchical()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Whether the post type is hierarchical. * * A false return value might also mean that the post type does not exist. * * @since 3.0.0 * * @see get_post_type_object() * * @param string $post_type Post type name * @return bool Whether post type is hierarchical. */ function is_post_type_hierarchical( $post_type ) { if ( ! post_type_exists( $post_type ) ) return false; $post_type = get_post_type_object( $post_type ); return $post_type->hierarchical; } |
関数 post_type_exists()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Check if a post type is registered. * * @since 3.0.0 * * @see get_post_type_object() * * @param string $post_type Post type name. * @return bool Whether post type is registered. */ function post_type_exists( $post_type ) { return (bool) get_post_type_object( $post_type ); } |
関数 get_post_type()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Retrieve the post type of the current post or of a given post. * * @since 2.1.0 * * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. * @return string|bool Post type on success, false on failure. */ function get_post_type( $post = null ) { if ( $post = get_post( $post ) ) return $post->post_type; return false; } |
関数 get_post_type_object()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Retrieve a post type object by name. * * @since 3.0.0 * * @global array $wp_post_types List of post types. * * @see register_post_type() * * @param string $post_type The name of a registered post type. * @return object A post type object. */ function get_post_type_object( $post_type ) { global $wp_post_types; if ( empty($wp_post_types[$post_type]) ) return null; return $wp_post_types[$post_type]; } |
関数 get_post_types()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /** * Get a list of all registered post type objects. * * @since 2.9.0 * * @global array $wp_post_types List of post types. * * @see register_post_type() * * @param array|string $args Optional. An array of key => value arguments to match against * the post type objects. Default empty array. * @param string $output Optional. The type of output to return. Accepts post type 'names' * or 'objects'. Default 'names'. * @param string $operator Optaionl. The logical operation to perform. 'or' means only one * element from the array needs to match; 'and' means all elements * must match. Default 'and'. * @return array A list of post type names or objects. */ function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { global $wp_post_types; $field = ('names' == $output) ? 'name' : false; return wp_filter_object_list($wp_post_types, $args, $operator, $field); } |