get_filesystem()->mkdir( $dir ); // IF a directory cannot be created, return with false status. if ( false === $status ) { astra_addon_filesystem()->update_filesystem_access_status( $status ); return false; } // Add an index file for security. astra_addon_filesystem()->get_filesystem()->put_contents( $dir . 'index.php', '' ); } return true; } /** * Update Filesystem status. * * @since 2.6.4 * @param boolean $status status for filesystem access. * @return void */ public function update_filesystem_access_status( $status ) { astra_update_option( 'file-write-access', $status ); } /** * Check if filesystem has write access. * * @since 2.6.4 * @return boolean True if filesystem has access, false if does not have access. */ public function can_access_filesystem() { return (bool) astra_get_option( 'file-write-access', true ); } /** * Reset filesystem access status. * * @since 2.6.4 * @return void */ public function reset_filesystem_access_status() { astra_delete_option( 'file-write-access' ); } /** * Returns an array of paths for the upload directory * of the current site. * * @since 2.6.4 * @param String $assets_dir directory name to be created in the WordPress uploads directory. * @return array */ public function get_uploads_dir( $assets_dir ) { $wp_info = wp_upload_dir( null, false ); // SSL workaround. if ( $this->is_ssl() ) { $wp_info['baseurl'] = str_ireplace( 'http://', 'https://', $wp_info['baseurl'] ); } // Build the paths. $dir_info = array( 'path' => $wp_info['basedir'] . '/' . $assets_dir . '/', 'url' => $wp_info['baseurl'] . '/' . $assets_dir . '/', ); return apply_filters( 'astra_addon_get_assets_uploads_dir', $dir_info ); } /** * Delete file from the filesystem. * * @since 2.6.4 * @param String $file Path to the file or directory. * @param boolean $recursive If set to true, changes file group recursively. * @param boolean $type Type of resource. 'f' for file, 'd' for directory. * @return void */ public function delete( $file, $recursive = false, $type = false ) { astra_addon_filesystem()->get_filesystem()->delete( $file, $recursive, $type ); } /** * Adds contents to the file. * * @param string $file_path Gets the assets path info. * @param string $style_data Gets the CSS data. * @since 2.6.4 * @return bool $put_content returns false if file write is not successful. */ public function put_contents( $file_path, $style_data ) { return astra_addon_filesystem()->get_filesystem()->put_contents( $file_path, $style_data ); } /** * Get contents of the file. * * @param string $file_path Gets the assets path info. * @since 2.6.4 * @return bool $get_contents Gets te file contents. */ public function get_contents( $file_path ) { return astra_addon_filesystem()->get_filesystem()->get_contents( $file_path ); } }