The scan_file function should also be modified accordingly :
public function scan_file( $dir, $extpattern, $mediafromftp_settings ) {
/* for media-from-ftp-add-on-wpcron and mediafromftpcmd.php */
$cmdoptions = array();
if ( $this->is_add_on_activate['cli'] ) {
$cmdoptions = getopt( 's:d:a:e:t:x:p:f:c:i:b:r:y:hgmo' );
}
if ( isset( $cmdoptions['f'] ) ) {
$search_limit_number = $cmdoptions['f'];
} else {
$search_limit_number = $mediafromftp_settings['search_limit_number'];
}
$thumb_deep_search = false;
if ( isset( $cmdoptions['m'] ) ) {
$thumb_deep_search = true;
} else {
$thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
}
if ( $thumb_deep_search ) {
$excludefile = 'media-from-ftp-tmp'; /* tmp dir file */
} else {
$excludefile = '-[0-9]+x[0-9]+\.|media-from-ftp-tmp'; /* thumbnail & tmp dir file */
}
$recursive_search = true;
if ( isset( $cmdoptions['o'] ) ) {
$recursive_search = false;
} else {
$recursive_search = $mediafromftp_settings['recursive_search'];
}
global $blog_id;
if ( is_multisite() && is_main_site( $blog_id ) ) {
$excludefile .= '|\/sites$';
}
if ( isset( $cmdoptions['e'] ) ) {
$excludefile .= '|' . $cmdoptions['e'];
} else {
if ( ! empty( $mediafromftp_settings['exclude'] ) ) {
$excludefile .= '|' . $mediafromftp_settings['exclude'];
}
}
$ext2typefilter = $mediafromftp_settings['ext2typefilter'];
if ( isset( $cmdoptions['t'] ) ) {
$ext2typefilter = $cmdoptions['t'];
} else {
if ( isset( $_POST['ext2type'] ) && ! empty( $_POST['ext2type'] ) ) {
if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
$ext2typefilter = sanitize_text_field( wp_unslash( $_POST['ext2type'] ) );
}
}
}
unset( $cmdoptions );
$searchtext = '.*';
if ( isset( $_POST['searchtext'] ) && ! empty( $_POST['searchtext'] ) ) {
if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
$searchtext = $this->mb_encode_multibyte( sanitize_text_field( wp_unslash( $_POST['searchtext'] ) ), $mediafromftp_settings['character_code'] );
}
} elseif ( isset( $_GET['searchtext'] ) && ! empty( $_GET['searchtext'] ) ) {
if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
$searchtext = $this->mb_encode_multibyte( sanitize_text_field( wp_unslash( $_GET['searchtext'] ) ), $mediafromftp_settings['character_code'] );
}
}
$files = scandir( $dir );
$list = array();
$count = 0;
foreach ( $files as $file ) {
if ( '.' == $file || '..' == $file ) {
continue;
}
$fullpath = rtrim( $dir, '/' ) . '/' . $file;
if ( is_file( $fullpath ) ) {
if ( ! preg_match( '/' . $excludefile . '/', $fullpath ) ) {
$exts = explode( '.', $file );
$ext = end( $exts );
$searchflag = @preg_match( '/' . $searchtext . '/', $fullpath );
if ( ! $searchflag ) {
/* for "preg_match error: Compilation failed: missing terminating ] for character class" */
$searchflag = preg_match( '/' . preg_quote( $searchtext, '/' ) . '/', $fullpath );
}
if ( $searchflag ) {
if ( preg_match( '/' . $extpattern . '/', $ext ) ) {
if ( wp_ext2type( $ext ) === $ext2typefilter || 'all' === $ext2typefilter ) {
++$count;
if ( $count > $search_limit_number ) {
break;
}
$list[] = $fullpath;
}
}
}
if ( is_dir( $fullpath ) && $recursive_search ) {
$list = array_merge( $list, $this->scan_file( $fullpath, $extpattern, $mediafromftp_settings ) );
}
}
}
}
return $list;
}