Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2018 07:03:35 PM (3 years ago)
Author:
boonebgorges
Message:

Emails: Ensure that default email tokens are pulled from root blog.

The email post type is always stored on the root blog, so we should be
sure to switch to that blog whenever referencing the post (such as
when pulling postmeta related to the post).

Fixes #7996.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-email.php

    r11895 r12284  
    7171
    7272    /**
     73     * Email preheader.
     74     *
     75     * @since 4.0.0
     76     *
     77     * @var string
     78     */
     79    protected $preheader = null;
     80
     81    /**
    7382     * Email headers.
    7483     *
     
    271280         */
    272281        return apply_filters( 'bp_email_get_property', $retval, $property_name, $transform, $this );
     282    }
     283
     284    /**
     285     * Get email preheader.
     286     *
     287     * @since 4.0.0
     288     */
     289    public function get_preheader() {
     290        if ( null !== $this->preheader ) {
     291            return $this->preheader;
     292        }
     293
     294        $preheader = '';
     295
     296        $post = $this->get_post_object();
     297        if ( $post ) {
     298            $switched = false;
     299
     300            // Switch to the root blog, where the email post lives.
     301            if ( ! bp_is_root_blog() ) {
     302                switch_to_blog( bp_get_root_blog_id() );
     303                $switched = true;
     304            }
     305
     306            $preheader = sanitize_text_field( get_post_meta( $post->ID, 'bp_email_preheader', true ) );
     307
     308            if ( $switched ) {
     309                restore_current_blog();
     310            }
     311        }
     312
     313        $this->preheader = $preheader;
     314
     315        return $this->preheader;
    273316    }
    274317
Note: See TracChangeset for help on using the changeset viewer.