get( 'any-ipsum-api-request' ) === '1' ) { $this->handle_api_request(); } } function handle_api_request() { header( 'Access-Control-Allow-Origin: *' ); $type = WPAnyIpsumCore::get_request( 'type' ); $callback = WPAnyIpsumCore::get_request( 'callback' ); $format = WPAnyIpsumCore::get_request( 'format' ); if ( !in_array($format, array( 'json', 'text' ) ) ) { $format = 'json'; } if ( ! empty ( $type ) || ! empty ( $callback ) ) { $args = apply_filters( 'anyipsum-parse-request-args', $_SERVER['REQUEST_METHOD'] === 'POST' ? $_REQUEST : $_SERVER['QUERY_STRING'] ); $paras = apply_filters( 'anyipsum-generate-filler', $args ); if ( ! empty( $args['callback'] ) ) { switch ($format) { case 'text': header( "Content-Type: text/plain" ); foreach ($paras as $para) { echo $para . "\n\n"; } break; default: header( "Content-Type: application/javascript" ); echo $args['callback'] . '(' . json_encode( $paras ) . ');'; break; } } else { switch ( $format ) { case 'text': header( "Content-Type: text/plain" ); foreach ($paras as $para) { echo $para . "\n\n"; } break; default: header( "Content-Type: application/json; charset=utf-8" ); echo json_encode( $paras ); } } exit; } } } }