• Resolved mechatherium

    (@mechatherium)


    I am experimenting with using WPCode to add functions to the action hooks on the ProfileGrid profile page, specifically:

    • Before Profile Section Tab,
    • Before Profile Section Content,
    • After Profile Section Content,
    • and After Profile Section Tab

    as described in your developer documentation.

    Each function is basic, just three lines of code to print lines of text, the User ID and the Primary Group ID passed in through the action hook, Just enough to experiment with:

    function cq_before_profile_section_tab_demo($uid) {
    	echo "<p>Before Profile Section Tab!</p>";
    	echo "<p>My User ID is $uid</p>";
    	//echo "<p>My Primary Group ID is $primary_gid</p>"
    }
    add_action( 'profile_magic_before_profile_section_tab', 'cq_before_profile_section_tab_demo');

    Notice the function takes only $uid as an argument, and not $uid and $primary_gid.

    This is because if I define the function to take 2 arguments as specified on the Before Profile Section Tab page <https://profilegrid.co/developer-documentation/actions/profile_magic_before_profile_section_tab/&gt;, I get fatal errors.

    Here are the relevant error logs:

    2023-11-11T01:34:01+00:00 Too few arguments to function cq_after_profile_section_content_demo(), 1 passed in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php on line 326 and exactly 2 expected
    2023-11-11T01:34:01+00:00 Uncaught ArgumentCountError: Too few arguments to function cq_after_profile_section_content_demo(), 1 passed in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php on line 326 and exactly 2 expected in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-content\plugins\insert-headers-and-footers\includes\class-wpcode-snippet-execute.php(287) : eval()'d code:1
    Stack trace:
    #0 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php(326): cq_after_profile_section_content_demo(1)
    #1 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
    #2 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\plugin.php(517): WP_Hook->do_action(Array)
    #3 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-content\plugins\profilegrid-user-profiles-groups-and-communities\public\class-profile-magic-public.php(3710): do_action('profile_magic_a...', 1, '1')
    #4 C:\Users\harri
    2023-11-11T01:40:09+00:00 Too few arguments to function cq_before_profile_section_tab_demo(), 1 passed in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php on line 326 and exactly 2 expected
    2023-11-11T01:40:09+00:00 Uncaught ArgumentCountError: Too few arguments to function cq_before_profile_section_tab_demo(), 1 passed in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php on line 326 and exactly 2 expected in C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-content\plugins\insert-headers-and-footers\includes\class-wpcode-snippet-execute.php(287) : eval()'d code:1
    Stack trace:
    #0 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php(326): cq_before_profile_section_tab_demo(1)
    #1 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
    #2 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-includes\plugin.php(517): WP_Hook->do_action(Array)
    #3 C:\Users\harri\Local Sites\cousinsquorum-com\app\public\wp-content\plugins\profilegrid-user-profiles-groups-and-communities\public\class-profile-magic-public.php(3668): do_action('profile_magic_b...', 1, '1')
    #4 C:\Users\harri\Local

    When I leave out $primary_gid as an argument, the functions work perfectly fine.

    As things stand, the way it’s working is not the end of the world; I should be able to implement the functionality I need with just my $gid. But I would still like to know the source of my problems and determine what, if anything, I’m doing wrong.

    Thanks.

    EDIT:

    I forgot to add my details:
    WordPress 6.4.1
    PHP 7.4.3.0
    MySQL 8.0.16
    Twenty Twenty-Three Theme v 1.3
    ProfileGrid 5.6.6
    WPCode Lite 2.1.5

    Developing on Local Version 8.0.2+6509 on Windows 11 Home v 22H2

    • This topic was modified 1 year ago by mechatherium. Reason: Edited to add details of WP installation and environment
Viewing 1 replies (of 1 total)
  • Plugin Author ProfileGrid Support

    (@profilegrid0)

    Hello @mechatherium,

    We checked and found that you doesn’t mention the parameter counts with actions,  so its default assumes 1 parameter instead of 2 . Here is the correct code :

    function cq_before_profile_section_tab_demo($uid,$primary_gid)?

    {
    ??echo “<p>Before Profile Section Tab!</p>”;
    ??echo “<p>My User ID is $uid</p>”;
    ??echo “<p>My Primary Group ID is $primary_gid</p>”;
    }

    add_action( ‘profile_magic_before_profile_section_tab’, ‘cq_before_profile_section_tab_demo’,10,2);

    Plese apply this code and then check. We will update the developer documentation.

    Let us know if you still face any issues.

Viewing 1 replies (of 1 total)
  • The topic ‘Problems with Profile Page Action Hooks’ is closed to new replies.