This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | |
export default Base64 = { | |
btoa: (input) => { | |
input = input || ''; | |
if(typeof input !== 'string'){ | |
throw new Error("Input must be string but you given "+(typeof input)); | |
} | |
let str = input; | |
let output = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_remote_content($url) | |
{ | |
return file_get_contents($url, false, stream_context_create(array( | |
'ssl' => array( | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
), | |
))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cleanHtml($html_source) | |
{ | |
$html_source = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $html_source); | |
$html_source = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html_source); | |
$html_source = preg_replace('#<link(.*?)>#is', '', $html_source); | |
$html_source = preg_replace('#<meta(.*?)>#is', '', $html_source); | |
$html_source = preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $html_source); | |
return $html_source; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function DOMInnerHTML(DOMNode $element) | |
{ | |
$innerHTML = ""; | |
$children = $element->childNodes; | |
foreach ($children as $child){ | |
$innerHTML .= $element->ownerDocument->saveHTML($child); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function url_format($value, $https = false) | |
{ | |
if(is_string($value)) | |
{ | |
if(preg_match('#^\/\/#', $value)){ | |
$value = ($https ? 'https:' : 'http:') . $value; | |
}else if(preg_match('#^[w]{3}#', $value)){ | |
$value = ($https ? 'https://' : 'http://') . $value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_generate_featured_image( $image_url, $post_id ) | |
{ | |
$upload_dir = wp_upload_dir(); | |
$image_data = __get_remote_content($image_url); | |
$filename = basename($image_url); | |
if(wp_mkdir_p($upload_dir['path'])){ | |
$file = $upload_dir['path'] . '/' . $filename; | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$remote_response = wp_remote_get( | |
add_query_arg(array( | |
), 'https://jsonplaceholder.typicode.com/todos/1'), | |
array( | |
'sslverify' => false, | |
'headers' => array( | |
'Content-Type' => 'application/json' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_wc_cart_shop_info() | |
{ | |
$item_quantities = WC()->cart->get_cart_item_quantities(); | |
return array( | |
'cart' => array( | |
'count' => WC()->cart->get_cart_contents_count(), | |
'total' => WC()->cart->get_cart_contents_total(), | |
'weight' => WC()->cart->get_cart_contents_weight(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function arr_end(array $array) | |
{ | |
if(!empty($array) && is_array($array)) | |
{ | |
if(function_exists('end')){ | |
return end($array); | |
}else{ | |
return $array[count($array) - 1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_wc_product_gallery_images() | |
{ | |
global $product; | |
if(!empty($product) && is_a($product, 'WC_Product')) | |
{ | |
$ids = $product->get_gallery_image_ids(); | |
if(!empty($ids)) |
OlderNewer