'POST', 'callback' => array( $this, 'create_starter_page' ), 'permission_callback' => function () { return current_user_can( 'publish_posts' ); }, ) ); } public function create_starter_page(): void { $post_id = wp_insert_post( array( 'post_title' => esc_html__( 'My first AffiliateX page', 'affiliatex' ), 'post_status' => 'draft', 'post_type' => 'post', 'post_content' => wp_slash( $this->get_starter_content() ), ), true ); if ( is_wp_error( $post_id ) ) { $this->send_json_plain_error( array( 'message' => $post_id->get_error_message() ) ); return; } $this->send_json_plain_success( array( 'post_id' => (int) $post_id, 'edit_url' => admin_url( 'post.php?post=' . (int) $post_id . '&action=edit' ), ) ); } private function get_starter_content(): string { $template = <<<'HTML' HTML; return str_replace( array( '__SP_ID__', '__BTN_ID__' ), array( 'block-' . wp_generate_uuid4(), 'block-' . wp_generate_uuid4() ), $template ); } }