Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:33:45 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve comments in some wp-admin files per the documentation standards.

Follow-up to [47084].

Props passoniate, apedog.
Fixes #49223, #49227.

File:
1 edited

Legend:

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

    r46826 r47119  
    9393        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
    9494
    95         // No longer an auto-draft
     95        // No longer an auto-draft.
    9696        if ( 'auto-draft' === $post_data['post_status'] ) {
    9797            $post_data['post_status'] = 'draft';
     
    103103    }
    104104
    105     // What to do based on which button they pressed
     105    // What to do based on which button they pressed.
    106106    if ( isset( $post_data['saveasdraft'] ) && '' != $post_data['saveasdraft'] ) {
    107107        $post_data['post_status'] = 'draft';
     
    133133    $published_statuses = array( 'publish', 'future' );
    134134
    135     // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
     135    // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
    136136    // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
    137137    if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) {
     
    209209    }
    210210
    211     // Pass through errors
     211    // Pass through errors.
    212212    if ( is_wp_error( $post_data ) ) {
    213213        return $post_data;
     
    269269        $revision  = current( $revisions );
    270270
    271         // Check if the revisions have been upgraded
     271        // Check if the revisions have been upgraded.
    272272        if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
    273273            _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
     
    297297    $translated = _wp_get_allowed_postdata( $post_data );
    298298
    299     // Post Formats
     299    // Post formats.
    300300    if ( isset( $post_data['post_format'] ) ) {
    301301        set_post_format( $post_ID, $post_data['post_format'] );
     
    337337    }
    338338
    339     // Meta Stuff
     339    // Meta stuff.
    340340    if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
    341341        foreach ( $post_data['meta'] as $key => $value ) {
     
    373373    }
    374374
    375     // Attachment stuff
     375    // Attachment stuff.
    376376    if ( 'attachment' == $post_data['post_type'] ) {
    377377        if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
    378378            $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
     379
    379380            if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) {
    380381                $image_alt = wp_strip_all_tags( $image_alt, true );
    381                 // update_meta expects slashed.
     382
     383                // update_post_meta() expects slashed.
    382384                update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
    383385            }
     
    406408
    407409    $success = wp_update_post( $translated );
    408     // If the save failed, see if we can sanity check the main fields and try again
     410
     411    // If the save failed, see if we can sanity check the main fields and try again.
    409412    if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
    410413        $fields = array( 'post_title', 'post_content', 'post_excerpt' );
     
    419422    }
    420423
    421     // Now that we have an ID we can fix any attachment anchor hrefs
     424    // Now that we have an ID we can fix any attachment anchor hrefs.
    422425    _fix_attachment_links( $post_ID );
    423426
     
    677680        }
    678681
    679         // Schedule auto-draft cleanup
     682        // Schedule auto-draft cleanup.
    680683        if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
    681684            wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
     
    817820    unset( $_POST['filter'] );
    818821
    819     // Edit don't write if we have a post id.
     822    // Edit, don't write, if we have a post ID.
    820823    if ( isset( $_POST['post_ID'] ) ) {
    821824        return edit_post();
     
    858861    add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    859862
    860     // Now that we have an ID we can fix any attachment anchor hrefs
     863    // Now that we have an ID we can fix any attachment anchor hrefs.
    861864    _fix_attachment_links( $post_ID );
    862865
     
    883886
    884887//
    885 // Post Meta
     888// Post Meta.
    886889//
    887890
     
    914917
    915918        if ( $metakeyinput ) {
    916             $metakey = $metakeyinput; // default
     919            $metakey = $metakeyinput; // Default.
    917920        }
    918921
     
    927930
    928931    return false;
    929 } // add_meta
     932}
    930933
    931934/**
     
    10181021
    10191022//
    1020 // Private
     1023// Private.
    10211024//
    10221025
     
    10391042    }
    10401043
    1041     // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero)
     1044    // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
    10421045    if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
    10431046        return;
     
    10451048
    10461049    $site_url = get_bloginfo( 'url' );
    1047     $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // remove the http(s)
     1050    $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
    10481051    $replace  = '';
    10491052
     
    10551058        }
    10561059
    1057         $quote  = $url_match[1]; // the quote (single or double)
     1060        $quote  = $url_match[1]; // The quote (single or double).
    10581061        $url_id = (int) $url_match[2];
    10591062        $rel_id = (int) $rel_match[1];
     
    13451348    }
    13461349
    1347     // If the user wants to set a new name -- override the current one
    1348     // Note: if empty name is supplied -- use the title instead, see #6072
     1350    // If the user wants to set a new name -- override the current one.
     1351    // Note: if empty name is supplied -- use the title instead, see #6072.
    13491352    if ( ! is_null( $name ) ) {
    13501353        $post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
     
    13571360    $permalink = get_permalink( $post, true );
    13581361
    1359     // Replace custom post_type Token with generic pagename token for ease of use.
     1362    // Replace custom post_type token with generic pagename token for ease of use.
    13601363    $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
    13611364
    1362     // Handle page hierarchy
     1365    // Handle page hierarchy.
    13631366    if ( $ptype->hierarchical ) {
    13641367        $uri = get_page_uri( $post );
     
    14321435                $view_link = get_permalink( $post );
    14331436            } else {
    1434                 // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
     1437                // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
    14351438                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
    14361439            }
     
    14381441    }
    14391442
    1440     // Permalinks without a post/page name placeholder don't have anything to edit
     1443    // Permalinks without a post/page name placeholder don't have anything to edit.
    14411444    if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
    14421445        $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     
    14491452        }
    14501453
    1451         // Encourage a pretty permalink setting
     1454        // Encourage a pretty permalink setting.
    14521455        if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' == get_option( 'show_on_front' ) && $id == get_option( 'page_on_front' ) ) ) {
    14531456            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
     
    16931696        if ( get_post_type_object( $post->post_type )->public ) {
    16941697            if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) {
    1695                 // Latest content is in autosave
     1698                // Latest content is in autosave.
    16961699                $nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
    16971700                $query_args['preview_id']    = $post->ID;
     
    17481751        }
    17491752
    1750         // Allow plugins to prevent some users overriding the post lock
     1753        // Allow plugins to prevent some users overriding the post lock.
    17511754        if ( $override ) {
    17521755            ?>
     
    18201823        $new_autosave['post_author'] = $post_author;
    18211824
     1825        $post = get_post( $post_id );
     1826
    18221827        // If the new autosave has the same content as the post, delete the autosave.
    1823         $post                  = get_post( $post_id );
    18241828        $autosave_is_different = false;
    18251829        foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
     
    18501854    $post_data = wp_unslash( $post_data );
    18511855
    1852     // Otherwise create the new autosave as a special post revision
     1856    // Otherwise create the new autosave as a special post revision.
    18531857    return _wp_put_post_revision( $post_data, true );
    18541858}
     
    19231927 */
    19241928function wp_autosave( $post_data ) {
    1925     // Back-compat
     1929    // Back-compat.
    19261930    if ( ! defined( 'DOING_AUTOSAVE' ) ) {
    19271931        define( 'DOING_AUTOSAVE', true );
     
    19511955
    19521956    if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
    1953         // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
     1957        // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
    19541958        return edit_post( wp_slash( $post_data ) );
    19551959    } else {
    1956         // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
     1960        // Non-drafts or other users' drafts are not overwritten.
     1961        // The autosave is stored in a special post revision for each user.
    19571962        return wp_create_post_autosave( wp_slash( $post_data ) );
    19581963    }
Note: See TracChangeset for help on using the changeset viewer.