Skip to content

Add WordPress plugin for LibreCaptcha integration#329

Merged
hrj merged 8 commits intomasterfrom
add-wordpress-plugin-7710305599071125477
Apr 4, 2026
Merged

Add WordPress plugin for LibreCaptcha integration#329
hrj merged 8 commits intomasterfrom
add-wordpress-plugin-7710305599071125477

Conversation

@hrj
Copy link
Copy Markdown
Contributor

@hrj hrj commented Apr 4, 2026

This PR introduces a WordPress plugin to integrate LibreCaptcha into common WordPress forms (Login, Registration, Comments) as well as any custom page via shortcode. It adds an administrative settings page to configure the API integration and handles secure server-to-server answer verification.


PR created automatically by Jules for task 7710305599071125477 started by @hrj

- Create a new WordPress plugin at `plugins/wordpress/librecaptcha.php`.
- Add settings page to configure server URL, configuration JSON, and checkboxes for Login, Registration, and Comments forms.
- Implement shortcode and standard WordPress hooks to inject the CAPTCHA and fetch it dynamically via JavaScript from the LibreCaptcha `/v2/captcha` endpoint.
- Add verification logic utilizing `wp_remote_post` to hit the `/v2/answer` endpoint and hook into standard authentication/submission filters to block invalid entries.
- Add installation instructions to the project README.md.

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@hrj
Copy link
Copy Markdown
Contributor Author

hrj commented Apr 4, 2026

In the settings page for the plugin, add a test button which will fetch a CAPTCHA from the server and show it, along with an input field and a check button. When the check button is clicked, the input will be validated through the API. This will help to quickly check the LC server and plugin setup.

@google-labs-jules
Copy link
Copy Markdown
Contributor

In the settings page for the plugin, add a test button which will fetch a CAPTCHA from the server and show it, along with an input field and a check button. When the check button is clicked, the input will be validated through the API. This will help to quickly check the LC server and plugin setup.

I've added the test button functionality to the settings page as requested. It allows administrators to fetch a test CAPTCHA and validate an answer to confirm their LC server integration is working correctly.

Added a UI section to the LibreCaptcha WordPress plugin settings page that
allows the site administrator to fetch a test CAPTCHA and validate an answer
against the configured LibreCaptcha server. This helps verify the API configuration.

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@hrj
Copy link
Copy Markdown
Contributor Author

hrj commented Apr 4, 2026

The test functionality should make the API calls on the server side not in the client, because the LC server may not be accessible to the client.

Also, add an option in the plugin settings to specify the auth key (optional).

@google-labs-jules
Copy link
Copy Markdown
Contributor

The test functionality should make the API calls on the server side not in the client, because the LC server may not be accessible to the client.

Also, add an option in the plugin settings to specify the auth key (optional).

I've added the optional lc_auth_key setting. Additionally, I've moved the test functionality to the server-side. The settings page now makes an AJAX request to the WordPress backend (wp_ajax_lc_test_load and wp_ajax_lc_test_check), which in turn calls the LibreCaptcha server using the configured server URL and auth key.

- Added an optional `Auth Key` field to the LibreCaptcha plugin settings.
- Modified CAPTCHA validation API requests (`wp_remote_post` to `/v2/answer`) to pass the `Auth` header if configured.
- Refactored the test connection functionality in the settings page to perform all LibreCaptcha API calls server-side (via WP AJAX hooks `lc_test_load` and `lc_test_check`) using the admin's currently configured settings (including auth key).

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@hrj
Copy link
Copy Markdown
Contributor Author

hrj commented Apr 4, 2026

Define OPTIONS method handler on all API endpoints (as and where appropriate). This is because in certain browser emulated environments, the server side code running inside a browser causes an issue of OPTIONS request before the actual API request.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Define OPTIONS method handler on all API endpoints (as and where appropriate). This is because in certain browser emulated environments, the server side code running inside a browser causes an issue of OPTIONS request before the actual API request.

I've added CORS OPTIONS preflight handlers to the /v2/captcha, /v2/media, and /v2/answer API routes to ensure they correctly serve the Access-Control-Allow- headers when accessed from browser environments.

- Added `OPTIONS` method support to the `picoserve` ServerBuilder.
- Modified `lc.server.Server` to attach `OPTIONS` handlers to the `/v2/captcha`, `/v2/media`, and `/v2/answer` endpoints. These handlers return a `200 OK` status with the necessary `Access-Control-Allow-*` headers when `corsHeader` is configured, ensuring LibreCaptcha APIs function correctly in cross-origin browser environments.

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@hrj
Copy link
Copy Markdown
Contributor Author

hrj commented Apr 4, 2026

Just like the test captcha component in settings, ensure that all LC API calls in the plugin are done through backend PHP, not frontend javascript.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Just like the test captcha component in settings, ensure that all LC API calls in the plugin are done through backend PHP, not frontend javascript.

I've refactored the CAPTCHA rendering logic in render_captcha(). It now performs the API call to /v2/captcha using server-side PHP (wp_remote_post), bypassing the need for any frontend Javascript requests. The resulting image and ID are injected directly into the HTML structure.

google-labs-jules bot and others added 2 commits April 4, 2026 17:39
- Refactored `render_captcha()` in the WordPress plugin to eliminate client-side JavaScript `fetch` calls.
- The CAPTCHA generation API request (`/v2/captcha`) is now executed entirely backend via `wp_remote_post`.
- This ensures LibreCaptcha instances that are not publicly exposed to the client's browser (e.g. internal network/localhost bound) can still successfully generate CAPTCHAs, preventing CORS and connectivity issues.

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@hrj
Copy link
Copy Markdown
Contributor Author

hrj commented Apr 4, 2026

You have added an OPTIONS builder to picoserve. This can be used to simplify the handler definitions in Server.scala. Also, there is code repetition in handling of OPTIONS method across endpoints. Try and refactor to a common function.

@google-labs-jules
Copy link
Copy Markdown
Contributor

You have added an OPTIONS builder to picoserve. This can be used to simplify the handler definitions in Server.scala. Also, there is code repetition in handling of OPTIONS method across endpoints. Try and refactor to a common function.

I've refactored Server.scala to use the .OPTIONS builder from picoserve instead of a custom .handle() method. I also abstracted the OPTIONS logic into a common getOptionsResponse function. Finally, I refactored picoserve so it correctly supports multiple handlers on the same path (e.g. one for GET/POST and one for OPTIONS). Tests are passing!

google-labs-jules bot and others added 2 commits April 4, 2026 18:17
…routing

- Refactored `Server.scala` to use the `.OPTIONS()` handler builder method from `picoserve` and deduplicated the `OPTIONS` CORS response logic into a common `getOptionsResponse` helper.
- Fixed `org.limium.picoserve.Server` Java code to group handlers by path so that multiple HTTP methods (e.g. `POST` and `OPTIONS`) can be correctly routed to their respective processors for the same path. Tests now pass.

Co-authored-by: hrj <345879+hrj@users.noreply.github.com>
@hrj hrj merged commit acc78cd into master Apr 4, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant