WordPress.org

Plugin Directory

Changeset 633570


Ignore:
Timestamp:
12/03/12 16:47:20 (17 months ago)
Author:
jbrinley
Message:

add field for link target

Location:
widget-builder/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • widget-builder/trunk/classes/widget-builder.php

    r596409 r633570  
    204204                        'link_url' => get_post_meta($widget->ID, '_' . Tribe_Widget_Builder::TOKEN . '_link_url', true), 
    205205                        'link_text' => get_post_meta($widget->ID, '_' . Tribe_Widget_Builder::TOKEN . '_link_text', true), 
     206                        'link_target' => get_post_meta($widget->ID, '_' . Tribe_Widget_Builder::TOKEN . '_link_target', true), 
    206207                        'widget_description' => get_post_meta($widget->ID, '_' . Tribe_Widget_Builder::TOKEN . '_widget_description', true), 
    207208                        'dashboard' => get_post_meta($widget->ID, '_' . Tribe_Widget_Builder::TOKEN . '_dashboard', true), 
     
    352353 
    353354            global $post_id; 
    354  
    355             // setup view fields 
    356             $fields = array( 
    357                 self::TOKEN . '_link_text' => __( 'Link Text', 'widget-builder' ), 
    358                 self::TOKEN . '_link_url' => __( 'Link URL', 'widget-builder' ) 
    359             ); 
    360355            $nonce = wp_create_nonce( plugin_basename(__FILE__) ); 
    361356            // get template hierarchy 
     
    415410 
    416411            // Authenticated 
    417             $fields = array( self::TOKEN . '_link_text', self::TOKEN . '_link_url', self::TOKEN . '_widget_description', self::TOKEN . '_dashboard', self::TOKEN . '_disable_sidebar' ); 
     412            $fields = array( self::TOKEN . '_link_text', self::TOKEN . '_link_url', self::TOKEN . '_link_target', self::TOKEN . '_widget_description', self::TOKEN . '_dashboard', self::TOKEN . '_disable_sidebar' ); 
    418413 
    419414            // Parse fields for add, update, delete 
    420415            foreach ( $fields as $f ) { 
    421416 
    422                 ${$f} = strip_tags(trim($_POST[$f])); 
    423  
    424                 if ( get_post_meta( $post_id, '_' . $f ) == '' ) { 
    425                     add_post_meta( $post_id, '_' . $f, ${$f}, true ); 
    426                 } elseif( ${$f} != get_post_meta( $post_id, '_' . $f, true ) ) { 
    427                     update_post_meta( $post_id, '_' . $f, ${$f} ); 
    428                 } elseif ( ${$f} == '' ) { 
    429                     delete_post_meta( $post_id, '_' . $f, get_post_meta( $post_id, '_' . $f, true ) ); 
     417                $value = empty($_POST[$f])?FALSE:strip_tags(trim($_POST[$f])); 
     418                if ( empty($value) ) { 
     419                    delete_post_meta( $post_id, '_' . $f ); 
     420                } else { 
     421                    update_post_meta( $post_id, '_' . $f, $value ); 
    430422                } 
    431423            } 
  • widget-builder/trunk/views/metabox_link.php

    r548812 r633570  
    99    die('-1'); 
    1010 
    11 $html = ''; 
     11$html = '<input type="hidden" name="' . self::TOKEN . '_nonce" id="' . self::TOKEN . '_noonce" value="' . $nonce . '" />'; 
    1212 
    13 foreach ( $fields as $f => $label ) { 
    14     $saved_value = get_post_meta( $post_id, '_' . $f, true ); 
     13$html .= '<p>'; 
     14$html .= sprintf('<label for="%s">%s</label><br />', self::TOKEN.'_link_text', __( 'Link Text', 'widget-builder' )); 
     15$html .= sprintf('<input type="text" id="%s" name="%s" value="%s" size="32" />', self::TOKEN.'_link_text', self::TOKEN.'_link_text', esc_attr(get_post_meta($post_id, '_'.self::TOKEN.'_link_text', TRUE))); 
     16$html .= '</p>'; 
    1517 
    16     // verify nonce setup 
    17     $html .= ($html != "") ? '<br /><br />' : '<input type="hidden" name="' . self::TOKEN . '_nonce" id="' . self::TOKEN . '_noonce" value="' . $nonce . '" />'; 
     18$html .= '<p>'; 
     19$html .= sprintf('<label for="%s">%s</label><br />', self::TOKEN.'_link_url', __( 'Link URL', 'widget-builder' )); 
     20$html .= sprintf('<input type="text" id="%s" name="%s" value="%s" size="32" />', self::TOKEN.'_link_url', self::TOKEN.'_link_url', esc_attr(get_post_meta($post_id, '_'.self::TOKEN.'_link_url', TRUE))); 
     21$html .= '</p>'; 
    1822 
    19     $html .= '<label for="' . $f . '">' . $label . '</label>'; 
    20     $html .= '<input type="text" id="' . $f . '" name="' . $f . '" value="' . $saved_value . '" size="32" />'; 
    21  
    22 } 
     23$html .= '<p>'; 
     24$html .= sprintf('<label for="%s">%s</label><br />', self::TOKEN.'_link_target', __( 'Link Target', 'widget-builder' )); 
     25$html .= sprintf('<select name="%s" id="%s">', self::TOKEN.'_link_target', self::TOKEN.'_link_target'); 
     26$target = get_post_meta($post_id, '_'.self::TOKEN.'_link_target', TRUE); 
     27$html .= sprintf('<option value="">%s</option>', __('Open in current window', 'widget-builder')); 
     28$html .= sprintf('<option value="_blank" %s>%s</option>', selected($target, '_blank', FALSE), __('Open in new window', 'widget-builder')); 
     29$html .= '</select>'; 
     30$html .= '</p>'; 
    2331 
    2432echo $html; 
  • widget-builder/trunk/views/widget.php

    r584349 r633570  
    1010 
    1111// build html 
     12$target = $link_target?'target="'.$link_target.'"':''; 
    1213$widget = $before_widget; 
    1314$widget .= ( !empty( $title ) && $instance['hide_widget_title'] == 'show' ) ? $before_title . $title . $after_title : ''; 
    1415if ( !empty( $image ) ) { 
    15     $widget .= ( !empty( $link_url ) ) ? '<a href="' . $link_url . '" target="_blank"><img src="' . $image[0] . '" /></a>' : '<img src="' . $image[0] . '" />';  
     16    $widget .= ( !empty( $link_url ) ) ? '<a href="' . $link_url . '" ' . $target . '><img src="' . $image[0] . '" /></a>' : '<img src="' . $image[0] . '" />'; 
    1617} 
    1718$widget .= $content; 
    18 $widget .= ( !empty( $link_url ) ) ? '<a href="' . $link_url . '" target="_blank">' . $link_text . '</a>' : ''; 
     19$widget .= ( !empty( $link_url ) ) ? '<a href="' . $link_url . '" ' . $target . '>' . $link_text . '</a>' : ''; 
    1920$widget .= $after_widget; 
    2021 
Note: See TracChangeset for help on using the changeset viewer.