Skip to content

Instantly share code, notes, and snippets.

@cheesman225
cheesman225 / Search and Filter Pro overwrite tables
Created May 9, 2019 23:28
SQL code for creating the tables needed by Search and Filter Pro since they can't be created on Pantheon and having the plugin create them on localhost does so in the wrong encoding.
--
-- Table structure for table `wp_search_filter_cache`
--
DROP TABLE IF EXISTS `wp_search_filter_cache`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `wp_search_filter_cache` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`post_id` bigint(20) NOT NULL,
@cheesman225
cheesman225 / Hide Acf admin area on pantheon
Created July 24, 2018 00:07
Hide Acf admin area on pantheon to stop improper editing.
<?php
function hide_acf_admin_on_pantheon() {
if (class_exists('acf')) { // If acf is installed
if(isset($_ENV['PANTHEON_ENVIRONMENT'])) { // If on pantheon
// hide the acf menu item
return false;
} else { // else on local host
// show the acf menu item
return true;
}
@cheesman225
cheesman225 / Get related posts by taxonomy
Created July 18, 2018 20:41
Get related posts by matching taxonomy or show most recent posts
/** Phone number stripper */
function strip_phone($number) {
$replace = array('.', '-', '(', ')', ' ');
$numberClean = str_replace($replace, '', $number);
return $numberClean;
}
// expected function get_the_excerpt($post_id) is deprecated
function get_post_excerpt_by_id($id) {
global $post;
$post = get_post($id);
setup_postdata($post);
$the_excerpt = get_the_excerpt();
wp_reset_postdata();
return $the_excerpt;
}
/**
* Overwrite for allowing plugin updates on localhost
*/
if ( is_admin() ) {
add_filter( 'filesystem_method', create_function( '$a', 'return "direct";' ) );
if ( ! defined( 'FS_CHMOD_DIR' ) ) {
define( 'FS_CHMOD_DIR', 0751 );
}
}
@cheesman225
cheesman225 / Add Check for Pantheon test or live environment
Created July 18, 2018 19:59
Function for only running code on test and live environments
// In wp-config
if ( in_array( $_ENV['PANTHEON_ENVIRONMENT'], array( 'test', 'live' ) ) ) {
define('IS_IT_LIVE', true);
}
else {
define( 'IS_IT_LIVE', false );
}
// Basic Example
@if(defined('IS_IT_LIVE'))
@cheesman225
cheesman225 / Wp-config HTTPS REDIRECT
Created July 18, 2018 19:48
Forces site to use https instead of http
/* HTTPS REDIRECT*/
if (isset($_SERVER['PANTHEON_ENVIRONMENT']) && ($_SERVER['HTTPS'] === 'OFF') && (php_sapi_name() != "cli")) {
if (!isset($_SERVER['HTTP_USER_AGENT_HTTPS']) || (isset($_SERVER['HTTP_USER_AGENT_HTTPS']) && $_SERVER['HTTP_USER_AGENT_HTTPS'] != 'ON')) {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
# Name transaction "redirect" in New Relic for improved reporting (optional)
if (extension_loaded('newrelic')) {