Pages

Thursday, November 5, 2015

Contact form 7 remoce select box (Dropdown) default value

function my_wpcf7_form_elements($html) {
function replace_include_blank($name, $text, &$html) {
$matches = false;
preg_match('/
if ($matches) {
$select = str_replace('', '', $matches[0]);
$html = preg_replace('/
}
}
replace_include_blank('mc4wp-age', 'AGE*', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');

Thursday, October 15, 2015

Get Vimeo video id from embaded code - PHP

function parse_vimeo($link){
        $regexstr = '~
            # Match Vimeo link and embed code
            (?:< iframe [^>]*src=")?       # If iframe match up to first quote of src
            (?:                         # Group vimeo url
                https?:\/\/             # Either http or https
                (?:[\w]+\.)*            # Optional subdomains
                vimeo\.com              # Match vimeo.com
                (?:[\/\w]*\/videos?)?   # Optional video sub directory this handles groups links also
                \/                      # Slash before Id
                ([0-9]+)                # $1: VIDEO_ID is numeric
                [^\s]*                  # Not a space
            )                           # End group
            "?                          # Match end quote if part of src
            (?:[^>]*></ iframe >)?        # Match the end of the iframe
            (?:.*
)?              # Match any title information stuff
            ~ix';
        preg_match($regexstr, $link, $matches);
        return $matches[1];
    }

Wednesday, October 14, 2015

Wordpress Activate plugin programatically

function run_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }

    return null;
}
run_activate_plugin( 'plugin_dir/plugin_file.php' );