Home › Toolset Professional Support › [Resolved] Multiple site failure
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 9 replies, has 2 voices.
Last updated by Shane 3 years, 8 months ago.
Assisted by: Shane.
Hello
I have recently updated all of my plugins and site theme and now am getting multiple errors when I login.. Please can you help..
Here is the main error:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function pets_custom_redirect(), 3 passed in /home/legacy/public_html/wp-includes/class-wp-hook.php on line 292 and exactly 4 expected in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php:759 Stack trace: #0 /home/legacy/public_html/wp-includes/class-wp-hook.php(292): pets_custom_redirect('hidden link...', 1387, Array) #1 /home/legacy/public_html/wp-includes/plugin.php(212): WP_Hook->apply_filters('hidden link...', Array) #2 /home/legacy/public_html/wp-content/plugins/cred-frontend-editor/application/models/form/user.php(137): apply_filters('cred_success_re...', 'hidden link...', 1387, Array) #3 /home/legacy/public_html/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(456): CRED_Form_User->check_redirection(1387, 1562, Object(CRED_Form_Data), Array, Array, Object(CRED_Form_Builder_Helper), false) #4 /home/legacy/public_html/wp-content/plugins/cred-frontend-editor/application/controllers/form_b in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 759
There has been a critical error on this website.
Many thanks
Geoff
Hi Geoff,
Thank you for getting in touch.
This error seems to be coming from a custom function in your functions.php file for you child theme.
The custom functions is called pets_custom_redirect() on line 759.
Can you copy and paste the function here so that I can have a look at it ?
Thanks,
Shane
Hi Shane
Here's the function:
/* Redirect to my pets if pets = Yes */
add_filter('cred_success_redirect', 'pets_custom_redirect',10,3);function pets_custom_redirect($url, $post_id, $form_data, $user_will_url){
global $user_will_url;
if ($form_data['id']==2344){
$url = 'hidden link';
if(isset($_REQUEST['wpcf-do-you-have-any-pets']) && $_REQUEST['wpcf-do-you-have-any-pets'] == 2){
$url = 'hidden link';
$url .= '?parent_landing-page_id=' . $post_id;
}
}
return $url;
}
/* END - Redirect to my children if children = Yes */
Thank you again
Best regards
Geoff
Hi Geoff,
Based on what I see here the code is incorrect. I see that you're passing 4 parameters into the hook, however the Hook only allows for a maximum of 3 parameters.
The corrected Hook should be.
/* Redirect to my pets if pets = Yes */ add_filter('cred_success_redirect', 'pets_custom_redirect',10,3); function pets_custom_redirect($url, $post_id, $form_data){ if ($form_data['id']==2344){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-do-you-have-any-pets']) && $_REQUEST['wpcf-do-you-have-any-pets'] == 2){ $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; }
Where i've removed the variable $user_will_url . Also i'm not sure the purpose of the line with global $user_will_url; as it is not used in your function at all.
Using the above code should clear up the fatal error as the format of the hook is now correct.
Thanks,
Shane
Hi Shane
Thank you for looking at this...I've made the fix you suggested and it corrected the first errors but now there are many more ..here are the error messages:
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1173
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1221
+++++++++++++++
And Also I have listed below the whole functions.pho file:
<?php /* This file is part of a child theme called Legacy Angel Child Theme. Functions in this file will be loaded before the parent theme's functions. For more information, please read https://developer.wordpress.org/themes/advanced-topics/child-themes/ */ // this code loads the parent's stylesheet (leave it in place unless you know what you're doing) function your_theme_enqueue_styles() { $parent_style = 'parent-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css'); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array($parent_style), wp_get_theme()->get('Version') ); } add_action('wp_enqueue_scripts', 'your_theme_enqueue_styles'); /* Add your own functions below this line. ======================================== */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('financial-asset') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('funeral-option') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('non-uk-resident') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('partner-email') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('person') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('user-questionnaire') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* Checks Number of Executors */ function executor_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-executor', 'meta_value' => 'Yes', ) ); //if it returns some posts $exec_number = count($all_posts); return $exec_number; //return summed value } add_shortcode( 'exec_func', 'executor_func' ); /* END - Checks Number of Executors */ /* TOOLSET - Redirect if post is different to logged in user */ add_action( 'template_redirect', function(){ if( is_singular('user-will') //replace user-will with your custom post type slug && get_post_field( 'post_author' ) != get_current_user_id() ){ wp_redirect(home_url( '/' )); // redirect to WordPress home URL } } ); /* END - TOOLSET - Redirect if post is different to logged in user */ /* Sets shortcode if user has a partner-page */ function partner_page_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'partner-page' ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 1; } else{$single_posts_value_sum = 0; } return $single_posts_value_sum; //return summed value } add_shortcode( 'i_have_partner_page_func', 'partner_page_func' ); /* END - Sets shortcode if user has a partner-page */ /* Create a dynamic post title by the CRED form. */ add_action('cred_save_data','func_custom_post_title',10,2); function func_custom_post_title($post_id,$form_data) { if ($form_data['id']==1678) { $name = get_post_meta($post_id, 'wpcf-first-name', true); $surname = get_post_meta($post_id, 'wpcf-surname', true); $title = $name. ' ' .$surname ; $args = array('ID' => $post_id, 'post_title' => $title); wp_update_post($args); $slug = sanitize_title($_POST['post_title']); wp_update_post(array('ID'=>$post_id,'post_name' => $slug)); } } /* END - Create a dynamic post title by the CRED form. */ /* Edit Partner Page */ function func_edit_partner_page() { $args = array( 'post_type' => 'partner-page', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $partner_page = get_posts( $args ); return $partner_page[0]; } add_shortcode('edit_your_partner_page', 'func_edit_partner_page'); /* / Edit Partner Page*/ /* Checks if User Has Partner and creates shortcode */ function i_have_a_partner_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-partner', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 1; } else{$single_posts_value_sum = 0; } return $single_posts_value_sum; //return summed value } add_shortcode( 'my_partner_func', 'i_have_a_partner_func' ); /* END - Checks if User Has Partner and creates shortcode */ /* Get User Role Shortcut */ function get_wp_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; } add_shortcode('get_user_role', 'get_wp_user_role'); /* END - Get User Role Shortcut */ /* Change user role to member if it is premember */ add_action('cred_before_save_data', 'change_user_role_action',10,1); function change_user_role_action($form_data) { // if a specific form if ($form_data['id']==1651) { $current_user = wp_get_current_user(); $user_id = $current_user->ID; if ( in_array( 'premember', (array) $current_user->roles ) ) { $current_user->set_role('member'); } } } /* END - Change user role to member if it is premember */ /* Get User role shortcode */ function get_author_role() { global $authordata; if($authordata == false){ return 'visitor'; } $author_roles = $authordata->roles; $author_role = array_shift($author_roles); return $author_role; } add_shortcode( 'user_role_func', 'get_author_role' ); /* /Get User role shortcode */ /* Create dat +12 months shortcode */ add_shortcode('wpv-post-today', 'today_shortcode'); function today_shortcode() { return date("d/m/Y", strtotime(" +12 months")); } /* /Create date +12 months shortcode */ /* bypass the cart page and go straight to the checkout page when the add to cart button is clicked */ add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { return WC()->cart->get_checkout_url(); } /* /bypass the cart page and go straight to the checkout page when the add to cart button is clicked */ /* Add Shortcode [cart_count] */ function get_cart_count() { // Code /** * Check if WooCommerce is active **/ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { global $woocommerce; return $woocommerce->cart->cart_contents_count; } } add_shortcode( 'cart_count', 'get_cart_count' ); /* /Add Shortcode [cart_count] */ /* Web Toffee code to define user class */ add_action('hf_subscription_status_updated', 'wt_change_customer_role', 10, 3); function wt_change_customer_role( $subscription, $status_to, $status_from ) { if ( !class_exists( 'HF_Woocommerce_Subscription') ) { return false; } $is_active_subscription = false; if( $status_to == 'active' ) { $is_active_subscription = true; } $user_id = $subscription->get_user_id(); $user = new WP_User( $user_id ); if ( ! $is_active_subscription ) { $subscriptions = hf_get_users_subscriptions( $user_id ); foreach ( $subscriptions as $user_subscription ) { if( $subscription->get_id() == $user_subscription->get_id() ) { continue; } if( $user_subscription->get_status == 'active' ) { $is_active_subscription = true; } } } $role_active_subscription = 'subscribed_member'; //For activ subscribers, specify the role here $role_no_active_subscription = 'member'; //For cancelled users, specify the role here $user->remove_role( 'subscriber' ); if( $is_active_subscription ) { $user->remove_role( $role_no_active_subscription ); $user->add_role( $role_active_subscription ); } else { $user->remove_role( $role_active_subscription ); $user->add_role( $role_no_active_subscription ); } } /* /End - Web Toffee code to define user class */ /* Redirect to User Hub if About Yourself section complete */ add_filter('cred_success_redirect', 'section_status_complete_2',10,3); function section_status_complete_2($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==3117) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if About Yourself section complete */ /* Redirect to User Hub if Financial Assets section complete */ add_filter('cred_success_redirect', 'section_status_complete_4',10,3); function section_status_complete_4($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==3284) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if Financial Assets section complete */ /* Redirect to User Hub if Residuary Estate section complete */ add_filter('cred_success_redirect', 'section_status_complete_6',10,3); function section_status_complete_6($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==3285) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if Residuary Estate section complete */ /* Redirect to User Hub if Executors section complete */ add_filter('cred_success_redirect', 'section_status_complete_8',10,3); function section_status_complete_8($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==3286) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if Executors section complete */ /* Redirect to User Hub if Guardians section complete */ add_filter('cred_success_redirect', 'section_status_complete_10',10,3); function section_status_complete_10($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==3287) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if Guardians section complete */ /* Redirect to User Hub if Pet Guardians section complete */ add_filter('cred_success_redirect', 'section_status_complete_12',10,3); function section_status_complete_12($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==4087) return get_current_will_url(); return $url; } /* END - Redirect to User Hub if Guardians section complete */ /* Redirect to User Hub when Funeral section complete */ add_filter('cred_success_redirect', 'section_status_complete_13',10,3); function section_status_complete_13($url, $post_id, $form_data){ global $user_will_url; if ($form_data['id']==7940) return get_current_will_url(); return $url; } /* END - Redirect to User Hub when funeral section complete */ /* User Will - Section Status 1 */ function func_user_will_section_status_1() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_1', 'func_user_will_section_status_1'); /* /User Will - Section Status 1*/ /* User Will - Section Status 2 */ function func_user_will_section_status_2() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_2', 'func_user_will_section_status_2'); /* /User Will - Section Status 2*/ /* User Will - Section Status 3 */ function func_user_will_section_status_3() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_3', 'func_user_will_section_status_3'); /* /User Will - Section Status 3*/ /* User Will - Section Status 4 */ function func_user_will_section_status_4() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_4', 'func_user_will_section_status_4'); /* /User Will - Section Status 4*/ /* User Will - Section Status 5 */ function func_user_will_section_status_5() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_5', 'func_user_will_section_status_5'); /* /User Will - Section Status 5*/ /* User Will - Section Status 6 */ function func_user_will_section_status_6() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_6', 'func_user_will_section_status_6'); /* /User Will - Section Status 6*/ /* User Will - Section Status 7 */ function func_user_will_section_status_7() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_7', 'func_user_will_section_status_7'); /* /User Will - Section Status 7*/ /* User Will - Section Status 8 */ function func_user_will_section_status_8() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_8', 'func_user_will_section_status_8'); /* /User Will - Section Status 8*/ /* User Will - Section Status 9 */ function func_user_will_section_status_9() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_9', 'func_user_will_section_status_9'); /* /User Will - Section Status 9*/ /* User Will - Section Status 10 */ function func_user_will_section_status_10() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_10', 'func_user_will_section_status_10'); /* /User Will - Section Status 10*/ /* User Will - Section Status 11 */ function func_user_will_section_status_11() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_11', 'func_user_will_section_status_11'); /* /User Will - Section Status 11*/ /* User Will - Section Status 12 */ function func_user_will_section_status_12() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_12', 'func_user_will_section_status_12'); /* /User Will - Section Status 12*/ /* User Will - Section Status 13 */ function func_user_will_section_status_13() { $args = array( 'post_type' => 'user-will', 'author' => get_current_user_id(), 'status' => 'publish', 'posts_per_page' => -1, 'fields'=>'ids' ); $user_will = get_posts( $args ); return $user_will[0]; } add_shortcode('user_will_section_status_13', 'func_user_will_section_status_13'); /* /User Will - Section Status 13*/ /* Return User Will URL */ function get_current_will_url(){ global $current_user; $ushub = array('post_type' => 'user-will', 'fields' => 'ids', 'meta_query' => array( array( 'key' => 'wpcf-user-id', 'value' => $current_user->ID ), ), ); $user_wills= get_posts($ushub); $user_will_url=get_permalink($user_wills[0]); return $user_will_url; } /* Return User Will URL */ /* Add User Hub Menu Item */ function custom_add_userhub_link( $items, $args ) { global $user_will_url; if ($args->theme_location == 'primary'){ if (is_user_logged_in()) { // $items .= '<li><a href="' . $user_will_url . '">User Hub</a></li>'; $items .= '<li><a href="' . get_current_will_url() . '">User Hub</a></li>'; } else { $items .= '<li><a href="<em><u>hidden link</u></em>">Log In</a></li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'custom_add_userhub_link', 10, 2 ); /* End - Add User Hub Menu Item */ /* Add User Hub to Mobile Menu Item */ function custom_add_userhub_mobile_link( $items, $args ) { global $user_will_url; if ($args->theme_location == 'mobile'){ if (is_user_logged_in()) { // $items .= '<li><a href="' . $user_will_url . '">User Hub</a></li>'; $items .= '<li><a href="' . get_current_will_url() . '">User Hub</a></li>'; } else { $items .= '<li><a href="<em><u>hidden link</u></em>">Log In</a></li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'custom_add_userhub_mobile_link', 10, 2 ); /* End - Add User Hub Menu Item */ /* Redirect to home page after logout */ add_action('wp_logout','ps_redirect_after_logout'); function ps_redirect_after_logout(){ wp_redirect( '<em><u>hidden link</u></em>' ); exit(); } /*/ Redirect to home page after logout */ /* Add User Hub Menu Item - Logout */ function custom_add_userhub_link_logout( $items, $args ) { global $user_will_url; if ($args->theme_location == 'primary'){ if (is_user_logged_in()) { $items .= '<li><a href=" '. wp_logout_url() .' ">Log out</a> </li>'; } } return $items; } add_filter( 'wp_nav_menu_items', 'custom_add_userhub_link_logout', 10, 2 ); /* End - Add User Hub Menu Item - Logout */ /* Create Shortcode for User Hub Link */ add_shortcode( 'uhlink', 'ul_func' ); function ul_func() { global $user_will_url; return get_current_will_url(); } /* /Create Shortcode for User Hub Link */ /* Redirect to add partner page if myself and partner selected */ add_filter('cred_success_redirect', 'custom_redirect',10,3);function custom_redirect($url, $post_id, $form_data){ if ($form_data['id']==1618){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-who-needs-an-online-will']) && $_REQUEST['wpcf-who-needs-an-online-will'] == 1){ $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; } /* END - Redirect to add partner page if myself and partner selected */ /* Redirect to add partner page if single not selected selected */ add_filter('cred_success_redirect', 'marital_custom_redirect',10,3);function marital_custom_redirect($url, $post_id, $form_data){ if ($form_data['id']==2313){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-marital-status-user']) && $_REQUEST['wpcf-marital-status-user'] == 3 or $_REQUEST['wpcf-marital-status-user'] == 4 or $_REQUEST['wpcf-marital-status-user'] == 5 or $_REQUEST['wpcf-marital-status-user'] == 7) { $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; } /* END - Redirect to add partner page if single not selected selected */ /* Limit number of executors - validation form 1797*/ add_filter('cred_form_validate','my_validation',10,2); function my_validation($field_data, $form_data){ global $wpdb; list($fields,$errors)=$field_data; if ($form_data['id']==1797 ){ if ($fields['wpcf-executor-code']['value'] == 1){ $results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->posts.' post, '.$wpdb->postmeta.' meta WHERE post.ID = meta.post_id and post.post_status = "publish" and meta.meta_key = "wpcf-executor-code" and meta.meta_value = "1" AND post.post_author = "'.get_current_user_id().'"', OBJECT ); if (count($results) > 5){ wp_redirect( '<em><u>hidden link</u></em>' ); } } return array($fields,$errors); } } /* END - Limit number of executors - validation form 1797*/ /* Redirect to my children if children = Yes */ add_filter('cred_success_redirect', 'children_custom_redirect',10,3);function children_custom_redirect($url, $post_id, $form_data){ if ($form_data['id']==2328){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-do-you-have-any-children']) && $_REQUEST['wpcf-do-you-have-any-children'] == 2){ $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; } /* END - Redirect to my children if children = Yes */ /* Redirect to my pets if pets = Yes */ add_filter('cred_success_redirect', 'pets_custom_redirect',10,3); function pets_custom_redirect($url, $post_id, $form_data){ if ($form_data['id']==2344){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-do-you-have-any-pets']) && $_REQUEST['wpcf-do-you-have-any-pets'] == 2){ $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; } /* END - Redirect to my children if children = Yes */ /* autofill the send partner personal link in cred form*/ add_shortcode( 'get_autofill_cred', 'autofill_cref_field'); function autofill_cref_field($attr){ global $partner_url; if($attr['field'] = 'unique-link'){ return $partner_url; /// your "email" fieldname } } /* END - autofill the send partner personal link in cred form*/ /* Redirect to send partner invite - email or personal link */ add_filter('cred_success_redirect', 'custom_partner_redirect',10,3); function custom_partner_redirect($url, $post_id, $form_data){ if ($form_data['id']==2038 || $form_data['id'] == 12769){ $url = '<em><u>hidden link</u></em>'; if(isset($_REQUEST['wpcf-how-do-you-want-to-let-your-partner-know']) && $_REQUEST['wpcf-how-do-you-want-to-let-your-partner-know'] == 1){ $url = '<em><u>hidden link</u></em>'; $url .= '?parent_landing-page_id=' . $post_id; } } return $url; } /* END - Redirect to add partner page if myself and partner selected */ /* Set variable for current user */ global $post; $current_user = wp_get_current_user(); /* END - Set variable for current user */ /* Checks number of current user_wills*/ $args = array('post_type' => 'user-will', 'fields' => 'ids', 'meta_query' => array( array( 'key' => 'wpcf-user-id', 'value' => $current_user->ID ), ), ); $will_ids= get_posts($args); $global_will_number=count($will_ids); /* END - Checks number of current user_wills*/ /* If Logged in and Page is not who needs a will and user will = 0*/ add_action( 'template_redirect', 'redirect_who_needs_a_will_page' ); function redirect_who_needs_a_will_page() { global $will_ids; if ( !is_page('who-needs-a-will') && is_user_logged_in() && count($will_ids) <1) { wp_redirect( '/who-needs-a-will/' ); exit; } } /* END - If Logged in and Page is not who needs a will and user will = 0*/ /* If Logged in and Page is who needs a will and user will > 1*/ add_action( 'template_redirect', 'redirect_user_hub' ); function redirect_user_hub() { global $will_ids; global $user_will_url; if ( is_page('who-needs-a-will') && is_user_logged_in() && count($will_ids) == 1) { wp_redirect( get_current_will_url() ); exit; } } /* END - If Logged in and Page is who needs a will and user will > 1*/ /* Checks number of Partner Pages */ $papage = array('post_type' => 'partner-page', 'fields' => 'ids', 'meta_query' => array( array( 'key' => 'wpcf-user-id', 'value' => $current_user->ID ), ), ); $partner_ids= get_posts($papage); $global_partner_number=count($partner_ids); if ($partner_ids){ $partner_url=get_permalink($partner_ids[0]);} /* END - Checks number of Partner Pages */ /* Checks if User Has Children */ function dependant_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-child', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 1; } else{$single_posts_value_sum = 0; } return $single_posts_value_sum; //return summed value } add_shortcode( 'child_func', 'dependant_func' ); /* END - Checks if User Has Children */ /* Checks if User Has Pets */ function dependant_pet_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-pet', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 1; } else{$single_posts_value_sum = 0; } return $single_posts_value_sum; //return summed value } add_shortcode( 'pet_func', 'dependant_pet_func' ); /* END - Checks if User Has Pets */ /* Checks all beneficiarys have a percentage split */ function beneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-beneficiary', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-inheritance-percentage', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value==0) { $single_posts_value_sum = $single_posts_value_sum + 1; } } } return $single_posts_value_sum; //return summed value } add_shortcode( 'bene_func', 'beneficiaries_func' ); /* END - Checks all beneficiarys have a percentage split */ /* Sums Beneficiary Percentage and adds shortcode */ function calc_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-beneficiary', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-inheritance-percentage', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields $single_posts_value_sum+= $single_post_value; } } return $single_posts_value_sum; //return summed value } add_shortcode( 'calc-total', 'calc_func' ); /* END - Sums Beneficiary Percentage and adds shortcode */ /* If Logged in and Page is Partner Page and partner pages = 1*/ add_action( 'template_redirect', 'redirect_partner_user_hub' ); function redirect_partner_user_hub() { global $partner_ids; global $user_will_url; if ( is_page('invite-your-partner') && is_user_logged_in() && count($partner_ids) == 1) { wp_redirect( $user_will_url ); exit; } } /* END - If Logged in and Page is Partner Page and partner pages = 1*/ /* If Logged in and Page is Sign In*/ add_action( 'template_redirect', 'redirect_to_specific_page' ); function redirect_to_specific_page() { global $user_will_url; if ( is_page(array('sign-up', 'everything-i-own-is-in-the-uk', 'lets-start-to-create-your-online-will/')) && is_user_logged_in() ) { global $user_will_url; wp_redirect(get_current_will_url() ); exit; } } /* END - If Logged in and Page is Sign In*/ /* Redirect to will incomplete if user has not paid ie not completed will*/ function my_login_redirect( $url, $request, $user ){ global $user_will_url; if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { if( $user->has_cap( 'member')) { $url = home_url('/it-looks-like-your-will-is-not-complete-yet/'); } else { $url = home_url($user_will_url); } } return $url; } add_filter('login_redirect', 'my_login_redirect', 10, 3 ); /* END - Redirect to will incomplete if user has not paid ie not completed will*/ /* Function to create shortcode to add parent ID to form */ function user_post_id( $atts ) { // Attributes $atts = shortcode_atts( array( 'author_id' => '', 'cpt' => '', ), $atts ); $args = array( 'author' => $atts['author_id'], 'orderby' => 'post_date', 'order' => 'ASC', 'posts_per_page' => 1, 'post_type'=> $atts['cpt'] ); $post=get_posts($args); return $post[0]->ID; } add_shortcode( 'user_post_id', 'user_post_id' ); /* END - Function to create shortcode to add parent ID to form */ /* START - Function to add current New PERSON CPT as child parent - Child ID sent in URL and add adopted to child post */ add_action('cred_save_data','func_update_parent_field',10,2); function func_update_parent_field($post_id,$form_data) { if ($form_data['id']==4033 || $form_data['id'] == 1787 || $form_data['id'] == 4049 || $form_data['id'] == 4051 || $form_data['id'] == 4050) { wp_update_post( array( 'ID' => $_GET['child_post_id'], 'post_parent' => $post_id ) ); update_post_meta($_GET['child_post_id'],'wpcf-adopted','Yes'); } } /* START - Function to add current New PERSON CPT as child parent - Child ID sent in URL and add adopted to child post*/ /* Functions of Child Theme */ /* Checks all cash gifts have a beneficiary */ function cashbeneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-cash-gift', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-adopted', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value=='Yes') { $single_posts_value_sum = $single_posts_value_sum + 1; } } } if ($single_posts_value_sum == count($all_posts)) return true; //return summed value } add_shortcode( 'cash_func', 'cashbeneficiaries_func' ); /* END - Checks all cash gifts have a beneficiary */ /* Checks all possessions have a beneficiary */ function possessionbeneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-possession', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-adopted', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value=='Yes') { $single_posts_value_sum = $single_posts_value_sum + 1; } } } if ($single_posts_value_sum == count($all_posts)) return true; //return summed value } add_shortcode( 'possession_func', 'possessionbeneficiaries_func' ); /* END - Checks all possessions have a beneficiary */ /* Checks all digital assets have a beneficiary */ function digitalbeneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-digital-asset', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-adopted', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value=='Yes') { $single_posts_value_sum = $single_posts_value_sum + 1; } } } if ($single_posts_value_sum == count($all_posts)) return true; //return summed value } add_shortcode( 'digital_func', 'digitalbeneficiaries_func' ); /* END - Checks all digital assets have a beneficiary */ //Defined Child Theme URL define('child_theme_uri', dirname( get_bloginfo('stylesheet_url')) ); add_action( "wp_enqueue_scripts", "theme_enqueue_styles",35); function theme_enqueue_styles() { wp_enqueue_style( "parent-style", child_theme_uri . "/style.css" ); }
Hi Geoff,
The problem here is with your custom code in the functions.php file.
If you check line 1125 you will see the line below.
if ($single_posts_value_sum == count($all_posts))
In the context of the code above you are getting the error below.
Notice: Undefined variable: single_posts_value_sum in /home/legacy/public_html/wp-content/themes/Legacy-Angel-Child-Theme/functions.php on line 1125
Now based on the full context of the code I can see why this error is being thrown because you have defined the $single_posts_value_sum inside an if statement. Now if you were using the above snippet inside the full context of the if statment then you wouldn't have any issue.
But now the problem arises because of its use outside of the scope of the if statement where the variable was previously defined. Essentially the variable is being called for outside of its usage scope where it has not been defined previously.
/* Checks all cash gifts have a beneficiary */ function cashbeneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-cash-gift', 'meta_value' => 'Yes', ) ); //if it returns some posts if( $all_posts ){ //Start the count on 0 $single_posts_value_sum = 0; //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-adopted', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value=='Yes') { $single_posts_value_sum = $single_posts_value_sum + 1; } } } if ($single_posts_value_sum == count($all_posts)) return true; //return summed value }
Now to solve this and all instances of where this error is being thrown is to move the variable definition outside of the if statement. Use the fixed code below and it should resolve your issue for this instance.
/* Checks all cash gifts have a beneficiary */ function cashbeneficiaries_func( $atts ){ global $current_user; wp_get_current_user(); // get all Posts of your type $all_posts = get_posts(array( 'numberposts' => -1, 'author' => $current_user->ID, 'post_type' => 'person', 'meta_key' => 'wpcf-cash-gift', 'meta_value' => 'Yes', ) ); $single_posts_value_sum = 0; //if it returns some posts if( $all_posts ){ //Start the count on 0 //now get the single posts fields values foreach( $all_posts as $single_post ){ //get each Posts post data $single_post_data = get_post($single_post); //get each ID $single_post_id = $single_post_data->ID; //get each posts field value $single_post_value = get_post_meta($single_post_id, 'wpcf-adopted', true); //we need to sum this up BEFORE the if is closed and BEFORE the foreach is closed //Sum the values all posts fields if ($single_post_value=='Yes') { $single_posts_value_sum = $single_posts_value_sum + 1; } } } if ($single_posts_value_sum == count($all_posts)) return true; //return summed value }
Please let me know if this helps.
Thanks,
Shane
That's perfect Shane...thank you so much...
It seems to work fine now..I'll run some testing and get back to you with any problems
Best wishes
Geoff
Hi Geoff,
Checking in here, has there been any updates? Are you still experiencing any issues with the site ? If not then you can go ahead and mark this ticket as resolved.
Thanks,
Shane
Hi Shane
I've run a few tests and all seems to be working fine...I'll close the ticket ..thanks for your help
Best regards
Geoff
Hi Geoff,
Thank you for the update. Should any issues arrive you are welcomed to open a new ticket.
Thanks,
Shane