avant corrections
This commit is contained in:
+153
@@ -100,7 +100,160 @@ collect(['setup', 'filters'])
|
||||
}
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user