Skip to content

Instantly share code, notes, and snippets.

View carl-alberto's full-sized avatar

Carl Alberto carl-alberto

View GitHub Profile
@carl-alberto
carl-alberto / functions.php
Last active June 18, 2019 19:47
Filter that fixes the missing file that is stored in the cachekey when deployed in an environment with multiple appservers. Can be in a custom mu-plugin, theme's functions.php or a custom plugin
/**
* Overrides the default wc_get_template_part cachekey to add the $_SERVER['SERVER_NAME'] as an additional unique identifier.
*
* @param string $template Template path.
* @param mixed $slug Template slug.
* @param string $name Template name (default: '').
* @return mixed $template Modified template path from new $cachekey.
*/
function wc_get_template_part_override( $template, $slug, $name ) {
if ( isset( $_SERVER['SERVER_NAME'] ) ) {
@carl-alberto
carl-alberto / plugin-filter.php
Last active May 10, 2021 05:36 — forked from carlodaniele/plugin-filter.php
A Must-use plugin to filter active plugins in on a per-page basis. selectively load plugin per page
<?php
/**
* @package active-plugins
* @version 1.0
*
* Plugin Name: Active Plugins
* Plugin URI: http://wordpress.org/extend/plugins/#
* Description: This is a development plugin
* Author: Carlo Daniele
* Version: 1.0
@carl-alberto
carl-alberto / wp-config.php
Last active April 24, 2019 22:17
Disable debug in different environments
// Best if put before this line
/* That's all, stop editing! Happy Pressing. */
if (!defined('WP_DEBUG') && isset($_ENV['PANTHEON_ENVIRONMENT'])) {
if(in_array( $_ENV['PANTHEON_ENVIRONMENT'], array('test', 'live'))) {
define('WP_DEBUG', false);
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define( 'WP_DEBUG_LOG', false );
@carl-alberto
carl-alberto / usermeta.md
Last active April 24, 2019 09:32
Modifying the user_meta table to set access in the DB manually

Modifying the user_meta table to set access in the DB manually

**Admin

wp_user_level 10**

wp_capabilities

a:1:{s:13:"administrator";b:1;}
@carl-alberto
carl-alberto / database_environment
Created April 20, 2019 20:25
Sample script that returns DB environment variables in Pantheon so 3rd party applications can check the changes and update accordingly. Disclaimer: This is just a sample script and you should put additional security in it like input/output validation and file access checks, etc... Usage: Upload this file in the root site and access by http://dev…
<?php
/**
* Sample script that returns DB environment variables in Pantheon so 3rd party
* applications can check the changes and update accordingly.
* Disclaimer: This is just a sample script and you should put additional security in it like input/output validation and file access checks, etc...
*
* Usage: Upload this file in the root site and access by http://dev-example.pantheonsite.io/dbenv.php?fetch=DB_PORT
* Will return to you the latest DB port number of that environment
*/
//
@carl-alberto
carl-alberto / .gitignore
Last active March 21, 2019 17:46
WordPress .gitignore file in a Nested docroot setup in Pantheon
# WordPress #
############
web/wp-config-local.php
web/wp-cli.local.yml
web/wp-content/uploads
web/wp-content/blogs.dir/
web/wp-content/upgrade/
web/wp-content/updraft/
web/wp-content/backupwordpress-*/
web/wp-content/backup-db/
@carl-alberto
carl-alberto / functions.php
Created February 5, 2019 15:39
Hide admin menu items in WP by user id
function menu_initial() {
if ( 894 !== get_current_user_id() ) {
$menu_slug = 'plugins.php';
remove_menu_page( 'admin.php?page=wp_stream' );
remove_menu_page( 'edit.php?post_type=wp_stream_alerts' );
remove_menu_page( 'admin.php?page=wp_stream_settings' );
remove_menu_page( 'admin.php?page=sib_page_home' );
remove_menu_page( 'wp_stream' );
remove_menu_page( 'sib_page_home' );
@carl-alberto
carl-alberto / wp-config.php
Created January 22, 2019 14:17
Debug function for outputting data on certain users
<?php
define('WP_APP_DEBUG', true );
define('WP_APP_DEBUG_UID', 58 );
/**
* Debug function
*
* @return true if debug parameters is enabled
*/
@carl-alberto
carl-alberto / adduser.php
Last active December 22, 2019 23:05
Temporary add an admin to your wp site
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your Wordpress root directory and run it from your browser. eg example.com/adduser.php
// Delete it when you're done.
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
// ----------------------------------------------------
// CONFIG VARIABLES
// Make sure that you set these before running the file.
$newusername = 'admin';
@carl-alberto
carl-alberto / wp-config.php
Last active January 9, 2019 10:32
Create mass 301 redirects with PHP in Nginx server without using a WP plugin. This will easily help you out in setting up multiple 301 redirects from the /old1 url to /new1
// You can easily put a list of many 301 url redirects in this format
// Trailing slashes matters here so /old-url1 is different from /old-url1/
$redirect_targets = array(
'/old-url1' => '/new-url1',
'/old-url2' => '/new-url2',
'/old-url3' => '/new-url3',
);
if ( (isset($redirect_targets[ $_SERVER['REQUEST_URI'] ] ) ) && (php_sapi_name() != "cli") ) {
echo 'https://'. $_SERVER['HTTP_HOST'] . $redirect_targets[ $_SERVER['REQUEST_URI'] ];