Browsing "WordPress"
Aug 25, 2014 - WordPress    Comments Off on Getting an attachment from a URL

Getting an attachment from a URL

Specifically, to get a different size of the image.

        $attachment_id = get_attachment_id_from_src($solutions_metabox->get_the_value('image'));
        $image_url = wp_get_attachment_image_src($attachment_id,'solutions');
Feb 27, 2014 - Genesis    Comments Off on Bootstrapping genesis

Bootstrapping genesis

This was kind of a cool thing I was doing to have two different sidebar layouts on pages vs. posts/cpts, but the client decided to go with one layout overall, so now I’m saving it here.

/*** Bootstrappin **/

add_filter( 'genesis_attr_site-inner', 'msdlab_bootstrap_site_inner', 10);
add_filter( 'genesis_attr_breadcrumb', 'msdlab_bootstrap_breadcrumb', 10);
add_filter( 'genesis_attr_content-sidebar-wrap', 'msdlab_bootstrap_content_sidebar_wrap', 10);
add_filter( 'genesis_attr_content', 'msdlab_bootstrap_content', 10);
add_filter( 'genesis_attr_sidebar-primary', 'msdlab_bootstrap_sidebar', 10);

/*** Bootstrappin **/

function msdlab_bootstrap_site_inner( $attributes ){
    $attributes['class'] .= ' container';
    return $attributes;
}

function msdlab_bootstrap_breadcrumb( $attributes ){
    $attributes['class'] .= ' row';
    return $attributes;
}

function msdlab_bootstrap_content_sidebar_wrap( $attributes ){
    $attributes['class'] .= ' row';
    return $attributes;
}

function msdlab_bootstrap_content( $attributes ){
    $layout = genesis_site_layout();
    switch($layout){
        case 'content-sidebar':
        case 'sidebar-content':
            if(is_page()){
                $attributes['class'] .= ' col-md-7 col-sm-12';
            } else {
                $attributes['class'] .= ' col-md-9 col-sm-12';
            }
            break;
        case 'content-sidebar-sidebar':
        case 'sidebar-sidebar-content':
        case 'sidebar-content-sidebar':
            break;
        case 'full-width-content':
            $attributes['class'] .= ' col-md-12';
            break;
    }
    return $attributes;
}

function msdlab_bootstrap_sidebar( $attributes ){
    $layout = genesis_site_layout();
    switch($layout){
        case 'content-sidebar':
        case 'sidebar-content':
            if(is_page()){
                $attributes['class'] .= ' col-md-4 col-md-offset-1 hidden-sm hidden-xs';
            } else {
                $attributes['class'] .= ' col-md-3 hidden-sm hidden-xs';
            }
            break;
        case 'content-sidebar-sidebar':
        case 'sidebar-sidebar-content':
        case 'sidebar-content-sidebar':
            break;
        case 'full-width-content':
            $attributes['class'] .= ' hidden';
            break;
    }
    return $attributes;
}
Feb 18, 2014 - Admin Area, WordPress    Comments Off on WPAlchemy repeating fileds and the wp_editor()

WPAlchemy repeating fileds and the wp_editor()

I may have something working. I’m still doing some testing, but I think the problem lies here:
” $editor_id (string) (required) HTML id attribute value for the textarea and TinyMCE. (may only contain lower-case letters)” (http://codex.wordpress.org/Function_Reference/wp_editor)

When you try to pass $mb->get_the_name(), it inputs all kinds of brackets and such, which are disallowed characters. Here’s where I’m at:

Using sanitize_key removes those illegal characters. Adding ‘textarea_name’=>$mb->get_the_name() to the settings array re-targets the input to that hidden textbox.

I’m using Extract Mode (I always do, for searchability) and so far it seems to be working.

Feb 17, 2014 - Genesis, jQuery    Comments Off on Making Genesis & Bootstrap play nice together

Making Genesis & Bootstrap play nice together

This is going to be a multi-post solution set, I’m sure. I started out with a jQuery solution. It worked ok, but wasn’t really what I wanted:

//bootstrap
    $('.site-inner').addClass('container');
    //$('.wrap').addClass('row');
    $('.content-sidebar .content-sidebar-wrap').addClass('row');
    $('.content-sidebar .content').addClass('col-md-8 col-sm-12');
    $('.content-sidebar .sidebar').addClass('col-md-4');

Then I started digging into the Genesis context filters. This will probably work better and be more portable in the future. (Obviously this is jsut a part of it.)

/*** Bootstrappin **/

add_filter( 'genesis_attr_site-inner', 'msdlab_bootstrap_site_inner', 10);
add_filter( 'genesis_attr_breadcrumb', 'msdlab_bootstrap_breadcrumb', 10);
add_filter( 'genesis_attr_content-sidebar-wrap', 'msdlab_bootstrap_content_sidebar_wrap', 10);
add_filter( 'genesis_attr_content', 'msdlab_bootstrap_content', 10);
add_filter( 'genesis_attr_sidebar-primary', 'msdlab_bootstrap_sidebar', 10);

function msdlab_bootstrap_site_inner( $attributes ){
    $attributes['class'] .= ' container';
    return $attributes;
}

function msdlab_bootstrap_breadcrumb( $attributes ){
    $attributes['class'] .= ' row';
    return $attributes;
}

function msdlab_bootstrap_content_sidebar_wrap( $attributes ){
    $attributes['class'] .= ' row';
    return $attributes;
}

function msdlab_bootstrap_content( $attributes ){
    $layout = genesis_site_layout();
    switch($layout){
        case 'content-sidebar':
        case 'sidebar-content':
            $attributes['class'] .= ' col-md-7 col-sm-12';
            break;
        case 'content-sidebar-sidebar':
        case 'sidebar-sidebar-content':
        case 'sidebar-content-sidebar':
            break;
        case 'full-width-content':
            $attributes['class'] .= ' col-md-12';
            break;
    }
    return $attributes;
}

function msdlab_bootstrap_sidebar( $attributes ){
    $layout = genesis_site_layout();
    switch($layout){
        case 'content-sidebar':
        case 'sidebar-content':
            $attributes['class'] .= ' col-md-4 col-md-offset-1 hidden-sm hidden-xs';
            break;
        case 'content-sidebar-sidebar':
        case 'sidebar-sidebar-content':
        case 'sidebar-content-sidebar':
            break;
        case 'full-width-content':
            $attributes['class'] .= ' hidden';
            break;
    }
    return $attributes;
}
Jan 7, 2014 - CSS, WordPress    Comments Off on Gravity forms CSS tricks

Gravity forms CSS tricks

http://kevinshoffner.com/wordpress/tipstricks/custom-css-gravity-forms/

Here is a quick list of all of the built-in classes:

Checkboxes and Lists Fields

gf_list_2col = 2 columned List
gf_list_3col = 3 columned List
gf_list_4col = 4 columned
gf_list_5col = 5 columned

Two Columns of Text Fields side by side

gf_left_half = The left column
gf_right_half = The right column

Three Columns side by side

gf_left_third = Left column
gf_middle_third = Middle column
gf_right_third = Right column

Some other miscellaneous styles

gf_scroll_text = Gets a scroll box into place, for those long sections where you need to give your visitor lots of information
scrolling-text
gf_hide_ampm = If you want to hide the AM/PM portion of the Time field
gf_list_inline = Simpliar to the above gf_list classes, but just show up next to each other using the amount of space the content can use on each line, instead of making it fit within 2,3,4,5 columns.
gf_hide_charleft = Do not display the amount of characters left / character counter

I’ve not found a great use for these, but they are available:
gf_list_height_25 = 25 pixels between list items
gf_list_height_50 = 50 pixels between list items
gf_list_height_75 = 75 pixels between list items
gf_list_height_100 = 100 pixels between list items
gf_list_height_125 = 125 pixels between list items
gf_list_height_150 = 150 pixels between list items

Dec 5, 2013 - Genesis, WordPress    Comments Off on Genesis Widget Formatting

Genesis Widget Formatting

Genesis has a pretty cool filter available to override the default settings for a widget area. You can use this to filter all of the widget area layouts:

function msdlab_register_sidebar_defaults($args){
    $args = array(
            'before_widget' => genesis_markup( array(
                'html5' => '<section id="%1$s" class="widget %2$s">',
                'xhtml' => '<div id="%1$s" class="widget %2$s">',
                'echo'  => false,
            ) ),
            'after_widget'  => genesis_markup( array(
                'html5' => '</div></section>' . "\n",
                'xhtml' => '</div></div>' . "\n",
                'echo'  => false
            ) ),
            'before_title'  => '<h4 class="widget-title widgettitle">',
            'after_title'   => genesis_markup( array(
                'html5' => '</h4>'."\n".'<div class="widget-wrap">',
                'xhtml' => '</h4>'."\n".'<div class="widget-wrap">',
                'echo'  => false,
            ) ),
        );
   return $args;
}

The issue comes when you try to activate it. Because the default widget areas are registered before the filter is defined, it won’t work unless you do something like so:

remove_action( 'genesis_setup', 'genesis_register_default_widget_areas' ); //remove initial setup of default widgets
add_action( 'after_setup_theme', 'genesis_register_default_widget_areas' ); //move them to AFTER the theme files are loaded
add_filter('genesis_register_sidebar_defaults','msdlab_register_sidebar_defaults'); //and here's the filter
Sep 8, 2013 - Genesis, WordPress    Comments Off on Genesis 2 CPT Archive Settings

Genesis 2 CPT Archive Settings

This is pretty cool.

Basically, you can add backend editing to the CPT archive with something like this:

function register_snippet_post_type(){
  
  // custom post type arguments
	$post_type_args = array(
		'label'		=> __( 'Snippet' ),
		'description'	=> __( 'Display code snippets' ),
		'public'	=> true,
		'show_ui'	=> true,
		'show_in_menu'	=> true,
		'has_archive'	=> true,
		'supports'	=> array( 'title', 'editor', 'genesis-cpt-archives-settings' )
	);
	
	// register the 'snippet' post type
	register_post_type( 'snippet', $post_type_args );
	
}
Jul 18, 2013 - WordPress    Comments Off on Combo image function

Combo image function

I created this to stack two images horizontally together, to make before and after images into one image. Designed for WordPress, but could be tweaked for other systems.

/**
 * use two images to create one image
 */
function msdlab_combine_images($params){
	extract(
		array_merge(
			array(
				'images' => array(),
				'orientation' => 'horizontal',
				'output_format' => 'jpg'
			)
		,$params)
	);
	//get info on each image
	foreach($images AS $key => $url){
		$imgs[$key]['url'] = $url;
		$imgs[$key]['path'] = $path = realpath(preg_replace('@'.site_url().'@i','.',$url));
		$imgs[$key]['file'] = $file = basename($path);
		$imgs[$key]['filename'] = $filename = preg_replace('/\.(?:jpg|jpeg|bmp|png|gif)/i','',$file);
		$imgs[$key]['info'] = $info = getimagesize($path);
		$comboname .= $filename;
		switch($orientation){
			case 'horizontal':
				$combowidth = $combowidth + $info[0];
				$comboheight = $info[1]>$comboheight?$info[1]:$comboheight;
				break;
			case 'vertical':
				$combowidth = $info[0]>$combowidth?$info[0]:$combowidth;
				$comboheight = $comboheight + $info[1];
				break;
		}
	}
	$comboname .= '.'.$output_format;
	$upload_dir = wp_upload_dir();
	//check if it exists
	if(file_exists($upload_dir['basedir'].'/'.$comboname)){
		return $upload_dir['baseurl'].'/'.$comboname;
	}
	//create a holding image
	$newimg = @imagecreatetruecolor($combowidth, $comboheight);
	foreach($imgs AS $key => $img){
		switch($img['info']['mime']){
			case 'image/jpeg':
				$src = @imagecreatefromjpeg($img['path']);
				break;
			case 'image/png':
				$src = @imagecreatefrompng($img['path']);
				break;
			case 'image/gif':
				$src = @imagecreatefromgif($img['path']);
				break;
			default:
				return 'unsupported file type';
		}
		//copy things
		switch($orientation){
			case 'horizontal':
				imagecopy($newimg, $src, $imgs[$key-1]['info'][0], 0, 0, 0, $img['info'][0], $img['info'][1]);
				break;
			case 'vertical':
				imagecopy($newimg, $src, 0, $imgs[$key-1]['info'][1], 0, 0, $img['info'][0], $img['info'][1]);
				break;
		}
		// free up memory
		imagedestroy($src);
	}
	// Save the image
	imagejpeg($newimg, $upload_dir['basedir'].'/'.$comboname);

	// Free up memory
	imagedestroy($newimg);

	//return the image
	return $upload_dir['baseurl'].'/'.$comboname;
}
Jun 25, 2013 - Admin Area, WordPress    Comments Off on Custom Login Page

Custom Login Page

Putting a custom login logo (or any other custom login styling) in place:

//Logo for login page
function custom_login_logo() {
	echo '<style type="text/css">
		#login h1 a { background-image: url('.INSERTLOGOHERE.') !important; }
	</style>';
}
add_action('login_head', 'custom_login_logo');
Pages:«12345»