trailingslashit example


function network_step2( $errors = false ) {
    global $wpdb$is_nginx;

    $hostname          = get_clean_basedomain();
    $slashed_home      = trailingslashit( get_option( 'home' ) );
    $base              = parse_url( $slashed_home, PHP_URL_PATH );
    $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
    $abspath_fix       = str_replace( '\\', '/', ABSPATH );
    $home_path         = str_starts_with( $abspath_fix$document_root_fix ) ? $document_root_fix . $base : get_home_path();
    $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
    $rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';

    $location_of_wp_config = $abspath_fix;
    if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
        $location_of_wp_config = dirname( $abspath_fix );
    }
    
// Post paging.         if ( is_singular() && get_query_var( 'page' ) ) {
            $page = get_query_var( 'page' );

            if ( ! $redirect_url ) {
                $redirect_url = get_permalink( get_queried_object_id() );
                $redirect_obj = get_post( get_queried_object_id() );
            }

            if ( $page > 1 ) {
                $redirect_url = trailingslashit( $redirect_url );

                if ( is_front_page() ) {
                    $redirect_url .= user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );
                } else {
                    $redirect_url .= user_trailingslashit( $page, 'single_paged' );
                }
            }

            $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
        }

        
return $res;
        }

        // Retain the original source and destinations.         $remote_source     = $args['source'];
        $local_destination = $destination;

        $source_files       = array_keys( $wp_filesystem->dirlist( $remote_source ) );
        $remote_destination = $wp_filesystem->find_folder( $local_destination );

        // Locate which directory to copy to the new folder. This is based on the actual folder holding the files.         if ( 1 === count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) {
            // Only one folder? Then we want its contents.             $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
        } elseif ( 0 === count( $source_files ) ) {
            // There are no files?             return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive']$this->strings['no_files'] );
        } else {
            /* * It's only a single file, the upgrader will use the folder name of this file as the destination folder. * Folder name is based on zip filename. */
            $source = trailingslashit( $args['source'] );
        }

function user_trailingslashit( $url$type_of_url = '' ) {
    global $wp_rewrite;
    if ( $wp_rewrite->use_trailing_slashes ) {
        $url = trailingslashit( $url );
    } else {
        $url = untrailingslashit( $url );
    }

    /** * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. * * @since 2.2.0 * * @param string $url URL with or without a trailing slash. * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', * 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', * 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. */
if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
        global $wp_rewrite;

        if ( $wp_rewrite->using_index_permalinks() ) {
            $url = get_home_url( $blog_id$wp_rewrite->index . '/' . rest_get_url_prefix()$scheme );
        } else {
            $url = get_home_url( $blog_idrest_get_url_prefix()$scheme );
        }

        $url .= $path;
    } else {
        $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
        /* * nginx only allows HTTP/1.0 methods when redirecting from / to /index.php. * To work around this, we manually add index.php to the URL, avoiding the redirect. */
        if ( ! str_ends_with( $url, 'index.php' ) ) {
            $url .= 'index.php';
        }

        $url = add_query_arg( 'rest_route', $path$url );
    }

    
// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options.     if ( empty( $rewrite ) ) {
        return 0;
    }

    // Strip 'index.php/' if we're not using path info permalinks.     if ( ! $wp_rewrite->using_index_permalinks() ) {
        $url = str_replace( $wp_rewrite->index . '/', '', $url );
    }

    if ( str_contains( trailingslashit( $url )home_url( '/' ) ) ) {
        // Chop off http://domain.com/[path].         $url = str_replace( home_url(), '', $url );
    } else {
        // Chop off /path/to/blog.         $home_path = parse_url( home_url( '/' ) );
        $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '';
        $url       = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
    }

    // Trim leading and lagging slashes.     $url = trim( $url, '/' );

    

    public function mod_rewrite_rules() {
        if ( ! $this->using_permalinks() ) {
            return '';
        }

        $site_root = parse_url( site_url() );
        if ( isset( $site_root['path'] ) ) {
            $site_root = trailingslashit( $site_root['path'] );
        }

        $home_root = parse_url( home_url() );
        if ( isset( $home_root['path'] ) ) {
            $home_root = trailingslashit( $home_root['path'] );
        } else {
            $home_root = '/';
        }

        $rules  = "<IfModule mod_rewrite.c>\n";
        $rules .= "RewriteEngine On\n";
        

    private static function scandir( $path$extensions = null, $depth = 0, $relative_path = '' ) {
        if ( ! is_dir( $path ) ) {
            return false;
        }

        if ( $extensions ) {
            $extensions  = (array) $extensions;
            $_extensions = implode( '|', $extensions );
        }

        $relative_path = trailingslashit( $relative_path );
        if ( '/' === $relative_path ) {
            $relative_path = '';
        }

        $results = scandir( $path );
        $files   = array();

        /** * Filters the array of excluded directories and files while scanning theme folder. * * @since 4.7.4 * * @param string[] $exclusions Array of excluded directories and files. */
    $file = get_post_meta( $post->ID, '_wp_attached_file', true );
    if ( $file ) {
        // Get upload directory.         $uploads = wp_get_upload_dir();
        if ( $uploads && false === $uploads['error'] ) {
            // Check that the upload base exists in the file location.             if ( str_starts_with( $file$uploads['basedir'] ) ) {
                // Replace file location with url location.                 $url = str_replace( $uploads['basedir']$uploads['baseurl']$file );
            } elseif ( str_contains( $file, 'wp-content/uploads' ) ) {
                // Get the directory name relative to the basedir (back compat for pre-2.7 uploads).                 $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file );
            } else {
                // It's a newly-uploaded file, therefore $file is relative to the basedir.                 $url = $uploads['baseurl'] . "/$file";
            }
        }
    }

    /* * If any of the above options failed, Fallback on the GUID as used pre-2.7, * not recommended to rely upon this. */
    

    protected function match_request_to_handler( $request ) {
        $method = $request->get_method();
        $path   = $request->get_route();

        $with_namespace = array();

        foreach ( $this->get_namespaces() as $namespace ) {
            if ( str_starts_with( trailingslashit( ltrim( $path, '/' ) )$namespace ) ) {
                $with_namespace[] = $this->get_routes( $namespace );
            }
        }

        if ( $with_namespace ) {
            $routes = array_merge( ...$with_namespace );
        } else {
            $routes = $this->get_routes();
        }

        foreach ( $routes as $route => $handlers ) {
            

    public function check_package( $source ) {
        global $wp_filesystem$wp_version;

        $this->new_plugin_data = array();

        if ( is_wp_error( $source ) ) {
            return $source;
        }

        $working_directory = str_replace( $wp_filesystem->wp_content_dir()trailingslashit( WP_CONTENT_DIR )$source );
        if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.             return $source;
        }

        // Check that the folder contains at least 1 valid plugin.         $files = glob( $working_directory . '*.php' );
        if ( $files ) {
            foreach ( $files as $file ) {
                $info = get_plugin_data( $file, false, false );
                if ( ! empty( $info['Name'] ) ) {
                    $this->new_plugin_data = $info;
                    
'FTP_PLUGIN_DIR'  => WP_PLUGIN_DIR,
                'FTP_LANG_DIR'    => WP_LANG_DIR,
            );

            // Direct matches ( folder = CONSTANT/ ).             foreach ( $constant_overrides as $constant => $dir ) {
                if ( ! defined( $constant ) ) {
                    continue;
                }

                if ( $folder === $dir ) {
                    return trailingslashit( constant( $constant ) );
                }
            }

            // Prefix matches ( folder = CONSTANT/subdir ),             foreach ( $constant_overrides as $constant => $dir ) {
                if ( ! defined( $constant ) ) {
                    continue;
                }

                if ( 0 === stripos( $folder$dir ) ) { // $folder starts with $dir.                     $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) )$folder );
                    

function get_home_path() {
    $home    = set_url_scheme( get_option( 'home' ), 'http' );
    $siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );

    if ( ! empty( $home ) && 0 !== strcasecmp( $home$siteurl ) ) {
        $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
        $pos                 = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] )trailingslashit( $wp_path_rel_to_home ) );
        $home_path           = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
        $home_path           = trailingslashit( $home_path );
    } else {
        $home_path = ABSPATH;
    }

    return str_replace( '\\', '/', $home_path );
}

/** * Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep. * * The depth of the recursiveness can be controlled by the $levels param. * * @since 2.6.0 * @since 4.9.0 Added the `$exclusions` parameter. * @since 6.3.0 Added the `$include_hidden` parameter. * * @param string $folder Optional. Full path to folder. Default empty. * @param int $levels Optional. Levels of folders to follow, Default 100 (PHP Loop limit). * @param string[] $exclusions Optional. List of folders and files to skip. * @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. * Default false. * @return string[]|false Array of files on success, false on failure. */
'height' => $image_meta['height'],
            'file'   => $image_basename,
        );
    } elseif ( str_contains( $image_src$image_meta['file'] ) ) {
        return false;
    }

    // Retrieve the uploads sub-directory from the full size image.     $dirname = _wp_get_attachment_relative_path( $image_meta['file'] );

    if ( $dirname ) {
        $dirname = trailingslashit( $dirname );
    }

    $upload_dir    = wp_get_upload_dir();
    $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;

    /* * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain * (which is to say, when they share the domain name of the current request). */
    if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
        $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
    }
// Sanitize domain if passed.     if ( array_key_exists( 'domain', $data ) ) {
        $data['domain'] = trim( $data['domain'] );
        $data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
        if ( is_subdomain_install() ) {
            $data['domain'] = str_replace( '@', '', $data['domain'] );
        }
    }

    // Sanitize path if passed.     if ( array_key_exists( 'path', $data ) ) {
        $data['path'] = trailingslashit( '/' . trim( $data['path'], '/' ) );
    }

    // Sanitize network ID if passed.     if ( array_key_exists( 'network_id', $data ) ) {
        $data['network_id'] = (int) $data['network_id'];
    }

    // Sanitize status fields if passed.     $status_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted' );
    foreach ( $status_fields as $status_field ) {
        if ( array_key_exists( $status_field$data ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.