• Hi there,

    I’ve created a child theme for Storefront and added this filter to hide the edit link on given page :

    add_filter(
    'edit_post_link',
    function( $link, $post_id, $text ) {
    $post = get_post($post_id);
    $slug = $post->post_name;

    if ( 'my-slug' === $slug ) {
    return '';
    }

    return $link;
    }
    );

    But that gives me a ? Uncaught ArgumentCountError ? fatal error :

    PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /www/wp-includes/class-wp-hook.php on line 326 and exactly 3 expected in /www/wp-content/themes/storefront-child/functions.php:24
    Stack trace:
    #0 /www/wp-includes/class-wp-hook.php(326): {closure}()
    #1 /www/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #2 /www/wp-includes/link-template.php(1542): apply_filters()
    #3 /www/wp-content/themes/storefront/inc/storefront-template-functions.php(519): edit_post_link()
    #4 /www/wp-includes/class-wp-hook.php(324): storefront_edit_post_link()
    #5 /www/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #6 /www/wp-includes/plugin.php(517): WP_Hook->do_action()
    #7 /www/wp-content/themes/storefront/content-page.php(18): do_action()
    #8 /www/wp-includes/template.php(812): require('...')
    #9 /www/wp-includes/template.php(745): load_template()
    #10 /www/wp-includes/general-template.php(206): locate_template()
    #11 /www/wp-content/themes/storefront/page.php(24): get_template_part()
    #12 /www/wp-includes/template-loader.php(106): include('...')
    #13 /www/wp-blog-header.php(19): require_once('...')
    #14 /www/index.php(17): require('...')
    #15 {main}
    thrown in /www/wp-content/themes/storefront-child/functions.php on line 24

    Maybe I’m doing something wrong but I have a feeling that Storefront is messing this filter up.

    Kind regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello glouton,

    Thank you for contacting WooCommerce support.

    Please note that custom code is outside of our support policy.
    I recommend consulting a web developer or posting your question in the Woo Community Facebook group or Woo Community Slack.

    I apprecaite your cooperation.

    Best regards.

    Thread Starter glouton

    (@glouton)

    Hello @doublezed2,

    Thanks for your anwser.

    The thing is I am a web developer (with over 30 years of experience).
    I understand that custom code is not supported and I do know that it may very well be something I’m missing, but this is a default WordPress hook:

    https://developer.www.ads-software.com/reference/hooks/edit_post_link/

    And it should work as expected, should it not?

    Regards,

    • This reply was modified 4 days, 6 hours ago by glouton.

    Hi there @glouton, could you try adding the priority and accepted_args parameters to the add_filter function, like so:

    add_filter(
    'edit_post_link',
    function( $link, $post_id, $text ) {
    $post = get_post($post_id);
    $slug = $post->post_name;

    if ( 'my-slug' === $slug ) {
    return '';
    }

    return $link;
    },
    10,
    3
    );

    The default value for the accepted_args is 1, but your closure is expecting 3, therefore apply_filters only sends the first argument over, resulting in the error.

    Let me know how this goes!

    Thanks, Thomas.

    Thread Starter glouton

    (@glouton)

    In the name of me, what a stupid idiot I am!

    Shame, shame, shame. Of course it is the explanation and solution.

    As I said, it may very well be something I’m missing.
    Another epic fail for the chair-keyboard interface.

    So focus on this trace and used to set these parameters I didn’t even see they were missing.

    Thank you very much @opr18 for showing to the world what a big noob I am.

    Best regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.