This file contains hidden or 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 create_unique_user_name_by_email ($email) { | |
$email_name = explode( '@', $email ); | |
if ( ! get_user_by( 'login', $email_name[0] ) ) { | |
$username = $email_name[0]; | |
} else { | |
$username = uniqid( $email_name[0], false ); | |
} |
This file contains hidden or 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 add_new_columns_to_easyexam_students_exams () { | |
global $wpdb; | |
$table_name = $wpdb->prefix . 'table_name'; | |
// Check if column exists | |
$column_exist = $wpdb->query("SHOW COLUMNS FROM $table_name LIKE 'column_name'"); | |
if ($column_exist == false) { | |
// alter the table with the new column name | |
$wpdb->query("ALTER TABLE $table ADD column_name VARCHAR(255) NOT NULL AFTER some_other_column_name"); | |
} |
This file contains hidden or 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
//Source: https://stackoverflow.com/questions/15194663/encrypt-and-decrypt-md5 | |
function encryptIt( $q ) { | |
$cryptKey = 'блалалаѝк777амайка'; | |
$qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) ); | |
return( $qEncoded ); | |
} | |
function decryptIt( $q ) { | |
$cryptKey = 'блалалаѝк777амайка'; |
This file contains hidden or 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
var derText = "This is some text with [a link](https://duckduckgo.com) \n\ and break line"; | |
//replace the linebreaks with <br> | |
derText = derText.replace(/(?:\r\n|\r|\n)/g, '<br>'); | |
//check for links [text](url) | |
let elements = derText.match(/\[.*?\)/g); | |
if( elements != null && elements.length > 0){ | |
for(el of elements){ | |
let txt = el.match(/\[(.*?)\]/)[1];//get only the txt | |
let url = el.match(/\((.*?)\)/)[1];//get only the link | |
derText = derText.replace(el,'<a href="'+url+'" target="_blank">'+txt+'</a>') |
This file contains hidden or 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 | |
//Loop through each item from the cart | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
//get the current product ID | |
$product_id = $cart_item['product_id']; | |
//first - check if product has variations | |
if(isset($cart_item['variation']) && count($cart_item['variation']) > 0 ){ | |
//get the WooCommerce Product object by product ID | |
$current_product = new WC_Product_Variable($product_id); | |
//get the variations of this product |
This file contains hidden or 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 | |
//Works with WooCommerce 3.2.6 | |
add_action( 'woocommerce_shipping_init', 'econt_shipping_method' ); | |
function econt_shipping_method() { | |
if ( ! class_exists( 'WC_Econt_Shipping_Method' ) ) { | |
class WC_Econt_Shipping_Method extends WC_Shipping_Method { | |
public function __construct( $instance_id = 0 ) { | |
$this->instance_id = absint( $instance_id ); | |
$this->id = 'econt';//this is the id of our shipping method |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
.verb-wrapper{ | |
width:400px; | |
border: 1px solid green; |
This file contains hidden or 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
var str = "string"; | |
var num = 123; | |
var boo = false; | |
var obj = {h:3}; | |
console.log(String(str)); // "string" | |
console.log(Number(str)); // NaN | |
console.log(Boolean(str)); // true | |
console.log(Object(str)); // "string" |
This file contains hidden or 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
console.log(null == undefined); // TRUE | |
console.log(null === undefined); // FALSE | |
console.log(null == ""); // FALSE | |
console.log(null == 0); // FALSE | |
console.log(undefined == ""); // FALSE | |
console.log(undefined == 0); // FALSE | |
console.log("" == 0); // TRUE | |
console.log("" === 0); // FALSE | |
console.log(false == 0); // TRUE | |
console.log(false == ""); // TRUE |
This file contains hidden or 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
var a; | |
var b = ""; | |
var c = 0; | |
var d = null; | |
var e = []; | |
var f = {}; | |
var g = false; | |
console.log("a: " + typeof a); // "undefined" |