/includes/Display/Shortcodes.php

  1. <?php 
  2.  
  3. final class NF_Display_Shortcodes 
  4. public function __construct() 
  5. add_shortcode( 'nf_preview', array( $this, 'display_form_preview' ) ); 
  6. add_shortcode( 'ninja_form', array( $this, 'display_form_front_end' ) ); 
  7. add_shortcode( 'ninja_forms', array( $this, 'display_form_front_end' ) ); 
  8. add_shortcode( 'ninja_forms_display_form', array( $this, 'display_form_front_end' ) ); 
  9.  
  10. public function display_form_preview( $atts = array() ) 
  11. if( ! isset( $atts[ 'id' ] ) ) return $this->display_no_id(); 
  12.  
  13. ob_start(); 
  14. Ninja_Forms()->display( $atts['id'], TRUE ); 
  15. return ob_get_clean(); 
  16.  
  17. public function display_form_front_end( $atts = array() ) 
  18. if( ! isset( $atts[ 'id' ] ) ) return $this->display_no_id(); 
  19.  
  20. ob_start(); 
  21. Ninja_Forms()->display( $atts['id'] ); 
  22. return ob_get_clean(); 
  23.  
  24. /** 
  25. * TODO: Extract output to template files. 
  26. * @return string 
  27. */ 
  28. private function display_no_id() 
  29. $output = __( 'Notice: Ninja Forms shortcode used without specifying a form.', 'ninja-forms' ); 
  30.  
  31. // TODO: Maybe support filterable permissions. 
  32. if( ! current_user_can( 'manage_options' ) ) return "<!-- $output -->"; 
  33.  
  34. // TODO: Log error for support reference. 
  35. // TODO: Maybe display notice if not logged in. 
  36. trigger_error( __( 'Ninja Forms shortcode used without specifying a form.', 'ninja-forms' ) ); 
  37.  
  38. return "<div style='border: 3px solid red; padding: 1em; margin: 1em auto;'>$output</div>"; 
.