fini il reste juste les corrections sur la tl

This commit is contained in:
Valentin
2023-11-30 02:57:55 +01:00
parent 4999a4a944
commit 54e7a2e847
18 changed files with 21509 additions and 1883 deletions
+79 -3
View File
@@ -217,6 +217,7 @@ collect(['setup', 'filters'])
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');
@@ -241,20 +242,95 @@ collect(['setup', 'filters'])
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));
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 supprimer_tous_les_articles() {
// $args = array(