Skip Navigation

[Resolved] Delete User from Form Not Working

This thread is resolved. Here is a description of the problem and solution.

Problem:
Using cred form to remove user was triggering a fatal error and not deleting the user
Solution:
I added a priority and fixed param numbers to the add_action call. I also test if the form_data is valid before moving forward to the deletion:

function efm_delete_user( $user_id, $form_data ){
 
  if ( isset($form_data) && !empty($form_data) && isset($form_data['id']) && $form_data['id'] == 5846 ) {
 
 
     require_once( ABSPATH.'wp-admin/includes/user.php' );
     wp_delete_user( $user_id );
  }
}
add_action( 'cred_submit_complete', 'efm_delete_user', 10, 2 );

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 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 4 replies, has 2 voices.

Last updated by Mateus Getulio 8 months, 2 weeks ago.

Assisted by: Mateus Getulio.

Author
Posts
#2686106

Ian

I am trying to let a manager or admin delete a user using a form.

I am following the example here: https://toolset.com/forums/topic/ad-a-delete-user-button/

I have added the following php:

function efm_delete_user( $user_id, $form_data ){
if ( 5846 == $form_data['id'] ) {

require_once( ABSPATH.'wp-admin/includes/user.php' );
wp_delete_user( $user_id );
}
}
add_action( 'cred_submit_complete', 'efm_delete_user' );

My form is called with the shortcode: [cred_user_form form='delete-vendor-application' user='[wpv-user field="ID"]']

When I submit the form I get: "There has been a critical error on this website."

#2686147

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

To get a better idea of what's causing the fatal error, I'd like your help enabling the debug mode, please add the following code to the wp-config.php file of the site:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
  
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
  
// Disable display of errors and warnings 
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
  
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

Please check following links to read more about debugging with WordPress.
- https://codex.wordpress.org/Debugging_in_WordPress
- https://codex.wordpress.org/Debugging_in_WordPress#Example_wp-config.php_for_Debugging

After adding the code above, please try to reproduce the issue again and check if you'll find a debug.log file inside the wp-content folder.

If you locate it there, please send us the last lines here in the ticket, especially error logs.

Thank you, please let me know.

#2686150

Ian

OK turned debug mode on. I get a number of errors right away about some depreciated aspects of CRED forms:

Deprecated: Creation of dynamic property Toolset_Theme_Integration_Settings_Front_End_Controller::$is_blocks_active is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-theme-settings/compatibility-modules/controllers/toolset-theme-integration-settings-abstract-controller.php on line 56
Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/common-es/server/Rest/Route/ShortcodeRender/WithMeta.php on line 55 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/common-es/server/Rest/Route/ShortcodeRender/WithMeta.php on line 55 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/dynamic-sources/server/DynamicSources.php on line 685

Here are the error messages after submitting the form:
Deprecated: Creation of dynamic property Toolset_Theme_Integration_Settings_Front_End_Controller::$is_blocks_active is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-theme-settings/compatibility-modules/controllers/toolset-theme-integration-settings-abstract-controller.php on line 56
Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/common-es/server/Rest/Route/ShortcodeRender/WithMeta.php on line 55 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /www/wp-content/plugins/toolset-blocks/vendor/toolset/common-es/server/Rest/Route/ShortcodeRender/WithMeta.php on line 55 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: Creation of dynamic property CRED_Form_Rendering::$form_type is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 70 Deprecated: Creation of dynamic property CRED_Form_Rendering::$_attributes is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_rendering.php on line 288 Deprecated: Creation of dynamic property CRED_Validator_Recaptcha::$message_controller is deprecated in /www/wp-content/plugins/cred-frontend-editor/application/controllers/validators/recaptcha.php on line 17 Fatal error: Uncaught ArgumentCountError: Too few arguments to function efm_delete_user(), 1 passed in /wordpress/wp-includes/class-wp-hook.php on line 326 and exactly 2 expected in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(582) : eval()'d code:1 Stack trace: #0 /wordpress/wp-includes/class-wp-hook.php(326): efm_delete_user(17) #1 /wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #2 /wordpress/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /www/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(720): do_action('cred_submit_com...', 17, Array) #4 /www/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(472): CRED_Form_Base->check_redirection(17, 5846, Object(CRED_Form_Data), Array, Array, Object(CRED_Form_Builder_Helper), false) #5 /www/wp-content/plugins/cred-frontend-editor/application/controllers/form_builder_base.php(42): CRED_Form_Base->print_form() #6 /www/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(1876): CRED_Form_Builder_Base->get_form(5846, '17') #7 /www/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(2460): CRED_Helper::cred_user_form('delete-vendor-a...', '17') #8 /wordpress/wp-includes/shortcodes.php(433): CRED_Helper::credUserFormShortcode(Array, '', 'cred_user_form') #9 [internal function]: do_shortcode_tag(Array) #10 /wordpress/wp-includes/shortcodes.php(273): preg_replace_callback('/\\[(\\[?)(wpv\\-u...', 'do_shortcode_ta...', '\n
apply_filters('\n
render() #31 /wordpress/wp-includes/class-wp-block.php(244): WP_Block->render() #32 /wordpress/wp-includes/class-wp-block.php(244): WP_Block->render() #33 /wordpress/wp-includes/class-wp-block.php(244): WP_Block->render() #34 /wordpress/wp-includes/blocks.php(1484): WP_Block->render() #35 /wordpress/wp-includes/blocks.php(1522): render_block(Array) #36 /wordpress/wp-includes/class-wp-hook.php(324): do_blocks('

This page needs admin or manager role to access content.

#2686262

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

By default cred_submit_complete expects 2 params, the post ID or user ID in this case and the form data: https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

The fatal error is triggering because by the time the hook is called, for some reason the form data is not available.

I checked your code and at first glance I didn't spot anything wrong.

Although I see you added the code using this plugin: code-snippets.

My guess is that it could be some compatibility issue or maybe the code not being called at the right time.

Just as a test, please temporarily remove the code from the plugin code-snippets and add it to your functions.php file to see if it gets the issue fixed.

If the issue remains, I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://toolset.com/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link

Please, let me know if you need any additional details. Have a nice day.

#2686562

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

I changed the code slightly in order to get it worked, this is the final version:


function efm_delete_user( $user_id, $form_data ){

  if ( isset($form_data) && !empty($form_data) && isset($form_data['id']) && $form_data['id'] == 5846 ) {


     require_once( ABSPATH.'wp-admin/includes/user.php' );
     wp_delete_user( $user_id );
  }
}
add_action( 'cred_submit_complete', 'efm_delete_user', 10, 2 );

I added priority and number of parameters to the add_action call and I added a check to see if the form_data is not null before checking the form ID just in case.

After that I tested the functionality and I was able to delete the test vendor just fine.

Please test it again and let us know the results.

Mateus

#2686701

Ian

Works great, I will take a closer look to see where I went wrong.