Skip to content

Instantly share code, notes, and snippets.

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

Tony Djukic tonydjukic

🏠
Working from home
View GitHub Profile
@pento
pento / php-block.js
Last active February 29, 2024 01:31
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@yanknudtskov
yanknudtskov / wp-admin-select2.php
Created March 7, 2017 22:51
Add select2 to all select fields in WordPress Admin
<?php
function enqueue_select2_jquery() {
wp_register_style( 'select2css', '//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.css', false, '1.0', 'all' );
wp_register_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'select2css' );
wp_enqueue_script( 'select2' );
}
add_action( 'admin_enqueue_scripts', 'enqueue_select2_jquery' );
@janneleppanen
janneleppanen / elasticpress-polylang.php
Last active June 4, 2020 20:48
ElasticPress - Polylang
// Filter Elasticsearch posts by current language
add_filter( 'ep_formatted_args', function($formatted_args, $args) {
$formatted_args['post_filter']['bool']['must'][] = [
'term' => [
'lang' => pll_current_language()
]
];
return $formatted_args;
}, 10, 2);
@jessepearson
jessepearson / wc_auto_complete_virtual.php
Created July 4, 2016 20:38
Auto Complete all WooCommerce virtual orders
<?php // only copy this line if needed
/**
* Auto Complete all WooCommerce virtual orders.
*
* @param int $order_id The order ID to check
* @return void
*/
function custom_woocommerce_auto_complete_virtual_orders( $order_id ) {
@ms-studio
ms-studio / add-term-to-custom-taxonomy.php
Created December 15, 2015 08:10
add term metabox to custom taxonomy - using WP 4.4 term meta functions
<?php
// source: http://wordpress.stackexchange.com/questions/211703/need-a-simple-but-complete-example-of-adding-metabox-to-taxonomy
// code authored by jgraup - http://wordpress.stackexchange.com/users/84219/jgraup
// CREATE CUSTOM TAXONOMY
add_action( 'init', '___create_my_custom_tax' );
@mathetos
mathetos / plugin.php
Last active April 13, 2023 16:48
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
@wkw
wkw / wp-exports-posts-csv.php
Created March 23, 2015 22:43
Export selected fields of all WordPress posts as CSV file
<?php
/*
* Stick this in your functions.php, or include it from a separate file,
* edit the post types you want to export,
* then use the URL: http://your-blog.com/?_inventory=1
*
*/
function return_csv_download($array_data, $filename){
header('Content-Type: text/csv'); // you can change this based on the file type
@tamarazuk
tamarazuk / woocommerce-csv-export-separate-item-meta.php
Last active August 31, 2018 04:42
Customer/Order CSV Export: Separate item meta into multiple columns in the Default – One Row per Item format
<?php // only copy this line if needed
/**
* The use of this snippet requires at least WooCommerce 3.2
*/
/**
* Alter the column headers for the orders CSV to split item_meta into separate columns
*
* Note that this change is only applied to the Default - One Row per Item format
@kalinchernev
kalinchernev / countries
Created October 6, 2014 09:42
Plain text list of countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
register_sidebar( array( 'name' => __( 'Header Widget', 'woothemes' ), 'id' => 'header-widget', 'description' => __( 'The default header widget area for your theme.', 'woothemes' ), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>' ) );