Make WordPress Core

Changeset 28041


Ignore:
Timestamp:
04/08/2014 06:48:32 AM (11 years ago)
Author:
DrewAPicture
Message:

Part I of inline documenation for hooks in wp-includes/post.php.

Adds docs for the following hooks:

  • get_attached_file
  • update_attached_file
  • _wp_relative_upload_path
  • post_type_labels_{$post_type}
  • edit_{$field}
  • {$field_no_prefix}_edit_pre
  • edit_post_{$field}
  • pre_{$field}
  • {$field_no_prefix}_save_pre
  • pre_post_{$field}
  • {$field}_pre
  • $field
  • post_{$field}
  • wp_count_posts
  • wp_count_attachments
  • post_mime_types
  • wp_insert_post_empty_content

See #25376.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r27807 r28041  
    192192    if ( $unfiltered )
    193193        return $file;
     194
     195    /**
     196     * Filter the attached file based on the given ID.
     197     *
     198     * @since 2.1.0
     199     *
     200     * @param string $file          Path to attached file.
     201     * @param int    $attachment_id Attachment ID.
     202     */
    194203    return apply_filters( 'get_attached_file', $file, $attachment_id );
    195204}
     
    202211 *
    203212 * @since 2.1.0
    204  * @uses apply_filters() Calls 'update_attached_file' on file path and attachment ID.
    205213 *
    206214 * @param int $attachment_id Attachment ID
     
    212220        return false;
    213221
     222    /**
     223     * Filter the path to the attached file to update.
     224     *
     225     * @since 2.1.0
     226     *
     227     * @param string $file          Path to the attached file to update.
     228     * @param int    $attachment_id Attachment ID.
     229     */
    214230    $file = apply_filters( 'update_attached_file', $file, $attachment_id );
     231
    215232    if ( $file = _wp_relative_upload_path( $file ) )
    216233        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
     
    225242 *
    226243 * @since 2.9.0
    227  * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
    228244 *
    229245 * @param string $path Full path to the file
     
    239255    }
    240256
     257    /**
     258     * Filter the relative path to an uploaded file.
     259     *
     260     * @since 2.9.0
     261     *
     262     * @param string $new_path Relative path to the file.
     263     * @param string $path     Full path to the file.
     264     */
    241265    return apply_filters( '_wp_relative_upload_path', $new_path, $path );
    242266}
     
    14941518
    14951519    $post_type = $post_type_object->name;
     1520
     1521    /**
     1522     * Filter the labels of a specific post type.
     1523     *
     1524     * The dynamic portion of the hook name, $post_type, refers to
     1525     * the post type slug.
     1526     *
     1527     * @since 3.5.0
     1528     *
     1529     * @see get_post_type_labels() for the full list of labels.
     1530     *
     1531     * @param array $labels Array of labels for the given post type.
     1532     */
    14961533    return apply_filters( "post_type_labels_{$post_type}", $labels );
    14971534}
     
    19381975 *
    19391976 * @since 2.3.0
    1940  * @uses apply_filters() Calls 'edit_$field' and '{$field_no_prefix}_edit_pre' passing $value and
    1941  *  $post_id if $context == 'edit' and field name prefix == 'post_'.
    1942  *
    1943  * @uses apply_filters() Calls 'edit_post_$field' passing $value and $post_id if $context == 'db'.
    1944  * @uses apply_filters() Calls 'pre_$field' passing $value if $context == 'db' and field name prefix == 'post_'.
    1945  * @uses apply_filters() Calls '{$field}_pre' passing $value if $context == 'db' and field name prefix != 'post_'.
    1946  *
    1947  * @uses apply_filters() Calls '$field' passing $value, $post_id and $context if $context == anything
    1948  *  other than 'raw', 'edit' and 'db' and field name prefix == 'post_'.
    1949  * @uses apply_filters() Calls 'post_$field' passing $value if $context == anything other than 'raw',
    1950  *  'edit' and 'db' and field name prefix != 'post_'.
    19511977 *
    19521978 * @param string $field The Post Object field name.
     
    19822008
    19832009        if ( $prefixed ) {
    1984             $value = apply_filters("edit_{$field}", $value, $post_id);
    1985             // Old school
    1986             $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id);
     2010
     2011            /**
     2012             * Filter the value of a specific post field to edit.
     2013             *
     2014             * The dynamic portion of the hook name, $field, refers to the prefixed
     2015             * post field name. For example, 'post_title'.
     2016             *
     2017             * @since 2.3.0
     2018             *
     2019             * @param mixed $value   Value of the post field.
     2020             * @param int   $post_id Post ID.
     2021             */
     2022            $value = apply_filters( "edit_{$field}", $value, $post_id );
     2023
     2024            /**
     2025             * Filter the value of a specific post field to edit.
     2026             *
     2027             * The dynamic portion of the hook name, $field_no_prefix, refers to
     2028             * the post field name with no prefix. For example, 'title' instead
     2029             * of 'post_title'.
     2030             *
     2031             * @since 2.3.0
     2032             * @deprecated 2.3.0 Use "edit_post_$field" instead.
     2033             *
     2034             * @param mixed $value   Value of the post field.
     2035             * @param int   $post_id Post ID.
     2036             */
     2037            $value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id );
    19872038        } else {
    1988             $value = apply_filters("edit_post_{$field}", $value, $post_id);
     2039
     2040            /**
     2041             * Filter the value of a specific post field to edit.
     2042             *
     2043             * The dynamic portion of the hook name, $field, refers to the un-prefixed
     2044             * post field. For example, 'title' instead of 'post_title'.
     2045             *
     2046             * @since 2.3.0
     2047             *
     2048             * @param mixed $value   Value of the un-prefixed post field.
     2049             * @param int   $post_id Post ID.
     2050             */
     2051            $value = apply_filters( "edit_post_{$field}", $value, $post_id );
    19892052        }
    19902053
     
    19992062    } else if ( 'db' == $context ) {
    20002063        if ( $prefixed ) {
    2001             $value = apply_filters("pre_{$field}", $value);
    2002             $value = apply_filters("{$field_no_prefix}_save_pre", $value);
     2064
     2065            /**
     2066             * Filter the value of a specific field before saving.
     2067             *
     2068             * The dynamic portion of the hook name, $field, refers to the
     2069             * prefixed post field name. For example, 'post_title'.
     2070             *
     2071             * @since 2.3.0
     2072             *
     2073             * @param mixed $value Value of the post field.
     2074             */
     2075            $value = apply_filters( "pre_{$field}", $value );
     2076
     2077            /**
     2078             * Filter the value of a specific field before saving.
     2079             *
     2080             * The dynamic portion of the hook name, $field_no_prefix, refers
     2081             * to the un-prefixed post field name. For example, 'title' instead
     2082             * of 'post_title'.
     2083             *
     2084             * @since 2.3.0
     2085             * @deprecated 2.3.0 Use "pre_post_{$field}" instead.
     2086             *
     2087             * @param mixed $value Value of the post field.
     2088             */
     2089            $value = apply_filters( "{$field_no_prefix}_save_pre", $value );
    20032090        } else {
    2004             $value = apply_filters("pre_post_{$field}", $value);
    2005             $value = apply_filters("{$field}_pre", $value);
     2091
     2092            /**
     2093             * Filter the value of a specific field before saving.
     2094             *
     2095             * The dynamic portion of the hook name, $field, refers to the un-prefixed
     2096             * post field name. For example, 'title' instead of 'post_title'.
     2097             *
     2098             * @since 2.3.0
     2099             *
     2100             * @param mixed $value Value of the post field.
     2101             */
     2102            $value = apply_filters( "pre_post_{$field}", $value );
     2103
     2104            /**
     2105             * Filter the value of a specific field before saving.
     2106             *
     2107             * The dynamic portion of the hook name, $field, refers to the un-prefixed
     2108             * post field name. For example, 'title' instead of 'post_title'.
     2109             *
     2110             * @since 2.3.0
     2111             * @deprecated 2.3.0 Use "pre_post_{$field}" instead.
     2112             *
     2113             * @param mixed $value Value of the post field.
     2114             */
     2115            $value = apply_filters( "{$field}_pre", $value );
    20062116        }
    20072117    } else {
     2118
    20082119        // Use display filters by default.
    2009         if ( $prefixed )
    2010             $value = apply_filters($field, $value, $post_id, $context);
    2011         else
    2012             $value = apply_filters("post_{$field}", $value, $post_id, $context);
     2120        if ( $prefixed ) {
     2121
     2122            /**
     2123             * Filter the value of a specific post field for display.
     2124             *
     2125             * The dynamic hook name, $field, refers to the prefixed post field
     2126             * name. For example, 'post_title'.
     2127             *
     2128             * @since
     2129             *
     2130             * @param mixed  $value   Value of the prefixed post field.
     2131             * @param int    $post_id Post ID.
     2132             * @param string $context Context for how to sanitize the field. Possible
     2133             *                        values include 'raw', 'edit', 'db', 'display',
     2134             *                        'attribute' and 'js'.
     2135             */
     2136            $value = apply_filters( $field, $value, $post_id, $context );
     2137        } else {
     2138
     2139            /**
     2140             * Filter the value of a specific post field for display.
     2141             *
     2142             * The dynamic portion of the hook name, $field, refers to the un-prefixed
     2143             * post field name. For example, 'title' instead of 'post_title'.'
     2144             *
     2145             * @since
     2146             *
     2147             * @param mixed  $value   Value of the un-prefixed post field.
     2148             * @param int    $post_id Post ID.
     2149             * @param string $context Context for how to sanitize the field. Possible
     2150             *                        values include 'raw', 'edit', 'db', 'display',
     2151             *                        'attribute' and 'js'.
     2152             */
     2153            $value = apply_filters( "post_{$field}", $value, $post_id, $context );
     2154        }
    20132155    }
    20142156
     
    21442286     * @since 3.7.0
    21452287     *
    2146      * @param object $counts An object containing the current post_type's post counts by status.
    2147      * @param string $type   The post type.
    2148      * @param string $perm   The permission to determine if the posts are 'readable' by the current user.
     2288     * @param object $counts An object containing the current post_type's post
     2289     *                       counts by status.
     2290     * @param string $type   Post type.
     2291     * @param string $perm   The permission to determine if the posts are 'readable'
     2292     *                       by the current user.
    21492293     */
    21502294    return apply_filters( 'wp_count_posts', $counts, $type, $perm );
     
    22012345    );
    22022346
    2203     return apply_filters('post_mime_types', $post_mime_types);
     2347    /**
     2348     * Filter the default list of post mime types.
     2349     *
     2350     * @since 2.5.0
     2351     *
     2352     * @param array $post_mime_types Default list of post mime types.
     2353     */
     2354    return apply_filters( 'post_mime_types', $post_mime_types );
    22042355}
    22052356
     
    27572908        && post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
    27582909
     2910    /**
     2911     * Filter whether the post should be considered "empty".
     2912     *
     2913     * The post is considered "empty" if both:
     2914     * 1. The post type supports the title, editor, and excerpt fields
     2915     * 2. The title, editor, and excerpt fields are all empty
     2916     *
     2917     * Returning a truthy value to the filter will effectively short-circuit
     2918     * the new post being inserted, returning 0. If $wp_error is true, a WP_Error
     2919     * will be returned instead.
     2920     *
     2921     * @since 3.3.0
     2922     *
     2923     * @param bool  $maybe_empty Whether the post should be considered "empty".
     2924     * @param array $postarr     Array of post data.
     2925     */
    27592926    if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
    27602927        if ( $wp_error )
Note: See TracChangeset for help on using the changeset viewer.