Home > Software design >  Use of Action hook in wordpress to prepopulate form field
Use of Action hook in wordpress to prepopulate form field

Time:08-27

I'm new to wordpress actions and i'm trying two things.

  • I'm tying to output the data based on a action hook. The documentation of the plugin only says the following: 6. Action eideasy_user_identified. Runs immediately after user data has been received and includes array of data returned by eID Easy.

Does anybody has a tip on how to output this data?

And even better how to use the output from this data to prepopulate form fields from another wordpress plugin.

I realy hope someone can help me or give me a example to get started.

Thank you

CodePudding user response:

The plugin in the picture is eID Easy

Here's how you can log the data in a file:

Step 1: Create a file called log.txt Step 2: Create a file called eid-log.php

Put the below code in the eid-log.php file:

<?php
/**
* eID LOG
*
* @package eID LOG
* @author Vinay
* @license gplv2-or-later
* @version 1.0.0
*
* @wordpress-plugin
* Plugin Name: eID LOG
* Plugin URI: https://stackoverflow.com/questions/73491338/use-of-action-hook-in-wordpress-to-prepopulate-form-field
* Description: Log the eID data in a file
* Version: 1.0.0
* Author: Vinay Jain
* Author URI: https://stackoverflow.com/users/17995563/vinay-jain
* Text Domain: eid-log
* Domain Path: /languages
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* You should have received a copy of the GNU General Public License
* along with Hot Recipes. If not, see <https://www.gnu.org/licenses/gpl-2.0.html/>.
*/

add_action('eideasy_user_identified', 'eid_log_to_file', 10, 1);
function eid_log_to_file($result){
    if (!is_null($result)) {
        $myfile = fopen(plugin_dir_path( __FILE__ )."log.txt", "w");
        fwrite($myfile, "==================================");
        fwrite($myfile, print_r($result, true));
        fclose($myfile);
    }
}

Step 3: Zip both the files and name it eid-log.zip, then go to Wp-admin > Plugins > Add new > Upload

Step 4. Activate the plugin and then use your eID Easy plugin.

Step 5: Read the log.txt file for the data.

This will log each entry in the log.txt file. This should work, if not then let me know.

  • Related