NF_WPCLI_NinjaFormsCommand

The Ninja Forms WP-CLI Command.

Defined (1)

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

/includes/WPCLI/NinjaFormsCommand.php  
  1. class NF_WPCLI_NinjaFormsCommand extends WP_CLI_Command 
  2. /** 
  3. * Display Ninja Forms Information 
  4. * @subcommand info 
  5. */ 
  6. function info() 
  7. $this->peeking_ninja(); 
  8. WP_CLI::success( 'Welcome to the Ninja Forms WP-CLI Extension!' ); 
  9. WP_CLI::line( '' ); 
  10. WP_CLI::line( '- Ninja Forms Version: ' . Ninja_Forms::VERSION ); 
  11. WP_CLI::line( '- Ninja Forms Directory: ' . Ninja_Forms::$dir ); 
  12. WP_CLI::line( '- Ninja Forms Public URL: ' . Ninja_Forms::$url ); 
  13. WP_CLI::line( '' ); 
  14.  
  15. /** 
  16. * Creates a Form 
  17. * ## OPTIONS 
  18. * <title> 
  19. * : The form title. 
  20. * ## EXAMPLES 
  21. * wp ninja-forms form "My New Form" 
  22. * @synopsis <title> 
  23. * @subcommand form 
  24. * @alias create-form 
  25. */ 
  26. public function create_form( $args, $assoc_args ) 
  27. list( $title ) = $args; 
  28.  
  29. $form = Ninja_Forms()->form()->get(); 
  30. $form->update_setting( 'title', $title ); 
  31. $form->save(); 
  32.  
  33. /** 
  34. * @subcommand list 
  35. * @alias list-forms 
  36. */ 
  37. public function list_forms( $args, $assoc_args ) 
  38. foreach( Ninja_Forms()->form()->get_forms() as $form ) { 
  39. WP_CLI::line( '#' . $form->get_id() . ' - ' . $form->get_setting( 'title' ) ); 
  40.  
  41. /** 
  42. * @synopsis <id> 
  43. * @subcommand get 
  44. * @alias get-form 
  45. */ 
  46. public function get_form( $args, $assoc_args ) 
  47. list( $id ) = $args; 
  48.  
  49. $form = Ninja_Forms()->form( $id )->get(); 
  50.  
  51. WP_CLI::line( '#' . $form->get_id() . ' - ' . $form->get_setting( 'title' ) ); 
  52.  
  53. foreach( Ninja_Forms()->form( $id )->get_fields() as $field ) { 
  54.  
  55. $key = $field->get_setting( 'key' ); 
  56. $label = $field->get_setting( 'label' ); 
  57.  
  58. if( ! $key ) $key = strtolower( str_replace( ' ', '', $label ) ); 
  59.  
  60. WP_CLI::line( "'$key': $label" ); 
  61.  
  62. /** 
  63. * Installs mock form data 
  64. */ 
  65. public function mock() 
  66. $mock_data = new NF_Database_MockData(); 
  67.  
  68. $mock_data->form_contact_form_1(); 
  69. $mock_data->form_contact_form_2(); 
  70. $mock_data->form_email_submission(); 
  71. $mock_data->form_long_form(); 
  72.  
  73. private function peeking_ninja() 
  74. $output = file_get_contents( Ninja_Forms::$dir . 'includes/Templates/wpcli-header-art.txt' ); 
  75. WP_CLI::line( $output ); 
  76.  
  77. } // END CLASS NF_WPCLI_NinjaFormsCommand