Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
forsvunnet / bring-filter-no-mailbox-shipping-class.php
Created January 26, 2024 11:03
Add a filter for bring shipping rates to exclude mail box services if a shipping class is present in the cart
<?php
/**
* Filter the bring shipping rates.
*/
add_filter('bring_shipping_rates', function( $rates ) {
$shipping_classes = [
'no-mailbox',
];
@forsvunnet
forsvunnet / Color.php
Created September 15, 2022 13:53
Terminal colour class for php
<?php
namespace App\Terminal;
class Color
{
private string $reset = "\033[0m";
private string $color = "\033[0;36m"; // Cyan
public function __construct(private readonly string $text)
@forsvunnet
forsvunnet / php-colors.php
Created June 14, 2022 10:46
Terminal colors for php
<?php
return [
'black' => "\033[0;30m",
'dark_gray' => "\033[1;30m",
'blue' => "\033[0;34m",
'light_blue' => "\033[1;34m",
'green' => "\033[0;32m",
'light_green' => "\033[1;32m",
'cyan' => "\033[0;36m",
'light_cyan' => "\033[1;36m",
@forsvunnet
forsvunnet / ComposerModuleAutoLoader.php
Last active February 3, 2022 07:36
Module loader script for composer
<?php
namespace App\Support;
class ComposerModuleAutoLoader
{
public static function load($event)
{
$package = $event->getComposer()->getPackage();
$base_path = dirname(__DIR__, 2).'/';
@forsvunnet
forsvunnet / rename_file_with_snake_case.php
Created January 26, 2022 09:54
Function to rename a file using snake case
<?php
function rename_file_with_snake_case(string $filename): string {
$basename = basename($filename);
$dir = dirname($filename);
$newName = strtolower($basename);
$newName = preg_replace('/[^\w\.]/', ' ', $newName);
$newName = preg_replace('/\s+/', ' ', $newName);
$newName = preg_replace('/\s/', '_', $newName);
$newName = preg_replace('/_\./', '.', $newName);
@forsvunnet
forsvunnet / headless-statamic.sh
Last active October 19, 2023 14:31
Script to install a headless version of statamic ready with graphQL
#!/bin/bash
COMPOSER=/usr/local/bin/composer
STATAMIC=~/.composer/vendor/bin/statamic
if [ ! -f "$COMPOSER" ]; then
echo "Composer CLI not found"
exit 1
fi
@forsvunnet
forsvunnet / AWordPressValetDriver.php
Last active August 28, 2023 11:50
A WordPress valet driver
<?php
class AWordPressValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
@forsvunnet
forsvunnet / wpadmin.php
Last active August 10, 2021 14:19
WPADMIN - Inject super admin user account to the wordpress installation in the current folder
#!/usr/bin/env php
<?php
error_reporting(-1);
ini_set( 'display_errors', 1 );
$files = [
"wp/wp-load.php",
"public/wp/wp-load.php",
];
@forsvunnet
forsvunnet / bring-weight-filter.php
Last active May 28, 2022 13:15
Bring weight filter
<?php
/**
* Filter the bring shipping rates.
* Sets the price of the chosen services based on weight
*/
add_filter( 'bring_shipping_rates', function( $rates ) {
// Configure services and prices.
$services = [ 'SERVICEPAKKE', '5800' ];
$prices = [
@forsvunnet
forsvunnet / quill.js
Last active February 19, 2021 22:51
Quill example
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
[{ header: [1, 2, 3, false] }],
[{ 'header': 1 }, { 'header': 2 }, 'bold', 'italic', 'underline'],
['image', 'code-block']
],
clipboard: {
matchVisual: false
}