composer install.', '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 %s
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 '';
echo '';
}
add_action('admin_head', 'cacher_bloc_head_admin');
function cacher_bloc_foot_admin() {
// Cache le bloc foot du plugin de PublicPress
echo '';
echo '';
echo '';
echo '';
}
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 '';
}
}
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');
wp_enqueue_script('custom-admin-script', get_template_directory_uri() . '/resources/scripts/custom-admin-script.js', array(), null, true);
}
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');
// Create my revisions page
$current_user = wp_get_current_user();
$author_id = $current_user->ID;
$revisionary_page = admin_url('admin.php?page=revisionary-q&author=' . $author_id);
// 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);
$website_url = site_url();
// Localize the page content to be accessible in your custom script
wp_localize_script('custom-editor-script', 'pageContentData', array(
'content' => $page_content,
'websiteUrl' => $website_url,
'myRevisionsUrl' => $revisionary_page,
));
}
}
add_action('admin_enqueue_scripts', 'customize_editor_for_editor_role');
function remove_roles() {
remove_role('author');
remove_role('editor');
remove_role('subscriber');
remove_role('contributor');
}
add_action('init', 'remove_roles');
// Redirect all post URLs to the homepage
function redirect_single_posts_to_homepage() {
if (is_single() && isset($_GET['p'])) {
wp_redirect(home_url(), 301);
exit();
}
}
add_action('template_redirect', 'redirect_single_posts_to_homepage');
function log_posts_with_user_revisions() {
$current_user = wp_get_current_user();
if (current_user_can('revisor')) {
if ($current_user instanceof WP_User) {
$current_user_id = $current_user->ID;
$args = array(
'post_type' => 'revision', // Fetch all post types including revisions
'post_status' => 'inherit', // Fetch all post statuses including revisions
'posts_per_page' => -1, // Retrieve all posts
'author' => $current_user_id,
'fields' => 'ids', // Retrieve only IDs to speed up the query
);
$all_posts = get_posts($args);
$parents_posts_ids = array();
$revisions_dates = array();
foreach ($all_posts as $post_id) {
$current_revision_date = array();
$current_revision_date[] = get_post(wp_get_post_parent_id($post_id))->post_title;
$current_revision_date[] = get_post($post_id)->post_date;
$revisions_dates[] = $current_revision_date;
$parents_posts_ids[] = wp_get_post_parent_id($post_id);
}
$parents_posts_ids = array_unique($parents_posts_ids);
$history_posts_titles = array();
$history_posts_contents = array();
foreach ($parents_posts_ids as $parent_post_id) {
$history_posts_titles[] = get_post($parent_post_id)->post_title;
$history_posts_contents[] = strip_tags(get_post($parent_post_id)->post_content);
}
// Enqueue the script
wp_enqueue_script('contribution-history-script', get_template_directory_uri() . '/resources/scripts/contribution_history.js', array('jquery'), '1.0', true);
// Localize script to pass data to JavaScript
wp_localize_script('contribution-history-script', 'historyData', array(
'titles' => $history_posts_titles,
'contents' => $history_posts_contents,
'dates' => $revisions_dates
));
}
}
}
add_action('admin_enqueue_scripts', 'log_posts_with_user_revisions');
function custom_logout_redirect() {
wp_redirect( home_url() );
exit();
}
add_action('wp_logout','custom_logout_redirect');
// 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');