Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Peter Elmered pelmered

🎯
Focusing
View GitHub Profile
View assignmentHelper.php
<?php
function incrementDeep(&$array, $value) {
$array += $value;
}
$test['foo']['bar']['test'] = 5;
incrementDeep($test['foo']['bar']['test'], 5);
incrementDeep($test['foo']['bar']['test2'], 5);
@pelmered
pelmered / BaseEnum.php
Last active June 16, 2020 12:22
Enum classes
View BaseEnum.php
<?php
namespace App\Enums;
use App\Rules\IsValidEnum;
use Illuminate\Support\Str;
abstract class BaseEnum
{
protected $name;
protected $values = array();
View pre-commit.sh
#!/bin/sh
echo "committing as $(git config user.name) ($(git config user.email))",
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
#STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep "app/.*\.php"`
PROJECT_PATH=`php -r "echo dirname(dirname(realpath('$0')));"`
VENDOR_BIN_DIR="${PROJECT_PATH}/vendor/bin/";
@pelmered
pelmered / wp-config.php
Created November 13, 2018 14:47
WordPress debug
View wp-config.php
<?php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@pelmered
pelmered / wp-config.php
Created February 27, 2017 20:56
Fix issues with symlinked wordpress
View wp-config.php
<?php
/**
* Fixes issues with symlinked wordpress
*/
if ( defined('ABSPATH') ) {
$fixed_abspath = str_replace( 'wordpress', 'public', ABSPATH );
define('WP_CONTENT_DIR', $fixed_abspath . 'wp-content');
define('WP_PLUGIN_DIR', $fixed_abspath . 'wp-content/plugins');
}
@pelmered
pelmered / letter-post-list.php
Last active February 22, 2017 19:24
Letter post list
View letter-post-list.php
<?php
$posts = get_posts([
'post_status' => 'publish',
'posts_per_page' => -1,
'post_type' => 'post'
]);
$post_index = array_fill_keys( array_merge( [ '#' ], range( 'a', 'z' ), ['å', 'ä', 'ö', ] ), [] );
foreach( $posts as $post ) {
$first_letter = strtolower( substr( $post->post_title, 0, 1 ) );
@pelmered
pelmered / hide-when-free-avaialble.php
Last active September 4, 2017 14:52
Hide other shipping methods except local delivery when “Free Shipping” is available
View hide-when-free-avaialble.php
/**
* Hide shipping rates except local delivery when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
$local_pickup = array();
@pelmered
pelmered / convert-to-composer.php
Last active March 20, 2018 14:03
Convert WP to Composer
View convert-to-composer.php
#!/usr/bin/php
<?php
/**
* USAGE:
*
* (optional) Download script:
* "wget https://gist.githubusercontent.com/pelmered/2ee27f1cb18b8c73a0205ded580e3195/raw/convert-to-composer.php"
*
* Basic usage:
* php convert-to-composer.php
@pelmered
pelmered / taxonomies.php
Last active January 4, 2016 16:49
Create taxonomy with rewrite with Post types creator https://github.com/pelmered/post-types-creator
View taxonomies.php
<?php
if( class_exists( 'PE_Post_Type_Creator' ) )
{
$ptc = new PE_Post_Type_Creator();
$text_domain = 'text-domain';
$ptc->set_taxonomies(array(
'min-taxonomi' => array(
'singular_label' => _x('Min taxonomi', 'Post type plural', $text_domain),
@pelmered
pelmered / composer.json
Created October 9, 2015 17:14
Example composer.json for WordPress
View composer.json
{
"repositories": [
{
"type": "composer",
"url": "http://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",