开发者

I'm developing a Wordpress Plugin and I need to create a Page with a form inside my plugin code

I am developing a Plugin.

I've developed the core of my plugin, I've also developed a Widget that I need to use with my plugin, but now I don't know where else to find information.

What I need to do, is this: in my Plugin's Widget I want to put a link "Register here!!!", and when the u开发者_运维技巧ser clicks there take him to a page like http://mysite.com/my_plugin_register

And there display a form so the user can register.

Is there any action hook to do this? Where can I find any example?


To get your widget to work you will create a class for your widget that extends the WP_Widget class. Example is below:

class My_Widget extends WP_Widget
{
  function My_Widget()
  {
    $this->WP_Widget( false, __( 'My Widget', 'my_widget_i18n') );
  }

  /* This is where the widget content is printed. */
  function widget( $args, $instance )
  {
    extract( $args );

    $title = empty( $instance[ 'title' ] ) ? ' ' : apply_filters( 'widget_title', $instance[ 'title'] );

    echo $before_widget;

    if( !empty( $title ) )
      echo $before_title . $title . $after_title;

    echo '<a href="http://mysite.com/my_plugin_register">My Form</a>';

    echo $after_widget;
  }

  /* Use this to update any widget options */
  function update( $new_instance, $old_instance)
  {
    $instance = $old_instance;
    $instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
    return $instance;
  }

  /* Use this to create the form for the widget options */
  function form( $instance )
  {
    $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    $title = strip_tags( $instance[ 'title' ] );
    echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'events_calendar' ) . ': <input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . attribute_escape( $title ) . '" /></label></p>';
  }
}

You can find more information on WP_Widget at the widgets API page

To create your page you should use a shortcode and put your form in the function for that.

/* This will write the form that you need to right */
function my_shortcode( $attrs )
{
  ?>
  <form>
    <input type="text" />
    <input type="submit" />
  </form>
  <?php
}
add_shortcode( 'my_shortcode', 'my_shortcode' );

You will then in the Wordpress Dashboard create a page with the slug 'my_plugin_register' and add the following content to it

[my_shortcode]

Here is the shortcode API page for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜