is_dir( $path ) ) { if ( ! wp_mkdir_p( $path ) ) { return false; } } return $path; } catch ( Exception $exception ) { return false; } } /** * @param string $path * @param string $data * * @return boolean * * @since 2.0.6 * */ public static function write_to_file( $path, $data ) { $filesystem = self::init_filesystem(); if ( ! $filesystem ) { return false; } try { return $filesystem->put_contents( $path, $data, FS_CHMOD_FILE ); } catch ( Exception $e ) { return false; } } /** * @param string $path * * @return false|string * * @since 2.0.6 */ public static function read_file( $path ) { $filesystem = self::init_filesystem(); if ( ! $filesystem ) { return false; } try { if ( ! $filesystem->exists( $path ) ) { return false; } $result = $filesystem->get_contents( $path ); return $result === false ? false : (string) $result; } catch ( Exception $exception ) { return false; } } /** * @return string * * @since 2.0.6 */ public static function get_upload_dir() { return rtrim( sprintf( '%s/%s/', wp_upload_dir()['basedir'], AS_CM_Manager::$action ), '/' ); } }