/library/admin/redux-framework/core/enqueue.php

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