Astra_Docs_Loader::write_json()

Write the CSS to the filesystem.


Description


Return

(string|false) Returns the absolute path of the file on success, or false on fail.


Source

File: inc/lib/docs/class-astra-docs-loader.php

	protected function write_json() {
		$file_path  = $this->get_local_docs_file_path();
		$filesystem = $this->get_filesystem();

		if ( ! defined( 'FS_CHMOD_DIR' ) ) {
			define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
		}

		// If the folder doesn't exist, create it.
		if ( ! file_exists( $this->get_docs_folder() ) ) {
			$this->get_filesystem()->mkdir( $this->get_docs_folder(), FS_CHMOD_DIR );
		}

		// If the file doesn't exist, create it. Return false if it can not be created.
		if ( ! $filesystem->exists( $file_path ) && ! $filesystem->touch( $file_path ) ) {
			return false;
		}

		// If we got this far, we need to write the file.
		// Get the CSS.
		if ( ! $this->docs_data ) {
			$this->get_remote_data();
		}

		// Put the contents in the file. Return false if that fails.
		if ( ! $filesystem->put_contents( $file_path, $this->docs_data ) ) {
			return false;
		}

		return $file_path;
	}

Changelog

Changelog
Version Description
4.6.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.