Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active November 21, 2022 15:41
Show Gist options
  • Save wpmudev-sls/ce692035e4eb0efbdb551ad1a37929df to your computer and use it in GitHub Desktop.
Save wpmudev-sls/ce692035e4eb0efbdb551ad1a37929df to your computer and use it in GitHub Desktop.
[Forminator Pro] - Send email to listing's author. Extend existing functionality of Easy Property Listing to send email to listing's author
<?php
/**
* Plugin Name: [Forminator Pro] - Send email to listing's author
* Plugin URI: https://premium.wpmudev.org/
* Description: Extend existing functionality of Easy Property Listing to send email to listing's author (as of 1.9)
* Author: Alessandro Kaounas @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WPMUDEV_Forminator_Listing_Author' ) ) {
class WPMUDEV_Forminator_Listing_Author {
private static $_instance = null;
public static function get_instance() {
if( is_null( self::$_instance ) ){
self::$_instance = new WPMUDEV_Forminator_Listing_Author();
}
return self::$_instance;
}
private function __construct() {
add_filter( 'forminator_form_get_admin_email_recipients', array( $this, 'wpmudev_forminator_author_email' ), 20, 5 );
}
function wpmudev_forminator_author_email( $recipients, $notification, $data, $custom_form, $entry ){
if( isset( $data['page_id'] ) ){
$listing_id = $data['page_id'];
}else{
$listing_id = url_to_postid( wp_get_referer() );
if( !isset( $listing_id ) ) return $recipients;
}
// Add post author email to recipients
$recipients[] = get_the_author_meta( 'user_email', get_post_field( 'post_author', $listing_id ) );
return $recipients;
}
}
if ( ! function_exists( 'WPMUDEV_Forminator_Listing_Author' ) ) {
function WPMUDEV_Forminator_Listing_Author() {
return WPMUDEV_Forminator_Listing_Author::get_instance();
};
add_action( 'plugins_loaded', 'WPMUDEV_Forminator_Listing_Author', 99 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment