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 / importer.php
Last active April 28, 2023 08:32
[Wordpress] Custom importer class
<?php
/**
* FM_Importer
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
@mattiasghodsian
mattiasghodsian / readme.md
Last active October 3, 2024 11:17
How to install Sonarr,Jackett,qBittorrent and mount network drive on Raspberry PI 4

~|~ I DO NOT INDORCE TORRENTING COPYRIGHT CONTENT - THIS IS MADE FOR EDUCATIONAL PURPOSES ONLY ~|~

1. Setup your Raspberry

  • Install Raspberry OS headless on your SD card and power it up with a screen, ether cable and keyboard
  • Enable SSH with sudo raspi-config and go to Interfaces and enable SSH
  • Change the password with Option one sudo raspi-config
  • sudo apt-get update then sudo apt-get upgrade -y

2. Install qbittorrent-nox

  • sudo apt-get update && sudo apt-get install qbittorrent-nox
@mattiasghodsian
mattiasghodsian / functions.php
Last active April 28, 2023 08:33
[WordPress] Get field data by field ID gravity forms
/**
* gf_get_field_data
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*
* @param int $form_id
* @param int $id the field integer key
* @param str $key what value to return
* @return string/boolean
@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 September 14, 2024 00:52
[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 ) {