/deprecated/includes/widget.php

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