Skip to content

Instantly share code, notes, and snippets.

View alanef's full-sized avatar

Alan Fuller alanef

View GitHub Profile
//Archive Ad Widget Area
genesis_register_sidebar( array(
'id' => 'archive-ad-widget',
'name' => 'Archive Ad Widget',
'description' => 'This is for the Archive Ad Widget Area'
) );
add_action( 'genesis_after_header', 'sk_archive_ad', 22 );
function sk_archive_ad() {
if ( is_category() ) {
@alanef
alanef / remove-img.php
Created April 16, 2018 19:59
Remove unused images
<?php
/* create this code in a file in the main wordpress directory e.g. delmedia.php
and access it via mydomain.com/delmedia.php
obviously this can do serious damage
set to delete 100 a time to avoid time outs and menatto be run perioidically by cron
otherise run directly by php command line and don't worry about limits
*/
@alanef
alanef / api.php
Last active May 2, 2018 12:17
Example API call snippets using tokens and transients
private function api_call( $url ) {
// a transient is used to store the token, this token in this API expires in 60 minute
if ( false === ( $this->api_token = get_transient( 'my_api_token' ) ) ) {
$response = $this->api_get_token( $url );
$response_code = wp_remote_retrieve_response_code( $response );
} else {
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . $this->api_token,
),
@alanef
alanef / disallowuserapi.php
Last active May 19, 2018 16:57
Disalow user resi api all users
add_action( 'rest_authentication_errors', 'disallow_user_rest_access_to_users' );
function disallow_user_rest_access_to_users( $access ) {
if ( ( isset( $_REQUEST['rest_route'] ) && ( preg_match( '/users/', $_REQUEST['rest_route'] ) !== 0 ) ) {
return new WP_Error( 'rest_cannot_access', esc_html__( 'No Access to User endpoint REST API.', 'mytext' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@alanef
alanef / my-custom-code.php
Last active August 21, 2018 07:47
shortcode to display hrml
<?php
/*
Plugin Name: My Custom Code
Plugin URI: https://fullworks.net/
Description: Custom code plugin
Version: 1.0
Author: Alan
Author URI: https://fullworks.net/
License: GPL2
*
@alanef
alanef / alternative.php
Last active March 24, 2019 13:23
snippet for functions.php or plugin to restrict user access
function restrict_access_if_logged_out(){
if (!is_user_logged_in() ){
$redirect = home_url() . '/wp-login.php?redirect_to=' . get_site_url;
wp_redirect( $redirect );
exit;
} else {
if (!current_user_can('manage_options') && !is_admin()) {
show_admin_bar(false);
}
}
@alanef
alanef / redirect-all
Created October 7, 2018 22:19
Redirect All Pages
<?php
/**
* Plugin Name: Redirect Everything to Home
* Plugin URI: http://fullworks.net/wordpress-plugins/redirect-404-error-page-to-homepage-or-custom-page/
* Description: Redirect Everything to Home
* Version: 1
* Author: Fullworks
* Author URI: http://fullworks.net/
* License: GPL-3.0+
@alanef
alanef / script.js
Last active October 16, 2018 21:27
Function to auth freemius and call API
function getSites() {
var date = Utilities.formatDate(new Date(), "GMT", "EEE, dd MMM yyyy HH:mm:ss Z");
var secret = 'sk_*****';
var public_key = 'pk_******';
var developer_id = '12**';
var plugin_id = '13**';
var resource_url = '/v1/developers/' + developer_id + '/plugins/' + plugin_id + '/installs.json';
@alanef
alanef / custom-header-footer.php
Last active October 17, 2018 13:55
Add code to header or footer of WordPress
@alanef
alanef / network.sh
Last active November 27, 2018 21:04
Network change
# multisite search replace
wp config set DOMAIN_CURRENT_SITE "multisite.blahnew.net"
wp search-replace "multisite.blah" "multisite.blahnew.net" --url=multisite.blah --precise
wp search-replace --network "https://multisite.blah.uk" "https://multisite.blahnew.net" --precise --all-tables
wp search-replace --network "http://multisite.blah.uk" "https://multisite.blahnew.net" --precise --all-tables
# single site
wp search-replace --all-tables --precise "http://old" "https://new"
wp search-replace --all-tables --precise "http://old" "https://new"