Caldera_Forms_Admin_Assets

Handles asset loading for admin.

Defined (1)

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

/classes/admin/assets.php  
  1. class Caldera_Forms_Admin_Assets { 
  2.  
  3. /** 
  4. * Enqueue scripts and styles used in the post editor 
  5. * @since 1.5.0 
  6. */ 
  7. public static function post_editor() { 
  8. self::maybe_register_all_admin(); 
  9. wp_enqueue_style( 'wp-color-picker' ); 
  10. wp_enqueue_script( 'wp-color-picker' ); 
  11.  
  12. self::admin_common(); 
  13. self::enqueue_script( 'shortcode-insert' ); 
  14.  
  15. /** 
  16. * Enqueue scripts and styles used in the form editor 
  17. * @since 1.5.0 
  18. */ 
  19. public static function form_editor() { 
  20. self::maybe_register_all_admin(); 
  21. wp_enqueue_style( 'wp-color-picker' ); 
  22. self::enqueue_script( 'edit-fields' ); 
  23. self::enqueue_script( 'edit-editor' ); 
  24. self::enqueue_style( 'editor-grid' ); 
  25. wp_enqueue_script( 'jquery-ui-users' ); 
  26. wp_enqueue_script( 'jquery-ui-sortable' ); 
  27. wp_enqueue_script( 'jquery-ui-droppable' ); 
  28.  
  29. /** 
  30. * Enqueue scripts and styles used in main admin and in form editor 
  31. * @since 1.5.0 
  32. */ 
  33. public static function admin_common() { 
  34. self::maybe_register_all_admin(); 
  35. Caldera_Forms_Render_Assets::maybe_register(); 
  36. Caldera_Forms_Render_Assets::enqueue_script( 'validator' ); 
  37. $locale = get_locale(); 
  38. if( $locale !== 'en_US' ) { 
  39. Caldera_Forms_Render_Assets::enqueue_validator_i18n(); 
  40.  
  41. Caldera_Forms_Render_Assets::enqueue_style( 'grid' ); 
  42. self::enqueue_style( 'admin' ); 
  43. wp_localize_script( self::slug( 'admin' ), 'CF_ADMIN', array( 
  44. 'adminAjax' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),  
  45. 'rest' => array( 
  46. 'root' => esc_url_raw( Caldera_Forms_API_Util::url() ),  
  47. ) ); 
  48.  
  49.  
  50. self::enqueue_style( 'modal' ); 
  51. self::enqueue_script( 'admin' ); 
  52. Caldera_Forms_Render_Assets::enqueue_style( 'field' ); 
  53.  
  54. self::enqueue_script( 'baldrick' ); 
  55.  
  56.  
  57. /** 
  58. * Register all scripts for Caldera Forms admin 
  59. * @since 1.5.0 
  60. */ 
  61. public static function register_scripts() { 
  62. $version = Caldera_Forms::VERSION; 
  63. Caldera_Forms_Render_Assets::maybe_validator_i18n( true ); 
  64.  
  65. wp_register_script( self::slug( 'shortcode-insert' ), Caldera_Forms_Render_Assets::make_url( 'shortcode-insert' ), array( 'jquery', 'wp-color-picker' ), $version ); 
  66.  
  67. wp_register_script( self::slug( 'baldrick' ), Caldera_Forms_Render_Assets::make_url( 'wp-baldrick-full' ), array( 'jquery' ), $version ); 
  68. wp_register_script( self::slug( 'admin' ), Caldera_Forms_Render_Assets::make_url( 'admin' ), array( 
  69. self::slug( 'baldrick' ),  
  70. Caldera_Forms_Render_Assets::make_slug( 'conditionals' ),  
  71. 'wp-pointer',  
  72. 'password-strength-meter' 
  73. ), $version ); 
  74.  
  75. wp_register_script( self::slug( 'edit-fields' ), Caldera_Forms_Render_Assets::make_url( 'fields' ), array( 'jquery', 'wp-color-picker' ), $version ); 
  76.  
  77. //this is bad, but fixes -> https://github.com/CalderaWP/Caldera-Forms/issues/1141 
  78. wp_register_script( self::slug( 'edit-editor' ), CFCORE_URL . 'assets/js/edit.js', array( 'jquery', 'wp-color-picker' ), $version ); 
  79.  
  80. wp_register_script( self::slug( 'support-page' ), Caldera_Forms_Render_Assets::make_url( 'support-page' ), array( 'jquery' ), $version ); 
  81.  
  82. wp_localize_script( self::slug( 'edit-fields' ), 'CF_ADMIN_TOOLTIPS', self::get_tooltips() ); 
  83. /** 
  84. * Runs after scripts are registered for Caldera Forms admin 
  85. * @since 1.5.0 
  86. */ 
  87. do_action( 'caldera_forms_admin_assets_scripts_registered' ); 
  88.  
  89. /** 
  90. * Register all styles for Caldera Forms admin 
  91. * @since 1.5.0 
  92. */ 
  93. public static function register_styles() { 
  94. $version = Caldera_Forms::VERSION; 
  95. wp_register_style( self::slug( 'modals', false ), Caldera_Forms_Render_Assets::make_url( 'modals', false ), array( 'wp-color-picker' ), $version ); 
  96. wp_register_style( self::slug( 'admin', false ), Caldera_Forms_Render_Assets::make_url( 'admin', false ), array( 
  97. self::slug( 'modals', false ),  
  98. 'wp-color-picker',  
  99. 'wp-pointer' 
  100. ), $version ); 
  101.  
  102. wp_register_style( self::slug( 'processors', false ), Caldera_Forms_Render_Assets::make_url( 'processors-edit', false ), array(), $version ); 
  103. wp_register_style( self::slug( 'editor-grid', false ), Caldera_Forms_Render_Assets::make_url( 'editor-grid', false ), array( 
  104. self::slug( 'processors', false ) 
  105. ), $version ); 
  106.  
  107. /** 
  108. * Runs after styles are registered for Caldera Forms admin 
  109. * @since 1.5.0 
  110. */ 
  111. do_action( 'caldera_forms_admin_assets_styles_registered' ); 
  112.  
  113.  
  114. /** 
  115. * Enqueue a style for Caldera Forms admin 
  116. * @since 1.5.0 
  117. * @param string $slug Style slug 
  118. */ 
  119. public static function enqueue_style( $slug ) { 
  120. if( 1 !== strpos( $slug, Caldera_Forms::PLUGIN_SLUG ) ) { 
  121. $slug = self::slug( $slug, false ); 
  122.  
  123. wp_enqueue_style( $slug ); 
  124.  
  125. /** 
  126. * Enqueue a script for Caldera Forms admin 
  127. * @since 1.5.0 
  128. * @param string $slug Script slug 
  129. */ 
  130. public static function enqueue_script( $slug ) { 
  131. if( 1 !== strpos( $slug, Caldera_Forms::PLUGIN_SLUG ) ) { 
  132. $slug = self::slug( $slug, true ); 
  133.  
  134. wp_enqueue_script( $slug ); 
  135.  
  136. /** 
  137. * Create a script/style slug for Caldera Forms admin 
  138. * @since 1.5.0 
  139. * @param string $slug Short slug 
  140. * @param bool|string $script Optional. True, the default append -scripts, false appends -style. A string appends that string. 
  141. * @return string 
  142. */ 
  143. public static function slug( $slug, $script = true ) { 
  144. if( 'baldrick' == $slug ) { 
  145. $slug = Caldera_Forms::PLUGIN_SLUG . '-' . $slug; 
  146. return $slug; 
  147. $slug = Caldera_Forms::PLUGIN_SLUG . '-' . $slug; 
  148. if( is_string( $script ) ) { 
  149. $slug .= $script; 
  150. }elseif( true === $script ) { 
  151. $slug .= '-scripts'; 
  152. }elseif( false === $script ) { 
  153. $slug .= '-styles'; 
  154.  
  155. return $slug; 
  156.  
  157. /** 
  158. * Load scripts for form editor panels 
  159. * @since 1.5.0 
  160. */ 
  161. public static function panels() { 
  162. $panels = Caldera_Forms_Admin_Panel::get_panels(); 
  163. if( ! empty( $panels ) ) { 
  164. foreach ( $panels as $panel ) { 
  165. if( ! empty( $panel[ 'setup' ][ 'scripts' ] ) ) { 
  166. foreach( $panel[ 'setup' ][ 'scripts' ] as $script ) { 
  167. if( filter_var( $script, FILTER_VALIDATE_URL ) ) { 
  168. self::enqueue_script( $script ); 
  169. }else{ 
  170. wp_enqueue_script( $script ); 
  171.  
  172. foreach( $panel[ 'setup' ][ 'styles' ] as $style ) { 
  173. if( filter_var( $style, FILTER_VALIDATE_URL ) ) { 
  174. self::enqueue_style( $style ); 
  175. }else{ 
  176. wp_enqueue_style( $style ); 
  177.  
  178. /** 
  179. * Registers all scripts needed if not registered yet 
  180. * @since 1.5.0 
  181. */ 
  182. protected static function maybe_register_all_admin() { 
  183. $front = false; 
  184. if( ! did_action( 'caldera_forms_admin_assets_styles_registered' ) ) { 
  185. Caldera_Forms_Render_Assets::register(); 
  186. Caldera_Forms_Render_Assets::enqueue_all_fields(); 
  187. $front = true; 
  188. self::register_styles(); 
  189.  
  190. if( ! did_action( 'caldera_forms_admin_assets_scripts_registered' ) ) { 
  191. if( false === $front ) { 
  192. Caldera_Forms_Render_Assets::register(); 
  193. Caldera_Forms_Render_Assets::enqueue_all_fields(); 
  194. self::register_scripts(); 
  195.  
  196. /** 
  197. * Get strings for admin tooltips 
  198. * @since 1.5.0.7 
  199. * @return array 
  200. */ 
  201. public static function get_tooltips() { 
  202. $tooltips = array( 
  203. 'add_field_row' => esc_html__( 'Add field to row', 'caldera-forms' ),  
  204. 'split_row' => esc_html__( 'Split row.', 'caldera-forms' ),  
  205. 'delete_row' => esc_html__( 'Delete row.', 'caldera-forms' ),  
  206. ); 
  207.  
  208. /** 
  209. * Filter admin tooltips 
  210. * @since 1.5.0.7 
  211. */ 
  212. return apply_filters( 'caldera_forms_admin_tooltip_strings', $tooltips ); 
  213.