Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
<?php
function my_is_valid_domain( $url ) {
$whitelisted_domains = array( 'mydomain.com', 'mydomain.net' );
$domain = parse_url( $url, PHP_URL_HOST );
// Check if we match the domain exactly
if ( in_array( $domain, $whitelisted_domains ) )
return true;
$valid = false;
@yanknudtskov
yanknudtskov / va_extended_user_search.php
Created July 17, 2014 10:17
WordPress Snippet to modify the WordPress Search Function with custom fields
public function va_extended_user_search( $user_query )
{
// Make sure this is only applied to user search
if ( $user_query->query_vars['search'] ){
$search = trim( $user_query->query_vars['search'], '*' );
if ( $_REQUEST['s'] == $search ){
global $wpdb;
$user_query->query_from .= " JOIN ".$wpdb->prefix ."usermeta MF ON MF.user_id = {$wpdb->users}.ID AND MF.meta_key = 'META_KEY_NAME'";
@yanknudtskov
yanknudtskov / enable-iris.php
Created August 5, 2014 10:19
Enqueue IRIS in WordPress editor
<?php
function load_mc_iris() {
if (wp_script_is( 'iris', 'enqueued' )) {
return; // if it's already enqueued, don't enqueue it again.
} else { // since it's NOT enqueued, let's enqueue it
wp_enqueue_script(
'iris', //iris.js handle
admin_url( 'js/iris.min.js' ), //path to wordpress iris file
@yanknudtskov
yanknudtskov / js_user_agent_version.js
Last active August 29, 2015 14:06
JavaScript to return the current user agent and version as a string.
function detectBrowserAndVersion()
{
var user_agent = navigator.userAgent, user_agent_version, user_agent_match = user_agent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(user_agent_match[1]))
{
user_agent_version = /\brv[ :]+(\d+)/g.exec(user_agent) || [];
return 'IE '+(user_agent_version[1] || '');
}
$(function(){
$('body').addClass(detectBrowserAndVersion);
});
function detectBrowserAndVersion()
{
var user_agent = navigator.userAgent, user_agent_version, user_agent_match = user_agent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(user_agent_match[1]))
{
@yanknudtskov
yanknudtskov / remove-outlines.css
Created November 21, 2014 09:46
Remove outlines
* {
outline: 0 !important;
}
@yanknudtskov
yanknudtskov / responsive-media-embed.txt
Created November 23, 2014 10:05
WordPress, Bootstrap 3 Render a responsive media embed
<?php
function get_embed_video_html($url) {
$embed_link = '[embed]'.$url.'[/embed]';
$embed_link = apply_filters('the_content', $embed_link);
$output = '';
$output .= '<div class="responsive-video">';
$output .= $embed_link;
$output .= '</div>';
@yanknudtskov
yanknudtskov / filesize-string.php
Created November 26, 2014 10:24
Get a filesize string
<?php
function get_filesize_string($path)
{
$bytes = sprintf('%u', filesize($path));
if ($bytes > 0)
{
$unit = intval(log($bytes, 1024));
$units = array('B', 'KB', 'MB', 'GB');
@yanknudtskov
yanknudtskov / acf-img-object.php
Last active August 29, 2015 14:13
Get <img> tag from ACF Image Object
<?php
function yanco_StringIsNullOrEmpty( $string ) {
return ( !isset( $string ) || trim( $string ) === '');
}
/**
* Advanced Custom Fields Get Image Tag From Image Object
* Dependencies: functions/function-common.php
* Usage:
@yanknudtskov
yanknudtskov / gform_security_filter.php
Created April 10, 2015 10:35
Gravity Forms Security Filter
<?php
add_filter( 'gform_upload_root_htaccess_rules', '__return_false' );
?>