/s', '', $html ); } /** * {@inheritDoc} * * Infers whatever it generically can from a package.json, if the * export happens to include one, and flags a hardcoded `/api/...` * backend dependency when a bundled JS file references one — no * server-backed functionality (auth, a database, live data) survives * conversion, whichever builder or backend produced it, so this is * reported rather than silently dropped. * * @param string $dir Absolute path to the extracted export root. * * @return array */ public function get_metadata( $dir ) { $metadata = array( 'source' => 'generic', 'backend_api_detected' => $this->bundled_js_contains( $dir, '/api/' ), ); $package_json_path = rtrim( $dir, '/' ) . '/package.json'; if ( is_file( $package_json_path ) ) { // Local file within the already-extracted export, not a // remote fetch — wp_remote_get() doesn't apply here. $decoded = json_decode( (string) file_get_contents( $package_json_path ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents if ( is_array( $decoded ) ) { $metadata['package_name'] = isset( $decoded['name'] ) ? $decoded['name'] : null; $metadata['package_version'] = isset( $decoded['version'] ) ? $decoded['version'] : null; } } return $metadata; } }