NF_MergeTags_Deprecated

Class NF_MergeTags_WordPress.

Defined (1)

The class is defined in the following location(s).

/includes/MergeTags/Deprecated.php  
  1. final class NF_MergeTags_Deprecated extends NF_Abstracts_MergeTags 
  2. protected $id = 'deprecated'; 
  3.  
  4. /** 
  5. * @var array 
  6. * $post_meta[ $meta_key ] = $meta_value; 
  7. */ 
  8. protected $post_meta = array(); 
  9.  
  10. public function __construct() 
  11. parent::__construct(); 
  12. $this->merge_tags = Ninja_Forms()->config( 'MergeTagsDeprecated' ); 
  13.  
  14. // Setup merge tag data for each post in The Loop. 
  15. add_action( 'the_post', array( $this, 'init' ) ); 
  16.  
  17. // Setup merge tag data when Doing AJAX. 
  18. add_action( 'admin_init', array( $this, 'init' ) ); 
  19.  
  20. public function init() 
  21. global $post; 
  22.  
  23. $this->setup_post_meta( $this->post_id() ); 
  24.  
  25. protected function post_id() 
  26. global $post; 
  27.  
  28. if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { 
  29. // If we are doing AJAX, use the referer to get the Post ID. 
  30. $post_id = url_to_postid( wp_get_referer() ); 
  31. } elseif( $post ) { 
  32. $post_id = $post->ID; 
  33. } else { 
  34. return false; // No Post ID found. 
  35.  
  36. return $post_id; 
  37.  
  38. protected function post_title() 
  39. $post_id = $this->post_id(); 
  40. if( ! $post_id ) return; 
  41. $post = get_post( $post_id ); 
  42. return ( $post ) ? $post->post_title : ''; 
  43.  
  44. protected function post_url() 
  45. $post_id = $this->post_id(); 
  46. if( ! $post_id ) return; 
  47. $post = get_post( $post_id ); 
  48. return ( $post ) ? get_permalink( $post->ID ) : ''; 
  49.  
  50. protected function post_author() 
  51. $post_id = $this->post_id(); 
  52. if( ! $post_id ) return; 
  53. $post = get_post( $post_id ); 
  54. if( ! $post ) return ''; 
  55. $author = get_user_by( 'id', $post->post_author); 
  56. return $author->display_name; 
  57.  
  58. protected function post_author_email() 
  59. $post_id = $this->post_id(); 
  60. if( ! $post_id ) return; 
  61. $post = get_post( $post_id ); 
  62. if( ! $post ) return ''; 
  63. $author = get_user_by( 'id', $post->post_author ); 
  64. return $author->user_email; 
  65.  
  66. public function setup_post_meta( $post_id ) 
  67. global $wpdb; 
  68.  
  69. // Get ALL post meta for a given Post ID. 
  70. $results = $wpdb->get_results( $wpdb->prepare( " 
  71. SELECT `meta_key`, `meta_value` 
  72. FROM {$wpdb->postmeta} 
  73. WHERE `post_id` = %d 
  74. ", $post_id ) ); 
  75.  
  76. foreach( $results as $result ) { 
  77. $this->post_meta[ $result->meta_key ] = $result->meta_value; 
  78.  
  79. protected function user_id() 
  80. $current_user = wp_get_current_user(); 
  81.  
  82. return ( $current_user ) ? $current_user->ID : ''; 
  83.  
  84. protected function user_first_name() 
  85. $current_user = wp_get_current_user(); 
  86.  
  87. return ( $current_user ) ? $current_user->user_firstname : ''; 
  88.  
  89. protected function user_last_name() 
  90. $current_user = wp_get_current_user(); 
  91.  
  92. return ( $current_user ) ? $current_user->user_lastname : ''; 
  93.  
  94. protected function user_display_name() 
  95. $current_user = wp_get_current_user(); 
  96.  
  97. return ( $current_user ) ? $current_user->display_name : ''; 
  98.  
  99. protected function user_email() 
  100. $current_user = wp_get_current_user(); 
  101.  
  102. return ( $current_user ) ? $current_user->user_email : ''; 
  103.  
  104. protected function admin_email() 
  105. return get_option( 'admin_email' ); 
  106.  
  107. protected function site_title() 
  108. return get_bloginfo( 'name' ); 
  109.  
  110. protected function site_url() 
  111. return get_bloginfo( 'url' ); 
  112.  
  113.  
  114. protected function system_date() 
  115. $format = Ninja_Forms()->get_setting( 'date_format' ); 
  116. if ( empty( $format ) ) { 
  117. $format = 'Y/m/d'; 
  118. return date( $format, time() ); 
  119.  
  120. protected function system_ip() 
  121. $ip = '127.0.0.1'; 
  122. if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { 
  123. //check ip from share internet 
  124. $ip = $_SERVER['HTTP_CLIENT_IP']; 
  125. } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { 
  126. //to check ip is pass from proxy 
  127. $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; 
  128. } elseif( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { 
  129. $ip = $_SERVER['REMOTE_ADDR']; 
  130.  
  131. return apply_filters( 'ninja_forms-get_ip', apply_filters( 'nf_get_ip', $ip ) ); 
  132.  
  133.  
  134. } // END CLASS NF_MergeTags_System