Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / basic-authentication.php
Created September 4, 2022 13:29
PHP Basic Authentication Header
<?php
$realm = 'My Realm Name';
//user => password
$users = [ 'user1' => 'pass1', 'user2' => 'pass2' ];
$authenticated = !empty( $_SERVER[ 'PHP_AUTH_DIGEST' ] );
if ( $authenticated && !( $data = http_digest_parse( $_SERVER[ 'PHP_AUTH_DIGEST' ] ) ) || !isset( $users[ $data[ 'username' ] ] ) ) {
@idokd
idokd / wc-product-vendors.php
Last active December 11, 2022 07:30
Woocommerce Product Vendors - Simple using Post Author
<?php
/* Product Vendors */
add_action( 'init', function() {
add_post_type_support( 'product', [ 'author' ] );
add_post_type_support( 'shop_order', [ 'author' ] );
@idokd
idokd / acf_group_63ee7c57739d9.json
Created February 16, 2023 19:56
Woocommerce Multiple Stripe Accounts By Country
[
{
"key": "group_63ee7c57739d9",
"title": "Stripe Accounts",
"fields": [
{
"key": "field_63ee7c579826f",
"label": "Stripe Accounts",
"name": "stripe_accounts",
"aria-label": "",