123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | Register The Auto Loader
- |--------------------------------------------------------------------------
- |
- | Composer provides a convenient, automatically generated class loader for
- | our theme. We will simply require it into the script here so that we
- | don't have to worry about manually loading any of our classes later on.
- |
- */
- if (! file_exists($composer = __DIR__.'/vendor/autoload.php')) {
- wp_die(__('Error locating autoloader. Please run <code>composer install</code>.', 'sage'));
- }
- require $composer;
- /*
- |--------------------------------------------------------------------------
- | Register The Bootloader
- |--------------------------------------------------------------------------
- |
- | The first thing we will do is schedule a new Acorn application container
- | to boot when WordPress is finished loading the theme. The application
- | serves as the "glue" for all the components of Laravel and is
- | the IoC container for the system binding all of the various parts.
- |
- */
- if (! function_exists('\Roots\bootloader')) {
- wp_die(
- __('You need to install Acorn to use this theme.', 'sage'),
- '',
- [
- 'link_url' => 'https://roots.io/acorn/docs/installation/',
- 'link_text' => __('Acorn Docs: Installation', 'sage'),
- ]
- );
- }
- \Roots\bootloader()->boot();
- /*
- |--------------------------------------------------------------------------
- | Register Sage Theme Files
- |--------------------------------------------------------------------------
- |
- | Out of the box, Sage ships with categorically named theme files
- | containing common functionality and setup to be bootstrapped with your
- | theme. Simply add (or remove) files from the array below to change what
- | is registered alongside Sage.
- |
- */
- collect(['setup', 'filters'])
- ->each(function ($file) {
- if (! locate_template($file = "app/{$file}.php", true, true)) {
- wp_die(
- /* translators: %s is replaced with the relative file path */
- sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file)
- );
- }
- });
- //ajout des champs personnalisés Minutage et Images; pour les afficher rdv dans le fichier content-single
- //le faire qu'une suele fois et après mettre en commentaire
- // function ajout_champs() {
- // add_post_meta(get_the_ID(), 'Index', true);
- // add_post_meta(get_the_ID(), 'Minutage', true);
- // add_post_meta(get_the_ID(), 'Images', true);
- // add_post_meta(get_the_ID(), 'BandeSon', true);
- // add_post_meta(get_the_ID(), 'Ecrits', true);
- // add_post_meta(get_the_ID(), 'VoixOffIn', true);
- // add_post_meta(get_the_ID(), 'isMainPart', true);
- // add_post_meta(get_the_ID(), 'isSubPart', true);
- // }
- // add_action('init', 'ajout_champs');
-
- function cacher_bloc_head_admin() {
- // Cache le bloc head du plugin de PublicPress
- echo '<style>.pp-version-notice-bold-purple { display: none; }</style>';
- echo '<style>.notice-warning { display: none; }</style>';
-
- }
- add_action('admin_head', 'cacher_bloc_head_admin');
-
- function cacher_bloc_foot_admin() {
- // Cache le bloc foot du plugin de PublicPress
- echo '<style>.pp-rating { display: none; }</style>';
- echo '<style>.pp-pressshack-logo { display: none; }</style>';
- echo '<style> footer nav{ display: none; }</style>';
- echo '<style> ul.subsubsub li:nth-child(1) a { display: none;}</style>';
-
- }
- add_action('admin_footer', 'cacher_bloc_foot_admin');
- function custom_filter_dropdown() {
- global $typenow;
- if ($typenow == 'post') { // Adjust post type if needed
- $selected = isset($_GET['custom_field_filter']) ? $_GET['custom_field_filter'] : '';
- $options = array(
- 'isMainPart' => __('isMainPart', 'textdomain'),
- 'isSubPart' => __('isSubPart', 'textdomain'),
- );
-
- echo '<select name="custom_field_filter">';
- echo '<option value="">' . __('All Custom Fields', 'textdomain') . '</option>';
- foreach ($options as $key => $label) {
- echo '<option value="' . $key . '"' . selected($selected, $key, false) . '>' . $label . '</option>';
- }
- echo '</select>';
- }
- }
-
- add_action('restrict_manage_posts', 'custom_filter_dropdown');
-
-
- function filter_by_custom_field($query) {
- global $pagenow;
- if (is_admin() && $pagenow == 'edit.php' && isset($_GET['custom_field_filter'])) {
- $custom_field_key = sanitize_text_field($_GET['custom_field_filter']);
- if (!empty($custom_field_key)) {
- $meta_query = array(
- array(
- 'key' => $custom_field_key,
- 'compare' => 'EXISTS',
- ),
- );
- $query->query_vars['meta_query'] = $meta_query;
- }
- }
- }
-
- add_filter('parse_query', 'filter_by_custom_field');
- add_action('wp', 'generate_csv');
- function generate_csv() {
- if ('csv' === (isset($_GET['format']) ? $_GET['format'] : null)) {
- // Query to get all posts
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => -1,
- 'meta_key' => 'index',
- 'meta_type' => 'NUMERIC',
- 'orderby' => 'meta_value',
- 'order' => 'ASC'
- );
-
- $posts = get_posts($args);
-
- if (!empty($posts)) {
- // Initialize CSV data array
- $csvData = array();
-
- // Add CSV header row
- $csvData[] = array('Temps', 'Images', 'Voix Off et In', 'Bande Son', 'Écrits', 'Section');
-
- // Loop through posts and add them to the CSV data array
- foreach ($posts as $post) {
- $post_content = wp_strip_all_tags($post->post_content);
- $content_array = explode("---", $post_content);
- $temps = $post->post_title;
- $images = isset($content_array[1]) ? $content_array[1] : '';
- $images = substr($images, 0, -15);
- $voixOffIn = isset($content_array[2]) ? $content_array[2] : '';
- $voixOffIn = substr($voixOffIn, 0, -10);
- $bandeson = isset($content_array[3]) ? $content_array[3] : '';
- $bandeson = substr($bandeson, 0, -8);
- $ecrits = isset($content_array[4]) ? $content_array[4] : '';
- if (get_post_meta($post->ID, 'isMainPart', true)) {
- $section = get_post_meta($post->ID, 'isMainPart', true);
- } elseif (get_post_meta($post->ID, 'isSubPart', true)) {
- $section = get_post_meta($post->ID, 'isSubPart', true);
- } else {
- $section = '';
- }
- $csvData[] = array(
- $temps,
- $images,
- $voixOffIn,
- $bandeson,
- $ecrits,
- $section,
- );
- }
-
- $csvFileName = 'partition_livre_d_image.csv';
-
- header('Content-Encoding: UTF-8');
- header('Content-Type: text/csv; charset=utf-8');
- header('Content-Disposition: attachment; filename=' . $csvFileName);
- echo "\xEF\xBB\xBF"; // UTF-8 BOM
-
- // Output CSV data
- $output = fopen('php://output', 'w');
- foreach ($csvData as $row) {
- fputcsv($output, $row);
- }
- fclose($output);
-
- exit;
- }
- }
- }
- function custom_admin_styles() {
- wp_enqueue_style('custom-admin', get_template_directory_uri() . '/resources/styles/admin_custom.css');
- }
- add_action('admin_enqueue_scripts', 'custom_admin_styles');
- function restrict_revisions_by_author($query) {
- global $current_user;
-
- // Check if the user is logged in
- if (is_user_logged_in()) {
- get_currentuserinfo();
- $author_id = $current_user->ID;
-
- // Modify the query to filter revisions by author
- if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'revision') {
- $query->set('author', $author_id);
- }
- }
- }
- add_action('pre_get_posts', 'restrict_revisions_by_author');
- function customize_editor_for_editor_role() {
- if (current_user_can('revisor')) {
- wp_enqueue_script('custom-editor-script', get_template_directory_uri() . '/resources/scripts/custom-editor-script.js', array(), null, true);
- wp_enqueue_style('custom-editor-style', get_template_directory_uri() . '/resources/styles/custom-editor-style.css');
-
- // Get the content of the specific page (replace '123' with the actual page ID)
- $page_id = 13940;
- $page_content = get_post_field('post_content', $page_id);
-
- // Localize the page content to be accessible in your custom script
- wp_localize_script('custom-editor-script', 'pageContentData', array('content' => $page_content));
- }
- }
- add_action('admin_enqueue_scripts', 'customize_editor_for_editor_role');
-
-
-
- // function supprimer_tous_les_articles() {
- // $args = array(
- // 'post_type' => 'post',
- // 'posts_per_page' => -1,
- // );
-
- // $posts = get_posts($args);
-
- // foreach ($posts as $post) {
- // wp_delete_post($post->ID, true);
- // }
- // }
- // add_action('init', 'supprimer_tous_les_articles');
|