private function form_template($content) { $settings = $this->get_settings(); $type = WPAnyIpsumCore::get_request('type', $settings['all_custom']); if (empty($settings['ipsum_name'])) { $settings['ipsum_name'] = 'Lorem'; } if (empty($settings['start_with'])) { $settings['start_with'] = 'Lorem ipsum dolor amet'; } return $this->form_template_html($content, $type, $settings); }
private function handle_oembed_request() { $url = WPAnyIpsumCore::get_request('url'); if (!empty($url)) { $html = $this->build_html(apply_filters('anyipsum-generate-filler', apply_filters('anyipsum-parse-request-args', $url))); $oembed = new stdClass(); $oembed->type = 'rich'; $oembed->html = $html; $oembed->provider_name = 'Bacon Ipsum'; $oembed->version = '1.0'; $oembed->provider_url = 'http://baconipsum.com'; wp_send_json($oembed); } }
function handle_api_request() { header('Access-Control-Allow-Origin: *'); $type = WPAnyIpsumCore::get_request('type'); $callback = WPAnyIpsumCore::get_request('callback'); $format = WPAnyIpsumCore::get_request('format'); // no need to keep going if there's nothing to do if (empty($type) && empty($callback)) { return; } if (!in_array($format, array('json', 'text', 'html'))) { $format = 'json'; } $args = apply_filters('anyipsum-parse-request-args', $_SERVER['REQUEST_METHOD'] === 'POST' ? $_REQUEST : $_SERVER['QUERY_STRING']); $paras = apply_filters('anyipsum-generate-filler', $args); $content_type = ''; $output = ''; if (!empty($args['callback'])) { $output_prefix = $args['callback'] . '('; $output_suffix = ');'; } else { $output_prefix = ''; $output_suffix = ''; } switch ($format) { case 'html': $content_type = 'text/html'; foreach ($paras as $para) { $output .= wpautop($para); } break; case 'text': $content_type = 'text/plain'; $output = implode("\n\n", $paras); break; default: // JSON $content_type = 'application/json'; $output = json_encode($paras); break; } if (!empty($args['callback'])) { $content_type = 'application/javascript'; } header('Content-Type: ' . $content_type . '; charset=' . get_bloginfo('charset')); header('Content-Length: ' . strlen($output_prefix . $output . $output_suffix)); echo $output_prefix . $output . $output_suffix; exit; }