$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 = afd_form_permision(); $global_form_id = $fieldsArray[0]; $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 '
Properties for this objest are defined as global with ACF tab on form: '.get_the_title($global_form_id).' Your changes ont this panes dont updated.

'; } 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' ); } } // FORM ACTIONS FORCED MESSAGE /*if (!defined('Forms_actions')) { echo '
Install more Actions to your form here
'; }*/ } /** * 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; //$content = apply_filters('the_content', $post->post_content); //$content = str_replace(']]>', ']]>', $content); //return $content; $must_login_msg = '
'.__('Login to edit this post.').'
'; $login_as_author_msg = '
'.__('Login as author to edit this post.').'
'; $hash_expired_msg = '
'.__('Your activation link was expired.').'
'; $hash_ok_msg = '
'.__('Registration completed.').'
'; // KEY param exist ------------------------------------------------------------- if($_GET['key'] != ''){ $args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); //$user_data = get_userdata( $_GET['user'] ); //$code = sha1( $_GET['user'] . $user_data->user_registered ); if( $_GET['key'] == get_user_meta( $_GET['user'], '_activation_key', true )){ delete_user_meta( $_GET['user'], '_activation_key' ); wp_update_user( array ('ID' => $_GET['user'], 'role' => 'subscriber' ) ) ; if($args['dependence_three'] == true){ $hash_ok_msg = '
'.$args['display_messages_hash_true'].'
'; } $content = $hash_ok_msg; if($_GET['redirect_id'] != ''){ wp_redirect(get_permalink($_GET['redirect_id'])); exit; } }else{ if($args['dependence_three'] == true){ $hash_expired_msg = '
'.$args['display_messages_hash_false'].'
'; } $content = $hash_expired_msg; } return $content; } // ---------------------------------------------------------------------------- /* check display guardian */ if( get_post_meta( $post->ID, '_meta_afd_form_render_box_key', true) == 'true'){ $args = json_decode( urldecode ( get_post_meta($post->ID,'_meta_afd_form_render_box_alpaca', true )), true ); $display_guardian = true; // EDIT MODE ------------------------------------------------------------- // Edit by author only if($args['display_edit'] == true) { $current_user_id = get_current_user_id(); if($_GET['edit'] == 'form'){ if($current_user_id != $post->post_author){ $display_guardian = false; if($args['dependence_three'] == true){ $login_as_author_msg = '
'.$args['display_messages_author'].'
'; } echo $login_as_author_msg; } } if($_GET['guid'] != $current_user_id){ $display_guardian = false; } } // LOGIN MODE ------------------------------------------------------------- // Display for login users if($args['display_login'] == true) { if ( !is_user_logged_in() ) { $display_guardian = false; if($args['dependence_three'] == true){ $must_login_msg = '
'.$args['display_messages_login'].'
'; } echo $must_login_msg; } } /* check form position */ if($args['in_content_pos'] == 'after'){ echo '
'.$content.'
'; } if($display_guardian == true){ unset($args['dependence_one']); afd_form_head(); wp_deregister_style( 'wp-admin' ); 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 '
'; } /* check form position */ if($args['in_content_pos'] == 'before'){ echo '
'.$content.'
'; } return false; }else{ return $content; } } 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');