Advertisement
estoyarto

zenva wishlist

Apr 28th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.47 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. *Plugin Name: Zenva wishlist
  5. *Plugin URI: http://localhost
  6. *Description: wishlist
  7. *Version: 1.0
  8. *Author: Erik & zenva
  9. *Author URI: http://localhost
  10. *License: GPL2
  11. */
  12.  
  13. add_action('widgets_init','zvawp_widget_init');
  14. add_action('wp','zvawp_init');//permite cargar archivo externo
  15.  
  16. add_action ('admin_init','zvawp_admin_init');
  17. add_action('admin_menu', 'zvawp_plugin_menu');
  18. add_action('wp_ajax_zvawp_add_wishlist','zvawp_add_wishlist_process');//wp_ajax_ prefijo para request ajax + el nombre de la funcion
  19.  
  20.  
  21.  
  22.  
  23.  
  24. function zvawp_init(){
  25.  
  26. wp_register_script('zenvawishlist-js', plugins_url('/zenvawishlist.js', __FILE__) , array('jquery'));
  27.  
  28. //cargo el js
  29. wp_enqueue_script('jquery');
  30. wp_enqueue_script('zenvawishlist-js');
  31.  
  32. }
  33.  
  34. function zvawp_add_wishlist_process(){
  35.  
  36. echo "-hola-";
  37. exit();
  38.  
  39. }
  40. ///inicio el widget
  41.  
  42. function zvawp_widget_init(){
  43.     register_widget(Zvawp_Widget);
  44.        
  45. }
  46.  
  47.  
  48.  
  49. class Zvawp_Widget extends WP_Widget{
  50.  
  51.     function Zvawp_Widget(){
  52.         $widget_options= array(
  53.         'classname' =>'zvawp_class',
  54.         'description'=> 'Add Items to Wishlist'
  55.            
  56.         );
  57.        
  58.         $this->WP_Widget('zvawp_id', 'wishlist',$widget_options);
  59.         }
  60.  
  61.         function form ($instance){
  62.         $defaults = array ('title' =>'wishlist');
  63.         $instance = wp_parse_args ((array) $instance, $defaults);
  64.         $title    = esc_attr($instance['title']);
  65.         echo '<p> Title <input class="widefat" name="'.$this->get_field_name('title').'" type="text" value="'.$title.'"/></p>';
  66.        
  67.        
  68.         }
  69.  
  70.         function update($new_instance, $old_instance){
  71.        
  72.         $instance = $old_instance;
  73.         $instance['title'] = strip_tags($new_instance['title']);
  74.         return $instance;
  75.        
  76.        }
  77.  
  78.         function widget ($args, $instance){
  79.         extract($args);
  80.         $title = apply_filters('widget_title', $instance['title']);
  81.         //si es un post solitario
  82.         if(is_single()){
  83.         echo $before_widget;
  84.         echo $before_title . $title . $after_title;
  85.         echo '<span id="zvawp_add_wishist_div"><a id="zvawp_add_wishlist" href=""> Add to wishlist </a></span>';
  86.         echo $after_widget;
  87.            
  88.         }
  89.        
  90.         }
  91.  
  92.  
  93. }
  94.  
  95. //opciones del admin
  96.  
  97. function zvawp_plugin_menu(){
  98.  
  99. add_options_page('zenva_wishlist Options', 'Zenva Wishlist','manage_options','zvawp','zvawp_plugin_options');  
  100.        
  101. }
  102.  
  103. function zvawp_admin_init(){
  104.  
  105. register_setting('zvawp-group','zvawp_dashboard_title',NULL);
  106. register_setting('zvawp-group','zvawp_number_of_items',NULL);
  107.    
  108.    
  109. }
  110.  
  111. function zvawp_plugin_options(){
  112.  
  113. ?>
  114.  
  115. <div class="wrap">
  116.     <?php screen_icon(); ?>
  117.         <h2> Zenva Wishlist </h2>
  118.                 <form action="options.php" method="post">
  119.                 <?php settings_fields('zvawp-group'); ?>
  120.                 <?php @do_settings_fields('zvawp-group'); ?>
  121.                         <table cass="form-table">
  122.                             <tr valign="top">
  123.                                 <th scope="row"> <label for="zvawp_dashboard_title">Dashboard widget title </label></th>
  124.                                 <td>
  125.                                 <input type="text" name="zvawp_dashboard_title" id="dashboard_title" value="<?php echo get_option('zvawp_dashboard_title'); ?>" />
  126.                                 <br/> <small>Titulo </small>
  127.                                 </td>
  128.                                
  129.                             </tr>
  130.                             <tr valign="top">
  131.                                 <th scope="row"> <label for="zvawp_number_of_items">Number of items </label></th>
  132.                                 <td>
  133.                                 <input type="text" name="zvawp_number_of_items" id="dashboard_title" value="<?php echo get_option('zvawp_number_of_items'); ?>" />
  134.                                 <br/> <small>Cantidad de items </small>
  135.                                 </td>
  136.                            
  137.                             </tr>
  138.                         </table> <?php @submit_button(); ?>
  139.  
  140.                 </form>
  141.         </div>
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     <?php
  149. }
  150.  
  151.  
  152.  
  153. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement