Skip to content

Instantly share code, notes, and snippets.

View paulgoodchild's full-sized avatar

Paul Goodchild paulgoodchild

View GitHub Profile
@paulgoodchild
paulgoodchild / functions.php
Created December 12, 2020 11:37
Automatically add WordPress site to your iControlWP control panel from ManageWP (or other)
<?php
/**
* You may automatically add any WordPress site to your iControlWP account by using the "code run"
* or "code snippets" feature in ManageWP.
*
* Please follow these steps:
*
* 1) Install and activate the iControlWP plugin on your WordPress site.
* 2) Grab your "AUTHENTICATION_KEY" from your iControlWP account:
* - https://app.icontrolwp.com/profile/preferences
@paulgoodchild
paulgoodchild / functions.php
Created December 7, 2020 12:06
WordPress: How to set that a request may use Application Password
<?php
/**
* WordPress (5.6+) allows the use of Application Passwords when authenticating logins.
* However, only certain requests are considered to be requests from an "Application". Officially, these are
* XML-RPC and REST API requests.
*
* However, you may customize this to ensure that authenticated requests from your service
* (if they don't use XML-PRC/RESTAPI) are put through the appropriate authentication process.
*
* To achieve this, you make use of the filter: application_password_is_api_request
@paulgoodchild
paulgoodchild / functions.php
Created November 3, 2020 14:14
Customise the contents and styles of Shield Security Plugin Badge
<?php
/**
* The plugin badge array has 5 attributes represented by the following keys:
* name, url, logo, protected_by, custom_css
*
* This filter is only available is the plugin is activated for ShieldPRO.
*
* You may also use your Whitelabel settings to overwrite many of the defaults:
* See: https://icontrolwp.freshdesk.com/support/solutions/articles/3000078466
@paulgoodchild
paulgoodchild / functions.php
Created September 23, 2020 11:26
Customise the hook/location where Shield's Antibot feature will output any content
<?php
/**
* Use this filter to change the precise location where Shield's Antibot features will be
* output within the Woocommerce checkout form.
*/
add_filter( 'icwp-wpsf-woocommerce_checkout_hook_location', function ( $hook ) {
/**
* This is the default hook location used by Shield.
@paulgoodchild
paulgoodchild / functions.php
Last active July 31, 2020 10:26
Check Is The Current Visitor IP WhiteListed?
<?php
/**
* Both of these functions return a boolean (true|false) on whether the current visitor
* IP address is whitelisted.
*
* Be sure to use the most appropriate, depending on your Shield version.
*/
if ( class_exists( '\FernleafSystems\Wordpress\Plugin\Shield\Controller\Controller' ) ) {
@paulgoodchild
paulgoodchild / functions.php
Created April 21, 2020 09:37
Find your outgoing server IP addresses.
<?php
/**
* Add this to your functions.php and then call your site URL with "get_my_server_ip" in your query.
* e.g. https://www.example.com/?get_my_server_ip=1
*/
if ( isset( $_GET[ 'get_my_server_ip' ] ) ) {
add_action( 'init', function () {
echo 'Server IPs:<br/>'.implode( '<br/>', array_unique( [
wp_remote_get( 'https://api.ipify.org' )[ 'body' ],
<?php
/**
* You can whitelist certain directories from the Shield malware scanner using
* the following WordPress filter.
*
* All paths you provide must be relative to your ABSPATH
* (i.e. from the directory where your wp-settings.php file resides)
*
* You must always return the $paths variable at the end.
@paulgoodchild
paulgoodchild / functions.php
Created February 17, 2020 11:32
Show Shield Dashboard Widget to admins only
<?php
add_action( 'admin_init', function () {
if ( function_exists( 'shield_security_get_plugin' ) ) {
$oShield = shield_security_get_plugin();
if ( !empty( $oShield ) ) {
add_filter(
$oShield->getController()->prefix( 'show_dashboard_widget' ),
function ( $bShow ) {
// restrict display to administrators only (i.e. they have capability to "manage_options")
@paulgoodchild
paulgoodchild / restrict_subscribers.php
Created September 18, 2019 09:45
Restrict WP Admin Dashboard Access From Subscribers
<?php
add_action( 'init', function () {
if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) && !current_user_can( 'edit_posts' ) ) {
wp_safe_redirect( home_url() );
}
} );
@paulgoodchild
paulgoodchild / functions.php
Created August 29, 2019 08:42
Shield Security - force English display in international sites
<?php
/**
* You can force Shield to display in any language (assuming the translation exists)
* regardless of which language your site is currently configured to operate in.
*
* In this example, we are forcing English. Adjust line #10 to change preferred locale.
*/
add_filter( 'shield_force_locale', function () {
return 'en_US';