PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / up-register-nonce-fields.php

up-register-nonce-fields.php in UpStream: a Project Management Plugin for WordPress trunk, at includes/up-register-nonce-fields.php

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle nonce fields registration on a single hooks.
4 * Nonce fields on meta boxes are not included, as they are registered on their meta boxes.
5 *
6 * @package UpStream
7 */
8
9 /**
10 * Add nonce field at the top of the post-editor form.
11 *
12 * @param WP_Post $post Post object.
13 */
14 function upstream_admin_nonce_field_on_edit_form_top( $post ) {
15 $nonce_fields = array(
16 'project' => array(
17 'nonce_field_name' => 'upstream_admin_project_form_nonce',
18 'nonce_key' => 'upstream_admin_project_form',
19 ),
20 'client' => array(
21 'nonce_field_name' => 'upstream_admin_client_form_nonce',
22 'nonce_key' => 'upstream_admin_client_form',
23 ),
24 'upst_milestone' => array(
25 'nonce_field_name' => 'upstream_admin_upst_milestone_form_nonce',
26 'nonce_key' => 'upstream_admin_upst_milestone_form',
27 ),
28 'up_custom_field' => array(
29 'nonce_field_name' => 'upstream_admin_up_custom_field_form_nonce',
30 'nonce_key' => 'upstream_admin_up_custom_field_form',
31 ),
32 );
33
34 // Just render on the registered post types.
35 if ( ! in_array( $post->post_type, array_keys( $nonce_fields ), true ) ) {
36 return;
37 }
38
39 // Prevent the nonce field to be rendered multiple time.
40 if ( defined( 'UPSTREAM_MAIN_NONCE_FIELD_RENDERED' ) ) {
41 return;
42 }
43
44 // Render nonce field.
45 wp_nonce_field(
46 $nonce_fields[ $post->post_type ]['nonce_key'],
47 $nonce_fields[ $post->post_type ]['nonce_field_name']
48 );
49
50 define( 'UPSTREAM_MAIN_NONCE_FIELD_RENDERED', 1 );
51 }
52 add_action( 'edit_form_top', 'upstream_admin_nonce_field_on_edit_form_top' );
53