Skip to content

Commit

Permalink
Include the admin kitchen sink for import (#1475)
Browse files Browse the repository at this point in the history
## What is this PR doing?

Similar to #1357, but taking a deeper cut at it, as import expects to be
run within an admin interface.

## What problem is it solving?

The following fatal will be triggered:
```
PHP Fatal error:  Uncaught Error: Call to undefined function wp_read_audio_metadata() in /wordpress/wp-admin/includes/image.php:2
Stack trace:
#0 /wordpress/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(1067): wp_generate_attachment_metadata(821, '/wordpress/wp-c...')
#1 /wordpress/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(861): WXR_Importer->process_attachment(Array, Array, 'https://raw.git...')
#2 /wordpress/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(383): WXR_Importer->process_post(Array, Array, Array, Array)
#3 /internal/eval.php(20): WXR_Importer->import('/tmp/import.wxr')
#4 {main}
  thrown in /wordpress/wp-admin/includes/image.php on line 2
```

Fixes #1444 (Since found this issue)

## How is the problem addressed?

Including includes/admin.php which pulls in all admin-related
functionality, rather than just the cropping functionality.

Alternatively, this could've been done by selectively importing
`includes/media.php` as well as `includes/image.php`, but I anticipate
that core is likely to include other related admin functions.

## Testing Instructions

Note: This is an untested change.

Try running
https://playground.wordpress.net/builder/builder.html#{%22preferredVersions%22:{%22php%22:%228.0%22,%22wp%22:%22latest%22},%22phpExtensionBundles%22:[%22kitchen-sink%22],%22features%22:{%22networking%22:true},%22steps%22:[{%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22},{%22step%22:%22importWxr%22,%22file%22:{%22resource%22:%22url%22,%22url%22:%22https://raw.githubusercontent.com/WordPress/theme-test-data/try/cors-accessible-images/themeunittestdata.wordpress.xml%22}}]}
  • Loading branch information
dd32 authored Jun 2, 2024
1 parent 09c2d17 commit 88aaf42
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/playground/blueprints/src/lib/steps/import-wxr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = async (
await playground.run({
code: `<?php
require ${phpVar(docroot)} . '/wp-load.php';
if ( ! function_exists( 'wp_crop_image' ) ) {
require ${phpVar(docroot)} . '/wp-admin/includes/image.php';
}
require ${phpVar(docroot)} . '/wp-admin/includes/admin.php';
kses_remove_filters();
$admin_id = get_users(array('role' => 'Administrator') )[0];
$importer = new WXR_Importer( array(
Expand Down

0 comments on commit 88aaf42

Please sign in to comment.