Make WordPress Core

Ticket #31616: 31616.diff

File 31616.diff, 25.0 KB (added by jipmoors, 10 years ago)
  • src/wp-admin/includes/file.php

     
    897897 * @return string The transport to use, see description for valid return values.
    898898 */
    899899function get_filesystem_method( $args = array(), $context = false, $allow_relaxed_file_ownership = false ) {
    900         $method = defined('FS_METHOD') ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
     900        static $results = array();
    901901
    902         if ( ! $context ) {
    903                 $context = WP_CONTENT_DIR;
    904         }
     902        // saving hash for static cache; file reads/writes are to be avoided when possible
     903        $hash = md5(serialize($args) . var_export($context, true) . var_export($allow_relaxed_file_ownership, true));
    905904
    906         // If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it.
    907         if ( WP_LANG_DIR == $context && ! is_dir( $context ) ) {
    908                 $context = dirname( $context );
    909         }
     905        if ( ! isset($results[$hash])) {
    910906
    911         $context = trailingslashit( $context );
     907                $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
    912908
    913         if ( ! $method ) {
     909                if ( ! $context ) {
     910                        $context = WP_CONTENT_DIR;
     911                }
    914912
    915                 $temp_file_name = $context . 'temp-write-test-' . time();
    916                 $temp_handle = @fopen($temp_file_name, 'w');
    917                 if ( $temp_handle ) {
     913                // If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it.
     914                if ( WP_LANG_DIR == $context && ! is_dir( $context ) ) {
     915                        $context = dirname( $context );
     916                }
    918917
    919                         // Attempt to determine the file owner of the WordPress files, and that of newly created files
    920                         $wp_file_owner = $temp_file_owner = false;
    921                         if ( function_exists('fileowner') ) {
    922                                 $wp_file_owner = @fileowner( __FILE__ );
    923                                 $temp_file_owner = @fileowner( $temp_file_name );
    924                         }
     918                $context = trailingslashit( $context );
    925919
    926                         if ( $wp_file_owner !== false && $wp_file_owner === $temp_file_owner ) {
    927                                 // WordPress is creating files as the same owner as the WordPress files,
    928                                 // this means it's safe to modify & create new files via PHP.
    929                                 $method = 'direct';
    930                                 $GLOBALS['_wp_filesystem_direct_method'] = 'file_owner';
    931                         } elseif ( $allow_relaxed_file_ownership ) {
    932                                 // The $context directory is writable, and $allow_relaxed_file_ownership is set, this means we can modify files
    933                                 // safely in this directory. This mode doesn't create new files, only alter existing ones.
    934                                 $method = 'direct';
    935                                 $GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership';
     920                if ( ! $method ) {
     921
     922                        $temp_file_name = $context . 'temp-write-test-' . time();
     923                        $temp_handle    = @fopen( $temp_file_name, 'w' );
     924                        if ( $temp_handle ) {
     925
     926                                // Attempt to determine the file owner of the WordPress files, and that of newly created files
     927                                $wp_file_owner = $temp_file_owner = false;
     928                                if ( function_exists( 'fileowner' ) ) {
     929                                        $wp_file_owner   = @fileowner( __FILE__ );
     930                                        $temp_file_owner = @fileowner( $temp_file_name );
     931                                }
     932
     933                                if ( $wp_file_owner !== false && $wp_file_owner === $temp_file_owner ) {
     934                                        // WordPress is creating files as the same owner as the WordPress files,
     935                                        // this means it's safe to modify & create new files via PHP.
     936                                        $method                                  = 'direct';
     937                                        $GLOBALS['_wp_filesystem_direct_method'] = 'file_owner';
     938                                } elseif ( $allow_relaxed_file_ownership ) {
     939                                        // The $context directory is writable, and $allow_relaxed_file_ownership is set, this means we can modify files
     940                                        // safely in this directory. This mode doesn't create new files, only alter existing ones.
     941                                        $method                                  = 'direct';
     942                                        $GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership';
     943                                }
     944
     945                                @fclose( $temp_handle );
     946                                @unlink( $temp_file_name );
    936947                        }
     948                }
    937949
    938                         @fclose($temp_handle);
    939                         @unlink($temp_file_name);
     950                if ( ! $method && isset( $args['connection_type'] ) && 'ssh' == $args['connection_type'] && extension_loaded( 'ssh2' ) && function_exists( 'stream_get_contents' ) ) {
     951                        $method = 'ssh2';
    940952                }
    941         }
     953                if ( ! $method && extension_loaded( 'ftp' ) ) {
     954                        $method = 'ftpext';
     955                }
     956                if ( ! $method && ( extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) ) {
     957                        $method = 'ftpsockets';
     958                } //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
    942959
    943         if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2';
    944         if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
    945         if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
     960                /**
     961                 * Filter the filesystem method to use.
     962                 *
     963                 * @since 2.6.0
     964                 *
     965                 * @param string $method Filesystem method to return.
     966                 * @param array $args An array of connection details for the method.
     967                 * @param string $context Full path to the directory that is tested for being writable.
     968                 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     969                 */
    946970
    947         /**
    948          * Filter the filesystem method to use.
    949          *
    950          * @since 2.6.0
    951          *
    952          * @param string $method  Filesystem method to return.
    953          * @param array  $args    An array of connection details for the method.
    954          * @param string $context Full path to the directory that is tested for being writable.
    955          * @param bool   $allow_relaxed_file_ownership Whether to allow Group/World writable.
    956          */
    957         return apply_filters( 'filesystem_method', $method, $args, $context, $allow_relaxed_file_ownership );
     971                $results[$hash] = apply_filters( 'filesystem_method', $method, $args, $context, $allow_relaxed_file_ownership );
     972        }
     973
     974        return $results[$hash];
    958975}
    959976
    960977/**
    961  * Displays a form to the user to request for their FTP/SSH details in order
    962  * to connect to the filesystem.
     978 * Get the filesystem credentials needed to connect to the site via supplied method
    963979 *
    964  * All chosen/entered details are saved, Excluding the Password.
    965  *
    966  * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467)
    967  * to specify an alternate FTP/SSH port.
    968  *
    969  * Plugins may override this form by returning true|false via the
    970  * {@see 'request_filesystem_credentials'} filter.
    971  *
    972  * @since 2.5.
    973  *
    974  * @todo Properly mark optional arguments as such
    975  *
    976980 * @param string $form_post the URL to post the form to
    977981 * @param string $type the chosen Filesystem method in use
    978982 * @param boolean $error if the current request has failed to connect
    979983 * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
    980984 * @param array $extra_fields Extra POST fields which should be checked for to be included in the post.
    981985 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
    982  * @return boolean False on failure. True on success.
     986 * @return mixed Credentials that are found, not guaranteed to contain all information
    983987 */
    984 function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null, $allow_relaxed_file_ownership = false ) {
     988function get_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null, $allow_relaxed_file_ownership = false) {
    985989
    986990        /**
    987991         * Filter the filesystem credentials form output.
     
    991995         *
    992996         * @since 2.5.0
    993997         *
    994          * @param mixed  $output      Form output to return instead. Default empty.
    995          * @param string $form_post    URL to POST the form to.
    996          * @param string $type         Chosen type of filesystem.
    997          * @param bool   $error        Whether the current request has failed to connect.
     998         * @param mixed $output Form output to return instead. Default empty.
     999         * @param string $form_post URL to POST the form to.
     1000         * @param string $type Chosen type of filesystem.
     1001         * @param bool $error Whether the current request has failed to connect.
    9981002         *                             Default false.
    999          * @param string $context      Full path to the directory that is tested for
     1003         * @param string $context Full path to the directory that is tested for
    10001004         *                             being writable.
    10011005         * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
    1002          * @param array  $extra_fields Extra POST fields.
     1006         * @param array $extra_fields Extra POST fields.
    10031007         */
    1004         $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
    1005         if ( '' !== $req_cred )
    1006                 return $req_cred;
     1008        $credentials = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
     1009        if ( !empty($credentials) ) {
     1010                return $credentials;
     1011        }
    10071012
    10081013        if ( empty($type) ) {
    10091014                $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
    10101015        }
    10111016
    1012         if ( 'direct' == $type )
     1017        if ( 'direct' == $type ) {
    10131018                return true;
     1019        }
    10141020
    1015         if ( is_null( $extra_fields ) )
    1016                 $extra_fields = array( 'version', 'locale' );
    1017 
    10181021        $credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
    10191022
     1023
    10201024        // 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)
    10211025        $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? wp_unslash( $_POST['hostname'] ) : $credentials['hostname']);
    10221026        $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? wp_unslash( $_POST['username'] ) : $credentials['username']);
     
    10461050        } elseif ( ! isset( $credentials['connection_type'] ) ) { //All else fails (And it's not defaulted to something else saved), Default to FTP
    10471051                $credentials['connection_type'] = 'ftp';
    10481052        }
    1049         if ( ! $error &&
    1050                         (
    1051                                 ( !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) ||
    1052                                 ( 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) )
    1053                         ) ) {
     1053
     1054        return $credentials;
     1055}
     1056
     1057/**
     1058 * @param array $credentials Credentials to check required parameters
     1059 * @param string $type Type of connection to check credentials against (direct, ftps, ftp, ssh, etc.)
     1060 * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
     1061 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     1062 *
     1063 * @return bool True when all required parameters have been set for supplied type, False when anything is missing
     1064 */
     1065function usable_filesystem_credentials($credentials, $type = '', $context = null, $allow_relaxed_file_ownership = false) {
     1066        if ( empty($type) ) {
     1067                $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
     1068        }
     1069
     1070        // Direct connection does not need any credentials
     1071        if ( 'direct' == $type ) {
     1072                return true;
     1073        }
     1074
     1075        // We need something to check against
     1076        if ( empty( $credentials ) ) {
     1077                return false;
     1078        }
     1079
     1080        // All the checks required an array for parameters; exit if we got something else
     1081        if ( ! is_array( $credentials ) ) {
     1082                return false;
     1083        }
     1084
     1085        // SSH needs public and private key
     1086        if ( 'ssh' == $credentials['connection_type'] ) {
     1087                return ( ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) );
     1088        }
     1089
     1090        // Other connection methods need hostname, password and username
     1091        return ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) );
     1092}
     1093
     1094/**
     1095 * Displays a form to the user to request for their FTP/SSH details in order
     1096 * to connect to the filesystem.
     1097 *
     1098 * All chosen/entered details are saved, Excluding the Password.
     1099 *
     1100 * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467)
     1101 * to specify an alternate FTP/SSH port.
     1102 *
     1103 * Plugins may override this form by returning true|false via the
     1104 * {@see 'request_filesystem_credentials'} filter.
     1105 *
     1106 * @since 2.5.
     1107 *
     1108 * @todo Properly mark optional arguments as such
     1109 *
     1110 * @param string $form_post the URL to post the form to
     1111 * @param string $type the chosen Filesystem method in use
     1112 * @param boolean $error if the current request has failed to connect
     1113 * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
     1114 * @param array $extra_fields Extra POST fields which should be checked for to be included in the post.
     1115 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     1116 * @return boolean False on failure. True on success.
     1117 */
     1118function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null, $allow_relaxed_file_ownership = false ) {
     1119        /**
     1120         * Filter the filesystem credentials form output.
     1121         *
     1122         * Returning anything other than an empty string will effectively short-circuit
     1123         * output of the filesystem credentials form, returning that value instead.
     1124         *
     1125         * @since 2.5.0
     1126         *
     1127         * @param mixed $output Form output to return instead. Default empty.
     1128         * @param string $form_post URL to POST the form to.
     1129         * @param string $type Chosen type of filesystem.
     1130         * @param bool $error Whether the current request has failed to connect.
     1131         *                             Default false.
     1132         * @param string $context Full path to the directory that is tested for
     1133         *                             being writable.
     1134         * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     1135         * @param array $extra_fields Extra POST fields.
     1136         */
     1137        $credentials = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
     1138        if ( ! empty( $credentials ) ) {
     1139                return $credentials;
     1140        }
     1141
     1142        if ( empty( $type ) ) {
     1143                $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
     1144        }
     1145
     1146        if ( 'direct' == $type ) {
     1147                return true;
     1148        }
     1149
     1150        $credentials = get_filesystem_credentials( $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
     1151
     1152        if ( ! $error && usable_filesystem_credentials( $credentials, $type ) ) {
     1153
    10541154                $stored_credentials = $credentials;
    1055                 if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code.
     1155                if ( ! empty( $stored_credentials['port'] ) ) //save port as part of hostname to simplify retrievement code
     1156                {
    10561157                        $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
     1158                }
    10571159
    1058                 unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
     1160                unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] );
     1161
    10591162                if ( ! defined( 'WP_INSTALLING' ) ) {
    10601163                        update_option( 'ftp_credentials', $stored_credentials );
    10611164                }
     1165
    10621166                return $credentials;
    10631167        }
     1168
     1169        // Display the credentials form to the user
     1170        request_filesystem_credentials_form( $form_post, $credentials, $type, $error, $context, $extra_fields );
     1171
     1172        // Nothing usable has been found yet.
     1173        return false;
     1174}
     1175
     1176/**
     1177 * Write the form needed to input credentials needed to connect for the specified type
     1178 *
     1179 * @param string $form_post the URL to post the form to
     1180 * @param $credentials
     1181 * @param string $type the chosen Filesystem method in use
     1182 * @param boolean $error if the current request has failed to connect
     1183 * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
     1184 * @param array $extra_fields Extra POST fields which should be checked for to be included in the post.
     1185 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     1186 */
     1187function request_filesystem_credentials_form($form_post, $credentials, $type = '', $error = false, $context = null, $extra_fields = null, $allow_relaxed_file_ownership = false) {
     1188        if ( empty( $type ) ) {
     1189                $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
     1190        }
     1191
     1192        if ( ! is_array($credentials)) {
     1193                $credentials = array();
     1194        }
     1195
    10641196        $hostname = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
    10651197        $username = isset( $credentials['username'] ) ? $credentials['username'] : '';
    10661198        $public_key = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
     
    10681200        $port = isset( $credentials['port'] ) ? $credentials['port'] : '';
    10691201        $connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
    10701202
     1203        if ( is_null( $extra_fields ) )
     1204                $extra_fields = array( 'version', 'locale' );
     1205
    10711206        if ( $error ) {
    10721207                $error_string = __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.');
    10731208                if ( is_wp_error($error) )
     
    10971232         */
    10981233        $types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context );
    10991234
    1100 ?>
    1101 <script type="text/javascript">
    1102 <!--
    1103 jQuery(function($){
    1104         jQuery("#ssh").click(function () {
    1105                 jQuery("#ssh_keys").show();
    1106         });
    1107         jQuery("#ftp, #ftps").click(function () {
    1108                 jQuery("#ssh_keys").hide();
    1109         });
    1110         jQuery('form input[value=""]:first').focus();
    1111 });
    1112 -->
    1113 </script>
    1114 <form action="<?php echo esc_url( $form_post ) ?>" method="post">
    1115 <div>
    1116 <h3><?php _e('Connection Information') ?></h3>
    1117 <p><?php
    1118         $label_user = __('Username');
    1119         $label_pass = __('Password');
    1120         _e('To perform the requested action, WordPress needs to access your web server.');
    1121         echo ' ';
    1122         if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) {
    1123                 if ( isset( $types['ssh'] ) ) {
    1124                         _e('Please enter your FTP or SSH credentials to proceed.');
    1125                         $label_user = __('FTP/SSH Username');
    1126                         $label_pass = __('FTP/SSH Password');
    1127                 } else {
    1128                         _e('Please enter your FTP credentials to proceed.');
    1129                         $label_user = __('FTP Username');
    1130                         $label_pass = __('FTP Password');
    1131                 }
    1132                 echo ' ';
    1133         }
    1134         _e('If you do not remember your credentials, you should contact your web host.');
    1135 ?></p>
    1136 <table class="form-table">
    1137 <tr>
    1138 <th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
    1139 <td><input name="hostname" type="text" id="hostname" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> size="40" /></td>
    1140 </tr>
     1235        ?>
     1236        <script type="text/javascript">
     1237                <!--
     1238                jQuery(function($){
     1239                        jQuery("#ssh").click(function () {
     1240                                jQuery("#ssh_keys").show();
     1241                        });
     1242                        jQuery("#ftp, #ftps").click(function () {
     1243                                jQuery("#ssh_keys").hide();
     1244                        });
     1245                        jQuery('form input[value=""]:first').focus();
     1246                });
     1247                -->
     1248        </script>
     1249        <form action="<?php echo esc_url( $form_post ) ?>" method="post">
     1250                <div>
     1251                        <h3><?php _e('Connection Information') ?></h3>
     1252                        <p><?php
     1253                                $label_user = __('Username');
     1254                                $label_pass = __('Password');
     1255                                _e('To perform the requested action, WordPress needs to access your web server.');
     1256                                echo ' ';
     1257                                if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) {
     1258                                        if ( isset( $types['ssh'] ) ) {
     1259                                                _e('Please enter your FTP or SSH credentials to proceed.');
     1260                                                $label_user = __('FTP/SSH Username');
     1261                                                $label_pass = __('FTP/SSH Password');
     1262                                        } else {
     1263                                                _e('Please enter your FTP credentials to proceed.');
     1264                                                $label_user = __('FTP Username');
     1265                                                $label_pass = __('FTP Password');
     1266                                        }
     1267                                        echo ' ';
     1268                                }
     1269                                _e('If you do not remember your credentials, you should contact your web host.');
     1270                                ?></p>
     1271                        <table class="form-table">
     1272                                <tr>
     1273                                        <th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
     1274                                        <td><input name="hostname" type="text" id="hostname" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> size="40" /></td>
     1275                                </tr>
    11411276
    1142 <tr>
    1143 <th scope="row"><label for="username"><?php echo $label_user; ?></label></th>
    1144 <td><input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> size="40" /></td>
    1145 </tr>
     1277                                <tr>
     1278                                        <th scope="row"><label for="username"><?php echo $label_user; ?></label></th>
     1279                                        <td><input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> size="40" /></td>
     1280                                </tr>
    11461281
    1147 <tr>
    1148 <th scope="row"><label for="password"><?php echo $label_pass; ?></label></th>
    1149 <td><div><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php disabled( defined('FTP_PASS') ); ?> size="40" /></div>
    1150 <div><em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em></div></td>
    1151 </tr>
     1282                                <tr>
     1283                                        <th scope="row"><label for="password"><?php echo $label_pass; ?></label></th>
     1284                                        <td><div><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php disabled( defined('FTP_PASS') ); ?> size="40" /></div>
     1285                                                <div><em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em></div></td>
     1286                                </tr>
    11521287
    1153 <?php if ( isset($types['ssh']) ) : ?>
    1154 <tr id="ssh_keys" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
    1155 <th scope="row"><?php _e('Authentication Keys') ?>
    1156 <div class="key-labels textright">
    1157 <label for="public_key"><?php _e('Public Key:') ?></label ><br />
    1158 <label for="private_key"><?php _e('Private Key:') ?></label>
    1159 </div></th>
    1160 <td><br /><input name="public_key" type="text" id="public_key" value="<?php echo esc_attr($public_key) ?>"<?php disabled( defined('FTP_PUBKEY') ); ?> size="40" />
    1161         <br /><input name="private_key" type="text" id="private_key" value="<?php echo esc_attr($private_key) ?>"<?php disabled( defined('FTP_PRIKEY') ); ?> size="40" />
    1162 <div><?php _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.') ?></div></td>
    1163 </tr>
    1164 <?php endif; ?>
     1288                                <?php if ( isset($types['ssh']) ) : ?>
     1289                                        <tr id="ssh_keys" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
     1290                                                <th scope="row"><?php _e('Authentication Keys') ?>
     1291                                                        <div class="key-labels textright">
     1292                                                                <label for="public_key"><?php _e('Public Key:') ?></label ><br />
     1293                                                                <label for="private_key"><?php _e('Private Key:') ?></label>
     1294                                                        </div></th>
     1295                                                <td><br /><input name="public_key" type="text" id="public_key" value="<?php echo esc_attr($public_key) ?>"<?php disabled( defined('FTP_PUBKEY') ); ?> size="40" />
     1296                                                        <br /><input name="private_key" type="text" id="private_key" value="<?php echo esc_attr($private_key) ?>"<?php disabled( defined('FTP_PRIKEY') ); ?> size="40" />
     1297                                                        <div><?php _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.') ?></div></td>
     1298                                        </tr>
     1299                                <?php endif; ?>
    11651300
    1166 <tr>
    1167 <th scope="row"><?php _e('Connection Type') ?></th>
    1168 <td>
    1169 <fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>
    1170 <?php
    1171         $disabled = disabled( (defined('FTP_SSL') && FTP_SSL) || (defined('FTP_SSH') && FTP_SSH), true, false );
    1172         foreach ( $types as $name => $text ) : ?>
    1173         <label for="<?php echo esc_attr($name) ?>">
    1174                 <input type="radio" name="connection_type" id="<?php echo esc_attr($name) ?>" value="<?php echo esc_attr($name) ?>"<?php checked($name, $connection_type); echo $disabled; ?> />
    1175                 <?php echo $text ?>
    1176         </label>
    1177         <?php endforeach; ?>
    1178 </fieldset>
    1179 </td>
    1180 </tr>
    1181 </table>
     1301                                <tr>
     1302                                        <th scope="row"><?php _e('Connection Type') ?></th>
     1303                                        <td>
     1304                                                <fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>
     1305                                                        <?php
     1306                                                        $disabled = disabled( (defined('FTP_SSL') && FTP_SSL) || (defined('FTP_SSH') && FTP_SSH), true, false );
     1307                                                        foreach ( $types as $name => $text ) : ?>
     1308                                                                <label for="<?php echo esc_attr($name) ?>">
     1309                                                                        <input type="radio" name="connection_type" id="<?php echo esc_attr($name) ?>" value="<?php echo esc_attr($name) ?>"<?php checked($name, $connection_type); echo $disabled; ?> />
     1310                                                                        <?php echo $text ?>
     1311                                                                </label>
     1312                                                        <?php endforeach; ?>
     1313                                                </fieldset>
     1314                                        </td>
     1315                                </tr>
     1316                        </table>
    11821317
     1318                        <?php
     1319                        foreach ( (array) $extra_fields as $field ) {
     1320                                if ( isset( $_POST[ $field ] ) )
     1321                                        echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
     1322                        }
     1323                        submit_button( __( 'Proceed' ), 'button', 'upgrade' );
     1324                        ?>
     1325                </div>
     1326        </form>
    11831327<?php
    1184 foreach ( (array) $extra_fields as $field ) {
    1185         if ( isset( $_POST[ $field ] ) )
    1186                 echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
    11871328}
    1188 submit_button( __( 'Proceed' ), 'button', 'upgrade' );
    1189 ?>
    1190 </div>
    1191 </form>
    1192 <?php
    1193         return false;
    1194 }