custom press plugin has option only for custom type plain TEXT

Hi,

Custom press plugin has option only for custom type plain TEXT . There is no option for clickable link. I want to use this custom fieled for entering website URL that should be click able.

Please do for this.

  • Alexander

    We found in live chat that this doesn't work because you're trying to get this to work in a way it wasn't meant to. That custom code works great on CustomPress pages, but not in widgets created by other plugins.

    Could you please share the widget code with me? You can email it to me at contact@wpmudev.org
    - Please include my name in the subject "Alexander Rohmann"
    - Please include a link back to this thread

  • WebHostingPeople

    mh-widget.php file complete code is here:

    <?php

    /***** Register Widgets *****/

    function register_mh_widgets() {
    register_widget('mh_facebook_widget');
    register_widget('mh_custom_posts_widget');
    register_widget('mh_slider_hp_widget');
    }
    add_action('widgets_init', 'register_mh_widgets');

    /***** Facebook Likebox Widget *****/

    class mh_facebook_widget extends WP_Widget {
    function mh_facebook_widget () {
    $widget_ops = array('classname' => 'mh_facebook', 'description' => __('Widget to display a Facebook likebox in your sidebar', 'mh'));
    $this->WP_Widget('mh_facebook', __('MH Facebook Likebox', 'mh'), $widget_ops);
    }
    function widget($args, $instance) {
    extract($args);
    $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
    $facebook_url = $instance['facebook_url'];
    $width = $instance['width'];
    $height = $instance['height'];

    echo $before_widget;

    if (!empty( $title)) { echo $before_title . $title . $after_title; }
    if ($facebook_url) { ?>
    <div class="fb-like-box" data-href="<?php echo $facebook_url; ?>" data-width="<?php echo $width; ?>" data-height="<?php echo $height; ?>" data-show-faces="true" data-show-border="false" data-stream="false" data-header="false"></div>
    <?php }

    echo $after_widget;
    }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['facebook_url'] = strip_tags($new_instance['facebook_url']);
    $instance['width'] = strip_tags($new_instance['width']);
    $instance['height'] = strip_tags($new_instance['height']);
    return $instance;
    }
    function form($instance) {
    $defaults = array('title' => __('Connect with us on Facebook', 'mh'), 'facebook_url' => 'https://www.facebook.com/MHthemes', 'width' => '300', 'height' => '190');
    $instance = wp_parse_args((array) $instance, $defaults); ?>

    <p>
    <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['title']); ?>" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('facebook_url'); ?>"><?php _e('Facebook Page URL:', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['facebook_url']); ?>" name="<?php echo $this->get_field_name('facebook_url'); ?>" id="<?php echo $this->get_field_id('facebook_url'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['width']); ?>" name="<?php echo $this->get_field_name('width'); ?>" id="<?php echo $this->get_field_id('width'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['height']); ?>" name="<?php echo $this->get_field_name('height'); ?>" id="<?php echo $this->get_field_id('height'); ?>" />
    </p>
    <?php
    }
    }

    /***** Custom Posts Widget *****/

    class mh_custom_posts_widget extends WP_Widget {
    function mh_custom_posts_widget () {
    $widget_ops = array('classname' => 'mh_custom_posts', 'description' => __('Custom Posts Widget to display posts based on categories or tags', 'mh'));
    $this->WP_Widget('mh_custom_posts', __('MH Custom Posts', 'mh'), $widget_ops);
    }

    //class mh_custom_posts_widget extends WP_Widget {
    // function mh_custom_posts_widget () {
    // $widget_ops = array('classname' => 'mh_custom_posts', 'description' => __('Custom Posts Widget to display posts based on categories or tags', 'mh'));
    // $this->WP_Widget('mh_custom_posts', __('MH Custom Posts', 'mh'), $widget_ops);
    // }

    function widget($args, $instance) {
    extract($args);
    $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
    $category = isset($instance['category']) ? $instance['category'] : '';
    $tags = empty($instance['tags']) ? '' : $instance['tags'];
    $postcount = empty($instance['postcount']) ? '5' : $instance['postcount'];
    $offset = empty($instance['offset']) ? '' : $instance['offset'];
    $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0;

    if ($category) {
    $cat_url = get_category_link($category);
    $before_title = $before_title . '';
    $after_title = '
    ' . $after_title;
    }

    echo $before_widget;

    if (!empty( $title)) { echo $before_title . $title . $after_title; } ?>

    <ul class="cp-widget row clearfix">
    <?php
    $args = array('posts_per_page' => $postcount, 'cat' => $category, 'tag' => $tags, 'offset' => $offset, 'orderby' => 'date', 'ignore_sticky_posts' => $sticky);
    $counter = 1;
    $widget_loop = new WP_Query($args);
    while ($widget_loop->have_posts()) : $widget_loop->the_post(); ?>
    <li class="cp-wrap clearfix">
    <div class="cp-thumb">
    " title="<?php the_title(); ?>">
    <?php if (has_post_thumbnail()) { the_post_thumbnail('cp_small'); } else { echo '<img src="' . get_template_directory_uri() . '/images/noimage_70x53.png' . '" alt="No Picture" />'; } ?>

    </div>
    <div class="cp-data">
    <p class="cp-widget-title">" title="<?php the_title(); ?>"><?php the_title(); ?></p>
    <p class="meta"><?php $date = get_the_date(); echo $date; ?> // <?php comments_number(__('0 Comments', 'mh'), __('1 Comment', 'mh'), __('% Comments', 'mh')); ?></p>
    </div>

    <?php
    endwhile;
    wp_reset_postdata(); ?>

    <?php

    echo $after_widget;
    }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['category'] = $new_instance['category'];
    $instance['tags'] = strip_tags($new_instance['tags']);
    $instance['postcount'] = strip_tags($new_instance['postcount']);
    $instance['offset'] = strip_tags($new_instance['offset']);
    $instance['sticky'] = $new_instance['sticky'];
    return $instance;
    }
    function form($instance) {
    $defaults = array('title' => '', 'category' => '', 'tags' => '', 'postcount' => '5', 'offset' => '0', 'sticky' => 0);
    $instance = wp_parse_args((array) $instance, $defaults); ?>

    <p>
    <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['title']); ?>" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mh'); ?></label>
    <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>">
    <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mh'); ?></option>
    <?php
    $categories = get_categories(array('type' => 'post'));
    foreach($categories as $cat) {
    echo '<option value="' . $cat->cat_ID . '"';
    if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; }
    echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')';
    echo '</option>';
    }
    ?>
    </select>
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('tags'); ?>"><?php _e('Filter Posts by Tags (e.g. lifestyle):', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['tags']); ?>" name="<?php echo $this->get_field_name('tags'); ?>" id="<?php echo $this->get_field_id('tags'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Show:', 'mh'); ?></label>
    <input type="text" size="2" value="<?php echo esc_attr($instance['postcount']); ?>" name="<?php echo $this->get_field_name('postcount'); ?>" id="<?php echo $this->get_field_id('postcount'); ?>" /> <?php _e('Posts', 'mh'); ?>
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip:', 'mh'); ?></label>
    <input type="text" size="2" value="<?php echo esc_attr($instance['offset']); ?>" name="<?php echo $this->get_field_name('offset'); ?>" id="<?php echo $this->get_field_id('offset'); ?>" /> <?php _e('Posts', 'mh'); ?>
    </p>
    <p>
    <input id="<?php echo $this->get_field_id('sticky'); ?>" name="<?php echo $this->get_field_name('sticky'); ?>" type="checkbox" value="1" <?php checked('1', $instance['sticky']); ?>/>
    <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh'); ?></label>
    </p>

    <?php
    }
    }

    /***** Slider Widget (Homepage) *****/

    class mh_slider_hp_widget extends WP_Widget {
    function mh_slider_hp_widget () {
    $widget_ops = array('classname' => 'mh_slider_hp', 'description' => __('Slider widget for use on homepage templates', 'mh'));
    $this->WP_Widget('mh_slider_hp', __('MH Slider Widget (Homepage)', 'mh'), $widget_ops);
    }
    function widget($args, $instance) {
    extract($args);
    $category = isset($instance['category']) ? $instance['category'] : '';
    $tags = empty($instance['tags']) ? '' : $instance['tags'];
    $postcount = empty($instance['postcount']) ? '5' : $instance['postcount'];
    $offset = empty($instance['offset']) ? '' : $instance['offset'];
    $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0;

    echo $before_widget; ?>

    <section id="slider" class="flexslider">
    <ul class="slides">
    <?php
    $args = array('posts_per_page' => $postcount, 'cat' => $category, 'tag' => $tags, 'offset' => $offset, 'ignore_sticky_posts' => $sticky);
    $slider = new WP_query($args);
    while ($slider->have_posts()) : $slider->the_post(); ?>

  • <article class="slide-wrap">
    " title="<?php the_title(); ?>">
    <?php if (has_post_thumbnail()) { the_post_thumbnail('content'); } else { echo '<img src="' . get_template_directory_uri() . '/images/noimage_620x264.png' . '" alt="No Picture" />'; } ?>

    <!--<div class="slide-caption">-->
    <!--<div class="slide-data">-->
    <?php /*?>" title="<?php the_title(); ?>"><h2 class="slide-title"><?php the_title(); ?></h2><?php */?>
    <?php /*?><div class="slide-excerpt"><?php the_excerpt(); ?></div><?php */?>
    <!--</div>
    </div> -->
    </article>
  • <?php endwhile; wp_reset_postdata(); ?>

    </section>
    <?php

    echo $after_widget;
    }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance['category'] = $new_instance['category'];
    $instance['tags'] = strip_tags($new_instance['tags']);
    $instance['postcount'] = strip_tags($new_instance['postcount']);
    $instance['offset'] = strip_tags($new_instance['offset']);
    $instance['sticky'] = $new_instance['sticky'];
    return $instance;
    }
    function form($instance) {
    $defaults = array('category' => '', 'tags' => '', 'postcount' => '5', 'cats' => '', 'offset' => '0', 'sticky' => 0);
    $instance = wp_parse_args((array) $instance, $defaults); ?>

    <p>
    <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mh'); ?></label>
    <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>">
    <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mh'); ?></option>
    <?php
    $categories = get_categories(array('type' => 'post'));
    foreach($categories as $cat) {
    echo '<option value="' . $cat->cat_ID . '"';
    if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; }
    echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')';
    echo '</option>';
    }
    ?>
    </select>
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('tags'); ?>"><?php _e('Filter Posts by Tags (e.g. lifestyle):', 'mh'); ?></label>
    <input class="widefat" type="text" value="<?php echo esc_attr($instance['tags']); ?>" name="<?php echo $this->get_field_name('tags'); ?>" id="<?php echo $this->get_field_id('tags'); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Show:', 'mh'); ?></label>
    <input type="text" size="2" value="<?php echo esc_attr($instance['postcount']); ?>" name="<?php echo $this->get_field_name('postcount'); ?>" id="<?php echo $this->get_field_id('postcount'); ?>" /> <?php _e('Posts', 'mh'); ?>
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip:', 'mh'); ?></label>
    <input type="text" size="2" value="<?php echo esc_attr($instance['offset']); ?>" name="<?php echo $this->get_field_name('offset'); ?>" id="<?php echo $this->get_field_id('offset'); ?>" /> <?php _e('Posts', 'mh'); ?>
    </p>
    <p>
    <input id="<?php echo $this->get_field_id('sticky'); ?>" name="<?php echo $this->get_field_name('sticky'); ?>" type="checkbox" value="1" <?php checked('1', $instance['sticky']); ?>/>
    <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh'); ?></label>
    </p>

    <?php
    }
    }

    ?>

  • Jack Kitterhing

    Hi there @Drew,

    Hope you're well today, sorry about the delay.

    Currently make_clickable wouldn't be the best work around for that, somehow we need to append mailto: to the email address, I'll check with @Alexander Rohmann :slight_smile:

    In the mean time, it's also worth noting that if we do add the mailto: the email address stand a high chance of being harvested by spam bots, I'd highly recommend plain text :slight_smile:

    Thanks!

    Kind Regards
    Jack.

  • Drew

    How about another way to skin this cat... and perhaps this warrants posting under the Directory help forum, as it's the reason I'm using Custom Press:

    How about setting Directory's "Contact User" button to use an address specified by a Custom Press field, rather than the user account associated with the Directory listing?

    For a Chamber of Commerce directory, which is my use case, this would make sense, as the User is often a billing contact, where as the public-facing Contact Me e-mail is likely to be a info@mybusiness.com address.

    Drew

  • Alexander

    Hi @Drew,

    Haven't tried this, but one thought would be to just add a new regular expression condition to Jack's plugin. Something like this perhaps:

    add_filter('ct_shortcode','ct_make_clickable_callback',10,3);
    function ct_make_clickable_callback($result, $atts, $content) {
    
        if(preg_match('(http://|https://)',$result)) {
    	    $result = make_clickable($result);
        }
    
        if(preg_match('^.*@.*\.*.$',$result)) {
          $result = '<a href="mailto:'.strtolower($result).'" rel="nofollow">'.$result.'</a>';
        }
    
        return $result;
    }

    make_clickable itself doesn't really work as there's no way to add more formatting.

    Best regards,

  • Sally

    Brilliant Jack, Thanks :slight_smile:

    So, just done this, and just to check, is this a nofollow link? (Please see screenshot) Because when I read up on nofollow links (not that I know a lot about them), I thought the rel="nofollow" went like this;

    <a rel="nofollow" href="http etc etc

    but this link seems to have the nofollow code stuck somewhere in the middle?

    https://www.facebook.com/pages/Poo-Ch/559695054124889?ref=hl

    Will it still work? Don't want to get into trouble with Google!

    Thanks

    Sally

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.