MailPoet_Add_ons

The MailPoet Newsletters MailPoet Add ons class.

Defined (1)

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

/add-ons/add-ons.php  
  1. class MailPoet_Add_ons { 
  2. /** 
  3. * Constructor 
  4. */ 
  5. public function __construct() { 
  6. $this->plugin_path = WYSIJA_DIR; 
  7. $this->wp_plugin_path = str_replace( 'wysija-newsletters', '', $this->plugin_path ); 
  8. $this->plugin_url = WYSIJA_URL; 
  9. $this->image_url = '//ps.w.org/wysija-newsletters/assets/add-ons/'; 
  10.  
  11. $this->mailpoet_add_on_activated_notice(); 
  12. $this->mailpoet_add_on_deactivated_notice(); 
  13.  
  14. /** 
  15. * Runs when the plugin is initialized. 
  16. */ 
  17. public function init_mail_poet_add_ons() { 
  18. // Load JavaScript and stylesheets. 
  19. $this->register_scripts_and_styles(); 
  20.  
  21. /** 
  22. * Registers and enqueues stylesheets for the 
  23. * administration panel and the public facing site. 
  24. */ 
  25. public function register_scripts_and_styles() { 
  26. if ( is_admin() ) { 
  27. wp_register_style( 'mail_poet_add_ons', WYSIJA_URL . 'css/add-ons.css' ); 
  28. wp_enqueue_style( 'mail_poet_add_ons' ); 
  29. } // end if 
  30. } // end register_scripts_and_styles 
  31.  
  32. /** 
  33. * This notifies the user that the add-on plugin 
  34. * is now activated and returns them back to the 
  35. * add-ons page. 
  36. */ 
  37. public function mailpoet_add_on_activated_notice() { 
  38. global $current_screen; 
  39.  
  40. require_once(ABSPATH.'/wp-admin/includes/plugin.php'); 
  41.  
  42. if ( isset($_GET['action'] ) && $_GET['action'] == 'activate' && isset( $_GET['module'] ) ) { 
  43.  
  44. $plugin = plugin_basename( $_GET['module'] ); 
  45. $plugin_data = get_plugin_data( $this->wp_plugin_path . $plugin ); 
  46.  
  47. $plugin_name = esc_attr( str_replace( ' ', '_', $plugin_data['Name'] ) ); 
  48. $plugin_name = esc_attr( str_replace( ''', '_', $plugin_name ) ); 
  49.  
  50. if ( isset( $_GET['requires'] ) ) { 
  51. if ( file_exists( $this->wp_plugin_path . plugin_basename( $_GET['requires'] ) ) ) { 
  52. if ( ! WYSIJA::is_plugin_active( $_GET['requires'] ) ) { 
  53. $location = admin_url( 'admin.php?page=wysija_config&status=not-activated&add-on=' . $plugin_name . '&requires=' . esc_attr( str_replace( ' ', '_', $_GET['requires_name'] ) ) . '#tab-add-ons' ); 
  54. wp_safe_redirect( $location ); 
  55. exit; 
  56. } else { 
  57. $location = admin_url( 'admin.php?page=wysija_config&status=not-installed&add-on=' . $plugin_name . '&requires=' . esc_attr( str_replace( ' ', '_', $_GET['requires_name'] ) ) . '#tab-add-ons' ); 
  58. wp_safe_redirect( $location ); 
  59. exit; 
  60.  
  61. // Activate the add-on plugin. 
  62. activate_plugin( $plugin ); 
  63.  
  64. // Return back to add-on page. 
  65. $location = admin_url( 'admin.php?page=wysija_config&status=activated&add-on=' . $plugin_name . '#tab-add-ons' ); 
  66. wp_safe_redirect( $location ); 
  67. exit; 
  68.  
  69. /** 
  70. * Display message if the plugin was not able to activate due 
  71. * to a required plugin is not active first. 
  72. */ 
  73. if ( $current_screen->parent_base == 'wysija_campaigns' && isset( $_GET['status'] ) && $_GET['status'] == 'not-activated' || isset( $_GET['status'] ) && $_GET['status'] == 'not-installed' ) { 
  74. echo 
  75. '<div id="message" class="error fade" style="display:block !important;">' . 
  76. '<p>' . 
  77. '<strong>' . esc_attr( str_replace( '_', ' ', $_GET['add-on'] ) ) . '</strong> ' . 
  78. wp_kses( sprintf( 
  79. __( 'was not activated as it requires <strong><a href="%s">%s</a></strong> to be installed and active first.', WYSIJA ),  
  80. esc_url( admin_url( 'plugin-install.php?tab=search&type=term&s=' . esc_attr( strtolower( str_replace( ' ', '+', $_GET['requires'] ) ) ) ) ),  
  81. str_replace( '_', ' ', $_GET['requires'] ) 
  82. ), array( 'a' => array( 'href' => array() ), 'strong' => array(), 'b' => array(), 'em' => array() ) ) . 
  83. ' <input type="button" class="button" value="' . esc_attr__( 'Hide this message', WYSIJA ) . '" onclick="document.location.href=\'' . esc_url( admin_url( 'admin.php?page=wysija_config#tab-add_ons' ) ) . '\';">' . 
  84. '</p>' . 
  85. '</div>'; 
  86.  
  87. // Display message once the add-on has been activated. 
  88. if ( $current_screen->parent_base == 'wysija_campaigns' && isset( $_GET['status'] ) && $_GET['status'] == 'activated' ) { 
  89. echo '<div id="message" class="updated fade" style="display:block !important;"><p><strong>' . esc_attr( str_replace( '_', ' ', $_GET['add-on'] ) ) . '</strong> ' . esc_attr__( 'has been activated.', WYSIJA ) . '</p></div>'; 
  90.  
  91. /** 
  92. * This notifies the user that the add-on plugin 
  93. * is now deactivated and returns them back to the 
  94. * add-ons page. 
  95. */ 
  96. public function mailpoet_add_on_deactivated_notice() { 
  97. global $current_screen; 
  98.  
  99. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  100.  
  101. if ( isset( $_GET['action'] ) && $_GET['action'] == 'deactivate' && isset( $_GET['module'] ) ) { 
  102. $plugin = plugin_basename( $_GET['module'] ); 
  103. $plugin_data = get_plugin_data( $this->wp_plugin_path . $plugin ); 
  104.  
  105. // Deactivate the add-on plugin. 
  106. deactivate_plugins( $plugin ); 
  107.  
  108. // Return back to add-on page. 
  109. $location = admin_url( 'admin.php?page=wysija_config&status=deactivated&add-on=' . esc_html( str_replace( ' ', '_', $plugin_data['Name'] ) ) . '#tab-add-ons' ); 
  110. wp_safe_redirect( $location ); 
  111. exit; 
  112.  
  113. // Display message once the add-on has been deactivated. 
  114. if ( $current_screen->parent_base == 'wysija_campaigns' && isset( $_GET['status'] ) && $_GET['status'] == 'deactivated' ) { 
  115. echo '<div id="message" class="updated fade" style="display:block !important;"><p><strong>' . esc_attr( str_replace( '_', ' ', $_GET['add-on'] ) ) . '</strong> ' . esc_attr__( 'has been de-activated.', WYSIJA ) . '</p></div>'; 
  116.  
  117.  
  118. /** 
  119. * Displays the add ons page and lists 
  120. * the plugins and services available. 
  121. */ 
  122. public function add_ons_page() { 
  123. require_once WYSIJA_DIR . '/add-ons/add-ons-list.php'; 
  124.  
  125. echo '<div class="module-container">'; 
  126. foreach ( add_ons_list() as $plugin => $product ) { 
  127. $status = ''; // Status class. 
  128.  
  129. /** 
  130. * Queries if the plugin is installed,  
  131. * active and meets the requirements 
  132. * it requires if any. 
  133. */ 
  134. if ( file_exists( $this->wp_plugin_path . plugin_basename( $product['plugin_url'] ) ) ) { 
  135. $status .= ' installed'; 
  136. } else { 
  137. $status .= ' not-installed'; 
  138.  
  139. if ( WYSIJA::is_plugin_active( $product['plugin_url'] ) ) { 
  140. $status .= ' active'; 
  141. } else { 
  142. $status .= ' inactive'; 
  143.  
  144. if ( empty( $product['requires'] ) ) { 
  145. $status .= ' ready'; 
  146. } elseif ( ! empty( $product['requires'] ) && file_exists( $this->wp_plugin_path . plugin_basename( $product['requires'] ) ) ) { 
  147. $status .= ' ready'; 
  148. if ( WYSIJA::is_plugin_active( $product['requires'] ) ) { 
  149. $status .= ' ready'; 
  150. } else { 
  151. $status .= ' not-ready'; 
  152. } elseif ( ! empty( $product['requires'] ) && ! file_exists( $this->wp_plugin_path . plugin_basename( $product['requires'] ) ) ) { 
  153. $status .= ' not-ready'; 
  154.  
  155. if ( WYSIJA::is_plugin_active( 'wysija-newsletters-premium/index.php' ) ) { 
  156. $status .= ' premium-active'; 
  157.  
  158. echo 
  159. '<div class="mailpoet-module' . esc_attr( $status ) . '" id="product">' . 
  160. '<h3>' . esc_attr( $product['name'] ) . '</h3>'; 
  161.  
  162. if ( ! empty( $product['thumbnail'] ) ) { 
  163. echo '<div class="mailpoet-module-image"><img src="' . esc_url( $this->image_url . $product['thumbnail'] ) . '" width="100%" title="' . esc_attr( $product['name'] ) . '" alt=""></div>'; 
  164.  
  165. echo 
  166. '<div class="mailpoet-module-content">' . 
  167. '<div class="mailpoet-module-description">' . 
  168. '<p>' . wp_kses( $product['description'], array() ) . '</p>'; 
  169.  
  170. if ( ! empty( $product['review'] ) ) { 
  171. echo '<p><strong>' . esc_attr__( 'MailPoet says: ', WYSIJA ) . '<em>' . esc_attr( $product['review'] ) . '</em>' . '</strong></p>'; 
  172.  
  173. if ( WYSIJA::is_plugin_active( 'wysija-newsletters-premium/index.php' ) && ! empty( $product['premium_offer'] ) ) { 
  174. echo '<p><strong>' . esc_attr( $product['premium_offer'] ) . '</strong></p>'; 
  175. echo 
  176. '</div>' . 
  177. '</div>' . 
  178.  
  179. '<div class="mailpoet-module-actions">'; 
  180.  
  181. if ( ! empty( $product['author_url'] ) ) { 
  182. echo '<a href="' . esc_url( $product['author_url'] ) . '" target="_blank" rel="external" class="button-primary website">' . esc_attr__( 'Website', WYSIJA ) . '</a> '; 
  183.  
  184. if ( $product['free'] == false && ! empty( $product['purchase_url'] ) ) { 
  185. if ( ! empty( $product['plugin_url'] ) && ! file_exists( $this->wp_plugin_path . plugin_basename( $product['plugin_url'] ) ) ) { 
  186. echo '<a href="' . esc_url( $product['purchase_url'] ) . '" target="_blank" rel="external" class="button-primary purchase">' . esc_attr__( 'Purchase', WYSIJA ) . '</a> '; 
  187. } // end if plugin is installed, don't show purchase button. 
  188. } // end if product is not free. 
  189.  
  190. if ( $product['service'] == false ) { 
  191. if ( $product['on_wordpress.org'] == true ) { 
  192. if ( ! file_exists( $this->wp_plugin_path . plugin_basename( $product['plugin_url'] ) ) ) { 
  193. echo '<a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&type=term&s=' . strtolower( str_replace( ' ', '+', $product['search'] ) ) ) ) . '" class="button-primary install">' . esc_attr__( 'Install from WordPress.org', WYSIJA ) . '</a> '; 
  194. } // end if $product['on_wordpress.org']; 
  195.  
  196. if ( ! empty( $product['plugin_url'] ) && file_exists( $this->wp_plugin_path . plugin_basename( $product['plugin_url'] ) ) ) { 
  197. if ( ! WYSIJA::is_plugin_active( $product['plugin_url'] ) ) { 
  198. if ( ! empty( $product['requires'] ) ) { 
  199. $requires = '&requires=' . $product['requires'] . '&requires_name=' . $product['requires_name']; 
  200. } else { 
  201. $requires = ''; 
  202. echo '<a href="' . esc_url( admin_url( 'admin.php?page=wysija_config&action=activate&module=' . $product['plugin_url'] . $requires ) ) . '" class="button-primary activate">' . esc_attr__( 'Activate', WYSIJA ) . '</a> '; 
  203. } else { 
  204. if ( ! empty( $product['config_url'] ) ) { 
  205. echo '<a href="' . esc_url( $product['config_url'] ) . '" class="mailpoet-configure-button button-secondary">' . esc_attr__( 'Configure', WYSIJA ) . '</a>'; 
  206.  
  207. echo 
  208. '</div>' . 
  209. '</div>'; 
  210. } // end if local is yes. 
  211.  
  212. echo 
  213. '<div class="submit-idea">' . 
  214. '<p>' . wp_kses( sprintf( __( 'Don\'t see the add-on you\'re looking for? <a href="%s">Submit it</a> in our contact form.', WYSIJA ), 'http://www.mailpoet.com/contact/" target="blank' ), array( 'a' => array( 'href' => array() ) ) ) . '</p>' . 
  215. '</div>' . 
  216. '</div>'; 
  217. } // end class