WYSIJA_object

The MailPoet Newsletters WYSIJA object class.

Defined (1)

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

/core/base.php  
  1. class WYSIJA_object{ 
  2.  
  3. /** 
  4. * Static variable holding core MailPoet's version 
  5. * @var array 
  6. */ 
  7. static $version = '2.7.9'; 
  8.  
  9. function __construct() {} 
  10.  
  11. /** 
  12. * Order an array by param name string compare 
  13. * @param array $a Array with the param to compare 
  14. * @param array $b Array with the param to compare 
  15. * @return int Sorting result from strcmp 
  16. */ 
  17. public static function sort_by_name( $a, $b ) { 
  18. return strcmp( strtolower( $a['name'] ), strtolower( $b['name'] ) ); 
  19.  
  20. /** 
  21. * Returns the version of based on a path 
  22. * @filter mailpoet/get_version 
  23. * @filter mailpoet/package 
  24. * @param string $path 
  25. * @return string Version of the package 
  26. */ 
  27. public static function get_version( $path = null ) { 
  28. $version = self::$version; 
  29. // Backwards compatibility for Premium Versions 
  30. if ( ! has_filter( 'mailpoet/get_version', '_filter_mailpoet_premium_version' ) && in_array( $path, array( 'premium', 'wysija-newsletters-premium', 'wysija-newsletters-premium/index.php' ) ) ) { 
  31. if ( ! function_exists( 'get_plugin_data' ) ) { 
  32. include_once ABSPATH . 'wp-admin/includes/plugin.php'; 
  33. $plugin_data = get_plugin_data( dirname( dirname( plugin_dir_path( __FILE__ ) ) ) . '/wysija-newsletters-premium/index.php' ); 
  34. $version = trim( $plugin_data['Version'] ); 
  35.  
  36. return apply_filters( 'mailpoet/get_version', $version, apply_filters( 'mailpoet/package', 'core', $path ) ); 
  37.  
  38. /** 
  39. * get the current_user data in a safe manner making sure a field exists before returning it's value 
  40. * @global type $current_user 
  41. * @param string $field 
  42. * @return mixed 
  43. */ 
  44. public static function wp_get_userdata( $field = false ) { 
  45. //WordPress globals be careful there 
  46. global $current_user; 
  47. if ( $field ) { 
  48. if ( function_exists( 'wp_get_current_user' ) ) { 
  49. // Here is an exception because of one of the weirdest bug 
  50. // the idea is to make sure we don't call wp_get_current_user() on the wysija_subscribers page when on a multisite 
  51. if ( ! ( isset( $_GET['page'] ) && $_GET['page'] === 'wysija_subscribers' && is_multisite() ) ) { 
  52. wp_get_current_user(); 
  53. if ( isset( $current_user->{$field} ) ) { 
  54. return $current_user->{$field}; 
  55. } elseif ( isset( $current_user->data->{$field} ) ) { 
  56. return $current_user->data->{$field}; 
  57. } else { 
  58. return $current_user; 
  59. return $current_user; 
  60.  
  61. /** 
  62. * set a global notice message 
  63. * @global array $wysija_wpmsg 
  64. * @param type $msg 
  65. */ 
  66. function wp_notice( $msg ) { 
  67. global $wysija_wpmsg; 
  68.  
  69. //add the hook only once 
  70. if ( ! $wysija_wpmsg ) { 
  71. add_action( 'admin_notices', array( $this, 'wp_msgs' ) ); 
  72.  
  73. //record msgs 
  74. $wysija_wpmsg['updated'][] = $msg; 
  75.  
  76. /** 
  77. * set a global error message 
  78. * @global array $wysija_wpmsg 
  79. * @param type $msg 
  80. */ 
  81. function wp_error( $msg ) { 
  82. global $wysija_wpmsg; 
  83.  
  84. //add the hook only once 
  85. if ( ! $wysija_wpmsg ) { 
  86. add_action( 'admin_notices', array( $this, 'wp_msgs' ) ); 
  87.  
  88. //record msgs 
  89. $wysija_wpmsg['error'][] = $msg; 
  90.  
  91. /** 
  92. * prints a global message in the WordPress' backend identified as belonging to wysija 
  93. * we tend to avoid as much as possible printing messages globally, since this is ugly 
  94. * and make the administrators immune to beige-yellowish messages :/ 
  95. * @global array $wysija_wpmsg 
  96. */ 
  97. function wp_msgs() { 
  98. global $wysija_wpmsg; 
  99. foreach ( $wysija_wpmsg as $keymsg => $wp2 ) { 
  100. $msgs = '<div class="' . $keymsg . ' fade">'; 
  101. foreach ( $wp2 as $mymsg ) { 
  102. $msgs .= '<p><strong>MailPoet</strong> : ' . $mymsg . '</p>'; 
  103. $msgs .= '</div>'; 
  104.  
  105. // This is bad, we should be checking for valid HTML here. 
  106. echo $msgs; 
  107.  
  108. /** 
  109. * returns an error message, it will appear as a red pinkish message in our interfaces 
  110. * @param string $msg 
  111. * @param boolean $public if set to true it will appear as a full message, otherwise it will appear behind a "Show more details." link 
  112. * @param boolean $global if set to true it will appear on all of the backend interfaces, not only wysija's own 
  113. */ 
  114. function error( $msg, $public = false, $global = false ) { 
  115. $status = 'error'; 
  116. if ( $global ) { 
  117. $status = 'g-' . $status; 
  118. $this->setInfo( $status, $msg, $public ); 
  119.  
  120. /** 
  121. * returns a success message, it will appear as a beige yellowish message in our interfaces 
  122. * @param string $msg 
  123. * @param boolean $public if set to true it will appear as a full message, otherwise it will appear behind a "Show more details." link 
  124. * @param boolean $global if set to true it will appear on all of the backend interfaces, not only wysija's own 
  125. */ 
  126. function notice( $msg, $public = true, $global = false ) { 
  127. $status = 'updated'; 
  128. if ( $global ) { 
  129. $status = 'g-' . $status; 
  130. $this->setInfo( $status, $msg, $public ); 
  131.  
  132. /** 
  133. * store all of the error and success messages in a global variable 
  134. * @global type $wysija_msg 
  135. * @param type $status whether this is a success message or an error message 
  136. * @param type $msg 
  137. * @param type $public if set to true it will appear as a full message, otherwise it will appear behind a "Show more details." link 
  138. */ 
  139. static function setInfo($status, $msg, $public=false) { 
  140. global $wysija_msg; 
  141. if(!$public) { 
  142.  
  143. if(!isset($wysija_msg['private'][$status])) { 
  144. $wysija_msg['private']=array(); 
  145. $wysija_msg['private'][$status]=array(); 
  146. array_push($wysija_msg['private'][$status], $msg); 
  147. }else{ 
  148. if(!isset($wysija_msg[$status])) $wysija_msg[$status]=array(); 
  149. array_push($wysija_msg[$status], $msg); 
  150.  
  151.  
  152. /** 
  153. * read the global function containing all of the error messages and print them 
  154. * @global type $wysija_msg 
  155. * @return type 
  156. */ 
  157. function getMsgs() { 
  158. global $wysija_msg; 
  159.  
  160. if(isset($wysija_msg['private']['error'])) { 
  161. $wysija_msg['error'][]=str_replace(array('[link]', '[/link]'), array('<a class="showerrors" href="javascript:;">', '</a>'), __('An error occurred. [link]Show more details.[/link]', WYSIJA)); 
  162.  
  163. if(isset($wysija_msg['private']['updated'])) { 
  164. $wysija_msg['updated'][]=str_replace(array('[link]', '[/link]'), array('<a class="shownotices" href="javascript:;">', '</a>'), __('[link]Show more details.[/link]', WYSIJA)); 
  165. if(isset($wysija_msg['private'])) { 
  166. $prv=$wysija_msg['private']; 
  167. unset($wysija_msg['private']); 
  168. if(isset($prv['error'])) $wysija_msg['xdetailed-errors']=$prv['error']; 
  169. if(isset($prv['updated'])) $wysija_msg['xdetailed-updated']=$prv['updated']; 
  170. return $wysija_msg; 
  171.  
  172. /** 
  173. * If the current server is Windows-based 
  174. * @return boolean 
  175. */ 
  176. public static function is_windows() { 
  177. $is_windows = false; 
  178. $windows = array( 
  179. 'windows nt',  
  180. 'windows',  
  181. 'winnt',  
  182. 'win32',  
  183. 'win' 
  184. ); 
  185. $operating_system = strtolower( php_uname( 's' ) ); 
  186. foreach ( $windows as $windows_name ) { 
  187. if (strpos($operating_system, $windows_name) !== false) { 
  188. $is_windows = true; 
  189. break; 
  190. return $is_windows; 
  191.