@ 2024-04-29T13:48:46Z <?php
class WP_Term {
public $foo = 'foo';
public $data; // Change the visibility to protected or private and the script will throw an error.
}
$_POST['action'] = 'action';
function wp_parse_args( $args, $defaults = array() ) {
if ( is_object( $args ) ) {
$parsed_args = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$parsed_args =& $args;
} else {
wp_parse_str( $args, $parsed_args );
}
if ( is_array( $defaults ) && $defaults ) {
return array_merge( $defaults, $parsed_args );
}
return $parsed_args;
}
class WP_Ajax_Response {
public $responses = array();
public function add( $args = '' ) {
$defaults = array(
'what' => 'object',
'action' => false,
'id' => '0',
'old_id' => false,
'position' => 1,
'data' => '',
'supplemental' => array(),
);
$parsed_args = wp_parse_args( $args, $defaults );
$position = preg_replace( '/[^a-z0-9:_-]/i', '', $parsed_args['position'] );
$id = $parsed_args['id'];
$what = $parsed_args['what'];
$action = $parsed_args['action'];
$old_id = $parsed_args['old_id'];
$data = $parsed_args['data'];
$response = "<response_data><![CDATA[$data]]></response_data>";
$s = '';
if ( is_array( $parsed_args['supplemental'] ) ) {
foreach ( $parsed_args['supplemental'] as $k => $v ) {
$s .= "<$k><![CDATA[$v]]></$k>";
}
$s = "<supplemental>$s</supplemental>";
}
if ( false === $action ) {
$action = $_POST['action'];
}
$x = '';
$x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action.
$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
$x .= $response;
$x .= $s;
$x .= "</$what>";
$x .= '</response>';
$this->responses[] = $x;
return $x;
}
}
$response = new WP_Ajax_Response();
$tag = new WP_Term();
$response->add(
array(
'what' => 'term',
'supplemental' => (array) $tag,
)
);
libxml_use_internal_errors( true );
$xml = simplexml_load_string( $response->responses[0], 'SimpleXMLElement' );
if ( $xml === false ) {
echo 'Failed loading XML: ';
foreach ( libxml_get_errors() as $error ) {
// Display each error
echo '<br>', $error->message . "\n";
}
// Clear the error buffer to free memory
libxml_clear_errors();
} else {
// Your XML is correctly parsed, proceed with your logic
echo 'XML loaded successfully.' . "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.13 0.000 0.009 17.06 8.3.12 0.003 0.007 19.41 8.3.11 0.003 0.006 20.94 8.3.10 0.000 0.009 24.06 8.3.9 0.004 0.004 26.77 8.3.8 0.013 0.000 17.13 8.3.7 0.015 0.006 18.81 8.3.6 0.017 0.007 25.92 8.3.5 0.011 0.006 25.92 8.3.4 0.008 0.008 25.92 8.2.25 0.006 0.003 18.81 8.2.24 0.016 0.003 17.41 8.2.23 0.006 0.003 22.58 8.2.22 0.007 0.003 37.54 8.2.21 0.004 0.004 26.77 8.2.20 0.003 0.007 19.04 8.2.19 0.010 0.007 16.72 8.2.18 0.018 0.007 25.92 8.2.17 0.017 0.003 25.92 8.1.30 0.006 0.003 20.35 8.1.29 0.003 0.007 18.88 8.1.28 0.006 0.013 25.92
preferences:dark mode live preview
24.4 ms | 403 KiB | 5 Q