WPCode Logo

WPCode Documentation

Documentation, Reference Materials, and Tutorials for WPCode

Most Popular

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

Using Remote-Only Mode

Would you like to make sure the code snippets on your site can only change through deploys that you approve with a passkey?

In this guide, we’ll show you how to turn on remote-only mode in WPCode and deploy snippet changes to your site from the WPCode Library.

Requirements: Remote-only mode is available in the paid versions of WPCode, version 2.4.1 or later. Your site must be connected to the WPCode Library with deploys approved by a passkey.

Before you get started, make sure WPCode is installed and activated on your WordPress site.

How Remote-Only Mode Works

Code snippets can run any code on your site. Normally, anyone who signs in as an administrator can change them. Remote-only mode removes that option. Every snippet on your site becomes read-only in the WordPress admin, for every user.

Your snippets keep running as usual. To change them, you deploy from your WPCode Library account. Each deploy has to be approved with a passkey on your device. Someone who gets into your WordPress admin still can’t change your snippets.

The mode is switched on in {WPCONFIG} rather than in the WPCode settings. That way, nobody can turn it off from the admin.

Preparing Your Library Connection

To get started, we’ll get your site’s library connection ready for remote-only mode.

Remote-only mode only accepts deploys approved with a passkey. Before you turn it on, set up your connection:

  1. Add a passkey to your WPCode Library account.
  2. Connect your site to the WPCode Library, with deploys enabled, while you’re signed in to that account.

Our guide on enabling deploys from the library walks through both steps. If your site was connected before you added a passkey, reconnect it so the passkey can approve deploys there.

Note: Set up the connection first. Once remote-only mode is on, WPCode won’t let anyone reconnect or disconnect the site from the library in the admin.

Turning On Remote-Only Mode

Remote-only mode is set in your site’s wp-config.php file. If you haven’t edited this file before, see How to Edit wp-config.php File in WordPress.

To turn it on, add this line above the line that says /* That's all, stop editing! */:

define( 'WPCODE_REMOTE_ONLY', true );

Once you’ve added the line, save the file. To check that the mode is on, go to Code Snippets » Code Snippets in your WordPress admin sidebar. A notice at the top says your snippets are managed remotely from the WPCode Library.

 

The Code Snippets list opened from the Code Snippets menu in the WordPress admin sidebar, with a notice saying snippets on this site are managed remotely from the WPCode Library and are read-only here

You can still open any snippet to see its code and settings. Saving changes isn’t possible, though. The Update button stays disabled. The same notice appears at the top of the editor.

The Edit Snippet screen for Candle Care Notice with the remote-only notice at the top and the Update button disabled

Adding, activating, deactivating, and deleting snippets are all refused in the admin too. The Testing Mode toggle is hidden because Testing Mode changes snippet code locally.

Deploying Snippet Changes from the Library

To change a snippet, edit it in your WPCode Library account and deploy it to your site.

First, sign in to the WPCode Library and go to My Snippets. Next, click the title of the snippet you want to deploy.

The My Snippets list in the WPCode Library, with an arrow pointing at the Free Shipping Notice snippet title

The snippet opens in the library editor. At the top of the editor, click Deploy.

The top of the WPCode Library snippet editor, with an arrow pointing at the Deploy button next to Update

In the Deploy snippet to your site window, check the box next to your site. Your site shows as Passkey protected. When you’re ready, click Review & deploy.

The Deploy snippet to your site window with the Alex's Candle Co. site ticked and marked Passkey protected, and an arrow pointing at the Review and deploy button

The review step shows the snippet and each site you picked. The Active switch beside each site decides whether the snippet runs there after the deploy. It’s on by default:

  • On deploys the code and activates the snippet.
  • Off deploys the code and leaves the snippet inactive.

Turn the switch off when you want the new code on your site without running it yet. If you’re not sure, leave it on.

When you’ve checked the details, click Authorize with your passkey. Your browser or device then asks you to confirm with your passkey.

The review step of the deploy window for Free Shipping Notice, with the Active switch on for Alex's Candle Co. and an arrow pointing at the Authorize with your passkey button

Note: The approval expires after two minutes. If it runs out before you confirm, nothing is deployed. The window then lets you try again with a new approval.

Once your site has accepted the code, the window shows Deployed beside it and confirms how many sites were updated.

The deploy window showing Deployed beside Alex's Candle Co. and a confirmation that the snippet was deployed to 1 site

On your site, the snippet appears in your Code Snippets list with the status you chose.

The Code Snippets list under the remote-only notice, showing the deployed Free Shipping Notice snippet with its status toggle switched on

When a Deployed Snippet Can’t Be Activated

Before activating a deployed PHP or Universal snippet, your site runs its code once to check it. If that check fails, the code is still saved on your site. The snippet stays inactive so the error can’t affect your visitors.

The deploy window shows Deployed, not activated beside that site, along with the reason.

The deploy window for Gift Wrap Fee showing Deployed, not activated beside Alex's Candle Co., with a message saying the snippet could not be activated because running its code caused an error

To activate it, fix the snippet in your library and deploy it again with the Active switch on. Once its code runs without an error, your site activates the snippet.

Turning Off Remote-Only Mode

To manage snippets in the admin again, remove the WPCODE_REMOTE_ONLY line from {WPCONFIG}. The change takes effect on the next page load. Your snippets stay as they are.

You’ll also need to remove the line before you reconnect or disconnect your site from the WPCode Library. You can add it back afterward.

That’s it! You now know how to lock your site’s snippets so they only change through passkey-approved deploys. Next, take a look at our guide on enabling deploys from the library to add more passkeys or connect more sites.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about remote-only mode.

What if my site was connected before I added a passkey?

Deploys to that site are refused while remote-only mode is on. Older connections don’t use a passkey to approve deploys. The notice on your Code Snippets list asks you to reconnect.

To fix this, remove the WPCODE_REMOTE_ONLY line. Next, reconnect the site with deploys enabled while you’re signed in to your library account. Then add the line back.

Can I still see my snippets and settings in the admin?

Yes. Every WPCode page stays open, and every snippet keeps showing in your Code Snippets list. You can review any snippet’s code and settings. Saving changes to snippets is what’s blocked.

What if I also manage snippets from files?

Files mode takes priority. If both WPCODE_REMOTE_ONLY and WPCODE_SNIPPETS_FROM_FILES are set, your snippets are managed from files. A notice in your Code Snippets list says remote-only mode is off.

See our guide on managing snippets from files for details.

Still stuck? How can we help?

Last Updated on

Get Started Today & Add Your Own Snippets

Future-proof your website with WPCode Snippets and improve the way you manage code across all your websites.