• Resolved annagater

    (@annagater)


    Hi there, I inherited a website that is using pods to allow members of an online community create bulletin board style listings on a page. The entries are set to be created as “pending” to allow moderators to approve before being published. They were getting notifications when a new listing was submitted and now they are not. I don’t see any way to set up notifications on submission. Any ideas on how to work this out without re-building? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @annagater

    Did you by any chance update to the latest Pods version? And if so, please check the new security updates for forms and dynamic data since v3.1!

    https://pods.io/2024/02/21/pods-3-1-feature-release-access-rights-revamp/

    If that is not the case or isn’t helping at all, please review if there are other changes made. It might be a plugin conflict that occurred after an update.

    Cheers, Jory

    Plugin Support Paul Clark

    (@pdclark)

    I am not aware of any default notification mechanism within Pods, so user interface for this would depend on which plugins are used to send the notification, and fixing it without changing anything would also depend on how it has been configured.

    Assuming the notification is an email, and assuming the pending posts are created with [pods-form], wp-admin, or any form method which ends up creating or updating post with post type pending, this is the generic action for sending an email when a post status changes is https://developer.www.ads-software.com/reference/functions/wp_transition_post_status/ combined with https://developer.www.ads-software.com/reference/functions/wp_mail/

    Here is a minimal example which sends an email when a post type of type post has its status set to Pending Review, where the emails notified are gathered from three locations including a site-wide Settings field, and the email contents contains links to both the page to edit and the URL it will be published on:

    <?php
    add_action(
    'transition_post_status',
    function( $new_status, $old_status, $post ) {
    // Send an email if:
    // - The status has changed to "Pending Review" from something else.
    // - The post_type is 'post'.
    if(
    $old_status !== $new_status
    && 'pending' === $new_status
    && 'post' === $post->post_type
    ) {
    // Set the email content type to HTML.
    add_filter( 'wp_mail_content_type','set_wp_mail_to_html', 1000 );
    // Send the notification.
    wp_mail(
    // An array of recipient addresses.
    array_unique( // Remove duplicates.
    array_merge( // Combine emails from various sources.
    [
    // Author of the Post.
    get_user_by( 'ID', $post->post_author )->user_email,
    ],
    [
    // Site admin.
    get_option( 'admin_email' ),
    ],
    // A list of emails, separated by returns, stored in a Plain Paragraph Text field on a Settings Page created with Pods. The Settings Page is called notification_settings and the field is called people_to_notify.
    (array) explode(
    PHP_EOL,
    (string) get_option( 'notification_settings_people_to_notify' ),
    ),
    )
    ),
    // Subject.
    '?? Pending Review: ' . $post->post_title,
    // Email HTML body.
    sprintf(
    <<<'TEMPLATE'
    <p>The post <a href="%s">%s</a> is ready for review.</p>
    <p>Click the link to edit or publish to <a href="%s">%s</a>.</p>
    TEMPLATE,
    esc_url( get_edit_post_link( $post->ID ) ),
    esc_html( $post->post_title ),
    get_permalink( $post->ID ),
    get_permalink( $post->ID )

    ),
    // Optional additional headers, such as BCC.
    [],
    // Optional attachments.
    []
    );
    // Set the email content type back to default.
    remove_filter( 'wp_mail_content_type','set_wp_mail_to_html', 1000 );
    }
    },
    20,
    3
    );
    function set_wp_mail_to_html() {
    return 'text/html';
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.