abort preventiont of publication if address country invalid
This commit is contained in:
@@ -167,69 +167,76 @@ add_action( 'save_post', 'post_published_coordinates', 10, 2 );
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
|
||||||
// https://developer.wordpress.org/reference/hooks/save_post/
|
|
||||||
function test1($id, $post, $update) {
|
|
||||||
|
|
||||||
// is doing autosaving ?
|
|
||||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// is post creation ?
|
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
||||||
if (!$update)
|
// // https://developer.wordpress.org/reference/hooks/save_post/
|
||||||
return;
|
// function test1($id, $post, $update) {
|
||||||
|
//
|
||||||
|
// // is doing autosaving ?
|
||||||
|
// if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// // is post creation ?
|
||||||
|
// if (!$update)
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// // if this is a revision, get real post ID
|
||||||
|
// if ( $parent_id = wp_is_post_revision( $id ) )
|
||||||
|
// $id = $parent_id;
|
||||||
|
//
|
||||||
|
// // is the user allowed to edit the post or page ?
|
||||||
|
// if ( !current_user_can( 'edit_post', $id ) )
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// // is not being published ?
|
||||||
|
// if ($post->post_status != "publish")
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// $prevent_publish= true; // set to true if data was invalid
|
||||||
|
// if ($prevent_publish) {
|
||||||
|
//
|
||||||
|
// // unhook this function to prevent indefinite loop
|
||||||
|
// remove_action('save_post', 'my_save_post');
|
||||||
|
//
|
||||||
|
// // update the post to change post status
|
||||||
|
// wp_update_post(array('ID' => $id, 'post_status' => 'draft'));
|
||||||
|
//
|
||||||
|
// // re-hook this function again
|
||||||
|
// add_action('save_post', 'my_save_post');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// add_action( 'save_post_post', 'test1', 10, 3);
|
||||||
|
|
||||||
// is the user allowed to edit the post or page ?
|
// function publish_error() {
|
||||||
if ( !current_user_can( 'edit_post', $id ) )
|
// wp_enqueue_script('mp_publish_error',
|
||||||
return;
|
// plugins_url('scripts/mp_publish_error.js', __FILE__),
|
||||||
|
// array( 'wp-data' ),
|
||||||
|
// '',
|
||||||
|
// true
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// add_action( 'enqueue_block_editor_assets', 'publish_error');
|
||||||
|
|
||||||
// is not being published ?
|
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
||||||
if ($post->post_status != "publish")
|
// // https://wordpress.stackexchange.com/questions/15546/dont-publish-custom-post-type-post-if-a-meta-data-field-isnt-valid
|
||||||
return;
|
// function my_redirect_location($location, $post_id) {
|
||||||
|
//
|
||||||
$prevent_publish= true; // set to true if data was invalid
|
// // if post was published...
|
||||||
if ($prevent_publish) {
|
// if (isset($_POST['publish'])){
|
||||||
|
//
|
||||||
echo '<div class="notice notice-warning is-dismissible">
|
// // obtain current post status
|
||||||
<p>my message</p>
|
// $status = get_post_status( $post_id );
|
||||||
</div>';
|
//
|
||||||
|
// // the post was 'published', but if it is still a draft, display draft message (10).
|
||||||
// unhook this function to prevent indefinite loop
|
// if($status=='draft') {
|
||||||
remove_action('save_post', 'my_save_post');
|
// $location = add_query_arg('message', 10, $location);
|
||||||
|
// }
|
||||||
// update the post to change post status
|
// }
|
||||||
wp_update_post(array('ID' => $post_id, 'post_status' => 'draft'));
|
//
|
||||||
|
// return $location;
|
||||||
// re-hook this function again
|
// }
|
||||||
add_action('save_post', 'my_save_post');
|
// add_filter('redirect_post_location', 'my_redirect_location', 10, 2);
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action( 'save_post_post', 'test1', 10, 3);
|
|
||||||
|
|
||||||
function my_notice() {
|
|
||||||
echo '<div class="notice notice-warning is-dismissible">
|
|
||||||
<p>my message</p>
|
|
||||||
</div>';
|
|
||||||
components-notice-list components-editor-notices__pinned
|
|
||||||
}
|
|
||||||
//add_action( 'admin_notices', 'my_notice');
|
|
||||||
|
|
||||||
function my_redirect_location($location,$post_id){
|
|
||||||
|
|
||||||
// if post was published...
|
|
||||||
if (isset($_POST['publish'])){
|
|
||||||
|
|
||||||
// obtain current post status
|
|
||||||
$status = get_post_status( $post_id );
|
|
||||||
|
|
||||||
// the post was 'published', but if it is still a draft, display draft message (10).
|
|
||||||
if($status=='draft')
|
|
||||||
$location = add_query_arg('message', 10, $location);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $location;
|
|
||||||
}
|
|
||||||
//add_filter('redirect_post_location', 'my_redirect_location', 10, 2);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
modification rapide, publie -> brouillon : 1 - draft
|
modification rapide, publie -> brouillon : 1 - draft
|
||||||
|
|||||||
21
srcs/plugins/map_prof/scripts/mp_publish_error.js
Normal file
21
srcs/plugins/map_prof/scripts/mp_publish_error.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
console.log("publish error");
|
||||||
|
|
||||||
|
wp.data.dispatch( 'core/notices' ).createNotice(
|
||||||
|
'error', // Can be one of: success, info, warning, error.
|
||||||
|
'impossible de publier : le pays est invalide', // Text string to display.
|
||||||
|
{
|
||||||
|
isDismissible: true, // Whether the user can dismiss the notice.
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//( function ( wp ) {
|
||||||
|
// console.log("publish error");
|
||||||
|
// wp.data.dispatch( 'core/notices' ).createNotice(
|
||||||
|
// 'error', // Can be one of: success, info, warning, error.
|
||||||
|
// 'impossible de publie : le pays est invalide', // Text string to display.
|
||||||
|
// {
|
||||||
|
// isDismissible: true, // Whether the user can dismiss the notice.
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
//} )( window.wp );
|
||||||
Reference in New Issue
Block a user