Skip to content

Instantly share code, notes, and snippets.

@janzikmund
janzikmund / disable-XMLRPC-in-WordPress-using-htaccess
Created July 25, 2022 06:52
Disable XMLRPC in WordPress using .htaccess
# Disable XMLRPC
<Files xmlrpc.php>
Order Allow,Deny
Deny from all
</Files>
@janzikmund
janzikmund / Postman-pre-request-script-csrf-token-laravel-sanctum.js
Last active March 20, 2024 00:37
Postman Pre-Request script to append CSRF token in header for POST requests in Laravel Sanctum authenticated SPA. Requires active environment with {{url}} variable defined for main app domain.
/**
* Postman Pre-Request script to append CSRF token in header for POST requests in Laravel
* Sanctum authenticated SPA. Requires active environment with {{url}} variable defined
* for main app domain.
*
* Postman Interceptor allows appending cookies from browser, but Laravel CSRF middleware
* only validates CSRF in headers or in _token form field, not in cookies. Axios automatically
* appends the CSRF from cookie to headers, but Postman cannot access intercepted cookies
* and use them, so we have to do one pre-request to get the CSRF token, store it
* in environment so it can be reused, and then append it to headers.
@janzikmund
janzikmund / CustomModel.php
Created January 6, 2020 19:29
Laravel eloquent model method to enable save with composite primary key
/**
* Set the composite keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$query
->where('user_id', '=', $this->getAttribute('user_id'))
@janzikmund
janzikmund / SaveQuietly.php
Created December 11, 2019 03:35
Laravel eloquent trait to add method for save model without triggering observers
<?php
namespace App\Traits;
/**
* Allows saving models without triggering observers
*/
trait SaveQuietly
{
/**
* Save model without triggering observers on model
@janzikmund
janzikmund / wp-version-enqueued-assets-styles-scripts-by-theme-plugin-version.php
Last active September 21, 2019 07:12
WordPress version enqueued styles and scripts
// theme
add_action( 'wp_enqueue_scripts', function() {
if ( ! is_admin() ) {
$version = wp_get_theme()->get( 'Version' );
wp_enqueue_style( 'child-theme', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', [], $version, 'all' );
}
});
// plugin
add_action( 'wp_enqueue_scripts', function() {
@janzikmund
janzikmund / simple-wordpress-logging-function.php
Created July 1, 2019 05:03
Simple WordPress logging function
/**
* Logs output into wp-content/logs/asana-api-debug.log
*/
protected function log($message)
{
$line = '[' . date('Y-m-d H:i:s') . '] ' . $message . "\n";
file_put_contents($this->logFile, $line, FILE_APPEND);
}
/**
<?php
ini_set('error_reporting', E_ERROR);
register_shutdown_function("fatal_handler");
function fatal_handler() {
$error = error_get_last();
echo("<pre>");
print_r($error);
}
@janzikmund
janzikmund / .htaccess
Last active April 26, 2021 07:38
redirect-non-www-http-to-www-https.htaccess
# Redirect from non-www or http to https www
<IfModule mod_rewrite.c>
RewriteEngine On
# exclude acme challenge urls from rewriting to not mess Let's Encrypt
RewriteRule ^\.well-known\/acme-challenge\/ - [L]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.jandhqualitykitchens.com.au/$1 [R=301,L]
@janzikmund
janzikmund / Magento_gitignore_version_only_skin_and_theme.gitignore
Created November 15, 2018 09:56
Magento .gitignore ignoring everything except theme and skin
# Ignore everything
# Only keep child theme and skin
# has to be written in this stupid way for git to handle ignores in subdirectories correctly
# ignore all
/*
#keep gitignore
!/.gitignore
@janzikmund
janzikmund / ie11.scss
Created October 26, 2018 21:02
ie11.scss
/**
* IE 10, 11 fixes
*/
// general fixes
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
}
// bound with media queries