Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hello, Samuel.
- I am using the following code listed below that you wrote. It was just what I had been searching for but I am haviing some trouble getting it to work.I am creating a book club. I am using your widget code to create a widget with the following fields:
- Member name (Members name)
- Bio (Members bio)
- Links (Members links to Author websites, Facebook, Twitter etc..)
- Using your code I get the title and bio to display 100%. When I try to enter some html linking say Facebook then hit save on the widget, the hyperlink disappers? The same with entering an image address from my media library in the bio field. When I click save the html is gone?
- Ideally I would like to be able to enter in the links field a ul that I could style with a background color etc.. like,
- Authorwebsite.net
- Facebook
- Twitter
- I have been working all night on trying to figure this out. I am hoping that you could help me.
- Thanks so much in advance.
- Shepard
- class my_custom_widget extends WP_Widget {
- function __construct() {
- parent::__construct(
- 'yiw_pro_widget',
- __('My Custom Widget', 'wordpress'),
- array( 'description' => __( 'my custom widget from w.org support forums', 'wordpress' ), )
- );
- }
- public function widget( $args, $instance ) {
- $title = apply_filters( 'widget_title', $instance['title'] );
- $name = apply_filters( 'widget_title', $instance['name'] );
- $email = apply_filters( 'widget_title', $instance['email'] );
- $phone = apply_filters( 'widget_title', $instance['phone'] );
- echo $args['before_widget'];
- if ( ! empty( $title ) )
- echo $args['before_title'] . $title . $args['after_title'];
- echo "<p><strong>Name:</strong> $name</p>";
- echo "<p><strong>Email:</strong> $email</p>";
- echo "<p><strong>Phone number:</strong> $phone</p>";
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : '';
- $name = ( isset( $instance[ 'name' ] ) ) ? $instance[ 'name' ] : '';
- $email = ( isset( $instance[ 'email' ] ) ) ? $instance[ 'email' ] : '';
- $phone = ( isset( $instance[ 'phone' ] ) ) ? $instance[ 'phone' ] : '';
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e( 'Name:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" type="text" value="<?php echo esc_attr( $name ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php _e( 'Email:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'email' ); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'phone' ); ?>"><?php _e( 'Phone:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'phone' ); ?>" name="<?php echo $this->get_field_name( 'phone' ); ?>" type="text" value="<?php echo esc_attr( $phone ); ?>" />
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- $instance['name'] = ( ! empty( $new_instance['name'] ) ) ? strip_tags( $new_instance['name'] ) : '';
- $instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
- $instance['phone'] = ( ! empty( $new_instance['phone'] ) ) ? strip_tags( $new_instance['phone'] ) : '';
- return $instance;
- }
- }
- function load_my_custom_widget() {
- register_widget( 'my_custom_widget' );
- }
- add_action( 'widgets_init', 'load_my_custom_widget' );
Advertisement
Add Comment
Please, Sign In to add comment