Ninja_Forms_Widget

Adds Ninja Forms widget.

Defined (1)

The class is defined in the following location(s).

/deprecated/includes/widget.php  
  1. class Ninja_Forms_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Register widget with WordPress. 
  5. */ 
  6. public function __construct() { 
  7. parent::__construct( 
  8. 'ninja_forms_widget', // Base ID 
  9. 'Ninja Forms Widget', // Name 
  10. array( 'description' => __( 'Ninja Forms Widget', 'ninja-forms' ), ) // Args 
  11. ); 
  12.  
  13. /** 
  14. * Front-end display of widget. 
  15. * @see WP_Widget::widget() 
  16. * @param array $args Widget arguments. 
  17. * @param array $instance Saved values from database. 
  18. */ 
  19. public function widget( $args, $instance ) { 
  20. extract( $args ); 
  21. $form_id = $instance['form_id']; 
  22. $form_row = ninja_forms_get_form_by_id( $form_id ); 
  23. $form_data = $form_row['data']; 
  24. if ( isset ( $form_data['form_title'] ) ) { 
  25. $title = $form_data['form_title']; 
  26. } else { 
  27. $title = ''; 
  28.  
  29. $title = apply_filters( 'widget_title', $title ); 
  30. $display_title = $instance['display_title']; 
  31.  
  32. echo $before_widget; 
  33. if ( ! empty( $title ) AND $display_title == 1 ) 
  34. echo $before_title . $title . $after_title; 
  35. ninja_forms_display_form( $form_id ); 
  36. echo $after_widget; 
  37.  
  38. /** 
  39. * Sanitize widget form values as they are saved. 
  40. * @see WP_Widget::update() 
  41. * @param array $new_instance Values just sent to be saved. 
  42. * @param array $old_instance Previously saved values from database. 
  43. * @return array Updated safe values to be saved. 
  44. */ 
  45. public function update( $new_instance, $old_instance ) { 
  46.  
  47. $instance = array(); 
  48. $instance['form_id'] = $new_instance['form_id']; 
  49. $instance['display_title'] = $new_instance['display_title']; 
  50.  
  51. return $instance; 
  52.  
  53. /** 
  54. * Back-end widget form. 
  55. * @see WP_Widget::form() 
  56. * @param array $instance Previously saved values from database. 
  57. */ 
  58. public function form( $instance ) { 
  59. if( isset( $instance['form_id'] ) ) { 
  60. $form_id = $instance['form_id']; 
  61. }else{ 
  62. $form_id = ''; 
  63.  
  64. if( isset( $instance['display_title'] ) ) { 
  65. $display_title = $instance['display_title']; 
  66. }else{ 
  67. $display_title = 0; 
  68.  
  69. ?> 
  70. <p> 
  71. <label> 
  72. <?php _e( 'Display Title', 'ninja-forms' ); ?> 
  73. <input type="hidden" value="0" name="<?php echo $this->get_field_name( 'display_title' ); ?>"> 
  74. <input type="checkbox" value="1" id="<?php echo $this->get_field_id( 'display_title' ); ?>" name="<?php echo $this->get_field_name( 'display_title' ); ?>" <?php checked( $display_title, 1 );?>> 
  75. </label> 
  76. </p> 
  77. <p> 
  78. <select id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>"> 
  79. <option value="0">-- <?php _e('None', 'ninja-forms');?></option> 
  80. <?php 
  81. $all_forms = ninja_forms_get_all_forms(); 
  82.  
  83. foreach($all_forms as $form) { 
  84. $title = $form['data']['form_title']; 
  85. $id = $form['id']; 
  86. ?> 
  87. <option value = "<?php echo $id;?>" <?php selected( $id, $form_id );?>> 
  88. <?php echo $title;?> 
  89. </option> 
  90. <?php 
  91. ?> 
  92. </select> 
  93. </p> 
  94.  
  95. <?php 
  96.  
  97. } // class Foo_Widget