put_contents( $path, $contents, FS_CHMOD_FILE ); } public static function move( string $from, string $to ): bool { $fs = self::fs( dirname( $to ) ); return null !== $fs && $fs->move( $from, $to, true ); } public static function remove_dir( string $dir ): bool { $fs = self::fs( dirname( $dir ) ); return null !== $fs && $fs->rmdir( $dir, false ); } public static function touch( string $path ): bool { $fs = self::fs( dirname( $path ) ); return null !== $fs && $fs->touch( $path ); } private static function fs( string $dir ): ?\WP_Filesystem_Base { global $wp_filesystem; if ( $wp_filesystem instanceof \WP_Filesystem_Direct && defined( 'FS_CHMOD_FILE' ) ) { return $wp_filesystem; } if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } if ( ! WP_Filesystem( false, $dir, true ) || ! $wp_filesystem instanceof \WP_Filesystem_Base ) { return null; } return $wp_filesystem; } }