WordPress.org

Make WordPress Core

Changeset 32622


Ignore:
Timestamp:
05/27/2015 07:22:59 PM (6 years ago)
Author:
wonderboymusic
Message:

Add missing doc blocks to rewrite.php.
Clarify @return values where necessary.
add_permastruct() doesn't need to return.
->using_index_permalinks() and ->using_mod_rewrite_permalinks() can just return their conditions, instead of if/else true/false.
->mod_rewrite_rules() and ->iis7_url_rewrite_rules() don't need to set a variable that is immediately returned.

See #32444.

File:
1 edited

Legend:

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

    r32293 r32622  
    1010 * Add a straight rewrite rule.
    1111 *
    12  * @see WP_Rewrite::add_rule() for long description.
    1312 * @since 2.1.0
    1413 *
    15  * @param string $regex Regular Expression to match request against.
     14 * @global WP_Rewrite $wp_rewrite
     15 *
     16 * @param string $regex    Regular Expression to match request against.
    1617 * @param string $redirect Page to redirect to.
    17  * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
     18 * @param string $after    Optional, default is 'bottom'. Where to add rule, can also be 'top'.
    1819 */
    1920function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
     
    2930 * to "$tag=", and for this to work a new query var has to be added.
    3031 *
    31  * @see WP_Rewrite::add_rewrite_tag()
    3232 * @since 2.1.0
    3333 *
    34  * @param string $tag Name of the new rewrite tag.
     34 * @global WP_Rewrite $wp_rewrite
     35 * @global WP         $wp
     36 *
     37 * @param string $tag   Name of the new rewrite tag.
    3538 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
    3639 * @param string $query String to append to the rewritten query. Must end in '='. Optional.
     
    5558 * Add permalink structure.
    5659 *
    57  * @see WP_Rewrite::add_permastruct()
    5860 * @since 3.0.0
    5961 *
    60  * @param string $name Name for permalink structure.
     62 * @global WP_Rewrite $wp_rewrite
     63 *
     64 * @param string $name   Name for permalink structure.
    6165 * @param string $struct Permalink structure.
    62  * @param array $args Optional configuration for building the rules from the permalink structure,
    63  *     see {@link WP_Rewrite::add_permastruct()} for full details.
     66 * @param array  $args  Optional configuration for building the rules from the permalink structure,
     67 *                       see {@link WP_Rewrite::add_permastruct()} for full details.
    6468 */
    6569function add_permastruct( $name, $struct, $args = array() ) {
     
    7276        $args['ep_mask'] = func_get_arg( 3 );
    7377
    74     return $wp_rewrite->add_permastruct( $name, $struct, $args );
     78    $wp_rewrite->add_permastruct( $name, $struct, $args );
    7579}
    7680
     
    8084 * @since 2.1.0
    8185 *
    82  * @param string $feedname
     86 * @global WP_Rewrite $wp_rewrite
     87 *
     88 * @param string   $feedname
    8389 * @param callback $function Callback to run on feed display.
    8490 * @return string Feed action name.
     
    98104 * Remove rewrite rules and then recreate rewrite rules.
    99105 *
    100  * @see WP_Rewrite::flush_rules()
    101106 * @since 3.0.0
    102107 *
     108 * @global WP_Rewrite $wp_rewrite
     109 *
    103110 * @param bool $hard Whether to update .htaccess (hard flush) or just update
    104  *  rewrite_rules transient (soft flush). Default is true (hard).
     111 *                   rewrite_rules transient (soft flush). Default is true (hard).
    105112 */
    106113function flush_rewrite_rules( $hard = true ) {
     
    246253 * @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
    247254 *
    248  * @see WP_Rewrite::add_endpoint()
    249  * @global object $wp_rewrite
     255 * @global WP_Rewrite $wp_rewrite
    250256 *
    251257 * @param string      $name      Name of the endpoint.
     
    285291 * @since 1.0.0
    286292 *
     293 * @global WP_Rewrite $wp_rewrite
     294 * @global WP         $wp
     295 *
    287296 * @param string $url Permalink to check.
    288297 * @return int Post ID, or 0 on failure.
    289298 */
    290 function url_to_postid($url) {
     299function url_to_postid( $url ) {
    291300    global $wp_rewrite;
    292301
     
    783792     */
    784793    public function using_index_permalinks() {
    785         if ( empty($this->permalink_structure) )
     794        if ( empty( $this->permalink_structure ) ) {
    786795            return false;
    787 
     796        }
    788797        // If the index is not in the permalink, we're using mod_rewrite.
    789         if ( preg_match('#^/*' . $this->index . '#', $this->permalink_structure) )
    790             return true;
    791 
    792         return false;
     798        return preg_match( '#^/*' . $this->index . '#', $this->permalink_structure );
    793799    }
    794800
     
    804810     */
    805811    public function using_mod_rewrite_permalinks() {
    806         if ( $this->using_permalinks() && ! $this->using_index_permalinks() )
    807             return true;
    808         else
    809             return false;
     812        return $this->using_permalinks() && ! $this->using_index_permalinks();
    810813    }
    811814
     
    846849     * @since 2.5.0
    847850     * @access public
     851     *
     852     * @global wpdb $wpdb
    848853     *
    849854     * @return array Array of page URIs as first element and attachment URIs as second element.
     
    980985        $structure = str_replace('%monthnum%', '', $structure);
    981986        $structure = str_replace('%day%', '', $structure);
    982 
    983987        $structure = preg_replace('#/+#', '/', $structure);
    984988
     
    10041008
    10051009        $structure = str_replace('%day%', '', $structure);
    1006 
    10071010        $structure = preg_replace('#/+#', '/', $structure);
    10081011
     
    10351038     * @access public
    10361039     *
    1037      * @return bool|string False on failure. Category permalink structure.
     1040     * @return string|false False on failure. Category permalink structure.
    10381041     */
    10391042    public function get_category_permastruct() {
     
    10521055     * @access public
    10531056     *
    1054      * @return bool|string False on failure. Tag permalink structure.
     1057     * @return string|false False on failure. Tag permalink structure.
    10551058     */
    10561059    public function get_tag_permastruct() {
     
    10651068     *
    10661069     * @param string $name Permalink structure name.
    1067      * @return string|bool False if not found. Permalink structure string.
     1070     * @return string|false False if not found. Permalink structure string.
    10681071     */
    10691072    public function get_extra_permastruct($name) {
     
    11911194     * @access public
    11921195     *
    1193      * @return string|bool False if not found. Permalink structure string.
     1196     * @return string|false False if not found. Permalink structure string.
    11941197     */
    11951198    public function get_comment_feed_permastruct() {
     
    12191222     * @access public
    12201223     *
    1221      * @param string $tag Name of the rewrite tag to add or update.
     1224     * @param string $tag   Name of the rewrite tag to add or update.
    12221225     * @param string $regex Regular expression to substitute the tag for in rewrite rules.
    12231226     * @param string $query String to append to the rewritten query. Must end in '='.
     
    12461249     *
    12471250     * @param string $permalink_structure The permalink structure.
    1248      * @param int $ep_mask Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
    1249      * @param bool $paged Should archive pagination rules be added for the structure? Default is true.
    1250      * @param bool $feed Should feed rewrite rules be added for the structure? Default is true.
    1251      * @param bool $forcomments Should the feed rules be a query for a comments feed? Default is false.
    1252      * @param bool $walk_dirs Should the 'directories' making up the structure be walked over and rewrite rules
    1253      *                        built for each in turn? Default is true.
    1254      * @param bool $endpoints Should endpoints be applied to the generated rewrite rules? Default is true.
     1251     * @param int    $ep_mask            Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
     1252     * @param bool   $paged              Should archive pagination rules be added for the structure? Default is true.
     1253     * @param bool   $feed                Should feed rewrite rules be added for the structure? Default is true.
     1254     * @param bool   $forcomments        Should the feed rules be a query for a comments feed? Default is false.
     1255     * @param bool   $walk_dirs          Should the 'directories' making up the structure be walked over and rewrite rules
     1256     *                                    built for each in turn? Default is true.
     1257     * @param bool   $endpoints          Should endpoints be applied to the generated rewrite rules? Default is true.
    12551258     * @return array Rewrite rule list.
    12561259     */
     
    15231526     *
    15241527     * @param string $permalink_structure The permalink structure to generate rules.
    1525      * @param bool $walk_dirs Optional, default is false. Whether to create list of directories to walk over.
     1528     * @param bool   $walk_dirs          Optional, default is false. Whether to create list of directories to walk over.
    15261529     * @return array
    15271530     */
     
    18571860         * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
    18581861         */
    1859         $rules = apply_filters( 'rewrite_rules', $rules );  // Deprecated
    1860 
    1861         return $rules;
     1862        return apply_filters( 'rewrite_rules', $rules );
    18621863    }
    18631864
     
    18741875     */
    18751876    public function iis7_url_rewrite_rules( $add_parent_tags = false ) {
    1876 
    18771877        if ( ! $this->using_permalinks() )
    18781878            return '';
     
    19101910         * @param string $rules Rewrite rules formatted for IIS web.config.
    19111911         */
    1912         $rules = apply_filters( 'iis7_url_rewrite_rules', $rules );
    1913 
    1914         return $rules;
     1912        return apply_filters( 'iis7_url_rewrite_rules', $rules );
    19151913    }
    19161914
     
    19241922     * @access public
    19251923     *
    1926      * @param string $regex Regular expression to match against request.
     1924     * @param string $regex    Regular expression to match against request.
    19271925     * @param string $redirect URL regex redirects to when regex matches request.
    1928      * @param string $after Optional, default is bottom. Location to place rule.
     1926     * @param string $after    Optional, default is bottom. Location to place rule.
    19291927     */
    19301928    public function add_rule($regex, $redirect, $after = 'bottom') {
     
    19511949     * @access public
    19521950     *
    1953      * @param string $regex Regular expression to match against request.
     1951     * @param string $regex    Regular expression to match against request.
    19541952     * @param string $redirect URL regex redirects to when regex matches request.
    19551953     */
     
    19671965     *
    19681966     * @see add_rewrite_endpoint() for full documentation.
    1969      * @uses WP::add_query_var()
     1967     *
     1968     * @global WP $wp
    19701969     *
    19711970     * @param string      $name      Name of the endpoint.
     
    20042003     * @access public
    20052004     *
    2006      * @param string $name Name for permalink structure.
     2005     * @param string $name   Name for permalink structure.
    20072006     * @param string $struct Permalink structure (e.g. category/%category%)
    2008      * @param array $args Optional configuration for building the rules from the permalink structure:
     2007     * @param array  $args  Optional configuration for building the rules from the permalink structure:
    20092008     *     - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true.
    20102009     *     - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
     
    20532052     * @since 2.0.1
    20542053     * @access public
     2054     *
     2055     * @staticvar bool $do_hard_later
     2056     *
    20552057     * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
    20562058     */
Note: See TracChangeset for help on using the changeset viewer.