Skip to content
Snippets Groups Projects
Commit 4f742c2d authored by Vasken Hauri's avatar Vasken Hauri
Browse files

Prevent warnings when SimpleXMLElement::xpath returns false instead of an...

Prevent warnings when SimpleXMLElement::xpath returns false instead of an array; return a single array element as a string when saving meta values, to insure we don't break existing behavior
parent 76fa1e0f
No related branches found
No related tags found
No related merge requests found
......@@ -211,8 +211,15 @@ class Syndication_WP_XML_Client implements Syndication_Client {
$value_array = $item->xpath( stripslashes( $save_location['xpath'] ) );
}
if (isset($save_location['is_meta']) && $save_location['is_meta']) {
$value_array = array_map( 'strval', $value_array );
$meta_data[$save_location['field']] = $value_array;
//SimpleXMLElement::xpath returns either an array or false if an element isn't returned
//checking $value_array first avoids the warning we get if the field isn't found
if( $value_array && ( count( $value_array ) > 1 ) ) {
$value_array = array_map( 'strval', $value_array );
$meta_data[$save_location['field']] = $value_array;
} else if ( $value_array ) {
//return a string if $value_array contains only a single element
$meta_data[$save_location['field']] = (string) $value_array[0];
}
} else if ( isset($save_location['is_tax']) && $save_location['is_tax'] ) {
//for some taxonomies, multiple values may be supplied in the field
foreach ( $value_array as $value ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment