Skip to content

Instantly share code, notes, and snippets.

@idokd
idokd / functions-wcpv-shop-order.php
Created August 29, 2022 15:42
Enable Woocommerce Product Vendors Metabox on Shop Order woocommerce-product-vendors
<?php
// Add Woocommerce Vendors Taxonomy to WC Order and enable Metabox on Shop Order
add_action( 'init', function() {
if ( defined( 'WC_PRODUCT_VENDORS_TAXONOMY' ) ) register_taxonomy_for_object_type( WC_PRODUCT_VENDORS_TAXONOMY, 'shop_order' );
} );
add_action( 'save_post', 'wcpv_product_vendors_save_order_vendor' );
function wcpv_product_vendors_save_order_vendor( $order_id ) {
@idokd
idokd / functions.php
Created August 26, 2022 08:23
WordPress Guteberg for RTL swticher
<?php
// When you like your admin in LTR but you have to edit a gutenberg page that is in hebrew or arabic that is RTL,
// and to avoid switching the user language, just paste this code on your functions.php and on the url of the edit page add
// the query param: dir=rtl and from there on the gutenberg editor area will keep RTL
// if you wish to all content to display in certain direction
define( 'VISUAL_EDITOR_DEFAULT_DIRECTION', 'rtl' );
@idokd
idokd / wp-yii2-user-authentication.php
Last active July 4, 2022 13:58
WordPress Yii2 User Authentication Support
<?php
/*
This will enable user authentication if you migrated the user/pass from yii database to the wordpress db
So you can support both wordpress standard users authentication and your previous yii2 users
*/
add_filter( 'authenticate', function( $user, $username, $password ) {
@idokd
idokd / ddev-gprc-php.sh
Last active April 19, 2022 19:19
Install gRPC for PHP on ddev docker image
ddev ssh
sudo apt-get install build-essential autoconf zlib1g-dev php-dev php-pear
sudo pecl channel-update pecl.php.net
sudo pecl install grpc
# Add this to php.ini
#extension=grpc.so
@idokd
idokd / fa-brands-6.1.1.json
Last active April 7, 2022 12:22
GenerateBlocks Asset Library FontAwsome Icons
{
"type": "icons",
"group": "FontAwesome - Brands",
"assets": [
{
"name": "xing-square",
"icon": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\"><g class=\"nc-icon-wrapper\" fill=\"#000000\"><path d=\"M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zM140.4 320.2H93.8c-5.5 0-8.7-5.3-6-10.3l49.3-86.7c.1 0 .1-.1 0-.2l-31.4-54c-3-5.6.2-10.1 6-10.1h46.6c5.2 0 9.5 2.9 12.9 8.7l31.9 55.3c-1.3 2.3-18 31.7-50.1 88.2-3.5 6.2-7.7 9.1-12.6 9.1zm219.7-214.1L257.3 286.8v.2l65.5 119c2.8 5.1.1 10.1-6 10.1h-46.6c-5.5 0-9.7-2.9-12.9-8.7l-66-120.3c2.3-4.1 36.8-64.9 103.4-182.3 3.3-5.8 7.4-8.7 12.5-8.7h46.9c5.7-.1 8.8 4.7 6 10z\"></path></g></svg>",
"set_id": 1
},
{
@idokd
idokd / TokenResolver.php
Last active March 16, 2022 12:06
CakePHP 4 TokenAuthentication Resolver on Token in associated table
<?php
declare(strict_types=1);
/*
This extends/replaces the OrmResolver in order to fetch the token from an associated table,
when you have Users table and Tokens table, where you may have many tokens to same user.
```
$service->loadIdentifier( 'Authentication.Token', [
'tokenField' => 'Tokens.token',
@idokd
idokd / DetailView-partial.php
Last active February 9, 2022 14:08
vtiger view actions with dropdown options - childLinks
$link = [
'linktype' => 'DETAILVIEWBASIC',
'linklabel' => vtranslate( 'Parent Button Label' )
];
$link = Vtiger_Link_Model::getInstanceFromValues( $link );
$link->addChildLink( Vtiger_Link_Model::getInstanceFromValues( [
'linklabel' => vtranslate( 'Child Link Label' ),
'linkurl' => '?url_to_go_to'
] ) );
@idokd
idokd / readable-strings.php
Created October 31, 2021 13:42
un-obfuscation
<?php
if ( !function_exists( 'str_ends_with' ) ) {
function str_ends_with( $str, $end ) {
return( @substr_compare( $str, $end, -strlen( $end ) ) == 0 );
}
}
function mocleanr( $filename, $replace = false ) {
if ( !is_dir( $filename ) ) {
@idokd
idokd / mailgun-api-force-template.php
Created September 19, 2021 15:57
WordPress + Mailgun plugin - Apply Template to all WordPress mail
<?php
/*
This code with conjunction of Wordpress Mailgun plugin will force all wordpress mails to apply mailgun wordpress to all mail,
This could be easy way to beautify emails.
use {{subject}} {{text}} or {{{html}}} - see that html has triple {{{ in order to use raw content and not escape special chars
*/
add_filter( 'mg_mutate_message_body', function( $body ) {
@idokd
idokd / wp-rocket-cache-gcp-cloud-cdn-invalidation.php
Last active September 19, 2021 09:20
WP Rocket Cache Purge / Invalidation with GCP Cloud CDN - Load Balancer
<?php
// Make sure that you have gcloud installed on server, and is accesible with the proper permissions to httpd/apache/ngix
// Update this variable with the GCP Cloud CDN Load Balancer name, or set it via filter: gcp_cloud_cdn_urlmap
define( 'GCP_CLOUD_CDN_URLMAP', 'your-load-balancer-id-goes-here' );
add_action( 'after_rocket_clean_home', 'gcp_cloud_cdn_invalidate_cdn_cache_home', 100 );
add_action( 'after_rocket_clean_domain', 'gcp_cloud_cdn_invalidate_cdn_cache_domain', 100 );
add_action( 'after_rocket_clean_cache_dir', 'gcp_cloud_cdn_invalidate_cdn_cache', 100 );