/deprecated/includes/shortcode.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. function ninja_forms_shortcode( $atts ) { 
  4. if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) { 
  5. $return = '[ninja_forms_display_form'; 
  6. if ( is_array ( $atts ) ) { 
  7. foreach ( $atts as $key => $value ) { 
  8. $return .= ' ' . $key . '=' . $value; 
  9. $return .= ']'; 
  10. return $return; 
  11. } else { 
  12. $form = ninja_forms_return_echo( 'ninja_forms_display_form', $atts['id'] ); 
  13. return $form; 
  14.  
  15. add_shortcode( 'ninja_forms', 'ninja_forms_shortcode' ); 
  16. add_shortcode( 'ninja_form', 'ninja_forms_shortcode' ); 
  17. /** 
  18. * Old Ninja Forms shortcode 
  19. */ 
  20. add_shortcode( 'ninja_forms_display_form', 'ninja_forms_shortcode' ); 
  21.  
  22. function ninja_forms_field_shortcode( $atts ) { 
  23. global $ninja_forms_processing; 
  24. $field_id = $atts['id']; 
  25. if ( is_object ( $ninja_forms_processing ) ) { 
  26. $value = $ninja_forms_processing->get_field_value( $field_id ); 
  27. $value = apply_filters( 'ninja_forms_field_shortcode', $value, $atts ); 
  28. if( is_array( $value ) ) { 
  29. $value = implode( ', ', $value ); 
  30. } else { 
  31. $value = ''; 
  32. return nf_wp_kses_post_deep( $value ); 
  33. add_shortcode( 'ninja_forms_field', 'ninja_forms_field_shortcode' ); 
  34.  
  35. function ninja_forms_sub_date_shortcode( $atts ) { 
  36. global $ninja_forms_processing; 
  37. if( isset( $atts['format'] ) ) { 
  38. $date_format = $atts['format']; 
  39. }else{ 
  40. $date_format = 'm/d/Y'; 
  41. $date = date( $date_format ); 
  42. return $date; 
  43. add_shortcode( 'ninja_forms_sub_date', 'ninja_forms_sub_date_shortcode' ); 
  44.  
  45.  
  46. function ninja_forms_pre_process_shortcode($content) { 
  47. global $shortcode_tags; 
  48. // Remove our previously registered shortcode. 
  49. //remove_shortcode( 'ninja_forms_display_form' ); 
  50. // Backup current registered shortcodes and clear them all out 
  51. $current_shortcodes = $shortcode_tags; 
  52. $shortcode_tags = array(); 
  53. add_shortcode( 'ninja_forms_display_form', 'ninja_forms_shortcode' ); 
  54. // Do the shortcode (only the one above is registered) 
  55. $content = do_shortcode($content); 
  56. // Put the original shortcodes back 
  57. $shortcode_tags = $current_shortcodes; 
  58. return $content; 
  59. add_filter('the_content', 'ninja_forms_pre_process_shortcode', 9999); 
  60.  
  61. /** 
  62. * Parse the [nf_sub_seq_num] shortcode 
  63. *  
  64. * @since 2.8.4 
  65. * @return string $setting 
  66. */ 
  67. function nf_parse_sub_seq_num_shortcode( $setting, $setting_name = '', $id = '' ) { 
  68. global $ninja_forms_processing; 
  69.  
  70. if ( ! is_object( $ninja_forms_processing ) ) 
  71. return $setting; 
  72.  
  73. $sub_id = $ninja_forms_processing->get_form_setting( 'sub_id' ); 
  74. if ( empty ( $sub_id ) ) 
  75. return $setting; 
  76.  
  77. $seq_num = Ninja_Forms()->sub( $sub_id )->get_seq_num(); 
  78.  
  79. $setting = str_replace( '[nf_sub_seq_num]', $seq_num, $setting ); 
  80. return $setting; 
  81.  
  82. add_filter( 'nf_email_notification_process_setting', 'nf_parse_sub_seq_num_shortcode', 10, 3 ); 
  83. add_filter( 'nf_success_msg', 'nf_parse_sub_seq_num_shortcode', 10, 2 ); 
  84.  
  85. /** 
  86. * Shortcode for ninja_forms_all_fields 
  87. * 
  88. * @since 2.8 
  89. * @return string $content 
  90. */ 
  91. function nf_all_fields_shortcode( $atts, $content = '' ) { 
  92. global $ninja_forms_fields, $ninja_forms_processing; 
  93.  
  94. if ( ! isset ( $ninja_forms_processing ) ) 
  95. return false; 
  96.  
  97. $html = isset ( $atts['html'] ) ? $atts['html'] : 1; 
  98.  
  99. if ( 1 == $html ) { 
  100. // Generate our "all fields" table for use as a JS var. 
  101. $field_list = '<table><tbody>'; 
  102. } else { 
  103. $field_list = ''; 
  104. foreach ( $ninja_forms_processing->get_all_fields() as $field_id => $user_value ) { 
  105. if ( ! $user_value ) 
  106. continue; 
  107.  
  108. $field = $ninja_forms_processing->get_field_settings( $field_id ); 
  109. $type = $field['type']; 
  110. if ( ! isset ( $ninja_forms_fields[ $type ] ) || ! $ninja_forms_fields[ $type ]['process_field'] ) 
  111. continue; 
  112.  
  113. $value = apply_filters( 'nf_all_fields_field_value', ninja_forms_field_shortcode( array( 'id' => $field_id ) ), $field_id ); 
  114.  
  115. if( isset( $field[ 'data' ][ 'admin_label' ] ) && $field[ 'data' ][ 'admin_label' ] ) { 
  116. $label = $field[ 'data' ][ 'admin_label' ]; 
  117. } else { 
  118. $label = $field['data']['label']; 
  119. $label = strip_tags( apply_filters( 'nf_all_fields_field_label', $label, $field_id ) ); 
  120.  
  121. if ( 1 == $html ) { 
  122. $field_list .= '<tr id="ninja_forms_field_' . $field_id . '"><td>' . $label .':</td><td>' . $value . '</td></tr>'; 
  123. } else { 
  124. $field_list .= $label . ' - ' . $value . "\r\n"; 
  125.  
  126. if ( 1 == $html ) 
  127. $field_list .= '</tbody></table>'; 
  128.  
  129. return apply_filters( 'nf_all_fields_table', $field_list, $ninja_forms_processing->get_form_ID() ); 
  130.  
  131.  
  132. add_shortcode( 'ninja_forms_all_fields', 'nf_all_fields_shortcode' ); 
  133.  
  134. /** 
  135. * Parse our [ninja_forms_field] shortcode, just incase the shortcode parser screwed up. 
  136. * 
  137. * @since 2.8.4 
  138. * @return content 
  139. */ 
  140. function nf_parse_fields_shortcode( $content ) { 
  141. global $ninja_forms_processing; 
  142.  
  143. if ( ! isset ( $ninja_forms_processing ) ) 
  144. return $content; 
  145.  
  146. if ( is_array ( $content ) ) 
  147. return $content; 
  148.  
  149. $matches = array(); 
  150. $pattern = '\[(\[?)(ninja_forms_field|ninja_forms_all_fields)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)'; 
  151.  
  152. preg_match_all('/'.$pattern.'/s', $content, $matches); 
  153.  
  154. if ( is_array( $matches ) && ! empty( $matches[2] ) ) { 
  155. foreach ( $matches[2] as $key => $shortcode ) { 
  156.  
  157. if ( 'ninja_forms_field' == $shortcode ) { 
  158. if ( isset ( $matches[3][ $key ] ) ) { 
  159. $atts = shortcode_parse_atts( $matches[3][ $key ] ); 
  160. $id = $atts['id']; 
  161. $value = $ninja_forms_processing->get_field_value( $id ); 
  162. if( is_array( $value ) ) { 
  163. $value = implode( ', ', $value ); 
  164. $content = str_replace( $matches[0][ $key ], $value, $content ); 
  165. } else if ( 'ninja_forms_all_fields' == $shortcode ) { 
  166. if ( isset ( $matches[3][ $key ] ) ) { 
  167. $atts = shortcode_parse_atts( $matches[3][ $key ] ); 
  168. $content = str_replace( $matches[0][ $key ], nf_all_fields_shortcode( $atts, $content ), $content ); 
  169. return $content; 
  170.  
  171. /** 
  172. * Shortcode for ninja_forms_all_fields 
  173. * 
  174. * @since 2.8 
  175. * @return string sub_limit_number 
  176. */ 
  177. function ninja_forms_display_sub_limit_number_shortcode( $atts ) { 
  178. $form = Ninja_Forms()->form( $atts[ 'id' ] ); 
  179.  
  180. if ( isset( $form->settings[ 'sub_limit_number' ] ) ) { 
  181. return $form->settings[ 'sub_limit_number' ]; 
  182. else { 
  183. return null; 
  184.  
  185. add_shortcode( 'ninja_forms_display_sub_limit_number', 'ninja_forms_display_sub_limit_number_shortcode' ); 
  186.  
  187. /** 
  188. * Shortcode for ninja_forms_display_sub_number 
  189. * 
  190. * @since 2.8 
  191. * @return int nf_get_sub_count() 
  192. * @see nf_get_sub_count() 
  193. */ 
  194. function ninja_forms_display_sub_number_shortcode( $atts ) { 
  195. $sub_count = nf_get_sub_count( $atts[ 'id' ] ); 
  196. return $sub_count; 
  197.  
  198. add_shortcode( 'ninja_forms_display_sub_number', 'ninja_forms_display_sub_number_shortcode' ); 
  199.  
  200. /** 
  201. * Shortcode for ninja_forms_display_sub_number_remaining 
  202. * 
  203. * @since 2.8 
  204. * @return int 
  205. * @see nf_get_sub_count() 
  206. */ 
  207. function ninja_forms_display_sub_number_remaining_shortcode( $atts ) { 
  208. $form = Ninja_Forms()->form($atts[ 'id' ]); 
  209.  
  210. if( isset( $form->settings[ 'sub_limit_number' ] ) ) { 
  211. $sub_count = nf_get_sub_count( $atts[ 'id' ] ); 
  212. $sub_limit = (int) $form->settings[ 'sub_limit_number' ]; 
  213.  
  214. if( $sub_count > $sub_limit ) 
  215. return 0; 
  216.  
  217. return $sub_limit - $sub_count; 
  218. else { 
  219. return null; 
  220. add_shortcode( 'ninja_forms_display_sub_number_remaining', 'ninja_forms_display_sub_number_remaining_shortcode' ); 
.