Skip to content

Instantly share code, notes, and snippets.

@zecka
zecka / billing_fields_to_registration.php
Created June 24, 2017 17:02
Add the billing form to the registration page of woocommerce
<?php
// Function to check starting char of a string
function zk_starts_with($haystack, $needle){
return $needle === '' || strpos($haystack, $needle) === 0;
}
// Custom function to display the Billing Address form to registration page
function zk_add_billing_form_to_registration(){
@zecka
zecka / zk_instagram_feed.php
Created May 1, 2019 21:02
WordPress function to grab instagram post with regex
<?php
/*
* Function to grab last 11 instagram posts into an array
* @args string $username : your username on instagram (instagram.com/username)
* @args float $cache_duration : Cache duration in hours, you can use integer or float eg: 0.5 (30 minutes)
* @require allow_url_fopen=1
*/
function zk_get_instagram_feed($username, $cache_duration=1){
$wp_upload=wp_upload_dir();
$upload_path=$wp_upload['basedir'].'/instagram-cache';
@zecka
zecka / filter-arg-multistep-plugin-option.php
Created July 23, 2019 06:57
Filter ARG Multistep Checkout Plugin Option
<?php
add_filter("option_arg-mc-options", "myprefix_filter_arg_plugin_options");
function myprefix_filter_arg_plugin_options( $option ){
$option = array (
'btn_next_text' => 'Next Step',
'btn_prev_text' => 'Previous',
'btn_submit_text' => 'Place Order',
'btn_skip_login_text' => 'Skip Login',
'error_required_text' => 'This field is required',
'error_required_checkbox' => 'You must accept the terms and conditions',
@zecka
zecka / measure-execution-time.php
Last active August 7, 2019 13:19
measure execution times of php scripts
<?php
function example_measure_execution_time(){
$start = microtime(true);
// Here your script
$duration = microtime(true) - $start; // in seconds
echo 'the script take '. $duration.' to be executed';
}
@zecka
zecka / Wordpress virtual page
Last active August 9, 2019 15:09 — forked from qutek/Wordpress virtual page
[Wordpress] Virtual Page
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
<?php
// attach a post type to pictifly regeneration
add_filter('pf_post_type_regenerate', 'prefix_pf_post_type_regenerate', 1, 1);
function prefix_pf_post_type_regenerate($post_types){
$post_types=['custom_type'];
return $post_types;
}
// Create custom method to regenerate image
add_action('pf_post_images_regenerate', 'prefix_pf_post_images_regenerate',10, 2);
@zecka
zecka / valet_new_drupal_site.sh
Created April 17, 2020 12:07
Create a new drupal site on Valet with MAMP on Mac OS
# =============================
# CHECK REQUIREMENTS
# =============================
requirement=1;
#check if pv command exist
if ! which pv >/dev/null; then
echo "You need to install pv"
requirement=0
fi
@zecka
zecka / class-wp-bulk-task.php
Last active April 29, 2020 18:17
Make Bulk taks tool in WordPress admin
<?php
/*
USAGE:
$task = new WP_Bulk_Task('test-bulk-task', 'product');
$task->set_callback(function($post){
error_log($post->ID);
});
$task->set_posts_per_page(1);
$task->register();
*/
@zecka
zecka / print-array-as-code.php
Last active May 13, 2020 10:26
Php print an array as php code
<?php
function bo_print_nice_array($array)
{
echo '$array=';
bo_print_nice_array_content($array, 1);
echo ';';
}
function bo_print_nice_array_content($array, $deep = 1)
@zecka
zecka / wp-kses-outside-wordpress.php
Last active May 27, 2020 12:52
wp_kses outside wordpress (Dirty copy of wp_kses)
<?php
function get_charset()
{
return 'utf-8';
}
/**
* kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
* Copyright (C) 2002, 2003, 2005 Ulf Harnhammar