NewFormTemplates.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. class NF_AJAX_REST_NewFormTemplates extends NF_AJAX_REST_Controller
  3. {
  4. protected $action = 'nf_new_form_templates';
  5. /**
  6. * GET new-form-templates/
  7. * @return array [ $new_form_templates ]
  8. */
  9. public function get()
  10. {
  11. $templates = Ninja_Forms()->config( 'NewFormTemplates' );
  12. usort( $templates, array( $this, 'cmp' ) );
  13. array_unshift( $templates, array(
  14. 'id' => 'new',
  15. 'title' => __( 'Blank Form', 'ninja-forms' ),
  16. 'template-desc' => __( 'The blank form allows you to create any type of form using our drag & drop builder.', 'ninja-forms' ),
  17. 'type' => 'default'
  18. ) );
  19. return array_values( $templates ); // Remove keys so that the JSON is an array.
  20. }
  21. /**
  22. * Comparison function used to sort templates alphabetically by title
  23. * @since 3.2.22
  24. * @param array $a item being compared
  25. * @param array $b item being compared
  26. * @return int
  27. */
  28. private function cmp( $a, $b )
  29. {
  30. return strcmp( $a[ 'title' ], $b[ 'title' ] );
  31. }
  32. }