PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/functions.php

https://gitlab.com/i-have-a-green/digitemis-v3
PHP | 282 lines | 209 code | 23 blank | 50 comment | 12 complexity | 0fa803cfd089f8a97c03b28755011448 MD5 | raw file
  1. <?php
  2. include_once("inc/acf.php");
  3. include_once("inc/acf-block.php");
  4. //include_once("inc/settings-gutenberg.php");
  5. include_once("inc/widget.php");
  6. include_once("inc/function-jobs.php");
  7. include_once("inc/clean.php");
  8. include_once("inc/no-comment.php");
  9. include_once("inc/images.php");
  10. include_once("inc/custom-post-type.php");
  11. include_once("inc/breadcrumb.php");
  12. include_once("inc/menu.php");
  13. include_once("inc/enqueue_scripts.php");
  14. include_once("inc/contact.php");
  15. //MNG
  16. register_block_style(
  17. 'core/button',
  18. array(
  19. 'name' => 'blue-border',
  20. 'label' => __( 'Bordure bleu' ),
  21. )
  22. );
  23. register_block_style(
  24. 'core/button',
  25. array(
  26. 'name' => 'white-border',
  27. 'label' => __( 'Bordure blanche' ),
  28. )
  29. );
  30. function setupcolor_digitemis(){
  31. $black = '#000000';
  32. $grey = '#a4a4a4';
  33. $white = '#ffffff';
  34. $blue_regular = '#144660';
  35. $blue_light = '#1ab8ec';
  36. $blue_medium = '#3D8695';
  37. $blue_green = '#54b3ba';
  38. $purple_regular = '#a2004c';
  39. add_theme_support(
  40. 'editor-color-palette',
  41. array(
  42. array(
  43. 'name' => esc_html__( 'Black', 'twentytwentyone' ),
  44. 'slug' => 'black',
  45. 'color' => $black,
  46. ),
  47. array(
  48. 'name' => esc_html__( 'Grey', 'twentytwentyone' ),
  49. 'slug' => 'grey',
  50. 'color' => $grey,
  51. ),
  52. array(
  53. 'name' => esc_html__( 'White', 'twentytwentyone' ),
  54. 'slug' => 'white',
  55. 'color' => $white,
  56. ),
  57. array(
  58. 'name' => esc_html__( 'Bleue', 'twentytwentyone' ),
  59. 'slug' => 'blue',
  60. 'color' => $blue_regular,
  61. ),
  62. array(
  63. 'name' => esc_html__( 'Bleue Moyen', 'twentytwentyone' ),
  64. 'slug' => 'blue_medium',
  65. 'color' => $blue_medium,
  66. ),
  67. array(
  68. 'name' => esc_html__( 'Bleue Verdâtre', 'twentytwentyone' ),
  69. 'slug' => 'blue_green',
  70. 'color' => $blue_green,
  71. ),
  72. array(
  73. 'name' => esc_html__( 'Bleue Clair', 'twentytwentyone' ),
  74. 'slug' => 'blue_light',
  75. 'color' => $blue_light,
  76. ),
  77. array(
  78. 'name' => esc_html__( 'Rouge Violet', 'twentytwentyone' ),
  79. 'slug' => 'purple_regular',
  80. 'color' => $purple_regular,
  81. ),
  82. )
  83. );
  84. }
  85. add_action('after_setup_theme', 'setupcolor_digitemis');
  86. // Adding excerpt for page
  87. //add_post_type_support( 'page', 'excerpt' );
  88. /**
  89. * Filter the excerpt length to 20 characters.
  90. *
  91. * @param int $length Excerpt length.
  92. * @return int (Maybe) modified excerpt length.
  93. */
  94. //add_filter( 'excerpt_length', function( $length ) { return 20; } );
  95. function ihag_unregister_taxonomy(){
  96. register_taxonomy('post_tag', array());
  97. register_taxonomy('category', array());
  98. add_post_type_support( 'page', 'excerpt' );
  99. remove_post_type_support( 'page', 'thumbnail' );
  100. }
  101. //add_action('init', 'ihag_unregister_taxonomy');
  102. // Copier le contenu d'une page ou d'un post à la création d'une traduction
  103. function cw2b_content_copy( $content ) {
  104. if ( isset( $_GET['from_post'] ) ) {
  105. $my_post = get_post( $_GET['from_post'] );
  106. if ( $my_post )
  107. return $my_post->post_content;
  108. }
  109. return $content;
  110. }
  111. //add_filter( 'default_content', 'cw2b_content_copy' );
  112. function my_pre_get_posts($query) {
  113. if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
  114. $query->set('post_type', array("post", "rendez-vous", "solution"));
  115. $query->set('posts_per_page', -1);
  116. }
  117. }
  118. //add_action( 'pre_get_posts', 'my_pre_get_posts' );
  119. function nbTinyURL($url) {
  120. $ch = curl_init();
  121. $timeout = 5;
  122. curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
  123. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  124. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  125. $data = curl_exec($ch);
  126. curl_close($ch);
  127. return $data;
  128. }
  129. /*
  130. add_action( 'wp_ajax_readMorePost', 'ihag_readMorePost' );
  131. add_action( 'wp_ajax_nopriv_readMorePost', 'ihag_readMorePost' );
  132. function ihag_readMorePost(){
  133. $offset = ((int)sanitize_text_field( $_POST["page"] ) - 1) * get_option( 'posts_per_page' );
  134. $args = array(
  135. 'posts_per_page' => get_option( 'posts_per_page' ),
  136. 'post_type' => "post",
  137. 'post_status' => 'publish',
  138. 'offset' => $offset,
  139. );
  140. if(!empty($_POST['category'])){
  141. $args['tax_query'] = array(
  142. array(
  143. 'taxonomy' => 'category',
  144. 'field' => 'term_id',
  145. 'terms' => $_POST["category"]
  146. )
  147. );
  148. }
  149. $custom_query = new WP_Query($args);
  150. if ( $custom_query->have_posts() ) :
  151. while ( $custom_query->have_posts() ) :
  152. $custom_query->the_post();
  153. get_template_part( 'template-parts/content', get_post_type() );
  154. endwhile;
  155. endif;
  156. wp_die();
  157. }*/
  158. function my_theme_setup() {
  159. // Nouveauté à ajouter
  160. add_theme_support('editor-styles');
  161. add_editor_style( 'style-editor.css' );
  162. add_editor_style(get_stylesheet_directory_uri().'/style-editor.css');
  163. add_theme_support( 'align-wide' );
  164. }
  165. add_action( 'after_setup_theme', 'my_theme_setup' );
  166. // Add custom validation for CF7 form fields
  167. function is_company_email($email){ // Check against list of common public email providers & return true if the email provided *doesn't* match one of them
  168. if(
  169. preg_match('/@gmail.com/i', $email) ||
  170. preg_match('/@gmail.fr/i', $email) ||
  171. preg_match('/@hotmail.com/i', $email) ||
  172. preg_match('/@hotmail.fr/i', $email) ||
  173. preg_match('/@live.com/i', $email) ||
  174. preg_match('/@msn.com/i', $email) ||
  175. preg_match('/@aol.com/i', $email) ||
  176. preg_match('/@yahoo.com/i', $email) ||
  177. preg_match('/@yahoo.fr/i', $email) ||
  178. preg_match('/@inbox.com/i', $email) ||
  179. preg_match('/@gmx.com/i', $email) ||
  180. preg_match('/@gmx.fr/i', $email) ||
  181. preg_match('/@mail.ru/i', $email) ||
  182. preg_match('/@rambler.ru/i', $email) ||
  183. preg_match('/@test4xrumer.store/i',$email) ||
  184. preg_match('/@yandex.ru/i', $email) ||
  185. preg_match('/@neuf.fr/i', $email) ||
  186. preg_match('/@sfr.fr/i', $email) ||
  187. preg_match('/@me.com/i', $email)
  188. ){
  189. return false; // It's a publicly available email address
  190. }else{
  191. return true; // It's probably a company email address
  192. }
  193. }
  194. function your_validation_filter_func($result,$tag){
  195. $type = $tag['type'];
  196. $name = $tag['name'];
  197. if('email' == $type || 'email*' == $type){ // Only apply to fields with the form field name of "company-email"
  198. $the_value = $_POST[$name];
  199. if(!is_company_email($the_value)){ // Isn't a company email address (it matched the list of free email providers)
  200. //$result['valid'] = false;
  201. $result->invalidate( $tag, __("Merci d'indiquer une adresse professionnelle et non une adresse personnelle", "digitemis"));
  202. //$result['reason'][$name] = 'Yzou need to provide an email address that isn\'t hosted by a free provider.<br />Please contact us directly if this isn\'t possible.';
  203. }
  204. }
  205. return $result;
  206. }
  207. add_filter( 'wpcf7_validate_email', 'your_validation_filter_func', 10, 2 ); // Email field or contact number field
  208. add_filter( 'wpcf7_validate_email*', 'your_validation_filter_func', 10, 2 ); // Req. Email field or contact number
  209. function wpd_update_taxonomy_args( $taxonomy, $object_type, $args ){
  210. if( 'category' == $taxonomy ){
  211. remove_action( current_action(), __FUNCTION__ );
  212. $args['rewrite'] = array( 'slug' => 'blog' );
  213. register_taxonomy( $taxonomy, $object_type, $args );
  214. }
  215. }
  216. add_action( 'registered_taxonomy', 'wpd_update_taxonomy_args', 10, 3 );
  217. function ihag_service_rewrite_url() {
  218. add_rewrite_rule(
  219. 'services/([^/]+)/([^/]+)/([^/]+)',
  220. 'index.php?post_type=service&name=$matches[3]',
  221. 'top'
  222. );
  223. /*add_rewrite_rule(
  224. 'services/([^/]+)/([^/]+)',
  225. 'index.php?post_type=service&name=$matches[2]',
  226. 'top'
  227. );*/
  228. /*add_rewrite_rule(
  229. 'services/([^/]+)',
  230. 'index.php?post_type=service&name=$matches[1]',
  231. 'top'
  232. );*/
  233. //flush_rewrite_rules();
  234. }
  235. add_action( 'init', 'ihag_service_rewrite_url' );
  236. function ihag_update_service_link( $post_link, $post ) {
  237. if ( 'service' != $post->post_type )return $post_link;
  238. $id_parent_page = get_field('parent_page', $post->ID);
  239. if($id_parent_page){
  240. return get_site_url().'/services'.str_replace(get_site_url(), '', get_permalink($id_parent_page)).$post->post_name;
  241. }
  242. return $post_link;
  243. }
  244. add_filter( 'post_type_link', 'ihag_update_service_link', 10, 2 );