Skip to content

Instantly share code, notes, and snippets.

// for windows
vendor\bin\phpunit tests/ExampleTest.php
// for Mac
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
function removeBomUtf8($s){
if(substr($s,0,3)==chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'))){
return substr($s,3);
}else{
return $s;
}
}
@redsoxfan2499
redsoxfan2499 / wordpress-snippets.js
Created November 18, 2019 02:07
wordpress snippets
WP FILTERS/HOOK/ACTIONS
// WP Filters
function hwy_change_my_array( $value ) {
$value['fourth'] = 4;
return $value;
}
add_filter( 'hwy_my_array', 'hwy_change_my_array' );
function hwy_change_my_array_again( $value ) {
$value['second'] = 222;
@redsoxfan2499
redsoxfan2499 / custom-hook-in-shortcode.php
Created November 18, 2019 02:04
WordPress Shortcode with Custom Action Hook
function example_shortcode( $atts ) {
$shortcode_output = "<p>Some shortcode content.</p>";
$shortcode_output .= "<p>More shortcode content.</p>";
ob_start();
do_action('below_shortcode');
$below_shortcode = ob_get_contents();
ob_end_clean();
@redsoxfan2499
redsoxfan2499 / wp-config.php
Last active November 18, 2019 02:08
wordpress wp-config settings
define( 'DISALLOW_FILE_EDIT', true ); // turn off Editors access for themes and plugin from admin
define( 'WP_AUTO_UPDATE_CORE', minor );
define( 'WP_DEBUG', true ); // turns on debugging for WP. Must be on to write to log file
define( 'WP_DEBUG_DISPLAY', false ); // this turns off debug errors from showing on the front end
define( 'WP_DEBUG_LOG', true ); // turn on writing to WP debug log file
// allow to do updates from admin
define('FS_METHOD', 'direct');
@redsoxfan2499
redsoxfan2499 / any.php
Created November 18, 2019 02:02
PHP Error Reporting
error_reporting(E_ALL);
ini_set("display_errors", 1);
@redsoxfan2499
redsoxfan2499 / themes functions.php file
Created November 18, 2019 02:01
WordPress Get Custom Fields / ACF Fields to be included in custom WP Query
/** Place this in themes functions.php file **/
function my_always_get_post_custom( $posts ) {
for ( $i = 0; $i < count($posts); $i++ ) {
$custom_fields = get_post_custom( $posts[$i]->ID );
$posts[$i]->custom_fields = $custom_fields;
}
return $posts;
}
add_filter( 'the_posts', 'my_always_get_post_custom' );
// Axios Globals
axios.defaults.headers.common["X-Auth-Token"] =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
// GET REQUEST
function getTodos() {
// axios({
// method: "get",
// url: "https://jsonplaceholder.typicode.com/todos",
// params: {
// _limit: 5
@redsoxfan2499
redsoxfan2499 / vue directory filter
Last active October 31, 2018 13:37
Vue JS Filter Directory, built in WP with Timber and Twig
/** template-directory.php file **/
<?php
/**
* Template Name: Directory Template
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
use Classes\Helper;