Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




request_filesystem_credentials [ WordPress Function ]

request_filesystem_credentials ( $form_post, $type = '', $error = false, $context = false, $extra_fields = null )
Parameters:
  • (string) $form_post the URL to post the form to
  • (string) $type the chosen Filesystem method in use
  • (boolean) $error if the current request has failed to connect
  • (string) $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
  • (string) $extra_fields Extra POST fields which should be checked for to be included in the post.
Returns:
  • (boolean) False on failure. True on success.
Defined at:



Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.

All chosen/entered details are saved, Excluding the Password.

Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port.

Plugins may override this form by returning true|false via the

request_filesystem_credentials

filter.

Source


<?php
function request_filesystem_credentials($form_post$type ''$error false$context false$extra_fields null) {
    
$req_cred apply_filters'request_filesystem_credentials'''$form_post$type$error$context$extra_fields );
    if ( 
'' !== $req_cred )
        return 
$req_cred;

    if ( empty(
$type) )
        
$type get_filesystem_method(array(), $context);

    if ( 
'direct' == $type )
        return 
true;

    if ( 
is_null$extra_fields ) )
        
$extra_fields = array( 'version''locale' );

    
$credentials get_option('ftp_credentials', array( 'hostname' => '''username' => ''));

    
// If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    
$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? stripslashes($_POST['hostname']) : $credentials['hostname']);
    
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? stripslashes($_POST['username']) : $credentials['username']);
    
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? stripslashes($_POST['password']) : '');

    
// Check to see if we are setting the public/private keys for ssh
    
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? stripslashes($_POST['public_key']) : '');
    
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? stripslashes($_POST['private_key']) : '');

    
//sanitize the hostname, Some people might pass in odd-data:
    
$credentials['hostname'] = preg_replace('|\w+://|'''$credentials['hostname']); //Strip any schemes off

    
if ( strpos($credentials['hostname'], ':') ) {
        list( 
$credentials['hostname'], $credentials['port'] ) = explode(':'$credentials['hostname'], 2);
        if ( ! 
is_numeric($credentials['port']) )
            unset(
$credentials['port']);
    } else {
        unset(
$credentials['port']);
    }

    if ( (
defined('FTP_SSH') && FTP_SSH) || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
        
$credentials['connection_type'] = 'ssh';
    else if ( (
defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type //Only the FTP Extension understands SSL
        
$credentials['connection_type'] = 'ftps';
    else if ( !empty(
$_POST['connection_type']) )
        
$credentials['connection_type'] = stripslashes($_POST['connection_type']);
    else if ( !isset(
$credentials['connection_type']) ) //All else fails (And its not defaulted to something else saved), Default to FTP
        
$credentials['connection_type'] = 'ftp';

    if ( ! 
$error &&
            (
                ( !empty(
$credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) ||
                ( 
'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) )
            ) ) {
        
$stored_credentials $credentials;
        if ( !empty(
$stored_credentials['port']) ) //save port as part of hostname to simplify above code.
            
$stored_credentials['hostname'] .= ':' $stored_credentials['port'];

        unset(
$stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
        
update_option('ftp_credentials'$stored_credentials);
        return 
$credentials;
    }
    
$hostname '';
    
$username '';
    
$password '';
    
$connection_type '';
    if ( !empty(
$credentials) )
        
extract($credentialsEXTR_OVERWRITE);
    if ( 
$error ) {
        
$error_string __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.');
        if ( 
is_wp_error($error) )
            
$error_string esc_html$error->get_error_message() );
        echo 
'<div id="message" class="error"><p>' $error_string '</p></div>';
    }

    
$types = array();
    if ( 
extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen') )
        
$types'ftp' ] = __('FTP');
    if ( 
extension_loaded('ftp') ) //Only this supports FTPS
        
$types'ftps' ] = __('FTPS (SSL)');
    if ( 
extension_loaded('ssh2') && function_exists('stream_get_contents') )
        
$types'ssh' ] = __('SSH2');

    
$types apply_filters('fs_ftp_connection_types'$types$credentials$type$error$context);

?>
<script type="text/javascript">
<!--
jQuery(function($){
    jQuery("#ssh").click(function () {
        jQuery("#ssh_keys").show();
    });
    jQuery("#ftp, #ftps").click(function () {
        jQuery("#ssh_keys").hide();
    });
    jQuery('form input[value=""]:first').focus();
});
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics