Updating logged in user's page when on other pages - php

I have a site that a user can sign up and build up their own profile page. This is done by creating a post when the user signs up, all the form data that is filled in is then saved to that post into the various custom fields. So essentially, every user has 1 post with all their profile data in.
Each user can see other people's profiles
I'm using the plugin http://www.advancedcustomfields.com and specifically using it's front end form capability.
When on the user's own profile, using the front end form capability, I can show a relationship field (http://www.advancedcustomfields.com/resources/field-types/relationship/), that then allows people to select other user's profile to essentially become a friend. This works great.
The problem I have is when a user goes to another person's profile, there is a "become a friend" button, when clicked, I want it to add that user's page to the current logged in users relationship field. Firstly, can that be done? If so, how?
Here's how I'm currently updating the relationship field when the logged in users on their own page (so they can add people).
<?php
$activity_information = array(
'post_id' => $post->ID, // post id to get field groups from and save data to
'field_groups' => array(58), // this will find the field groups for this post (post ID's of the acf post objects)
'form_attributes' => array( // attributes will be added to the form element
'class' => ''
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_field_open' => '<div>', // field wrapper open
'html_field_close' => '</div>', // field wrapper close
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => '', // default updated message. Can be false to show no message
);
?>
<?php acf_form( $activity_information ); ?>

Related

Prepopulating gravityforms fields based on logged in users latest form entry

Can anyone help/have some ideas on how to prepopulate gravityforms fields based on users latest entry of the same form.
I've users, who will "register" to an event every year and fill the same form, so it would be nice to have the same fields already filled and if the client wants, they can refill some of the changed fields themselves.
So far I've found some info from gravityforms docs myself, but this code seems only to be prepopulating only one field? Still haven't gotten it to work.
The code ->
add_filter( 'gform_field_value_previous_value', 'populate_previous_value', 10, 2 );
function populate_previous_value( $value, $field ) {
$entries = GFAPI::get_entries(
$field->formId,
array(
'field_filters' => array(
array(
'key' => 'created_by',
'value' => get_current_user_id(),
),
),
),
array(),
array( 'page_size' => 1 )
);
return rgars( $entries, '0/' . $field->id );
}
I assume, the value between the rgars apostrophes aka the field id needs to be filled?
If anyone else is wondering/struggling to solve this issue - I've come to the realization that the best and easiest way to pre-populate fields values based on logged in user is through gravity forms merge tags.
Best way to use merge tags based on logged in user is next:
{user:[meta_tag}
You can use all the meta fields available, also the billing_address and billing_postcode and so on, as long as you include 'user:' before.
So the fields get populated based on logged in users meta fields. The merge tags need to be placed to form field->advanced->under default value.
For example if you need logged in users first name and last name to be populated you would add {user:first_name} to the first name default value field and {user:last_name} to the last name value field.

How can I create a Custom Text Box on a WooCommerce Product Page?

I am working on a WordPress website, with WooCommerce functionality.
I have created 2 Custom Fields, for the Product Data box within the backend of the Product Page, using the following Code:
<?php
function theme_name_woocommerce_custom_fields() {
// Price Per Character
woocommerce_wp_text_input(
array(
'id' => '_character_price',
'label' => 'Price Per Character',
'description' => 'This is the amount a customer pays per letter entered.',
'desc_tip' => 'true',
'placeholder' => 'Enter Amount per Letter (Exclude the £)'
)
);
// Custom Text Box
woocommerce_wp_checkbox(
array(
'id' => '_custom_text_box',
'label' => 'Show Custom Text Box',
'description' => 'Select this box, if you would like a Custom Text Box to appear on the Product's page.',
'desc_tip' => 'true',
)
);
}
add_action( 'woocommerce_product_options_general_product_data', 'theme_name_woocommerce_custom_fields' );
function save_theme_name_woocommerce_custom_field( $post_id ) {
if ( ! empty( $_POST['_custom_text_field'] ) ) {
update_post_meta( $post_id, '_custom_text_field', esc_attr( $_POST['_custom_text_field'] ) );
}
}
add_action( 'woocommerce_process_product_meta', 'save_theme_name_woocommerce_custom_fields' );
?>
In reference to the woocommerce_wp_checkbox, I would like to create a function whereby when this checkbox is selected, it creates a Custom Text Box on the associated Product's page. This Custom Text Box can then be used by a potential customer to enter a piece of text, which they would like to have printed to the page's Product.
Is anyone aware of what additional piece of coding I would need to enter, in order to achieve said goal?
You can override simple/variable product's template file and add custom field there. Keep logic of show/hide textbox when checkbox is checked there only.
When add to cart is done, you will get all posted data in POST. Grab it from there and put into woocommerce' object.
=======================================================
Edited:
You can follow this steps:
Copy woocommerce/templates/single-product/add-to-cart/variable.php this template to your child theme and customize it. You will see a form tag there. In that you can put your custom created checkbox(which you added from admin). Also, add a custom textbox(in which user will enter text) - and hide it.
Add custom js from functions.php. - In this js you can write logic that if checkbox is checked then you will show the textbox, else not.
Now, when user does add to cart, add this custom textbox data to woocommerce object. How to enter custom data to woocommerce object - you can have step by step details here: https://wisdmlabs.com/blog/add-custom-data-woocommerce-order/

How to create Repeater field in Redux Framework from wordpress?

Repeater field plugin is purchased in Redux framework. But I am creating it as a custom filed .
I have created 3 fields(title, phone, Textarea) with add more and delete button. In this, I want to add upload button along with that three fields . But I failed to add upload button . I tried a lot but it's not working .
Can you please tell me what is the way to add upload image button in custom field extension.
$fields = array(
'id'=>'multi-text',
'type' => 'multi_text',
'title' => __('Multi Text Option - Color Validated', 'textdomain'),
'validate' => 'color',
'subtitle' => __('If you enter an invalid color it will be removed. Try using the text "blue" as a color. ;)', 'texdoma'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo')
),
);
Example Usage
This example in based on the example usage provided above. Be sure to change $redux_demo to the value you specified in your opt_name argument.
global $redux_demo;
echo 'First Text Entry: ' . $redux_demo['multi-text'][0];
// The array number of additional entries will increase by one.

Dynamically pre-populate Gravity Forms field with custom fields from custom post types

Tried to be as specific as possible in the title. Essentially I have a real estate site that I am working on that has property listings. The property listing is a custom post type and there are several other custom post types (each with their own custom fields) attached to it.
Each property has an agent (custom post type) attached to it with custom fields such as email, facebook, phone number, etc.
I need to dynamically pre-populate a hidden field on Gravity Forms with the agent email (which is NOT the same as the author email) so that I can send an email to that address.
I have tried the following with no luck because I'm sure something is missing to call the custom field from the Agent custom post type, but I'm not sure how. This is what I'm working with so far:
add_filter('gform_field_value_agentemail', 'populate_post_agent_email');
function populate_post_agent_email($value){
global $post;
$agents_email = get_post_meta($post->ID, 'agent_email', true);
return $agents_email;
}
I have added the parameter name "agentemail" to the gravity form field. If anyone knows what I am missing to be able to get this field (or any field from the agent custom post) into this form, it would be much appreciated.
Thanks.
Here's How I Populated my GravityForms Dropdown using a little code that I found created by Joshua David Nelson, josh#joshuadnelson.com
With a few minor modifications I was able to get the proper output to the dropdown box (was looking for user email addresses instead of user nicenames, but you can modify this script to output anything you want with a few small changes to the query args)
// Gravity Forms User Populate, update the '1' to the ID of your form
add_filter( 'gform_pre_render_1', 'populate_user_email_list' );
function populate_user_email_list( $form ){
// Add filter to fields, populate the list
foreach( $form['fields'] as &$field ) {
// If the field is not a dropdown and not the specific class, move onto the next one
// This acts as a quick means to filter arguments until we find the one we want
if( $field['type'] !== 'select' || strpos($field['cssClass'], 'your-field-class') === false )
continue;
// The first, "select" option
$choices = array( array( 'text' => 'Just Send it to the Default Email', 'value' => 'me#mysite.com' ) );
// Collect user information
// prepare arguments
$args = array(
// order results by user_nicename
'orderby' => 'user_email',
// Return the fields we desire
'fields' => array( 'id', 'display_name', 'user_email' ),
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query( $args );
// Get the results
$users = $wp_user_query->get_results();
//print_r( $users );
// Check for results
if ( !empty( $users ) ) {
foreach ( $users as $user ){
// Make sure the user has an email address, safeguard against users can be imported without email addresses
// Also, make sure the user is at least able to edit posts (i.e., not a subscriber). Look at: http://codex.wordpress.org/Roles_and_Capabilities for more ideas
if( !empty( $user->user_email ) && user_can( $user->id, 'edit_posts' ) ) {
// add users to select options
$choices[] = array(
'text' => $user->user_email,
'value' => $user->id,
);
}
}
}
$field['choices'] = $choices;
}
return $form;
}
/* end of populate advisors for dropdown field */
To get this to work all you should need to do is add the above code to your functions.php file, add the 'ID' (into the add_filter reference) of the GravityForm that you're looking to alter and add the 'Class' of your dropdown field (where is says 'your-field-class').
If you have any questions about the above code, let me know.
Adam
I'm working on this one right now - I was able to pass the values from one page to another appending the information onto the end of the url -
ex. http://www.your-website.com/?agentemail=agent#email.com
For this to work you have to check the 'Allow this field to be populated Conditionally' when editing the field in question.
It's not the be-all-end-all for me (I'd like to generate this on page load, rather than attaching it to a button, but it's a start. I'll comment again when I have the filtering worked out.
Adam

wordpress custom post type meta data does not displaying

Hello Everyone i am using Easy-WordPress-Custom-Post-Types by JeffreyWay for crating custom post type for my post rating theme.the code for adding meta is as:$review = new JW_Post_Type('Review',array('taxonomies' => array('category', 'post_tag')));
$review->add_meta_box('Admin Ratings', array(
'Rating' => array('select',array( '1.0','1.5','2.0','2.5','3.0','3.5','4.0','4.5','5.0'))));
and for displaying data i'm using:echo get_post_meta( $postid, 'Admin Rating', true );
but it doesn't displays anything.
Your meta names do not match. One is Admin Rating, the other is Admin Ratings.

Categories