get_status_labels();
$nonce = wp_create_nonce( 'aiforya_ma_admin' );
$assignments = $db->get_assignments_by_status( array_keys( $status_labels ) );
$recent_posts = get_posts( [
'post_type' => 'post',
'post_status' => [ 'publish', 'draft', 'pending', 'future', 'private' ],
'numberposts' => 100,
'orderby' => 'date',
'order' => 'DESC',
] );
$authors = get_users( [
'role__in' => [ 'aiforya_ma_writer', 'aiforya_ma_editor', 'aiforya_ma_publisher', 'administrator', 'editor', 'author' ],
'orderby' => 'display_name',
'order' => 'ASC',
] );
// Helper D2 : pastille d'aide « ? » charte (AiforyaTooltip). $text déjà traduit.
$tip = static function ( $text ) {
printf( '', esc_attr( $text ) );
};
?>
|
|
|
|
post_id );
if ( ! $post ) {
continue;
}
$author = get_user_by( 'id', (int) $assignment->user_id );
$coauthors = $db->get_coauthors_for_post( (int) $assignment->post_id );
$co_names = array_map( static fn( $c ) => (string) ( $c->display_name ?? '' ), $coauthors );
?>
| post_title !== '' ? $post->post_title : __( '(no title)', 'aiforya-multi-author' ) ); ?> |
display_name : __( 'Unassigned', 'aiforya-multi-author' ) ); ?> |
|
ID (vérifié sur la requête).
*/
$co_ids = array_map( static fn( $c ) => (int) ( $c->user_id ?? 0 ), $coauthors );
?>
(int) $u->ID !== (int) $assignment->user_id && ! in_array( (int) $u->ID, $co_ids, true )
);
?>
—
display_name ?? '' ) ); ?>
|
$nonce,
'articleAssigne' => __( 'Post assigned.', 'aiforya-multi-author' ),
'echecDeLAssignation' => __( 'Assignment failed.', 'aiforya-multi-author' ),
'erreurReseau' => __( 'Network error.', 'aiforya-multi-author' ),
'statutMisAJour' => __( 'Status updated.', 'aiforya-multi-author' ),
'echecDuChangementDe' => __( 'Status change failed.', 'aiforya-multi-author' ),
'erreurReseau2' => __( 'Network error.', 'aiforya-multi-author' ),
'coAuteurAjoute' => __( 'Co-author added.', 'aiforya-multi-author' ),
'echecAjoutCoAuteur' => __( 'Adding the co-author failed.', 'aiforya-multi-author' ),
'coAuteurRetire' => __( 'Co-author removed.', 'aiforya-multi-author' ),
'echecRetraitCoAuteur' => __( 'Removing the co-author failed.', 'aiforya-multi-author' ),
)
);
$js = <<<'JS'
var L = window.aiforyaMultiAuthorTabArticlesL10n || {};
(function () {
if (typeof jQuery === 'undefined') { return; }
jQuery(function ($) {
var nonce = L.nonce;
var ajaxUrl = ajaxurl;
function notify(type, message) {
if (window.AiforyaToast && typeof window.AiforyaToast[type] === 'function') {
window.AiforyaToast[type](message);
}
}
$('#aiforya-ma-assign-btn').on('click', function () {
var $btn = $(this);
$btn.prop('disabled', true);
$.post(ajaxUrl, {
action: 'aiforya_ma_assign_article',
nonce: nonce,
post_id: $('#aiforya-ma-assign-post').val(),
user_id: $('#aiforya-ma-assign-user').val()
}).done(function (response) {
if (response && response.success) {
notify('success', (response.data && response.data.message) || L.articleAssigne);
window.location.reload();
} else {
notify('error', (response && response.data && response.data.message) || L.echecDeLAssignation);
}
}).fail(function () {
notify('error', L.erreurReseau);
}).always(function () {
$btn.prop('disabled', false);
});
});
$('.aiforya-ma-status-select').on('change', function () {
var $select = $(this);
var postId = $select.data('post');
$.post(ajaxUrl, {
action: 'aiforya_ma_change_status',
nonce: nonce,
post_id: postId,
new_status: $select.val()
}).done(function (response) {
if (response && response.success) {
notify('success', (response.data && response.data.message) || L.statutMisAJour);
} else {
notify('error', (response && response.data && response.data.message) || L.echecDuChangementDe);
}
}).fail(function () {
notify('error', L.erreurReseau2);
});
});
/*
* Co-auteurs — AJOUTÉ LE 17/08/2026.
* Les deux handlers existaient depuis l'origine et rien ne les appelait :
* la fonctionnalité annoncée par le readme n'avait aucune interface.
* Les deux attendent post_id + user_id (lus dans le handler PHP, pas devinés).
*/
$(document).on('click', '.aiforya-ma-co-add', function () {
var $btn = $(this);
var $wrap = $btn.closest('.aiforya-ma-coauthors');
var userId = $wrap.find('.aiforya-ma-co-select').val();
if (!userId) { return; }
$btn.prop('disabled', true);
$.post(ajaxUrl, {
action: 'aiforya_ma_add_coauthor',
nonce: nonce,
post_id: $wrap.data('post'),
user_id: userId
}).done(function (response) {
if (response && response.success) {
notify('success', (response.data && response.data.message) || L.coAuteurAjoute);
window.location.reload();
} else {
notify('error', (response && response.data && response.data.message) || L.echecAjoutCoAuteur);
$btn.prop('disabled', false);
}
}).fail(function () {
notify('error', L.erreurReseau);
$btn.prop('disabled', false);
});
});
$(document).on('click', '.aiforya-ma-co-remove', function () {
var $btn = $(this);
var $wrap = $btn.closest('.aiforya-ma-coauthors');
$btn.prop('disabled', true);
$.post(ajaxUrl, {
action: 'aiforya_ma_remove_coauthor',
nonce: nonce,
post_id: $wrap.data('post'),
user_id: $btn.data('user')
}).done(function (response) {
if (response && response.success) {
notify('success', (response.data && response.data.message) || L.coAuteurRetire);
window.location.reload();
} else {
notify('error', (response && response.data && response.data.message) || L.echecRetraitCoAuteur);
$btn.prop('disabled', false);
}
}).fail(function () {
notify('error', L.erreurReseau);
$btn.prop('disabled', false);
});
});
});
})();
JS;
wp_add_inline_script( $handle, $js );
?>