Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.90 KB | None | 0 0
  1. <?php if ( ! defined( 'FW' ) ) {
  2. die( 'Forbidden' );
  3. }
  4. /**
  5. * Filters and Actions
  6. */
  7.  
  8. /**
  9. * Option types
  10. */
  11. {
  12. /**
  13. * @internal
  14. */
  15. function _action_fw_init_option_types() {
  16. FW_Option_Type::register( 'FW_Option_Type_Hidden' );
  17. FW_Option_Type::register( 'FW_Option_Type_Text' );
  18. FW_Option_Type::register( 'FW_Option_Type_Short_Text' );
  19. FW_Option_Type::register( 'FW_Option_Type_Password' );
  20. FW_Option_Type::register( 'FW_Option_Type_Textarea' );
  21. FW_Option_Type::register( 'FW_Option_Type_Html' );
  22. FW_Option_Type::register( 'FW_Option_Type_Html_Fixed' );
  23. FW_Option_Type::register( 'FW_Option_Type_Html_Full' );
  24. FW_Option_Type::register( 'FW_Option_Type_Checkbox' );
  25. FW_Option_Type::register( 'FW_Option_Type_Checkboxes' );
  26. FW_Option_Type::register( 'FW_Option_Type_Radio' );
  27. FW_Option_Type::register( 'FW_Option_Type_Select' );
  28. FW_Option_Type::register( 'FW_Option_Type_Short_Select' );
  29. FW_Option_Type::register( 'FW_Option_Type_Select_Multiple' );
  30. FW_Option_Type::register( 'FW_Option_Type_Unique' );
  31. FW_Option_Type::register( 'FW_Option_Type_GMap_Key' );
  32. FW_Option_Type::register( 'FW_Option_Type_Addable_Box' );
  33. FW_Option_Type::register( 'FW_Option_Type_Addable_Option' );
  34. FW_Option_Type::register( 'FW_Option_Type_Addable_Popup' );
  35. FW_Option_Type::register( 'FW_Option_Type_Addable_Popup_Full' );
  36. FW_Option_Type::register( 'FW_Option_Type_Background_Image' );
  37. FW_Option_Type::register( 'FW_Option_Type_Color_Picker' );
  38. FW_Option_Type::register( 'FW_Option_Type_Date_Picker' );
  39. FW_Option_Type::register( 'FW_Option_Type_Datetime_Picker' );
  40. FW_Option_Type::register( 'FW_Option_Type_Datetime_Range' );
  41. FW_Option_Type::register( 'FW_Option_Type_Gradient' );
  42. FW_Option_Type::register( 'FW_Option_Type_Icon' );
  43. FW_Option_Type::register( 'FW_Option_Type_Image_Picker' );
  44. FW_Option_Type::register( 'FW_Option_Type_Map' );
  45. FW_Option_Type::register( 'FW_Option_Type_Multi' );
  46. FW_Option_Type::register( 'FW_Option_Type_Multi_Picker' );
  47. FW_Option_Type::register( 'FW_Option_Type_Multi_Upload' );
  48. FW_Option_Type::register( 'FW_Option_Type_Popup' );
  49. FW_Option_Type::register( 'FW_Option_Type_Radio_Text' );
  50. FW_Option_Type::register( 'FW_Option_Type_Range_Slider' );
  51. FW_Option_Type::register( 'FW_Option_Type_Rgba_Color_Picker' );
  52. FW_Option_Type::register( 'FW_Option_Type_Slider' );
  53. FW_Option_Type::register( 'FW_Option_Type_Slider_Short' );
  54. FW_Option_Type::register( 'FW_Option_Type_Switch' );
  55. FW_Option_Type::register( 'FW_Option_Type_Typography' );
  56. FW_Option_Type::register( 'FW_Option_Type_Typography_v2' );
  57. FW_Option_Type::register( 'FW_Option_Type_Upload' );
  58. FW_Option_Type::register( 'FW_Option_Type_Wp_Editor' );
  59.  
  60. {
  61. $favorites = new FW_Icon_V2_Favorites_Manager();
  62. $favorites->attach_ajax_actions();
  63.  
  64. FW_Option_Type::register( 'FW_Option_Type_Icon_v2' );
  65. }
  66.  
  67. {
  68. FW_Option_Type::register( 'FW_Option_Type_Multi_Select' );
  69. }
  70.  
  71. {
  72. FW_Option_Type::register( 'FW_Option_Type_Oembed' );
  73. }
  74. }
  75.  
  76. add_action( 'fw_option_types_init', '_action_fw_init_option_types' );
  77.  
  78. /**
  79. * Some option-types have add_action('wp_ajax_...')
  80. * so init all option-types if current request is ajax
  81. * @since 2.6.1
  82. */
  83. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  84. function _action_fw_init_option_types_on_ajax() {
  85. foreach (fw()->backend->get_option_types() as $type) {
  86. fw()->backend->option_type($type);
  87. }
  88. }
  89.  
  90. add_action( 'fw_init', '_action_fw_init_option_types_on_ajax' );
  91. }
  92.  
  93. /**
  94. * Prevent Fatal Error if someone is registering option-types in old way (right away)
  95. * not in 'fw_option_types_init' action
  96. *
  97. * @param string $class
  98. */
  99. function _fw_autoload_option_types( $class ) {
  100. if ( 'FW_Option_Type' === $class ) {
  101. if ( is_admin() && defined( 'WP_DEBUG' ) && WP_DEBUG ) {
  102. FW_Flash_Messages::add(
  103. 'option-type-register-wrong',
  104. __( "Please register option-types on 'fw_option_types_init' action", 'fw' ),
  105. 'warning'
  106. );
  107. }
  108. } elseif ( 'FW_Container_Type' === $class ) {
  109. if ( is_admin() && defined( 'WP_DEBUG' ) && WP_DEBUG ) {
  110. FW_Flash_Messages::add(
  111. 'container-type-register-wrong',
  112. __( "Please register container-types on 'fw_container_types_init' action", 'fw' ),
  113. 'warning'
  114. );
  115. }
  116. }
  117. }
  118.  
  119. spl_autoload_register( '_fw_autoload_option_types' );
  120. }
  121.  
  122. /**
  123. * Container types
  124. */
  125. {
  126. /**
  127. * @internal
  128. */
  129. function _action_fw_init_container_types() {
  130. FW_Container_Type::register( 'FW_Container_Type_Group' );
  131. FW_Container_Type::register( 'FW_Container_Type_Box' );
  132. FW_Container_Type::register( 'FW_Container_Type_Popup' );
  133. FW_Container_Type::register( 'FW_Container_Type_Tab' );
  134. }
  135.  
  136. add_action( 'fw_container_types_init', '_action_fw_init_container_types' );
  137. }
  138.  
  139. /**
  140. * Custom Github API service
  141. * Provides the same responses but is "unlimited"
  142. * To prevent error: Github API rate limit exceeded 60 requests per hour
  143. * https://github.com/ThemeFuse/Unyson/issues/138
  144. * @internal
  145. */
  146. function _fw_filter_github_api_url( $url ) {
  147. return 'https://github-api-cache.unyson.io';
  148. }
  149.  
  150. add_filter( 'fw_github_api_url', '_fw_filter_github_api_url' );
  151.  
  152. /**
  153. * Javascript events related to tinymce init
  154. * @since 2.6.0
  155. */
  156. {
  157. add_action( 'wp_tiny_mce_init', '_fw_action_tiny_mce_init' );
  158. function _fw_action_tiny_mce_init( $mce_settings ) {
  159. ?>
  160. <script type="text/javascript">
  161. if (typeof fwEvents != 'undefined') {
  162. fwEvents.trigger('fw:tinymce:init:before');
  163. }
  164. </script>
  165. <?php
  166. }
  167.  
  168. add_action( 'after_wp_tiny_mce', '_fw_action_after_wp_tiny_mce' );
  169. function _fw_action_after_wp_tiny_mce( $mce_settings ) {
  170. ?>
  171. <script type="text/javascript">
  172. if (typeof fwEvents != 'undefined') {
  173. fwEvents.trigger('fw:tinymce:init:after');
  174. }
  175. </script>
  176. <?php
  177. }
  178. }
  179.  
  180. // FW_Form hooks
  181. {
  182. if ( is_admin() ) {
  183. /**
  184. * Display form errors in admin side
  185. * @internal
  186. */
  187. function _action_fw_form_show_errors_in_admin() {
  188. $form = FW_Form::get_submitted();
  189.  
  190. if ( ! $form || $form->is_valid() ) {
  191. return;
  192. }
  193.  
  194. foreach ( $form->get_errors() as $input_name => $error_message ) {
  195. FW_Flash_Messages::add( 'fw-form-admin-' . $input_name, $error_message, 'error' );
  196. }
  197. }
  198.  
  199. add_action( 'wp_loaded', '_action_fw_form_show_errors_in_admin', 111 );
  200. } else {
  201. /**
  202. * to disable this use remove_action('wp_print_styles', '_action_fw_form_frontend_default_styles');
  203. * @internal
  204. */
  205. function _action_fw_form_frontend_default_styles() {
  206. $form = FW_Form::get_submitted();
  207.  
  208. if ( ! $form || $form->is_valid() ) {
  209. return;
  210. }
  211.  
  212. echo '<style type="text/css">.fw-form-errors { color: #bf0000; }</style>';
  213. }
  214.  
  215. add_action( 'wp_print_styles', '_action_fw_form_frontend_default_styles' );
  216. }
  217. }
  218.  
  219. // FW_Flash_Messages hooks
  220. {
  221. if ( is_admin() ) {
  222. /**
  223. * Start the session before the content is sent to prevent the "headers already sent" warning
  224. * @internal
  225. */
  226. function _action_fw_flash_message_backend_prepare() {
  227. if ( apply_filters( 'fw_use_sessions', true ) && ! session_id() ) {
  228. session_start();
  229. }
  230. }
  231.  
  232. add_action( 'current_screen', '_action_fw_flash_message_backend_prepare', 9999 );
  233.  
  234. /**
  235. * Display flash messages in backend as notices
  236. */
  237. add_action( 'admin_notices', array( 'FW_Flash_Messages', '_print_backend' ) );
  238. } else {
  239. /**
  240. * Start the session before the content is sent to prevent the "headers already sent" warning
  241. * @internal
  242. */
  243. function _action_fw_flash_message_frontend_prepare() {
  244. if (
  245. apply_filters( 'fw_use_sessions', true )
  246. &&
  247. /**
  248. * In ajax it's not possible to call flash message after headers were sent,
  249. * so there will be no "headers already sent" warning.
  250. * Also in the Backups extension, are made many internal ajax request,
  251. * each creating a new independent request that don't remember/use session cookie from previous request,
  252. * thus on server side are created many (not used) new sessions.
  253. */
  254. ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
  255. &&
  256. ! session_id()
  257. ) {
  258. session_start();
  259. }
  260. }
  261.  
  262. add_action( 'send_headers', '_action_fw_flash_message_frontend_prepare', 9999 );
  263.  
  264. /**
  265. * Print flash messages in frontend if this has not been done from theme
  266. */
  267. function _action_fw_flash_message_frontend_print() {
  268. if ( FW_Flash_Messages::_frontend_printed() ) {
  269. return;
  270. }
  271.  
  272. if ( ! FW_Flash_Messages::_print_frontend() ) {
  273. return;
  274. }
  275.  
  276. ?>
  277. <script type="text/javascript">
  278. (function () {
  279. if (typeof jQuery === "undefined") {
  280. return;
  281. }
  282.  
  283. jQuery(function ($) {
  284. var $container;
  285.  
  286. // Try to find the content element
  287. {
  288. var selector, selectors = [
  289. '#main #content',
  290. '#content #main',
  291. '#main',
  292. '#content',
  293. '#content-container',
  294. '#container',
  295. '.container:first'
  296. ];
  297.  
  298. while (selector = selectors.shift()) {
  299. $container = $(selector);
  300.  
  301. if ($container.length) {
  302. break;
  303. }
  304. }
  305. }
  306.  
  307. if (!$container.length) {
  308. // Try to find main page H1 container
  309. $container = $('h1:first').parent();
  310. }
  311.  
  312. if (!$container.length) {
  313. // If nothing found, just add to body
  314. $container = $(document.body);
  315. }
  316.  
  317. $(".fw-flash-messages").prependTo($container);
  318. });
  319. })();
  320. </script>
  321. <style type="text/css">
  322. .fw-flash-messages .fw-flash-type-error {
  323. color: #f00;
  324. }
  325.  
  326. .fw-flash-messages .fw-flash-type-warning {
  327. color: #f70;
  328. }
  329.  
  330. .fw-flash-messages .fw-flash-type-success {
  331. color: #070;
  332. }
  333.  
  334. .fw-flash-messages .fw-flash-type-info {
  335. color: #07f;
  336. }
  337. </style>
  338. <?php
  339. }
  340.  
  341. add_action( 'wp_footer', '_action_fw_flash_message_frontend_print', 9999 );
  342. }
  343. }
  344.  
  345. // FW_Resize hooks
  346. {
  347. if ( ! function_exists( 'fw_delete_resized_thumbnails' ) ) {
  348. function fw_delete_resized_thumbnails( $id ) {
  349. $images = wp_get_attachment_metadata( $id );
  350. if ( ! empty( $images['resizes'] ) ) {
  351. $uploads_dir = wp_upload_dir();
  352. foreach ( $images['resizes'] as $image ) {
  353. $file = $uploads_dir['basedir'] . '/' . $image;
  354. @unlink( $file );
  355. }
  356. }
  357. }
  358.  
  359. add_action( 'delete_attachment', 'fw_delete_resized_thumbnails' );
  360. }
  361. }
  362.  
  363. //WPML Hooks
  364. {
  365. if ( is_admin() ) {
  366. add_action( 'icl_save_term_translation', '_fw_action_wpml_duplicate_term_options', 20, 2 );
  367. function _fw_action_wpml_duplicate_term_options( $original, $translated ) {
  368. $original_options = fw_get_db_term_option(
  369. fw_akg( 'term_id', $original ),
  370. fw_akg( 'taxonomy', $original )
  371. );
  372.  
  373. if ( $original_options !== null ) {
  374. fw_set_db_term_option(
  375. fw_akg( 'term_id', $translated ),
  376. fw_akg( 'taxonomy', $original ),
  377. null,
  378. $original_options
  379. );
  380. }
  381. }
  382. }
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement