Skip to content

Instantly share code, notes, and snippets.

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

Diogenes Oliveira Junior diogenesjup

🏠
Working from home
View GitHub Profile
function Range(start, stop, step) {
return Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
}
console.log(Range(0,5,1)) // [0, 1, 2, 3, 4, 5]
console.log(Range(0,9,3)) // [0, 3, 6, 9]
console.log(Range('A'.charCodeAt(0), 'Z'.charCodeAt(0), 1).map(x => String.fromCharCode(x)));
// ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
const map = new Map([[1, 2], [2, 4], [4, 8]]);
Array.from(map)
// [1, 2], [2, 4], [4, 8]
Array.from(map.values());
// [2, 4, 8]
Array.from(map.keys());
// [1, 2, 4]
@cyberwani
cyberwani / wordpress-upload-base64.php
Created September 13, 2019 10:19
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
@paaljoachim
paaljoachim / functions.php
Last active May 29, 2022 00:49
Tutorial: WooCommerce Checkout: Add multiple custom fields to billing area. This code adds priority placement of field. Shows the custom fields in the backend Order Details screen and in e-mails to the admin and customer. I have also adjusted the checkbox field to give a text result instead of a value of 1. Checkbox is also pre-selected.
/* --------- Adds custom fields using filters. ------
The below custom fields shows various types one can use.
It is then displayed in the backend Order Details page and in admin and customer e-mails.
Checkboxes by default result only show the number 1 when clicked. I have added code so that when the a checkbox is clicked it will
show text such as On and Yes. Checkbox is also pre-selected.
Tutorial: https://easywebdesigntutorials.com/woocommerce-modifying-the-checkout-page/
*/
// Initial inspiration: https://businessbloomer.com/woocommerce-add-shipping-phone-checkout/
// My Custom Fields
@bporcelli
bporcelli / dokan-custom-settings-tab.php
Last active October 23, 2023 15:04
Adding a custom settings tab to the Dokan vendor dashboard
<?php
/**
* NOTE: This code example uses the generic vendor prefix 'prefix_' and omits text domains where
* the WordPress internationalization functions are used. You should replace 'prefix_' with your
* own prefix and insert your text domain where appropriate when incorporating this code into your
* plugin or theme.
*/
/**
@shamimmoeen
shamimmoeen / custom-file-upload-form-in-wordpress.php
Last active October 31, 2023 10:42
Create custom file upload form in WordPress
<?php
if ( ! function_exists( 'wpcfu_output_file_upload_form' ) ) {
/**
* Output the form.
*
* @param array $atts User defined attributes in shortcode tag
*/
function wpcfu_output_file_upload_form( $atts ) {
@maxfenton
maxfenton / add_custom_column_to_edit_tag.php
Last active December 7, 2023 18:59 — forked from simongcc/add_custom_column_to_edit_tag.php
Adding custom column displaying in Wordpress Manage Category/Custom Taxonomy editing page
/*
Purpose: add custom column header and custom column content to respective custom header in Manage Category Editing Page
Version Tested: 3.8
Story:
Because I found no explanation nor documents in Wordpress.org, I tried to trace the code in wp-admin folder
after understanding the operation of apply_filter(), add_action() and add_filter()
Logic:
The table list in edit_tag.php is based on
@JiveDig
JiveDig / acf_create_posts_acf_form.php
Last active February 28, 2023 06:29
Page template to create posts on the front end via Advanced Custom Fields Pro
<?php
/**
* Template Name: Create Post
*
* @author Mike Hemberger
* @link http://thestizmedia.com/front-end-posting-with-acf-pro/
* @uses Advanced Custom Fields Pro
*/
/**
@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active April 11, 2024 12:33
WP: Insert attachment from URL
<?php
/**
* Insert an attachment from a URL address.
*
* @param string $url The URL address.
* @param int|null $parent_post_id The parent post ID (Optional).
* @return int|false The attachment ID on success. False on failure.
*/
function wp_insert_attachment_from_url( $url, $parent_post_id = null ) {
@quagliato
quagliato / select_estados.html
Last active April 27, 2024 01:10
<select> com todos os estados brasileiros
<select id="estado" name="estado">
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="AP">Amapá</option>
<option value="AM">Amazonas</option>
<option value="BA">Bahia</option>
<option value="CE">Ceará</option>
<option value="DF">Distrito Federal</option>
<option value="ES">Espírito Santo</option>
<option value="GO">Goiás</option>