array( 'max_link_words' => $max_link_words, 'max_items' => $max_links, ), 'text' => $content, ); $decoded = $this->post_request( array(), $body ); if ( is_wp_error( $decoded ) ) { return $decoded; } if ( ! property_exists( $decoded, 'result' ) || ! is_array( $decoded->result ) ) { return new WP_Error( 400, __( 'Unable to parse suggested links from upstream API', 'wp-parsely' ) ); } // Convert the links to Link_Suggestion objects. $links = array(); foreach ( $decoded->result as $link ) { $link_obj = new Link_Suggestion(); $link_obj->href = $link->canonical_url; $link_obj->title = $link->title; $link_obj->text = $link->text; $link_obj->offset = $link->offset; $links[] = $link_obj; } return $links; } }