Individua una cartella nel filesystem remoto.


Si aspetta un percorso sanificato da Windows.



(stringa)(Richiesto)La cartella da individuare.


(stringa)(Opzionale)La cartella da cui iniziare la ricerca.

Valore predefinito: '.


(bool)(Opzionale)Se la funzione è ricorsiva. Solo per uso interno.

Valore predefinito: false


(stringa|falso) La posizione del percorso remoto, falso per interrompere il ciclo.


File: wp-admin/includes/class-wp-filesystem-base.php

publicfunctionsearch_for_folder($folder,$base='.',$loop=false){if(empty($base)||'.'===$base){$base=trailingslashit($this->cwd());}$folder=untrailingslashit($folder);if($this->verbose){/* translators: 1: Folder to locate, 2: Folder to start searching from. */printf("n"__('Looking for %1$s in %2$s')"
,$folder,$base);}$folder_parts=explode('/',$folder);$folder_part_keys=array_keys($folder_parts);$last_index=array_pop($folder_part_keys);$last_path=$folder_parts[$last_index];$files=$this->dirlist($base);foreach($folder_partsas$index=>$key){if($index==$last_index){continue;// We want this to be caught by the next code block.}/* * Working from /home/ to /user/ to /wordpress/ see if that file exists within * the current folder, If it's found, change into it and follow through looking * for it. If it can't find WordPress down that route, it'll continue onto the next * folder level, and see if that matches, and so on. If it reaches the end, and still * can't find it, it'll return false for the entire function. */if(isset($files[$key])){// Let's try that folder:$newdir=trailingslashit(path_join($base,$key));if($this->verbose){/* translators: %s: Directory name. */printf("n"__('Changing to %s')"
,$newdir);}// Only search for the remaining path tokens in the directory, not the full path again.$newfolder=implode('/',array_slice($folder_parts,$index+1));$ret=$this->search_for_folder($newfolder,$newdir,$loop);if($ret){return$ret;}}}// Only check this as a last resort, to prevent locating the incorrect install.// All above procedures will fail quickly if this is the right branch to take.if(isset($files[$last_path])){if($this->verbose){/* translators: %s: Directory name. */printf("n"__('Found %s')"
,$base$last_path);}returntrailingslashit($base$last_path);}// Prevent this function from looping again.// No need to proceed if we've just searched in `/`.if($loop||'/'===$base){returnfalse;}// As an extra last resort, Change back to / if the folder wasn't found.// This comes into effect when the CWD is /home/user/ but WP is at /var/www/....return$this->search_for_folder($folder,'/',true);}



Usi Descrizione
wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::dirlist()

Ottiene i dettagli dei file in una cartella o in un file specifico.

wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::cwd()

Ottiene la directory di lavoro corrente.

wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::search_for_folder()

Individua una cartella sul filesystem remoto.

wp-includes/l10n.php: __()

Recupera la traduzione di $testo.

wp-includes/formatting.php: trailingslashit()

Aggiunge una barra di separazione.

wp-includes/formatting.php: untrailingslashit()

Rimuove gli slash in avanti e i backslash in coda, se esistono.

wp-includes/functions.php: path_join()

Unisce due percorsi del filesystem.

Utilizzato da

Usato da Descrizione
wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::find_folder()

Individua una cartella sul filesystem remoto.

wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::search_for_folder()

Individua una cartella sul filesystem remoto.


Versione Descrizione
2.7.0 Introdotto.