@@ -55,27 +55,29 @@ function sse_is_path_within_export_source( string $path, string $directory ): bo
5555 * Creates a site archive with database and files.
5656 *
5757 * @since 1.0.0
58- * @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
59- * @param array{filename: string, filepath: string} $database_file Database file information.
60- * @param string $site_identifier Sanitized site identifier.
61- * @param string $timestamp Export timestamp.
58+ * @param array $export_paths Export directory paths.
59+ * @param array $database_file Database file information.
60+ * @param string $site_identifier Sanitized site identifier.
61+ * @param string $timestamp Export timestamp.
62+ * @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
63+ * @psalm-param array{filename: string, filepath: string} $database_file
6264 * @return array{filename: string, filepath: string}|WP_Error Archive info on success, WP_Error on failure.
6365 */
6466function sse_create_site_archive ( array $ export_paths , array $ database_file , string $ site_identifier , string $ timestamp ) {
6567 $ requirements_result = sse_validate_archive_requirements ();
66- if ( is_wp_error ( $ requirements_result ) ) {
68+ if ( sse_is_wp_error ( $ requirements_result ) ) {
6769 return $ requirements_result ;
6870 }
6971
7072 $ bundle_paths = sse_prepare_engine_script_bundle_paths ( $ export_paths , $ site_identifier , $ timestamp );
7173 $ setup_result = sse_create_bundle_staging_directories ( $ bundle_paths );
72- if ( is_wp_error ( $ setup_result ) ) {
74+ if ( sse_is_wp_error ( $ setup_result ) ) {
7375 return $ setup_result ;
7476 }
7577
7678 try {
7779 $ archive_result = sse_build_engine_script_bundle ( $ export_paths , $ database_file , $ bundle_paths , $ site_identifier );
78- if ( is_wp_error ( $ archive_result ) ) {
80+ if ( sse_is_wp_error ( $ archive_result ) ) {
7981 return $ archive_result ;
8082 }
8183
@@ -115,30 +117,33 @@ function sse_validate_archive_requirements() {
115117 * Builds the staged EngineScript bundle payload.
116118 *
117119 * @since 2.0.0
118- * @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
119- * @param array{filename: string, filepath: string} $database_file Database file information.
120- * @param array{database_path: string, files_archive_path: string, manifest_path: string, database_gz_filename: string, files_archive_filename: string, combined_zip_path: string, combined_zip_filename: string} $bundle_paths Bundle paths.
121- * @param string $site_identifier Sanitized site identifier.
120+ * @param array $export_paths Export directory paths.
121+ * @param array $database_file Database file information.
122+ * @param array $bundle_paths Bundle paths.
123+ * @param string $site_identifier Sanitized site identifier.
124+ * @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
125+ * @psalm-param array{filename: string, filepath: string} $database_file
126+ * @psalm-param array{database_path: string, files_archive_path: string, manifest_path: string, database_gz_filename: string, files_archive_filename: string, combined_zip_path: string, combined_zip_filename: string, ...} $bundle_paths
122127 * @return true|WP_Error True on success, WP_Error on failure.
123128 */
124129function sse_build_engine_script_bundle ( array $ export_paths , array $ database_file , array $ bundle_paths , string $ site_identifier ) {
125130 $ database_result = sse_create_compressed_database_file ( $ database_file ['filepath ' ], $ bundle_paths ['database_path ' ] );
126- if ( is_wp_error ( $ database_result ) ) {
131+ if ( sse_is_wp_error ( $ database_result ) ) {
127132 return $ database_result ;
128133 }
129134
130135 $ file_result = sse_create_wordpress_files_archive ( $ bundle_paths ['files_archive_path ' ], $ export_paths ['export_dir ' ] );
131- if ( is_wp_error ( $ file_result ) ) {
136+ if ( sse_is_wp_error ( $ file_result ) ) {
132137 return $ file_result ;
133138 }
134139
135140 $ manifest_result = sse_write_engine_script_manifest ( $ bundle_paths , $ site_identifier );
136- if ( is_wp_error ( $ manifest_result ) ) {
141+ if ( sse_is_wp_error ( $ manifest_result ) ) {
137142 return $ manifest_result ;
138143 }
139144
140145 $ zip_result = sse_create_combined_engine_script_zip ( $ bundle_paths );
141- if ( is_wp_error ( $ zip_result ) ) {
146+ if ( sse_is_wp_error ( $ zip_result ) ) {
142147 return $ zip_result ;
143148 }
144149
@@ -149,16 +154,17 @@ function sse_build_engine_script_bundle( array $export_paths, array $database_fi
149154 * Prepares canonical EngineScript bundle paths and filenames.
150155 *
151156 * @since 2.0.0
152- * @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
153- * @param string $site_identifier Sanitized site identifier.
154- * @param string $timestamp Export timestamp.
157+ * @param array $export_paths Export directory paths.
158+ * @param string $site_identifier Sanitized site identifier.
159+ * @param string $timestamp Export timestamp.
160+ * @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
155161 * @return array{staging_dir: string, bundle_root_dir: string, database_dir: string, files_dir: string, manifest_path: string, database_filename: string, database_gz_filename: string, database_path: string, files_archive_filename: string, files_archive_path: string, combined_zip_filename: string, combined_zip_path: string}
156162 */
157163function sse_prepare_engine_script_bundle_paths ( array $ export_paths , string $ site_identifier , string $ timestamp ): array {
158- $ staging_dir = trailingslashit ( $ export_paths ['export_dir ' ] ) . 'staging- ' . $ timestamp ;
159- $ bundle_root_dir = trailingslashit ( $ staging_dir ) . 'bundle ' ;
160- $ database_dir = trailingslashit ( $ bundle_root_dir ) . 'database ' ;
161- $ files_dir = trailingslashit ( $ bundle_root_dir ) . 'files ' ;
164+ $ staging_dir = trailingslashit ( $ export_paths ['export_dir ' ] ) . 'staging- ' . $ timestamp ;
165+ $ bundle_root_dir = trailingslashit ( $ staging_dir ) . 'bundle ' ;
166+ $ database_dir = trailingslashit ( $ bundle_root_dir ) . 'database ' ;
167+ $ files_dir = trailingslashit ( $ bundle_root_dir ) . 'files ' ;
162168 $ database_filename = "{$ site_identifier }_db_ {$ timestamp }.sql " ;
163169 $ database_gz_filename = $ database_filename . '.gz ' ;
164170 $ files_archive_filename = "{$ site_identifier }_files_ {$ timestamp }.tar.gz " ;
@@ -184,7 +190,8 @@ function sse_prepare_engine_script_bundle_paths( array $export_paths, string $si
184190 * Creates bundle staging directories.
185191 *
186192 * @since 2.0.0
187- * @param array{database_dir: string, files_dir: string} $bundle_paths Bundle paths.
193+ * @param array $bundle_paths Bundle paths.
194+ * @psalm-param array{database_dir: string, files_dir: string, ...} $bundle_paths
188195 * @return true|WP_Error True on success, WP_Error on failure.
189196 */
190197function sse_create_bundle_staging_directories ( array $ bundle_paths ) {
@@ -258,7 +265,7 @@ function sse_create_wordpress_files_archive( string $files_archive_path, string
258265 $ file_result = sse_add_wordpress_files_to_tar ( $ tar_archive , $ export_dir );
259266 unset( $ tar_archive );
260267
261- if ( is_wp_error ( $ file_result ) ) {
268+ if ( sse_is_wp_error ( $ file_result ) ) {
262269 sse_cleanup_files ( [ $ tar_path , $ files_archive_path ] );
263270 return $ file_result ;
264271 }
@@ -290,8 +297,9 @@ function sse_create_wordpress_files_archive( string $files_archive_path, string
290297 * Writes the EngineScript archive manifest.
291298 *
292299 * @since 2.0.0
293- * @param array{manifest_path: string, database_gz_filename: string, files_archive_filename: string} $bundle_paths Bundle paths.
294- * @param string $site_identifier Sanitized site identifier.
300+ * @param array $bundle_paths Bundle paths.
301+ * @param string $site_identifier Sanitized site identifier.
302+ * @psalm-param array{manifest_path: string, database_gz_filename: string, files_archive_filename: string, ...} $bundle_paths
295303 * @return true|WP_Error True on success, WP_Error on failure.
296304 */
297305function sse_write_engine_script_manifest ( array $ bundle_paths , string $ site_identifier ) {
@@ -308,7 +316,7 @@ function sse_write_engine_script_manifest( array $bundle_paths, string $site_ide
308316 ) . "\n" ;
309317
310318 $ filesystem_init = sse_init_filesystem ();
311- if ( is_wp_error ( $ filesystem_init ) ) {
319+ if ( sse_is_wp_error ( $ filesystem_init ) ) {
312320 return $ filesystem_init ;
313321 }
314322
@@ -324,7 +332,8 @@ function sse_write_engine_script_manifest( array $bundle_paths, string $site_ide
324332 * Creates the outer EngineScript ZIP archive.
325333 *
326334 * @since 2.0.0
327- * @param array{combined_zip_path: string, manifest_path: string, database_path: string, database_gz_filename: string, files_archive_path: string, files_archive_filename: string} $bundle_paths Bundle paths.
335+ * @param array $bundle_paths Bundle paths.
336+ * @psalm-param array{combined_zip_path: string, manifest_path: string, database_path: string, database_gz_filename: string, files_archive_path: string, files_archive_filename: string, ...} $bundle_paths
328337 * @return true|WP_Error True on success, WP_Error on failure.
329338 */
330339function sse_create_combined_engine_script_zip ( array $ bundle_paths ) {
@@ -344,7 +353,7 @@ function sse_create_combined_engine_script_zip( array $bundle_paths ) {
344353 $ zip ->addEmptyDir ( 'files ' );
345354
346355 $ entries = [
347- 'manifest.txt ' => $ bundle_paths ['manifest_path ' ],
356+ 'manifest.txt ' => $ bundle_paths ['manifest_path ' ],
348357 'database/ ' . $ bundle_paths ['database_gz_filename ' ] => $ bundle_paths ['database_path ' ],
349358 'files/ ' . $ bundle_paths ['files_archive_filename ' ] => $ bundle_paths ['files_archive_path ' ],
350359 ];
@@ -381,12 +390,16 @@ function sse_create_combined_engine_script_zip( array $bundle_paths ) {
381390 * @return bool True if deleted or absent, false on failure.
382391 */
383392function sse_delete_directory_tree ( string $ directory ): bool {
384- if ( is_wp_error ( sse_init_filesystem () ) ) {
393+ if ( sse_is_wp_error ( sse_init_filesystem () ) ) {
385394 return false ;
386395 }
387396
388397 $ export_dir = sse_get_export_directory_path ();
389- if ( is_wp_error ( $ export_dir ) || ! sse_is_path_within_directory ( $ directory , $ export_dir ) ) {
398+ if ( sse_is_wp_error ( $ export_dir ) ) {
399+ return false ;
400+ }
401+
402+ if ( ! sse_is_path_within_directory ( $ directory , $ export_dir ) ) {
390403 return false ;
391404 }
392405
@@ -408,7 +421,7 @@ function sse_delete_directory_tree( string $directory ): bool {
408421 */
409422function sse_add_wordpress_files_to_tar ( PharData $ tar , string $ export_dir ) {
410423 $ source_path = realpath ( ABSPATH );
411- if ( ! $ source_path ) {
424+ if ( false === $ source_path ) {
412425 sse_log ( 'Could not resolve real path for ABSPATH. Using ABSPATH directly. ' , 'warning ' );
413426 $ source_path = ABSPATH ;
414427 }
@@ -422,7 +435,7 @@ function sse_add_wordpress_files_to_tar( PharData $tar, string $export_dir ) {
422435
423436 foreach ( $ files as $ file_info ) {
424437 $ file_result = sse_process_file_for_tar ( $ tar , $ file_info , $ source_path , $ export_dir );
425- if ( is_wp_error ( $ file_result ) ) {
438+ if ( sse_is_wp_error ( $ file_result ) ) {
426439 return $ file_result ;
427440 }
428441 }
@@ -570,10 +583,17 @@ function sse_should_exclude_file( string $pathname, string $relative_path, strin
570583 *
571584 * @param int $max_file_size Maximum file size in bytes. Default is user's selection or 0 (no limit).
572585 */
573- $ cached_max_file_size ??= (int ) apply_filters (
574- SSE_FILTER_MAX_FILE_SIZE ,
575- get_transient ( 'sse_export_max_file_size_ ' . get_current_user_id () ) ?: 0
576- );
586+ if ( null === $ cached_max_file_size ) {
587+ $ selected_max_file_size = get_transient ( 'sse_export_max_file_size_ ' . get_current_user_id () );
588+ if ( false === $ selected_max_file_size || ! is_numeric ( $ selected_max_file_size ) ) {
589+ $ selected_max_file_size = 0 ;
590+ }
591+
592+ $ cached_max_file_size = (int ) apply_filters (
593+ SSE_FILTER_MAX_FILE_SIZE ,
594+ (int ) $ selected_max_file_size
595+ );
596+ }
577597
578598 if ( $ cached_max_file_size > 0 && $ file_info ->getSize () > $ cached_max_file_size ) {
579599 sse_log ( 'Excluding large file: ' . $ pathname . ' (Size: ' . size_format ( $ file_info ->getSize () ) . ', Limit: ' . size_format ( $ cached_max_file_size ) . ') ' , 'info ' );
0 commit comments