param.'=1', 'top' ); global $wp_rewrite; $wp_rewrite->flush_rules(true); \add_filter('query_vars', [$this, 'add_query_var']); \add_action('parse_request', [$this, 'parse_request']); return $this; } public function add_query_var(array $vars) : array { array_push($vars, $this->param); return $vars; } public function parse_request($request) : void { if (!array_key_exists($this->param, $request->query_vars)) { return; } if (!\current_user_can('export')) { echo('You must login as user that could export content.'); exit(); } $mapper = new customers_mapper( $this->get_database(), $this->get_tables() ); $converter = new customers_converter(); $all = []; foreach ($mapper->load_all() as $customer) { $customer = $converter->load_object($customer)->get_array(); unset($customer['id']); array_push($all, $customer); } echo(json_encode($all)); header("Content-Type: application/json"); exit(); } private string $param = 'cx_newsletter_must_export_customers_now'; }