strip_invalid_text_for_column( $wpdb->options, 'option_value', $value ?? '' ); if ( is_wp_error( $value ) ) { $value = ''; } $value = esc_url_raw( trim( $value ) ); $value = str_replace( 'http://', '', $value ); return untrailingslashit( $value ); } /** * Function to add array after specific key * * @since 1.0.0 */ function em_wcw_add_array(&$array, $value, $index, $from_last = false) { if( is_array($array) && is_array($value) ) { if( $from_last ) { $total_count = count($array); $index = (!empty($total_count) && ($total_count > $index)) ? ($total_count-$index): $index; } $split_arr = array_splice($array, max(0, $index)); $array = array_merge( $array, $value, $split_arr); } return $array; } /** * Function to unique number value * * @since 1.0.0 */ function em_wcw_get_unique() { static $unique = 0; $unique++; // For VC front end editing if ( ( function_exists('vc_is_page_editable') && vc_is_page_editable() ) || ( defined('ELEMENTOR_PLUGIN_BASE') && isset( $_POST['action'] ) && $_POST['action'] == 'elementor_ajax' && isset($_POST['editor_post_id']) ) ) { return wp_rand() .'-'. current_time( 'timestamp' ); } return $unique; } /** * Convert color hex value to rgb format * * @since 1.0.0 */ function em_wcw_hex2rgb( $hex = '', $format = 'string' ) { if( empty($hex) ) return false; $hex = str_replace("#", "", $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); } $rgb = array($r, $g, $b); if( $format == 'string' ) { $rgb = implode(",", $rgb); } return $rgb; } /** * Converts a string (e.g. 'yes' or 'no') to a bool. * * @since 1.0.0 * @param string|bool $string String to convert. If a bool is passed it will be returned as-is. * @return bool */ function em_wcw_string_to_bool( $string ) { if ( is_array( $string ) ) { return false; } $string = $string ? trim( $string ) : ''; return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string ); } /** * Function to validate that public script should be enqueue at last. * Call this function at last. * * @since 1.0.0 */ function em_wcw_enqueue_script() { // Check public script is in queue if( wp_script_is( 'em-wcw-public', 'enqueued' ) ) { // Dequeue Script wp_dequeue_script( 'em-wcw-public' ); // Enqueue Script wp_enqueue_script( 'em-wcw-public' ); } }