PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/ravens-egg-2022/inc/plugin-mods.php

https://gitlab.com/ravenseyedesign/ravensegg
PHP | 403 lines | 41 code | 37 blank | 325 comment | 1 complexity | 1aa3ddc2547fb7bddaa66b72548b71f4 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin mods
  4. *
  5. * @package WordPress
  6. * @subpackage Ravens_Egg_2022
  7. * @since 1.0
  8. * @version 1.0
  9. */
  10. namespace ravensegg2022;
  11. // ******************** RCP ************************ //
  12. /**
  13. * This will remove the username requirement on the registration form
  14. * and use the email address as the username.
  15. */
  16. function rcp_user_registration_data( $user ) {
  17. rcp_errors()->remove( 'username_empty' );
  18. $user['login'] = $user['email'];
  19. return $user;
  20. }
  21. // add_filter( 'rcp_user_registration_data', 'ravensegg2022\rcp_user_registration_data' );
  22. /**
  23. * Change RCP text output.
  24. *
  25. * @param $translated_text
  26. *
  27. * @return string
  28. */
  29. function replace_rcp_text( $translated_text ) {
  30. if ( $translated_text === 'ORIGINAL TEXT' ) {
  31. $translated_text = 'NEW TEXT';
  32. }
  33. return $translated_text;
  34. }
  35. // add_filter( 'gettext', 'ravensegg2022\replace_rcp_text', 20 );
  36. // ******************** Download Monitor ************************ //
  37. /**
  38. * Sets S3 request expiration to 24 hours from 15 minutes.
  39. */
  40. //add_filter( 'dlm_as3_request_valid_minutes', function ( $minutes, $download, $version, $path ) {
  41. // return 1440;
  42. //}, 10, 4 );
  43. // ******************** ACF ************************ //
  44. /**
  45. * Adds ACF Options page.
  46. *
  47. * @package ACF
  48. */
  49. //if ( function_exists( 'acf_add_options_page' ) ) {
  50. // acf_add_options_page( array(
  51. // 'page_title' => 'Site Options',
  52. // 'menu_title' => 'Site Options',
  53. // 'menu_slug' => 'site-options',
  54. // 'capability' => 'edit_posts',
  55. // 'redirect' => false,
  56. // 'icon_url' => 'dashicons-admin-tools',
  57. // 'position' => 8
  58. // ) );
  59. //}
  60. /**
  61. * Adds Google Maps API key to ACF.
  62. */
  63. // function acf_google_map_init() {
  64. // acf_update_setting('google_api_key', 'insert_key_here');
  65. // }
  66. // add_action('acf/init', 'ravensegg20221\acf_google_map_init');
  67. /**
  68. * Sorts subfields by subfield with key shown below.
  69. *
  70. * @param $value
  71. * @param $post_id
  72. * @param $field
  73. *
  74. * @return mixed
  75. *
  76. * @package ACF
  77. */
  78. //function acf_load_value( $value, $post_id, $field ) {
  79. // $order = array();
  80. // if ( empty( $value ) ) {
  81. // return $value;
  82. // }
  83. // foreach ( $value as $i => $row ) {
  84. // $order[ $i ] = $row['field_538a33275738e'];
  85. // }
  86. // array_multisort( $order, SORT_DESC, $value );
  87. //
  88. // return $value;
  89. //}
  90. //
  91. //add_filter( 'acf/load_value/name=scores', 'ravensegg2022\acf_load_value', 10, 3 );
  92. /**
  93. * Customizes TinyMCE in ACF.
  94. *
  95. * @param $toolbars
  96. *
  97. * @return mixed
  98. *
  99. * @package ACF
  100. */
  101. //function modify_acf_toolbars( $toolbars ) {
  102. // // Uncomment to view format of $toolbars
  103. // // echo '< pre >';
  104. // // print_r( $toolbars );
  105. // // echo '< /pre >';
  106. // // die;
  107. //
  108. // $toolbars['RED'] = array();
  109. // $toolbars['RED'][1] = array(
  110. // 'formatselect',
  111. // 'bold',
  112. // 'italic',
  113. // 'bullist',
  114. // 'numlist',
  115. // 'blockquote',
  116. // 'link',
  117. // 'unlink',
  118. // );
  119. // $toolbars['RED'][2] = array(
  120. // 'strikethrough',
  121. // 'hr',
  122. // 'pastetext',
  123. // 'removeformat',
  124. // 'charmap',
  125. // 'undo',
  126. // 'redo',
  127. // 'wp_help',
  128. // 'styleselect',
  129. // );
  130. //
  131. // return $toolbars;
  132. //}
  133. //
  134. //add_filter( 'acf/fields/wysiwyg/toolbars', 'ravensegg2022\modify_acf_toolbars' );
  135. // ******************** Tribe The Events Calendar ************************ //
  136. /**
  137. * Removes unwanted styles from The Events Calendar plugin.
  138. */
  139. function remove_tec_styles() {
  140. $styles = array(
  141. 'tribe-events-bootstrap-datepicker-css',
  142. // 'tribe-events-calendar-style',
  143. // 'tribe-events-custom-jquery-styles',
  144. // 'tribe-events-calendar-style',
  145. // 'tribe-events-calendar-pro-style'
  146. );
  147. wp_deregister_style( $styles );
  148. }
  149. add_action( 'wp_enqueue_scripts', 'ravensegg2022\remove_tec_styles', 100 );
  150. /**
  151. * Hides all past events.
  152. *
  153. * @param $wp_query
  154. *
  155. * @return mixed
  156. *
  157. * @package TheEventsCalendar
  158. */
  159. //function filter_tribe_all_occurrences( $wp_query ) {
  160. //
  161. // if ( ! is_admin() ) {
  162. //
  163. // $new_meta = array();
  164. // $today = new DateTime();
  165. //
  166. // // Join with existing meta_query
  167. // if ( is_array( $wp_query->meta_query ) ) {
  168. // $new_meta = $wp_query->meta_query;
  169. // }
  170. //
  171. // // Add new meta_query, select events ending from now forward
  172. // $new_meta[] = array(
  173. // 'key' => '_EventEndDate',
  174. // 'type' => 'DATETIME',
  175. // 'compare' => '>=',
  176. // 'value' => $today->format( 'Y-m-d H:i:s' )
  177. // );
  178. //
  179. // $wp_query->set( 'meta_query', $new_meta );
  180. // }
  181. //
  182. // return $wp_query;
  183. //}
  184. //
  185. //add_filter( 'tribe_events_pre_get_posts', 'ravensegg2022\filter_tribe_all_occurrences', 100 );
  186. /**
  187. * Excludes categories from month view.
  188. *
  189. * @param $month_query
  190. *
  191. * @return mixed
  192. *
  193. * @package TheEventsCalendar
  194. */
  195. //function exclude_month_events_category( $month_query ) {
  196. //
  197. // if ( $month_query->query_vars['eventDisplay'] == 'month' && $month_query->query_vars['post_type'] == TribeEvents::POSTTYPE && ! is_tax( TribeEvents::TAXONOMY ) && empty( $month_query->query_vars['suppress_filters'] ) ) {
  198. // $month_query->set( 'tax_query', array(
  199. // array(
  200. // 'taxonomy' => TribeEvents::TAXONOMY,
  201. // 'field' => 'slug',
  202. // 'terms' => array( 'workshop-intro-international', 'workshop-intro-usa', ),
  203. // 'operator' => 'NOT IN'
  204. // )
  205. // )
  206. // );
  207. // }
  208. //
  209. // return $month_query;
  210. //}
  211. //
  212. //add_action( 'pre_get_posts', 'ravensegg2022\exclude_month_events_category' );
  213. /**
  214. * Excludes category from list view.
  215. *
  216. * @param $list_query
  217. *
  218. * @return mixed
  219. *
  220. * @package TheEventsCalendar
  221. */
  222. //function exclude_list_events_category( $list_query ) {
  223. // if ( $list_query->query_vars['eventDisplay'] == 'upcoming' || $list_query->query_vars['eventDisplay'] == 'past' && $list_query->query_vars['post_type'] == TribeEvents::POSTTYPE && ! is_tax( TribeEvents::TAXONOMY ) && empty( $list_query->query_vars['suppress_filters'] ) ) {
  224. // $list_query->set( 'tax_query', array(
  225. // array(
  226. // 'taxonomy' => TribeEvents::TAXONOMY,
  227. // 'field' => 'slug',
  228. // 'terms' => array( 'calendar-only' ),
  229. // 'operator' => 'NOT IN'
  230. // )
  231. // )
  232. // );
  233. // }
  234. //
  235. // return $list_query;
  236. //}
  237. //
  238. //add_action( 'pre_get_posts', 'ravensegg2022\exclude_list_events_category' );
  239. /**
  240. * String replacement for any text in The Events Calendar
  241. *
  242. * @param $translations
  243. * @param $text
  244. * @param $domain
  245. *
  246. * @return mixed
  247. *
  248. * @link http://codex.wordpress.org/Translating_WordPress#Localization_Technology
  249. *
  250. * @package TheEventsCalendar
  251. *
  252. * Put your custom text here in a key => value pair
  253. * Example: 'Text you want to change' => 'This is what it will be changed to'
  254. * The text you want to change is the key, and it is case-sensitive
  255. * The text you want to change it to is the value
  256. * You can freely add or remove key => values, but make sure to separate them with a comma
  257. * This example changes the label "Event" to "Webinar"
  258. */
  259. //function tribe_custom_theme_text( $translations, $text, $domain ) {
  260. //
  261. //
  262. // $custom_text = array(
  263. // 'Event' => 'Webinar',
  264. // 'event' => 'webinar',
  265. // 'Events' => 'Webinars',
  266. // 'events' => 'webinars',
  267. // );
  268. //
  269. // // If this text domain starts with "tribe-" or "the-events-", and we have replacement text
  270. // if ( ( strpos( $domain, 'tribe-' ) === 0 || strpos( $domain, 'the-events-' ) === 0 ) && array_key_exists( $text, $custom_text ) ) {
  271. // $text = $custom_text[ $text ];
  272. // }
  273. //
  274. // return $text;
  275. //}
  276. //
  277. //add_filter( 'gettext', 'ravensegg2022\tribe_custom_theme_text', 20, 3 );
  278. // Customizes the medium responsive breakpoint for month view from 768px to 600px
  279. // function customize_tribe_events_v2_view_month_medium_breakpoint( $breakpoints ) {
  280. // $breakpoints['medium'] = 600;
  281. // return $breakpoints;
  282. // }
  283. // add_filter( 'tribe_events_views_v2_view_month_breakpoints', 'ravensegg2022\customize_tribe_events_v2_view_month_medium_breakpoint' );
  284. // ******************** Gravity Forms ************************ //
  285. /**
  286. * Change Gravity Forms Entries page size.
  287. *
  288. * @return int
  289. *
  290. * @package GravityForms
  291. */
  292. function entry_page_size() {
  293. return 100;
  294. }
  295. add_filter( 'gform_entry_page_size', 'ravensegg2022\entry_page_size' );
  296. /**
  297. * Filters the next, previous and submit buttons.
  298. * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
  299. *
  300. * @param string $button Contains the <input> tag to be filtered.
  301. * @param object $form Contains all the properties of the current form.
  302. *
  303. * @return string The filtered button.
  304. */
  305. function input_to_button( $button, $form ) {
  306. $dom = new \DOMDocument();
  307. $dom->loadHTML( $button );
  308. $input = $dom->getElementsByTagName( 'input' )->item( 0 );
  309. $new_button = $dom->createElement( 'button' );
  310. $new_button->appendChild( $dom->createTextNode( $input->getAttribute( 'value' ) ) );
  311. $input->removeAttribute( 'value' );
  312. foreach ( $input->attributes as $attribute ) {
  313. $new_button->setAttribute( $attribute->name, $attribute->value );
  314. }
  315. $input->parentNode->replaceChild( $new_button, $input );
  316. return $dom->saveHtml( $new_button );
  317. }
  318. add_filter( 'gform_next_button', 'ravensegg2022\input_to_button', 10, 2 );
  319. add_filter( 'gform_previous_button', 'ravensegg2022\input_to_button', 10, 2 );
  320. add_filter( 'gform_submit_button', 'ravensegg2022\input_to_button', 10, 2 );
  321. // Disables all but essential gforms styles.
  322. add_filter( 'gform_disable_form_theme_css', '__return_true' );
  323. /**
  324. * Debug Pending Updates
  325. *
  326. * Crude debugging method that will spit out all pending plugin
  327. * and theme updates for admin level users when ?debug_updates is
  328. * added to a /wp-admin/ URL.
  329. *
  330. */
  331. // add_action( 'init', 'ravensegg2022\debug_pending_updates' );
  332. //function debug_pending_updates() {
  333. //
  334. // // Rough safety nets
  335. // if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
  336. // return;
  337. // }
  338. // if ( ! isset( $_GET['debug_updates'] ) ) {
  339. // return;
  340. // }
  341. //
  342. // $output = "";
  343. //
  344. // // Check plugins
  345. // $plugin_updates = get_site_transient( 'update_plugins' );
  346. // if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
  347. // foreach ( $plugin_updates->response as $plugin => $details ) {
  348. // $output .= "<p><strong>Plugin</strong> <u>$plugin</u> is reporting an available update.</p>";
  349. // }
  350. // }
  351. //
  352. // // Check themes
  353. // wp_update_themes();
  354. // $theme_updates = get_site_transient( 'update_themes' );
  355. // if ( $theme_updates && ! empty( $theme_updates->response ) ) {
  356. // foreach ( $theme_updates->response as $theme => $details ) {
  357. // $output .= "<p><strong>Theme</strong> <u>$theme</u> is reporting an available update.</p>";
  358. // }
  359. // }
  360. //
  361. // if ( empty( $output ) ) {
  362. // $output = "No pending updates found in the database.";
  363. // }
  364. //
  365. // wp_die( $output );
  366. //}