reduxCoreEnqueue

The evolve reduxCoreEnqueue class.

Defined (1)

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

/library/admin/redux-framework/core/enqueue.php  
  1. class reduxCoreEnqueue { 
  2. public $parent = null; 
  3.  
  4. private $min = ''; 
  5. private $timestamp = ''; 
  6.  
  7. public function __construct( $parent ) { 
  8. $this->parent = $parent; 
  9.  
  10. Redux_Functions::$_parent = $parent; 
  11.  
  12. public function init() { 
  13. $this->min = Redux_Functions::isMin(); 
  14.  
  15. $this->timestamp = ReduxFramework::$_version; 
  16. if ( $this->parent->args['dev_mode'] ) { 
  17. $this->timestamp .= '.' . time(); 
  18.  
  19. $this->register_styles(); 
  20. $this->register_scripts(); 
  21.  
  22. add_thickbox(); 
  23.  
  24. $this->enqueue_fields(); 
  25.  
  26. add_filter("redux/{$this->parent->args['opt_name']}/localize", array('Redux_Helpers', 'localize')); 
  27.  
  28. $this->set_localized_data(); 
  29.  
  30. /** 
  31. * action 'redux-enqueue-{opt_name}' 
  32. * @deprecated 
  33. * @param object $this ReduxFramework 
  34. */ 
  35. do_action( "redux-enqueue-{$this->parent->args['opt_name']}", $this->parent ); // REMOVE 
  36.  
  37. /** 
  38. * action 'redux/page/{opt_name}/enqueue' 
  39. */ 
  40. do_action( "redux/page/{$this->parent->args['opt_name']}/enqueue" ); 
  41.  
  42. private function register_styles() { 
  43.  
  44. //***************************************************************** 
  45. // Redux Admin CSS 
  46. //***************************************************************** 
  47. wp_enqueue_style( 
  48. 'redux-admin-css',  
  49. ReduxFramework::$_url . 'assets/css/redux-admin.css',  
  50. array(),  
  51. $this->timestamp,  
  52. 'all' 
  53. ); 
  54.  
  55. //***************************************************************** 
  56. // Redux Fields CSS 
  57. //***************************************************************** 
  58. if ( ! $this->parent->args['dev_mode'] ) { 
  59. wp_enqueue_style( 
  60. 'redux-fields-css',  
  61. ReduxFramework::$_url . 'assets/css/redux-fields.css',  
  62. array(),  
  63. $this->timestamp,  
  64. 'all' 
  65. ); 
  66.  
  67. //***************************************************************** 
  68. // Select2 CSS 
  69. //***************************************************************** 
  70. Redux_CDN::register_style( 
  71. 'select2-css',  
  72. '//cdn.jsdelivr.net/select2/3.5.2/select2.css',  
  73. array(),  
  74. '3.5.2', //$this->timestamp,  
  75. 'all' 
  76. ); 
  77.  
  78. //***************************************************************** 
  79. // Spectrum CSS 
  80. //***************************************************************** 
  81. $css_file = 'redux-spectrum.min.css'; 
  82. if ($this->parent->args['dev_mode']) { 
  83. $css_file = 'redux-spectrum.css'; 
  84. }  
  85.  
  86. wp_register_style( 
  87. 'redux-spectrum-css',  
  88. ReduxFramework::$_url . 'assets/css/vendor/spectrum/' . $css_file,  
  89. array(),  
  90. '1.3.3',  
  91. 'all' 
  92. ); 
  93.  
  94. //***************************************************************** 
  95. // Elusive Icon CSS 
  96. //***************************************************************** 
  97. wp_enqueue_style( 
  98. 'redux-elusive-icon',  
  99. ReduxFramework::$_url . 'assets/css/vendor/elusive-icons/elusive-icons.css',  
  100. array(),  
  101. $this->timestamp,  
  102. 'all' 
  103. ); 
  104.  
  105. //***************************************************************** 
  106. // QTip CSS 
  107. //***************************************************************** 
  108. $css_file = 'jquery.qtip.min.css'; 
  109. if ($this->parent->args['dev_mode']) { 
  110. $css_file = 'jquery.qtip.css'; 
  111.  
  112. wp_enqueue_style( 
  113. 'qtip-css',  
  114. ReduxFramework::$_url . 'assets/css/vendor/qtip/' . $css_file,  
  115. array(),  
  116. '2.2.0',  
  117. 'all' 
  118. ); 
  119.  
  120. //***************************************************************** 
  121. // JQuery UI CSS 
  122. //***************************************************************** 
  123. wp_enqueue_style( 
  124. 'jquery-ui-css',  
  125. apply_filters( "redux/page/{$this->parent->args['opt_name']}/enqueue/jquery-ui-css", ReduxFramework::$_url . 'assets/css/vendor/jquery-ui-bootstrap/jquery-ui-1.10.0.custom.css' ),  
  126. array(),  
  127. $this->timestamp,  
  128. 'all' 
  129. ); 
  130.  
  131. //***************************************************************** 
  132. // Iris CSS 
  133. //***************************************************************** 
  134. wp_enqueue_style( 'wp-color-picker' ); 
  135.  
  136. if ( $this->parent->args['dev_mode'] ) { 
  137.  
  138. //***************************************************************** 
  139. // Color Picker CSS 
  140. //***************************************************************** 
  141. wp_register_style( 
  142. 'redux-color-picker-css',  
  143. ReduxFramework::$_url . 'assets/css/color-picker/color-picker.css',  
  144. array( 'wp-color-picker' ),  
  145. $this->timestamp,  
  146. 'all' 
  147. ); 
  148.  
  149. //***************************************************************** 
  150. // Media CSS 
  151. //***************************************************************** 
  152. wp_enqueue_style( 
  153. 'redux-field-media-css',  
  154. ReduxFramework::$_url . 'assets/css/media/media.css',  
  155. array(),  
  156. time(),  
  157. 'all' 
  158. ); 
  159.  
  160. //***************************************************************** 
  161. // RTL CSS 
  162. //***************************************************************** 
  163. if ( is_rtl() ) { 
  164. wp_enqueue_style( 
  165. 'redux-rtl-css',  
  166. ReduxFramework::$_url . 'assets/css/rtl.css',  
  167. array( 'redux-admin-css' ),  
  168. $this->timestamp,  
  169. 'all' 
  170. ); 
  171.  
  172.  
  173. private function register_scripts() { 
  174. //***************************************************************** 
  175. // JQuery / JQuery UI JS 
  176. //***************************************************************** 
  177. wp_enqueue_script( 'jquery' ); 
  178. wp_enqueue_script( 'jquery-ui-core' ); 
  179. wp_enqueue_script( 'jquery-ui-dialog' ); 
  180.  
  181. //***************************************************************** 
  182. // Select2 Sortable JS 
  183. //***************************************************************** 
  184. wp_register_script( 
  185. 'redux-select2-sortable-js',  
  186. ReduxFramework::$_url . 'assets/js/vendor/redux.select2.sortable' . $this->min . '.js',  
  187. array( 'jquery' ),  
  188. $this->timestamp,  
  189. true 
  190. ); 
  191.  
  192. Redux_CDN::register_script( 
  193. 'select2-js',  
  194. '//cdn.jsdelivr.net/select2/3.5.2/select2' . $this->min . '.js',  
  195. array( 'jquery', 'redux-select2-sortable-js' ),  
  196. '3.5.2',  
  197. true 
  198. ); 
  199.  
  200. //***************************************************************** 
  201. // QTip JS 
  202. //***************************************************************** 
  203. $js_file = 'jquery.qtip.min.js'; 
  204. if ($this->parent->args['dev_mode']) { 
  205. $js_file = 'jquery.qtip.js'; 
  206.  
  207. wp_enqueue_script( 
  208. 'qtip-js',  
  209. ReduxFramework::$_url . 'assets/js/vendor/qtip/' . $js_file,  
  210. array( 'jquery' ),  
  211. '2.2.0',  
  212. true 
  213. ); 
  214.  
  215. //***************************************************************** 
  216. // Spectrum JS 
  217. //***************************************************************** 
  218. $js_file = 'redux-spectrum.min.js'; 
  219. if ($this->parent->args['dev_mode']) { 
  220. $js_file = 'redux-spectrum.js'; 
  221.  
  222. wp_register_script( 
  223. 'redux-spectrum-js',  
  224. ReduxFramework::$_url . 'assets/js/vendor/spectrum/' . $js_file,  
  225. array( 'jquery' ),  
  226. '1.3.3',  
  227. true 
  228. );  
  229.  
  230. $depArray = array( 'jquery' ); 
  231.  
  232. //***************************************************************** 
  233. // Vendor JS 
  234. //***************************************************************** 
  235. if ( $this->parent->args['dev_mode'] ) { 
  236. wp_register_script( 
  237. 'redux-vendor',  
  238. ReduxFramework::$_url . 'assets/js/vendor.min.js',  
  239. array( 'jquery' ),  
  240. $this->timestamp,  
  241. true 
  242. ); 
  243.  
  244. array_push( $depArray, 'redux-vendor' ); 
  245.  
  246. //***************************************************************** 
  247. // Redux JS 
  248. //***************************************************************** 
  249. wp_register_script( 
  250. 'redux-js',  
  251. ReduxFramework::$_url . 'assets/js/redux' . $this->min . '.js',  
  252. $depArray,  
  253. $this->timestamp,  
  254. true 
  255. ); 
  256.  
  257. wp_enqueue_script( 
  258. 'webfontloader',  
  259. 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.0/webfont.js',  
  260. array( 'jquery' ),  
  261. '1.5.0',  
  262. true 
  263. ); 
  264.  
  265. public function _enqueue_field($field) { 
  266. // TODO AFTER GROUP WORKS - Revert IF below 
  267. // if( isset( $field['type'] ) && $field['type'] != 'callback' ) { 
  268. if ( isset( $field['type'] ) && $field['type'] != 'callback' ) { 
  269.  
  270. $field_class = 'ReduxFramework_' . $field['type']; 
  271.  
  272. /** 
  273. * Field class file 
  274. * filter 'redux/{opt_name}/field/class/{field.type} 
  275. * @param string field class file path 
  276. * @param array $field field config data 
  277. */ 
  278. $class_file = apply_filters( "redux/{$this->parent->args['opt_name']}/field/class/{$field['type']}", ReduxFramework::$_dir . "inc/fields/{$field['type']}/field_{$field['type']}.php", $field ); 
  279. if ( $class_file ) { 
  280. if ( ! class_exists( $field_class ) ) { 
  281. if ( file_exists( $class_file ) ) { 
  282. require_once $class_file; 
  283.  
  284. if ( ( method_exists( $field_class, 'enqueue' ) ) || method_exists( $field_class, 'localize' ) ) { 
  285.  
  286. if ( ! isset( $this->parent->options[ $field['id'] ] ) ) { 
  287. $this->parent->options[ $field['id'] ] = ""; 
  288. $theField = new $field_class( $field, $this->parent->options[ $field['id'] ], $this->parent ); 
  289.  
  290. // Move dev_mode check to a new if/then block 
  291. if ( ! wp_script_is( 'redux-field-' . $field['type'] . '-js', 'enqueued' ) && class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) { 
  292. $theField->enqueue(); 
  293.  
  294. if ( method_exists( $field_class, 'localize' ) ) { 
  295. $params = $theField->localize( $field ); 
  296. if ( ! isset( $this->parent->localize_data[ $field['type'] ] ) ) { 
  297. $this->parent->localize_data[ $field['type'] ] = array(); 
  298. $this->parent->localize_data[ $field['type'] ][ $field['id'] ] = $theField->localize( $field ); 
  299.  
  300. unset( $theField ); 
  301.  
  302. private function enqueue_fields() { 
  303. foreach ( $this->parent->sections as $section ) { 
  304. if ( isset( $section['fields'] ) ) { 
  305. foreach ( $section['fields'] as $field ) { 
  306. $this->_enqueue_field( $field ); 
  307.  
  308. public function get_warnings_and_errors_array() { 
  309. // Construct the errors array. 
  310. if ( isset( $this->parent->transients['last_save_mode'] ) && ! empty( $this->parent->transients['notices']['errors'] ) ) { 
  311. $theTotal = 0; 
  312. $theErrors = array(); 
  313.  
  314. foreach ( $this->parent->transients['notices']['errors'] as $error ) { 
  315. $theErrors[ $error['section_id'] ]['errors'][] = $error; 
  316.  
  317. if ( ! isset( $theErrors[ $error['section_id'] ]['total'] ) ) { 
  318. $theErrors[ $error['section_id'] ]['total'] = 0; 
  319.  
  320. $theErrors[ $error['section_id'] ]['total'] ++; 
  321. $theTotal ++; 
  322.  
  323. $this->parent->localize_data['errors'] = array( 'total' => $theTotal, 'errors' => $theErrors ); 
  324. unset( $this->parent->transients['notices']['errors'] ); 
  325.  
  326. // Construct the warnings array. 
  327. if ( isset( $this->parent->transients['last_save_mode'] ) && ! empty( $this->parent->transients['notices']['warnings'] ) ) { 
  328. $theTotal = 0; 
  329. $theWarnings = array(); 
  330.  
  331. foreach ( $this->parent->transients['notices']['warnings'] as $warning ) { 
  332. $theWarnings[ $warning['section_id'] ]['warnings'][] = $warning; 
  333.  
  334. if ( ! isset( $theWarnings[ $warning['section_id'] ]['total'] ) ) { 
  335. $theWarnings[ $warning['section_id'] ]['total'] = 0; 
  336.  
  337. $theWarnings[ $warning['section_id'] ]['total'] ++; 
  338. $theTotal ++; 
  339.  
  340. unset( $this->parent->transients['notices']['warnings'] ); 
  341. $this->parent->localize_data['warnings'] = array( 
  342. 'total' => $theTotal,  
  343. 'warnings' => $theWarnings 
  344. ); 
  345.  
  346. if ( empty( $this->parent->transients['notices'] ) ) { 
  347. unset( $this->parent->transients['notices'] ); 
  348.  
  349. private function set_localized_data() { 
  350. if (!empty($this->parent->args['last_tab'])) { 
  351. $this->parent->localize_data['last_tab'] = $this->parent->args['last_tab']; 
  352.  
  353. $this->parent->localize_data['required'] = $this->parent->required; 
  354. $this->parent->localize_data['fonts'] = $this->parent->fonts; 
  355. $this->parent->localize_data['required_child'] = $this->parent->required_child; 
  356. $this->parent->localize_data['fields'] = $this->parent->fields; 
  357.  
  358. if ( isset( $this->parent->font_groups['google'] ) ) { 
  359. $this->parent->localize_data['googlefonts'] = $this->parent->font_groups['google']; 
  360.  
  361. if ( isset( $this->parent->font_groups['std'] ) ) { 
  362. $this->parent->localize_data['stdfonts'] = $this->parent->font_groups['std']; 
  363.  
  364. if ( isset( $this->parent->font_groups['customfonts'] ) ) { 
  365. $this->parent->localize_data['customfonts'] = $this->parent->font_groups['customfonts']; 
  366.  
  367. $this->parent->localize_data['folds'] = $this->parent->folds; 
  368.  
  369. // Make sure the children are all hidden properly. 
  370. foreach ( $this->parent->fields as $key => $value ) { 
  371. if ( in_array( $key, $this->parent->fieldsHidden ) ) { 
  372. foreach ( $value as $k => $v ) { 
  373. if ( ! in_array( $k, $this->parent->fieldsHidden ) ) { 
  374. $this->parent->fieldsHidden[] = $k; 
  375. $this->parent->folds[ $k ] = "hide"; 
  376.  
  377.  
  378.  
  379. $this->parent->localize_data['fieldsHidden'] = $this->parent->fieldsHidden; 
  380. $this->parent->localize_data['options'] = $this->parent->options; 
  381. $this->parent->localize_data['defaults'] = $this->parent->options_defaults; 
  382.  
  383. /** 
  384. * Save pending string 
  385. * filter 'redux/{opt_name}/localize/save_pending 
  386. * @param string save_pending string 
  387. */ 
  388. $save_pending = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/save_pending", __( 'You have changes that are not saved. Would you like to save them now?', 'evolve' ) ); 
  389.  
  390. /** 
  391. * Reset all string 
  392. * filter 'redux/{opt_name}/localize/reset 
  393. * @param string reset all string 
  394. */ 
  395. $reset_all = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/reset", __( 'Are you sure? Resetting will lose all custom values.', 'evolve' ) ); 
  396.  
  397. /** 
  398. * Reset section string 
  399. * filter 'redux/{opt_name}/localize/reset_section 
  400. * @param string reset section string 
  401. */ 
  402. $reset_section = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/reset_section", __( 'Are you sure? Resetting will lose all custom values in this section.', 'evolve' ) ); 
  403.  
  404. /** 
  405. * Preset confirm string 
  406. * filter 'redux/{opt_name}/localize/preset 
  407. * @param string preset confirm string 
  408. */ 
  409. $preset_confirm = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/preset", __( 'Your current options will be replaced with the values of this preset. Would you like to proceed?', 'evolve' ) ); 
  410. global $pagenow; 
  411. $this->parent->localize_data['args'] = array( 
  412. 'save_pending' => $save_pending,  
  413. 'reset_confirm' => $reset_all,  
  414. 'reset_section_confirm' => $reset_section,  
  415. 'preset_confirm' => $preset_confirm,  
  416. 'please_wait' => __( 'Please Wait', 'evolve' ),  
  417. 'opt_name' => $this->parent->args['opt_name'],  
  418. 'slug' => $this->parent->args['page_slug'],  
  419. 'hints' => $this->parent->args['hints'],  
  420. 'disable_save_warn' => $this->parent->args['disable_save_warn'],  
  421. 'class' => $this->parent->args['class'],  
  422. 'ajax_save' => $this->parent->args['ajax_save'],  
  423. 'menu_search' => $pagenow . '?page=' . $this->parent->args['page_slug'] . "&tab=" 
  424. ); 
  425.  
  426. $this->parent->localize_data['ajax'] = array( 
  427. 'console' => __( 'There was an error saving. Here is the result of your action:', 'evolve' ),  
  428. 'alert' => __( 'There was a problem with your action. Please try again or reload the page.', 'evolve' ),  
  429. ); 
  430.  
  431. $this->parent->localize_data = apply_filters( "redux/{$this->parent->args['opt_name']}/localize", $this->parent->localize_data ); 
  432.  
  433. $this->get_warnings_and_errors_array(); 
  434.  
  435. wp_localize_script( 
  436. 'redux-js',  
  437. 'redux',  
  438. $this->parent->localize_data 
  439. ); 
  440.  
  441. wp_enqueue_script( 'redux-js' ); // Enque the JS now 
  442.