<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28041] trunk/src/wp-includes/post.php: Part I of inline documenation for hooks in wp-includes/post.php.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28041">28041</a></dd>
<dt>Author</dt> <dd>DrewAPicture</dd>
<dt>Date</dt> <dd>2014-04-08 06:48:32 +0000 (Tue, 08 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/25376">#25376</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/post.php (28040 => 28041)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/post.php   2014-04-08 06:25:56 UTC (rev 28040)
+++ trunk/src/wp-includes/post.php      2014-04-08 06:48:32 UTC (rev 28041)
</span><span class="lines">@@ -191,6 +191,15 @@
</span><span class="cx">          $file = $uploads['basedir'] . "/$file";
</span><span class="cx">  if ( $unfiltered )
</span><span class="cx">          return $file;
</span><ins>+
+       /**
+        * Filter the attached file based on the given ID.
+        *
+        * @since 2.1.0
+        *
+        * @param string $file          Path to attached file.
+        * @param int    $attachment_id Attachment ID.
+        */
</ins><span class="cx">   return apply_filters( 'get_attached_file', $file, $attachment_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -201,7 +210,6 @@
</span><span class="cx">  * '_wp_attached_file' to store the path of the attachment.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span><del>- * @uses apply_filters() Calls 'update_attached_file' on file path and attachment ID.
</del><span class="cx">  *
</span><span class="cx">  * @param int $attachment_id Attachment ID
</span><span class="cx">  * @param string $file File path for the attachment
</span><span class="lines">@@ -211,7 +219,16 @@
</span><span class="cx">  if ( !get_post( $attachment_id ) )
</span><span class="cx">          return false;
</span><span class="cx"> 
</span><ins>+       /**
+        * Filter the path to the attached file to update.
+        *
+        * @since 2.1.0
+        *
+        * @param string $file          Path to the attached file to update.
+        * @param int    $attachment_id Attachment ID.
+        */
</ins><span class="cx">   $file = apply_filters( 'update_attached_file', $file, $attachment_id );
</span><ins>+
</ins><span class="cx">   if ( $file = _wp_relative_upload_path( $file ) )
</span><span class="cx">          return update_post_meta( $attachment_id, '_wp_attached_file', $file );
</span><span class="cx">  else
</span><span class="lines">@@ -224,7 +241,6 @@
</span><span class="cx">  * The path is relative to the current upload dir.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.9.0
</span><del>- * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
</del><span class="cx">  *
</span><span class="cx">  * @param string $path Full path to the file
</span><span class="cx">  * @return string relative path on success, unchanged path on failure.
</span><span class="lines">@@ -238,6 +254,14 @@
</span><span class="cx">                  $new_path = ltrim( $new_path, '/' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Filter the relative path to an uploaded file.
+        *
+        * @since 2.9.0
+        *
+        * @param string $new_path Relative path to the file.
+        * @param string $path     Full path to the file.
+        */
</ins><span class="cx">   return apply_filters( '_wp_relative_upload_path', $new_path, $path );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1493,6 +1517,19 @@
</span><span class="cx">  $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
</span><span class="cx"> 
</span><span class="cx">  $post_type = $post_type_object->name;
</span><ins>+
+       /**
+        * Filter the labels of a specific post type.
+        *
+        * The dynamic portion of the hook name, $post_type, refers to
+        * the post type slug.
+        *
+        * @since 3.5.0
+        *
+        * @see get_post_type_labels() for the full list of labels.
+        *
+        * @param array $labels Array of labels for the given post type.
+        */
</ins><span class="cx">   return apply_filters( "post_type_labels_{$post_type}", $labels );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1937,18 +1974,7 @@
</span><span class="cx">  * when calling filters.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.3.0
</span><del>- * @uses apply_filters() Calls 'edit_$field' and '{$field_no_prefix}_edit_pre' passing $value and
- *  $post_id if $context == 'edit' and field name prefix == 'post_'.
</del><span class="cx">  *
</span><del>- * @uses apply_filters() Calls 'edit_post_$field' passing $value and $post_id if $context == 'db'.
- * @uses apply_filters() Calls 'pre_$field' passing $value if $context == 'db' and field name prefix == 'post_'.
- * @uses apply_filters() Calls '{$field}_pre' passing $value if $context == 'db' and field name prefix != 'post_'.
- *
- * @uses apply_filters() Calls '$field' passing $value, $post_id and $context if $context == anything
- *  other than 'raw', 'edit' and 'db' and field name prefix == 'post_'.
- * @uses apply_filters() Calls 'post_$field' passing $value if $context == anything other than 'raw',
- *  'edit' and 'db' and field name prefix != 'post_'.
- *
</del><span class="cx">  * @param string $field The Post Object field name.
</span><span class="cx">  * @param mixed $value The Post Object value.
</span><span class="cx">  * @param int $post_id Post ID.
</span><span class="lines">@@ -1981,11 +2007,48 @@
</span><span class="cx">          $format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password');
</span><span class="cx"> 
</span><span class="cx">          if ( $prefixed ) {
</span><del>-                       $value = apply_filters("edit_{$field}", $value, $post_id);
-                       // Old school
-                       $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id);
</del><ins>+
+                       /**
+                        * Filter the value of a specific post field to edit.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the prefixed
+                        * post field name. For example, 'post_title'.
+                        *
+                        * @since 2.3.0
+                        *
+                        * @param mixed $value   Value of the post field.
+                        * @param int   $post_id Post ID.
+                        */
+                       $value = apply_filters( "edit_{$field}", $value, $post_id );
+
+                       /**
+                        * Filter the value of a specific post field to edit.
+                        *
+                        * The dynamic portion of the hook name, $field_no_prefix, refers to
+                        * the post field name with no prefix. For example, 'title' instead
+                        * of 'post_title'.
+                        *
+                        * @since 2.3.0
+                        * @deprecated 2.3.0 Use "edit_post_$field" instead.
+                        *
+                        * @param mixed $value   Value of the post field.
+                        * @param int   $post_id Post ID.
+                        */
+                       $value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id );
</ins><span class="cx">           } else {
</span><del>-                       $value = apply_filters("edit_post_{$field}", $value, $post_id);
</del><ins>+
+                       /**
+                        * Filter the value of a specific post field to edit.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the un-prefixed
+                        * post field. For example, 'title' instead of 'post_title'.
+                        *
+                        * @since 2.3.0
+                        *
+                        * @param mixed $value   Value of the un-prefixed post field.
+                        * @param int   $post_id Post ID.
+                        */
+                       $value = apply_filters( "edit_post_{$field}", $value, $post_id );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          if ( in_array($field, $format_to_edit) ) {
</span><span class="lines">@@ -1998,18 +2061,97 @@
</span><span class="cx">          }
</span><span class="cx">  } else if ( 'db' == $context ) {
</span><span class="cx">          if ( $prefixed ) {
</span><del>-                       $value = apply_filters("pre_{$field}", $value);
-                       $value = apply_filters("{$field_no_prefix}_save_pre", $value);
</del><ins>+
+                       /**
+                        * Filter the value of a specific field before saving.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the
+                        * prefixed post field name. For example, 'post_title'.
+                        *
+                        * @since 2.3.0
+                        *
+                        * @param mixed $value Value of the post field.
+                        */
+                       $value = apply_filters( "pre_{$field}", $value );
+
+                       /**
+                        * Filter the value of a specific field before saving.
+                        *
+                        * The dynamic portion of the hook name, $field_no_prefix, refers
+                        * to the un-prefixed post field name. For example, 'title' instead
+                        * of 'post_title'.
+                        *
+                        * @since 2.3.0
+                        * @deprecated 2.3.0 Use "pre_post_{$field}" instead.
+                        *
+                        * @param mixed $value Value of the post field.
+                        */
+                       $value = apply_filters( "{$field_no_prefix}_save_pre", $value );
</ins><span class="cx">           } else {
</span><del>-                       $value = apply_filters("pre_post_{$field}", $value);
-                       $value = apply_filters("{$field}_pre", $value);
</del><ins>+
+                       /**
+                        * Filter the value of a specific field before saving.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the un-prefixed
+                        * post field name. For example, 'title' instead of 'post_title'.
+                        *
+                        * @since 2.3.0
+                        *
+                        * @param mixed $value Value of the post field.
+                        */
+                       $value = apply_filters( "pre_post_{$field}", $value );
+
+                       /**
+                        * Filter the value of a specific field before saving.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the un-prefixed
+                        * post field name. For example, 'title' instead of 'post_title'.
+                        *
+                        * @since 2.3.0
+                        * @deprecated 2.3.0 Use "pre_post_{$field}" instead.
+                        *
+                        * @param mixed $value Value of the post field.
+                        */
+                       $value = apply_filters( "{$field}_pre", $value );
</ins><span class="cx">           }
</span><span class="cx">  } else {
</span><ins>+
</ins><span class="cx">           // Use display filters by default.
</span><del>-               if ( $prefixed )
-                       $value = apply_filters($field, $value, $post_id, $context);
-               else
-                       $value = apply_filters("post_{$field}", $value, $post_id, $context);
</del><ins>+                if ( $prefixed ) {
+
+                       /**
+                        * Filter the value of a specific post field for display.
+                        *
+                        * The dynamic hook name, $field, refers to the prefixed post field
+                        * name. For example, 'post_title'.
+                        *
+                        * @since
+                        *
+                        * @param mixed  $value   Value of the prefixed post field.
+                        * @param int    $post_id Post ID.
+                        * @param string $context Context for how to sanitize the field. Possible
+                        *                        values include 'raw', 'edit', 'db', 'display',
+                        *                        'attribute' and 'js'.
+                        */
+                       $value = apply_filters( $field, $value, $post_id, $context );
+               } else {
+
+                       /**
+                        * Filter the value of a specific post field for display.
+                        *
+                        * The dynamic portion of the hook name, $field, refers to the un-prefixed
+                        * post field name. For example, 'title' instead of 'post_title'.'
+                        *
+                        * @since
+                        *
+                        * @param mixed  $value   Value of the un-prefixed post field.
+                        * @param int    $post_id Post ID.
+                        * @param string $context Context for how to sanitize the field. Possible
+                        *                        values include 'raw', 'edit', 'db', 'display',
+                        *                        'attribute' and 'js'.
+                        */
+                       $value = apply_filters( "post_{$field}", $value, $post_id, $context );
+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  if ( 'attribute' == $context )
</span><span class="lines">@@ -2143,9 +2285,11 @@
</span><span class="cx">   *
</span><span class="cx">   * @since 3.7.0
</span><span class="cx">   *
</span><del>-        * @param object $counts An object containing the current post_type's post counts by status.
-        * @param string $type   The post type.
-        * @param string $perm   The permission to determine if the posts are 'readable' by the current user.
</del><ins>+         * @param object $counts An object containing the current post_type's post
+        *                       counts by status.
+        * @param string $type   Post type.
+        * @param string $perm   The permission to determine if the posts are 'readable'
+        *                       by the current user.
</ins><span class="cx">    */
</span><span class="cx">  return apply_filters( 'wp_count_posts', $counts, $type, $perm );
</span><span class="cx"> }
</span><span class="lines">@@ -2200,7 +2344,14 @@
</span><span class="cx">          'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
</span><span class="cx">  );
</span><span class="cx"> 
</span><del>-       return apply_filters('post_mime_types', $post_mime_types);
</del><ins>+        /**
+        * Filter the default list of post mime types.
+        *
+        * @since 2.5.0
+        *
+        * @param array $post_mime_types Default list of post mime types.
+        */
+       return apply_filters( 'post_mime_types', $post_mime_types );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -2756,6 +2907,22 @@
</span><span class="cx">  $maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' )
</span><span class="cx">          && post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
</span><span class="cx"> 
</span><ins>+       /**
+        * Filter whether the post should be considered "empty".
+        *
+        * The post is considered "empty" if both:
+        * 1. The post type supports the title, editor, and excerpt fields
+        * 2. The title, editor, and excerpt fields are all empty
+        *
+        * Returning a truthy value to the filter will effectively short-circuit
+        * the new post being inserted, returning 0. If $wp_error is true, a WP_Error
+        * will be returned instead.
+        *
+        * @since 3.3.0
+        *
+        * @param bool  $maybe_empty Whether the post should be considered "empty".
+        * @param array $postarr     Array of post data.
+        */
</ins><span class="cx">   if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
</span><span class="cx">          if ( $wp_error )
</span><span class="cx">                  return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
</span></span></pre>
</div>
</div>

</body>
</html>