Advertisement
tanim

Multiple Checkbox Widget

Dec 5th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.44 KB | None | 0 0
  1.  <?php
  2.         error_reporting('E_ALL');
  3.         /**
  4.          * Created by PhpStorm.
  5.          * User: User
  6.          * Date: 12/4/13
  7.          * Time: 5:08 PM
  8.          */
  9.         // Creating the widget
  10.         class wplinkedinFullProfileResumeWidget extends WP_Widget {
  11.  
  12.             public function __construct() {
  13.                 add_action( 'widgets_init', array($this,'wplnFullResume_load_widget' ));
  14.                 parent::__construct(
  15.                 // Base ID of your widget
  16.                     'wplinkedinFullProfileResumeWidget',
  17.  
  18.                     // Widget name will appear in UI
  19.                     __('Linkedin Full Profile Info Display', 'wplnFullResume_widget_domain'),
  20.  
  21.                     // Widget description
  22.                     array( 'description' => __( 'Linkedin Full Profile Info Display in Widget', 'wplnFullResume_widget_domain' ), )
  23.                 );
  24.             }
  25.  
  26.             // Register and load the widget
  27.             public function wplnFullResume_load_widget() {
  28.                 register_widget( 'wplinkedinFullProfileResumeWidget' );
  29.             }
  30.  
  31.             // Creating widget front-end
  32.              //This is where the action happens
  33.             public function widget( $args, $instance ) {
  34.                 $title = apply_filters( 'widget_title', $instance['title'] );
  35.                 $infotype = $instance['checktype'];
  36.                 var_dump($infotype);
  37.                 // before and after widget arguments are defined by themes
  38.                 echo $args['before_widget'];
  39.                 if ( ! empty( $title ) )
  40.                     echo $args['before_title'] . $title . $args['after_title'];
  41.  
  42.                 // This is where you run the code and display the output
  43.  
  44.                 $className = 'linkedinUserDataRendersimple';
  45.                 $render_str = 'render_'.$infotype;
  46.  
  47.                 require_once(plugin_dir_path(__DIR__).'/templates/simple.php');
  48.  
  49.                 $wplinkedinUserDataRender = new $className();
  50.  
  51.                 $html = '<div class="cblinkedinwrapper simple">';
  52.                 if (method_exists($wplinkedinUserDataRender, $render_str)){
  53.                     $rendered_data = call_user_func(array($wplinkedinUserDataRender, $render_str));
  54.                     $html .= $rendered_data;
  55.                     $html .= '<div class="clear"></div>';
  56.                 }
  57.                 $html .= '</div>';
  58.                 echo $rendered_data;
  59.                 echo $args['after_widget'];
  60.             }
  61.  
  62.             // Widget Backend
  63.             function form($instance) {
  64.                 $wplinkedinSortableItem = (array)get_option('wplinkedinresume');
  65.                 //var_dump($wplinkedinSortableItem['linkedinSortableItem']);
  66.                 $sortable_item  = array(
  67.                     'about'             => 'About Me',
  68.                     'summary'           => 'Summary',
  69.                     'experience'        => 'Experience',
  70.                     'education'         => 'Education',
  71.                     'skills'            => 'Skills',
  72.                     'publications'      => 'Publications',
  73.                     'volunteer'         => 'Volunteer & Causes',
  74.                     'recommendations'   => 'Recommendations',
  75.                     'language'          => 'Languages',
  76.                     'certifications'    => 'Certifications',
  77.                     'linkedinStatus'    => 'Publish Recent Status'
  78.                 );
  79.  
  80.                 $defaults = array( 'title' => 'Linkedin Profile', 'checktype' => array() );
  81.                 $instance = wp_parse_args( (array) $instance, $defaults );
  82.  
  83.                 $title = $instance['title'];
  84.                 $checktype = $instance['checktype'];
  85.  
  86.                 var_dump($checktype);
  87.  
  88.                 $output = '<p>Title:  <input class="widefat" name="'.$this->get_field_name( 'title' ).'" type="text" value="'.esc_attr( $title ).'"/>';
  89.                 $output .= '<p class="paragraph_div">';
  90.                 foreach($wplinkedinSortableItem['linkedinSortableItem'] as $sortKey => $sortVal){
  91.                     $output .= '<label for="'. $this->get_field_id('checktype').$sortKey .'"> '. $sortable_item[$sortKey] .' </label>';
  92.                     $output .= '<input class="checktype_checkbox" type="checkbox" id="'.$this->get_field_id('checktype').$sortKey .'" name="checktype['.$sortKey.']" value="1"';
  93.                     $output .= checked(1, $checktype[$sortKey]);var_dump($checktype[$sortKey]);
  94.                     //$output .= ($checktype[$sortKey] == 1) ? 'checked="checked"' : '';
  95.                     $output .= ' /><br>';
  96.  
  97.                 }
  98.                 $output .= '</ul>';
  99.                 $output .= '</p>';
  100.                 echo $output;
  101.                 echo '<style type="text/css">.checktype_checkbox{float:right;} .paragraph_div{width:150px;}</style>';
  102.             }
  103.  
  104.             // Updating widget replacing old instances with new
  105.             public function update($new_instance, $old_instance) {
  106.                 //var_dump($new_instance);
  107.                 $instance = $old_instance;
  108.                 $instance['title']      = strip_tags( $new_instance['title'] );
  109.                 $instance['checktype']  =  $new_instance['checktype'] ;
  110. //                for($i=0; $i<sizeof($instance['checktype']); $i++) {
  111. //                    $instance['checktype'][$i]['selected'] = (int)$new_instance['checktype'][$i]['selected'];
  112. //              }
  113.                 return $instance;
  114.             }
  115.         } // Class wpb_widget ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement