$value) { $screens[] = $key; } foreach ( $screens as $screen ) { /* only editors or administrator can display forms */ if( current_user_can('edit_others_pages') ) { /* display ACF frontend metabox */ add_meta_box( 'myplugin_sectionid', __( 'afd - view form on front of page', 'myplugin_textdomain' ), 'afd_frontend_meta_box_callback', $screen, 'side' ); } } } add_action( 'add_meta_boxes', 'afd_frontend_add_meta_box'); function afd_frontend_meta_box_callback( $post ) { // Add an nonce field so we can check for it later. wp_nonce_field( 'afd_frontend_meta_box', 'afd_frontend_meta_box_nonce' ); /* * Use get_post_meta() to retrieve an existing value * from the database and use the value for the form. */ $value_render = get_post_meta( $post->ID, '_meta_afd_form_render_box_key', true ); $value_alpaca = get_post_meta( $post->ID, '_meta_afd_form_render_box_alpaca', true ); //echo ''; if(esc_attr( $value_render ) == 'true'){ $checked = 'checked=checked'; }else{ $checked = ''; } if(afd_form_permision() == true){ echo ''; echo ' '; echo ''; ?>
acf form to this post'; } } /** * When the post is saved, saves our custom data. * * @param int $post_id The ID of the post being saved. */ function afd_save_meta_box_data( $post_id ) { /* * We need to verify this came from our screen and with proper authorization, * because the save_post action can be triggered at other times. */ // Check if our nonce is set. if ( ! isset( $_POST['afd_frontend_meta_box_nonce'] ) ) { return; } // Verify that the nonce is valid. if ( ! wp_verify_nonce( $_POST['afd_frontend_meta_box_nonce'], 'afd_frontend_meta_box' ) ) { return; } // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } // Check the user's permissions. if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) { return; } } else { if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } } // Sanitize user input. $my_data_afd_render = sanitize_text_field( $_POST['afd_form_render_box_field'] ); $my_data_afd_alpaca = $_POST['afd_alpaca_data']; // Update the meta field in the database. update_post_meta( $post_id, '_meta_afd_form_render_box_key', $my_data_afd_render ); update_post_meta( $post_id, '_meta_afd_form_render_box_alpaca', $my_data_afd_alpaca ); } add_action( 'save_post', 'afd_save_meta_box_data' ); /* METABOX end ------------------------------------ */ /* DISPLAY filter ------------------------------------ */ function afd_add_form_to_frontend_page($content) { /* IMPORTANT !!! afd bug fix - disable NOW */ /* This script dont't work in wp_enqueue_script method */ /* afd plugin call to it before wp_enqueue finished load */ //echo ''; //echo ''; /* ------------------------------------------------------------- */ acf_form_head(); wp_deregister_style( 'wp-admin' ); global $post; $args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); unset($args['dependence_one']); echo '