$upload_dir['basedir'] . '/astra-sites/' . self::$folder_name,
'file_name' => 'astra_sites_import_data.json',
'file_content' => array(),
);
$this->create_single_file( $file );
}
/**
* Delete a JSON file from the uploads directory.
*
* @param string $file_name File name to be deleted.
* @return void True on success, false on failure.
*/
public function delete_json_file( $file_name ) {
$upload_dir = wp_upload_dir();
$file_name = $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name . '/' . $file_name;
if ( file_exists( $file_name ) ) {
wp_delete_file( $file_name );
} else {
astra_sites_error_log( 'File not found: ' . $file_name );
}
}
/**
* Getting json file for templates from uploads.
*
* @param string $file_name File data.
* @param bool $array_format Is The file content array.
*
* @return mixed
*/
public function get_json_file_content( $file_name, $array_format = true ) {
$upload_dir = wp_upload_dir();
$file_name = $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name . '/' . $file_name;
if ( file_exists( $file_name ) ) {
// Ignoring the rule as it is not a remote file.
$file_content = file_get_contents( $file_name ); //phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
if ( $array_format ) {
return json_decode( (string) $file_content, true );
} else {
return $file_content;
}
}
return '';
}
/**
* Getter for get_json_file_content
*
* @since 4.2.0
*
* @return mixed
*/
public function get_demo_content() {
return $this->get_json_file_content( 'astra_sites_import_data.json' );
}
/**
* Delete for get_json_file_content
*
* @since 4.2.0
*
* @return mixed
*/
public function delete_demo_content() {
$this->delete_json_file( 'astra_sites_import_data.json' );
}
/**
* Create single json file.
*
* @since 4.2.2
* @param array