functions.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Register The Auto Loader
  5. |--------------------------------------------------------------------------
  6. |
  7. | Composer provides a convenient, automatically generated class loader for
  8. | our theme. We will simply require it into the script here so that we
  9. | don't have to worry about manually loading any of our classes later on.
  10. |
  11. */
  12. if (! file_exists($composer = __DIR__.'/vendor/autoload.php')) {
  13. wp_die(__('Error locating autoloader. Please run <code>composer install</code>.', 'sage'));
  14. }
  15. require $composer;
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Register The Bootloader
  19. |--------------------------------------------------------------------------
  20. |
  21. | The first thing we will do is schedule a new Acorn application container
  22. | to boot when WordPress is finished loading the theme. The application
  23. | serves as the "glue" for all the components of Laravel and is
  24. | the IoC container for the system binding all of the various parts.
  25. |
  26. */
  27. if (! function_exists('\Roots\bootloader')) {
  28. wp_die(
  29. __('You need to install Acorn to use this theme.', 'sage'),
  30. '',
  31. [
  32. 'link_url' => 'https://roots.io/acorn/docs/installation/',
  33. 'link_text' => __('Acorn Docs: Installation', 'sage'),
  34. ]
  35. );
  36. }
  37. \Roots\bootloader()->boot();
  38. /*
  39. |--------------------------------------------------------------------------
  40. | Register Sage Theme Files
  41. |--------------------------------------------------------------------------
  42. |
  43. | Out of the box, Sage ships with categorically named theme files
  44. | containing common functionality and setup to be bootstrapped with your
  45. | theme. Simply add (or remove) files from the array below to change what
  46. | is registered alongside Sage.
  47. |
  48. */
  49. collect(['setup', 'filters'])
  50. ->each(function ($file) {
  51. if (! locate_template($file = "app/{$file}.php", true, true)) {
  52. wp_die(
  53. /* translators: %s is replaced with the relative file path */
  54. sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file)
  55. );
  56. }
  57. });
  58. //ajout des champs personnalisés Minutage et Images; pour les afficher rdv dans le fichier content-single
  59. //le faire qu'une suele fois et après mettre en commentaire
  60. // function ajout_champs() {
  61. // add_post_meta(get_the_ID(), 'Index', true);
  62. // add_post_meta(get_the_ID(), 'Minutage', true);
  63. // add_post_meta(get_the_ID(), 'Images', true);
  64. // add_post_meta(get_the_ID(), 'BandeSon', true);
  65. // add_post_meta(get_the_ID(), 'Ecrits', true);
  66. // add_post_meta(get_the_ID(), 'VoixOffIn', true);
  67. // add_post_meta(get_the_ID(), 'isMainPart', true);
  68. // add_post_meta(get_the_ID(), 'isSubPart', true);
  69. // }
  70. // add_action('init', 'ajout_champs');
  71. function cacher_bloc_head_admin() {
  72. // Cache le bloc head du plugin de PublicPress
  73. echo '<style>.pp-version-notice-bold-purple { display: none; }</style>';
  74. echo '<style>.notice-warning { display: none; }</style>';
  75. }
  76. add_action('admin_head', 'cacher_bloc_head_admin');
  77. function cacher_bloc_foot_admin() {
  78. // Cache le bloc foot du plugin de PublicPress
  79. echo '<style>.pp-rating { display: none; }</style>';
  80. echo '<style>.pp-pressshack-logo { display: none; }</style>';
  81. echo '<style> footer nav{ display: none; }</style>';
  82. echo '<style> ul.subsubsub li:nth-child(1) a { display: none;}</style>';
  83. }
  84. add_action('admin_footer', 'cacher_bloc_foot_admin');
  85. function custom_filter_dropdown() {
  86. global $typenow;
  87. if ($typenow == 'post') { // Adjust post type if needed
  88. $selected = isset($_GET['custom_field_filter']) ? $_GET['custom_field_filter'] : '';
  89. $options = array(
  90. 'isMainPart' => __('isMainPart', 'textdomain'),
  91. 'isSubPart' => __('isSubPart', 'textdomain'),
  92. );
  93. echo '<select name="custom_field_filter">';
  94. echo '<option value="">' . __('All Custom Fields', 'textdomain') . '</option>';
  95. foreach ($options as $key => $label) {
  96. echo '<option value="' . $key . '"' . selected($selected, $key, false) . '>' . $label . '</option>';
  97. }
  98. echo '</select>';
  99. }
  100. }
  101. add_action('restrict_manage_posts', 'custom_filter_dropdown');
  102. function filter_by_custom_field($query) {
  103. global $pagenow;
  104. if (is_admin() && $pagenow == 'edit.php' && isset($_GET['custom_field_filter'])) {
  105. $custom_field_key = sanitize_text_field($_GET['custom_field_filter']);
  106. if (!empty($custom_field_key)) {
  107. $meta_query = array(
  108. array(
  109. 'key' => $custom_field_key,
  110. 'compare' => 'EXISTS',
  111. ),
  112. );
  113. $query->query_vars['meta_query'] = $meta_query;
  114. }
  115. }
  116. }
  117. add_filter('parse_query', 'filter_by_custom_field');
  118. add_action('wp', 'generate_csv');
  119. function generate_csv() {
  120. if ('csv' === (isset($_GET['format']) ? $_GET['format'] : null)) {
  121. // Query to get all posts
  122. $args = array(
  123. 'post_type' => 'post',
  124. 'posts_per_page' => -1,
  125. 'meta_key' => 'index',
  126. 'meta_type' => 'NUMERIC',
  127. 'orderby' => 'meta_value',
  128. 'order' => 'ASC'
  129. );
  130. $posts = get_posts($args);
  131. if (!empty($posts)) {
  132. // Initialize CSV data array
  133. $csvData = array();
  134. // Add CSV header row
  135. $csvData[] = array('Temps', 'Images', 'Voix Off et In', 'Bande Son', 'Écrits', 'Section');
  136. // Loop through posts and add them to the CSV data array
  137. foreach ($posts as $post) {
  138. $post_content = wp_strip_all_tags($post->post_content);
  139. $content_array = explode("---", $post_content);
  140. $temps = $post->post_title;
  141. $images = isset($content_array[1]) ? $content_array[1] : '';
  142. $images = substr($images, 0, -15);
  143. $voixOffIn = isset($content_array[2]) ? $content_array[2] : '';
  144. $voixOffIn = substr($voixOffIn, 0, -10);
  145. $bandeson = isset($content_array[3]) ? $content_array[3] : '';
  146. $bandeson = substr($bandeson, 0, -8);
  147. $ecrits = isset($content_array[4]) ? $content_array[4] : '';
  148. if (get_post_meta($post->ID, 'isMainPart', true)) {
  149. $section = get_post_meta($post->ID, 'isMainPart', true);
  150. } elseif (get_post_meta($post->ID, 'isSubPart', true)) {
  151. $section = get_post_meta($post->ID, 'isSubPart', true);
  152. } else {
  153. $section = '';
  154. }
  155. $csvData[] = array(
  156. $temps,
  157. $images,
  158. $voixOffIn,
  159. $bandeson,
  160. $ecrits,
  161. $section,
  162. );
  163. }
  164. $csvFileName = 'partition_livre_d_image.csv';
  165. header('Content-Encoding: UTF-8');
  166. header('Content-Type: text/csv; charset=utf-8');
  167. header('Content-Disposition: attachment; filename=' . $csvFileName);
  168. echo "\xEF\xBB\xBF"; // UTF-8 BOM
  169. // Output CSV data
  170. $output = fopen('php://output', 'w');
  171. foreach ($csvData as $row) {
  172. fputcsv($output, $row);
  173. }
  174. fclose($output);
  175. exit;
  176. }
  177. }
  178. }
  179. function custom_admin_styles() {
  180. wp_enqueue_style('custom-admin', get_template_directory_uri() . '/resources/styles/admin_custom.css');
  181. }
  182. add_action('admin_enqueue_scripts', 'custom_admin_styles');
  183. function restrict_revisions_by_author($query) {
  184. global $current_user;
  185. // Check if the user is logged in
  186. if (is_user_logged_in()) {
  187. get_currentuserinfo();
  188. $author_id = $current_user->ID;
  189. // Modify the query to filter revisions by author
  190. if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'revision') {
  191. $query->set('author', $author_id);
  192. }
  193. }
  194. }
  195. add_action('pre_get_posts', 'restrict_revisions_by_author');
  196. function customize_editor_for_editor_role() {
  197. if (current_user_can('revisor')) {
  198. wp_enqueue_script('custom-editor-script', get_template_directory_uri() . '/resources/scripts/custom-editor-script.js', array(), null, true);
  199. wp_enqueue_style('custom-editor-style', get_template_directory_uri() . '/resources/styles/custom-editor-style.css');
  200. // Get the content of the specific page (replace '123' with the actual page ID)
  201. $page_id = 13940;
  202. $page_content = get_post_field('post_content', $page_id);
  203. // Localize the page content to be accessible in your custom script
  204. wp_localize_script('custom-editor-script', 'pageContentData', array('content' => $page_content));
  205. }
  206. }
  207. add_action('admin_enqueue_scripts', 'customize_editor_for_editor_role');
  208. // function supprimer_tous_les_articles() {
  209. // $args = array(
  210. // 'post_type' => 'post',
  211. // 'posts_per_page' => -1,
  212. // );
  213. // $posts = get_posts($args);
  214. // foreach ($posts as $post) {
  215. // wp_delete_post($post->ID, true);
  216. // }
  217. // }
  218. // add_action('init', 'supprimer_tous_les_articles');