Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- *Plugin Name: Zenva wishlist
- *Plugin URI: http://localhost
- *Description: wishlist
- *Version: 1.0
- *Author: Erik & zenva
- *Author URI: http://localhost
- *License: GPL2
- */
- add_action('widgets_init','zvawp_widget_init');
- add_action('wp','zvawp_init');//permite cargar archivo externo
- add_action ('admin_init','zvawp_admin_init');
- add_action('admin_menu', 'zvawp_plugin_menu');
- add_action('wp_ajax_zvawp_add_wishlist','zvawp_add_wishlist_process');//wp_ajax_ prefijo para request ajax + el nombre de la funcion
- function zvawp_init(){
- wp_register_script('zenvawishlist-js', plugins_url('/zenvawishlist.js', __FILE__) , array('jquery'));
- //cargo el js
- wp_enqueue_script('jquery');
- wp_enqueue_script('zenvawishlist-js');
- }
- function zvawp_add_wishlist_process(){
- echo "-hola-";
- exit();
- }
- ///inicio el widget
- function zvawp_widget_init(){
- register_widget(Zvawp_Widget);
- }
- class Zvawp_Widget extends WP_Widget{
- function Zvawp_Widget(){
- $widget_options= array(
- 'classname' =>'zvawp_class',
- 'description'=> 'Add Items to Wishlist'
- );
- $this->WP_Widget('zvawp_id', 'wishlist',$widget_options);
- }
- function form ($instance){
- $defaults = array ('title' =>'wishlist');
- $instance = wp_parse_args ((array) $instance, $defaults);
- $title = esc_attr($instance['title']);
- echo '<p> Title <input class="widefat" name="'.$this->get_field_name('title').'" type="text" value="'.$title.'"/></p>';
- }
- function update($new_instance, $old_instance){
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- return $instance;
- }
- function widget ($args, $instance){
- extract($args);
- $title = apply_filters('widget_title', $instance['title']);
- //si es un post solitario
- if(is_single()){
- echo $before_widget;
- echo $before_title . $title . $after_title;
- echo '<span id="zvawp_add_wishist_div"><a id="zvawp_add_wishlist" href=""> Add to wishlist </a></span>';
- echo $after_widget;
- }
- }
- }
- //opciones del admin
- function zvawp_plugin_menu(){
- add_options_page('zenva_wishlist Options', 'Zenva Wishlist','manage_options','zvawp','zvawp_plugin_options');
- }
- function zvawp_admin_init(){
- register_setting('zvawp-group','zvawp_dashboard_title',NULL);
- register_setting('zvawp-group','zvawp_number_of_items',NULL);
- }
- function zvawp_plugin_options(){
- ?>
- <div class="wrap">
- <?php screen_icon(); ?>
- <h2> Zenva Wishlist </h2>
- <form action="options.php" method="post">
- <?php settings_fields('zvawp-group'); ?>
- <?php @do_settings_fields('zvawp-group'); ?>
- <table cass="form-table">
- <tr valign="top">
- <th scope="row"> <label for="zvawp_dashboard_title">Dashboard widget title </label></th>
- <td>
- <input type="text" name="zvawp_dashboard_title" id="dashboard_title" value="<?php echo get_option('zvawp_dashboard_title'); ?>" />
- <br/> <small>Titulo </small>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row"> <label for="zvawp_number_of_items">Number of items </label></th>
- <td>
- <input type="text" name="zvawp_number_of_items" id="dashboard_title" value="<?php echo get_option('zvawp_number_of_items'); ?>" />
- <br/> <small>Cantidad de items </small>
- </td>
- </tr>
- </table> <?php @submit_button(); ?>
- </form>
- </div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement