• Resolved Generosus

    (@generosus)


    Is there a way we can apply a code snippet to an individual plugin? How about several? For example to akismet.php and/or mailpoet.php.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Generosus

    (@generosus)

    Solution:

    Well, we may have found a solution. The sample code snippet provided below does the trick for us.

    ———————-

    function disable_admin_notices( $value) {
    if ( isset( $value ) && is_object( $value ) ) {
    unset( $value->response[ 'akismet/akismet.php' ] );
    unset( $value->response[ 'mailpoet/mailpoet.php' ] );
    }
    // insert your code here
    return $value;
    }
    add_action( 'admin_print_scripts', 'disable_admin_notices' );

    Where:

    function and add_action (both lines) will vary according to your needs.

    Recommendation:

    Once you confirm the above works, it would be great if you can add it to your documentation. Similar to “How to make a snippet run on only one page”

    Thank you ??

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @generosus,

    I definitely appreciate you working out a solution and sharing it here, but I’m not sure how widely applicable this would be. Unsetting the array values works in that specific example of wanting to remove scripts for those plugins, but it’s not a generalised solution that can be used for any snippet, in my understanding.

    I’m also a little confused by what you mean by ‘applying’ a snippet to a plugin. What would this actually look like?

    Thread Starter Generosus

    (@generosus)

    Hey Shea. Thanks for the prompt reply. In response:

    (1) The sample code snippet would help disable — for example — unnecessary plugin messages displayed in the backend or frontend. Stack OVerflow and GitHub are good sources of information to develop variants of the above code snippet for other meaningful purposes.

    (2) Semantics. You can also call it: “How to make a snippet run only for one plugin or several.”

    Expanding your documentation to reflect the basics of the above might be helpful to many — especially your PRO users.

    Peace ??

    Thread Starter Generosus

    (@generosus)

    Solution:

    Your code snippet, Disable Admin Notices by Text String, solved our issue.

    Apologies for not being a bit clearer with our past request. Specifically, we were trying to disable unwanted or unnecessary admin notices generated by specific plugins. The “text string” approach worked beautifully!

    Thanks for that. You rock!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Apply Code Snippet to Individual Plugin’ is closed to new replies.