<?php

function mp_update_publish() {
	$post_args = array(
		'numberposts' => -1,
		//'post_status' => 'draft',
		'post_status' => 'publish',
		'post_type'   => 'post',
	);
	$post_list = get_posts($post_args);
	foreach ($post_list as $post) {
		wp_update_post(array(
			'ID' => $post->ID,
			//'post_status' => 'draft',
			'post_status' => 'publish',
		));
	};
}
add_action( 'admin_post_update_publish', 'mp_update_publish' );
add_action( 'admin_post_nopriv_update_publish', 'mp_update_publish' );

// https://developer.wordpress.org/reference/hooks/admin_post_action/
// https://wordpress.stackexchange.com/questions/309440/wordpress-plugin-how-to-run-function-when-button-is-clicked
function mp_create_republish_button() {
	$content = '
		<br />
		<div style="border:1px solid black;padding:20px;">
			<h2>mettre a jour les publications</h2>
			<p>
				cliquez sur ce bouton pour mettre a jour toutes les publications
				<br />
				une nouvelle page vide va s\'ouvrir dans un nouvel onglet, vous pouvez la fermer
			</p>
			<form action="'.admin_url('admin-post.php').'" method="post" target="_blank">
				<input type="hidden" name="action" value="update_publish">
				<input type="submit" value="mettre a jour">
			</form>
		</div>
		<br />
	';
	return $content;
}

?>
