This is a simple PHP example demonstrating how to implement WordPress.com Connect (OAuth2 authentication) in your application.
- PHP 7.0 or higher
- A local web server (e.g., PHP built-in server, Apache, or Nginx)
- A WordPress.com Developer Application
-
Clone this repository (if you haven't already):
git clone https://github.com/Automattic/wpcom-connect-examples.git cd wpcom-connect-examples/php -
Register a new application at WordPress.com Developer Console:
- Set the Redirect URL to:
http://localhost:8000/connected.php - Note your Client ID and Client Secret.
- Set the Redirect URL to:
-
Configure your credentials:
- Open
config.phpin this folder. - Replace the values for
CLIENT_IDandCLIENT_SECRETwith those from your app's settings. - Adjust
LOGIN_URLandREDIRECT_URLif you use a different port or domain.
- Open
-
Start the PHP built-in server:
php -S localhost:8000
- This will serve the demo at http://localhost:8000
-
Test the demo:
- Open http://localhost:8000/index.php in your browser.
- Click the "Connect using your WordPress.com account" button.
- Authorize the app and you should see a "Connection successful!" message.
- This demo is for educational purposes. In a real application, you should securely store the access token and handle errors appropriately.
- If you change the port or domain, update
LOGIN_URLandREDIRECT_URLinconfig.phpand in your WordPress.com app settings. - For more details, see the official documentation.