1+ <?php
2+
3+ // Add WP Content Merge Tag
4+ class NFMTA_AddonTag extends NF_Abstracts_MergeTags {
5+
6+ protected $ id = 'nfmta_merge_tags ' ;
7+
8+ public function __construct (){
9+ parent ::__construct ();
10+ $ this ->title = __ ( 'Merge Addon ' , 'nfmta ' );
11+ $ this ->merge_tags = array (
12+ 'nfmtacontent ' => array (
13+ 'id ' => 'nfmta_merge_content ' ,
14+ 'tag ' => '{nfmta:nfmtacontent} ' ,
15+ 'label ' => __ ( 'WordPress Single Page Content ' , 'nfmta ' ),
16+ 'callback ' => 'nfmta_merge_content '
17+ ),
18+ );
19+ add_action ( 'init ' , array ( $ this , 'init ' ) );
20+ add_action ( 'admin_init ' , array ( $ this , 'admin_init ' ) );
21+ }
22+
23+ // Add Post Meta from WordPress
24+ protected function post_id (){
25+ global $ post ;
26+
27+ if ( is_admin () && defined ( 'DOING_AJAX ' ) && DOING_AJAX ) {
28+ $ post_id = url_to_postid ( wp_get_referer () );
29+ } elseif ( $ post ) {
30+ $ post_id = $ post ->ID ;
31+ } else {
32+ return false ;
33+ }
34+ return $ post_id ;
35+ }
36+
37+ // Return the Content
38+ protected function nfmta_merge_content (){
39+ $ post_id = $ this ->post_id ();
40+
41+ if ( ! $ post_id ) return ;
42+ $ post = get_post ( $ post_id );
43+ return ( $ post ) ? $ post ->post_content : '' ;
44+ }
45+ }
0 commit comments