Skip to content

Instantly share code, notes, and snippets.

View mattiasghodsian's full-sized avatar
🏠
Working from home

mattiasghodsian

🏠
Working from home
View GitHub Profile
@mattiasghodsian
mattiasghodsian / fucntions.php
Last active April 28, 2023 08:33
[Wordpress] Add profit to datalayer (gtm4wp)
/**
* Requires Plugin: Google Tag Manager for Wordpress & WooCommerce Cost of Goods
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
function gtm4wp_add_profit_datalayer_data( $dataLayer ){
if ( is_order_received_page() ){
$orderID = $dataLayer['ecommerce']['purchase']['actionField']['id'];
$orderItems = $dataLayer['ecommerce']['purchase']['products'];
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:33
[WordPress] Simple way to protect REST API from the public
/**
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*
* custom_rest_api_authentication_token
*
* Protect REST API from the public | Generate token: https://bit.ly/2W5qDrB
*
* @param obj $wp_rest_server
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:33
[WordPress] Remove Page content editor for specific template
/**
* Title: Remove Page content editor for specific template
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
add_action('admin_init', 'mg_remove_editor_init');
function mg_remove_editor_init() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template = get_post_meta( $post_id, '_wp_page_template', true );
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:33
[WordPress] Gravity Forms send entry to child site (WP)
/**
* Title: Gravity Forms send entry to child site (WP | Enable GF REST API on child site)
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
add_action( 'gform_after_submission_2', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$entry['form_id'] = 1; // change form ID to same ID on your child site
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:34
[WordPress] Populate ACF select field options with Gravity Forms forms
/**
* Title: Populate ACF select field options with Gravity Forms forms
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
// $choices[ $form->id ] = 'Select a form';
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:34
[WordPress] Menu change link source by user role
/**
* Title: Menu change link source by user role
* Description: Changes source(href) list all venues link by user role
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
add_filter( 'nav_menu_item_args', 'change_menu_link_by_user_role', 10, 2 );
function change_menu_link_by_user_role( $args, $item ) {
// if ( 'primary' !== $args->theme_location ) {
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:34
[WordPress] Gravity Forms display price
/**
* Title: Gravity Forms display price
* Description: Display (has) price on Drop Down and Radio Button Product Fields
* Source: https://www.gravityhelp.com/documentation/article/gform_field_choice_markup_pre_render/#2-include-price-for-product-fields
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) {
@mattiasghodsian
mattiasghodsian / unzip.bat
Last active April 28, 2023 08:34
UnRAR/UnZip files in sub directory's + rename + move
::Title: UnRAR/UnZip files in sub directory's + rename + move
::Author: Mattias Ghodsian
::Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
::Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
SETLOCAL ENABLEEXTENSIONS
FOR /D /r %%F in ("*") DO (
pushd %CD%
cd %%F
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:34
[WooCommerce] Add missing Schema
/**
* Title: Add missing Schema WooCommerce
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
**/
function woo_missing_schema_fields($data) {
global $product;
@mattiasghodsian
mattiasghodsian / readme.md
Last active December 19, 2019 15:02
[Wordpress] Manually backup WordPress

Export database with wp-cli

SSH to your site and go to the root folder of the WordPress installation and do

wp db export

Compress site

Move outside the root folder of WordPress and compress the folder (The db fils is located in the root folder and will be included).