$value) { $screens[] = $key; } foreach ( $screens as $screen ) { /* only editors or administrator can display forms */ if( current_user_can('edit_others_pages') ) { if( $screen == 'acf' ){ $title_box = __( 'Display Form', 'acf_frontend_display' ); }else{ $title_box = __( 'Display Form', 'acf_frontend_display' ); } /* display ACF frontend metabox */ add_meta_box( 'myplugin_sectionid', $title_box, 'afd_frontend_meta_box_callback', $screen, 'side' ); } } } add_action( 'add_meta_boxes', 'afd_frontend_add_meta_box'); function afd_frontend_meta_box_callback( $post ) { /* create global guardian */ if( get_post_type( $post->ID ) == 'acf'){ $gloabal_guardian = false; echo '
Global properties for '.$post->post_title.'
'; } /* check is globals are defined (in first fieldgroup) */ /* TODO use new function from API afd_attached_forms_array */ $fieldsArray = apply_filters('acf/get_field_groups', array()); $global_form_id = $fieldsArray[0]['id']; $global_render = get_post_meta( $global_form_id, '_meta_afd_form_render_box_key', true ); $global_alpaca = get_post_meta( $global_form_id, '_meta_afd_form_render_box_alpaca', true ); // 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. */ $create_object = get_post_meta( $post->ID, '_meta_afd_form_create_object', true ); // bolean $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 ); /* overwrite lolal settings for global settings */ if($global_render != ''){ /* insert global data olny with create new post (no edit) */ if($create_object != 'false'){ $value_render = $global_render; $value_alpaca = $global_alpaca; } } //echo ''; if(esc_attr( $value_render ) == 'true'){ $checked = 'checked=checked'; }else{ $checked = ''; } if( (afd_form_permision() == true) || ($post->post_type == 'acf') ){ echo ''; echo ''; echo ' '; echo ''; ?>
'.__( 'Plugin website', 'acf_frontend_display' ).''; }else{ echo __( 'Add', 'acf_frontend_display' ).' '.__( 'ACF form', 'acf_frontend_display' ).' '.__( 'to this post', 'acf_frontend_display' ); } } } /** * When the post is saved, saves our custom data. *__( 'Install Advanced Custom Fields plugin', 'acf_frontend_display' ). * @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']; $my_data_afd_create_object = $_POST['afd_create_object']; if($my_data_afd_create_object == ''){ $my_data_afd_create_object = 'false'; } // Update the meta field in the database. update_post_meta( $post_id, '_meta_afd_form_create_object', $my_data_afd_create_object ); 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) { global $post; echo '
'.$content.'
'; /* check display guardian */ if( get_post_meta( $post->ID, '_meta_afd_form_render_box_key', true) == 'true'){ afd_form_head(); wp_deregister_style( 'wp-admin' ); $args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); unset($args['dependence_one']); echo '
'; if( empty($args) == true){ /* afd_frontend_form() is afd_form() extended method */ afd_frontend_form(); //acf_form(); }else{ /* afd_frontend_form() is afd_form() extended method */ afd_frontend_form($args); //acf_form($args); } echo '
'; } } add_filter( 'the_content', 'afd_add_form_to_frontend_page', 6); function acf_js_init() { /* this actior included acf scripts with official documentation: */ /* http://www.advancedcustomfields.com/resources/create-a-front-end-form/ */ /* scripts list: 'jquery','jquery-ui-core','jquery-ui-tabs','jquery-ui-sortable','wp-color-picker','thickbox','media-upload','acf-input','acf-datepicker', */ /* style list: 'thickbox', 'wp-color-picker', 'acf-global', 'acf-input', 'acf-datepicker', */ global $post; if( get_post_meta( $post->ID, '_meta_afd_form_render_box_key', true) == 'true'){ /* Conditional Logic */ $path = plugins_url() . '/advanced-custom-fields/'; $output = ''; $output.=""; $output.=""; $output.= ''; echo $output; } } add_action('wp_head','acf_js_init'); ?>