/easy-peasy-mailchimp.php

  1. <?php 
  2. /** 
  3. Plugin Name: Easy Peasy MailChimp Ajax Form 
  4. Plugin URI: http://themesdepot.org 
  5. Description: Easy Peasy MailChimp allows you to easily include an ajax powered mailchimp newsletter signup form into your website through widget or shortcode. 
  6. Author: Alessandro Tesoro 
  7. Version: 1.0.5 
  8. Author URI: http://alessandrotesoro.me 
  9. Requires at least: 3.8 
  10. Tested up to: 4.0 
  11. Text Domain: easy-peasy-mailchimp 
  12. Domain Path: /languages 
  13. License: GPLv2 or later 
  14. */ 
  15.  
  16. /** 
  17. Copyright 2014 Alessandro Tesoro 
  18.   
  19. This program is free software; you can redistribute it and/or 
  20. modify it under the terms of the GNU General Public License 
  21. as published by the Free Software Foundation; either version 2 
  22. of the License, or (at your option) any later version. 
  23.   
  24. This program is distributed in the hope that it will be useful,  
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  27. GNU General Public License for more details. 
  28.   
  29. You should have received a copy of the GNU General Public License 
  30. along with this program; if not, write to the Free Software 
  31. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 
  32. */ 
  33.  
  34. // Exit if accessed directly 
  35. if ( ! defined( 'ABSPATH' ) ) 
  36. exit; 
  37.  
  38. /** 
  39. * Easy Google Analytics class. 
  40. */ 
  41. class Easy_Peasy_MailChimp { 
  42.  
  43. /** 
  44. * Constructor - get the plugin hooked in and ready 
  45. * @since 1.0.0 
  46. */ 
  47. public function __construct() { 
  48.  
  49. // Define constants 
  50. define( 'EPM_VERSION', '1.0.5' ); 
  51. define( 'EPM_SLUG', plugin_basename(__FILE__)); 
  52. define( 'EPM_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); 
  53. define( 'EPM_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); 
  54.  
  55. //Filters 
  56. register_activation_hook(__FILE__, array( $this, 'plugin_activation_check'));  
  57.  
  58. add_filter( "plugin_action_links_".EPM_SLUG , array( $this, 'epm_add_settings_link') ); 
  59. add_filter( 'plugin_row_meta', array( $this, 'epm_plugin_row_meta'), 10, 2 ); 
  60.  
  61. //Actions 
  62. add_action('plugins_loaded', array($this, 'epm_load_plugin_textdomain')); 
  63. add_action('admin_menu', array($this, 'epm_add_options_link'), 10); 
  64. add_action('epm_settings_sidebar', array($this, 'epm_add_settings_box'), 10); 
  65. add_action('epm_settings_sidebar', array($this, 'epm_add_settings_box_advert'), 10); 
  66. add_action('epm_next_to_settings_title', array($this, 'epm_add_links_to_title')); 
  67.  
  68. // Load required files 
  69. $this->epm_includes(); 
  70.  
  71.  
  72. /** 
  73. * Add Settings Link To WP-Plugin Page 
  74. * @since 1.0.0 
  75. */ 
  76. public function epm_add_settings_link( $links ) { 
  77. $settings_link = '<a href="options-general.php?page=epm-settings">'.__('Settings', 'easy-peasy-mailchimp').'</a>'; 
  78. array_push( $links, $settings_link ); 
  79. return $links; 
  80.  
  81. /** 
  82. * Plugin row meta links 
  83. * @since 1.8 
  84. */ 
  85. function epm_plugin_row_meta( $input, $file ) { 
  86. if ( $file != 'easy-peasy-mailchimp/easy-peasy-mailchimp.php' ) 
  87. return $input; 
  88.  
  89. $links = array( 
  90. '<a href="http://themeforest.net/user/ThemesDepot/portfolio" target="_blank">' . esc_html__( 'Get Premium WordPress Themes', 'easy-peasy-mailchimp' ) . '</a>',  
  91. '<a href="http://profiles.wordpress.org/alessandrotesoro/" target="_blank">' . esc_html__( 'Get More Free Plugins', 'easy-peasy-mailchimp' ) . '</a>',  
  92. ); 
  93.  
  94. $input = array_merge( $input, $links ); 
  95.  
  96. return $input; 
  97.  
  98. /** 
  99. * Localization 
  100. * @since 1.0.0 
  101. */ 
  102. public function epm_load_plugin_textdomain() { 
  103. load_plugin_textdomain( 'easy-peasy-mailchimp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  104.  
  105. /** 
  106. * Include required files 
  107. * @since 1.0.0 
  108. */ 
  109. private function epm_includes() { 
  110.  
  111. // Plugin options handler 
  112. global $epm_options; 
  113. require_once EPM_PLUGIN_DIR . '/includes/admin/settings/register-settings.php'; 
  114. $epm_options = epm_get_settings(); 
  115.  
  116. if(is_admin()) { 
  117. require_once EPM_PLUGIN_DIR . '/includes/admin/settings/display-settings.php'; 
  118.  
  119. // Load MailChimp API Class 
  120. require_once EPM_PLUGIN_DIR . '/includes/MailChimp.php'; 
  121.  
  122. // Easy Peasy MailChimp Template Manager 
  123. require_once EPM_PLUGIN_DIR . '/includes/template.php'; 
  124.  
  125. // Easy Peasy MailChimp Shortcode 
  126. require_once EPM_PLUGIN_DIR . '/includes/shortcode.php'; 
  127.  
  128. // Easy Peasy Ajax Handler 
  129. require_once EPM_PLUGIN_DIR . '/includes/ajax.php';  
  130.  
  131.  
  132. /** 
  133. * Add Plugin Menu Page 
  134. * @since 1.0.0 
  135. */ 
  136. public function epm_add_options_link() { 
  137. global $epm_settings_page; 
  138. $epm_settings_page = add_submenu_page( 'options-general.php', __( 'Easy Peasy MailChimp Settings', 'easy-peasy-mailchimp' ), __( 'MailChimp Settings', 'easy-peasy-mailchimp' ), 'manage_options', 'epm-settings', 'epm_options_page' ); 
  139.  
  140. /** 
  141. * Add box into the sidebar of the settings page. 
  142. * @since 1.0.0 
  143. */ 
  144. public function epm_add_settings_box() { 
  145.  
  146. echo '<div class="postbox"> 
  147. <h3 class="hndle">'.__('MailChimp Form Usage', 'easy-peasy-mailchimp').'</h3> 
  148. <div class="inside"> 
  149. '.__('To display a mailchimp signup form use the shortcode below here.', 'easy-peasy-mailchimp').' 
  150. <br/><br/> 
  151. <code>[epm_mailchimp]</code> 
  152. </div> 
  153.  
  154. <div id="major-publishing-actions"> 
  155. <a href="http://kb.mailchimp.com/article/where-can-i-find-my-api-key" target="_blank" class="button">'.__('Get Your API Key', 'easy-peasy-mailchimp').'</a> 
  156. <a href="http://kb.mailchimp.com/article/how-can-i-find-my-list-id" target="_blank" class="button">'.__('Get Your List ID', 'easy-peasy-mailchimp').'</a>  
  157. </div> 
  158. </div>'; 
  159.  
  160. /** 
  161. * Add box into the sidebar of the settings page. 
  162. * @since 1.0.0 
  163. */ 
  164. public function epm_add_settings_box_advert() { 
  165.  
  166. echo '<div class="postbox"> 
  167. <h3 class="hndle">'.__('Premium WordPress Themes', 'easy-peasy-mailchimp').'</h3> 
  168. <div class="inside"> 
  169. '.__('Are you looking for Premium WordPress Themes? <a href="http://themesdepot.org" target="_blank">ThemesDepot</a> provides premium and affordable WordPress themes for any kind of website.', 'easy-peasy-mailchimp').' 
  170. </div> 
  171.  
  172. <div id="major-publishing-actions"> 
  173. <a href="http://themeforest.net/user/ThemesDepot/portfolio?ref=ThemesDepot" target="_blank" class="button-primary">'.__('Browse Premium Themes', 'easy-peasy-mailchimp').'</a> 
  174. </div> 
  175. </div>'; 
  176.  
  177. /** 
  178. * Add links next to title in settings page 
  179. * @since 1.0.0 
  180. */ 
  181. public function epm_add_links_to_title() { 
  182.  
  183. echo '<a href="http://profiles.wordpress.org/alessandrotesoro/" class="add-new-h2" target="_blank">'.__('Get More Free Plugins', 'easy-peasy-mailchimp').'</a>'; 
  184. echo '<a href="http://themeforest.net/user/ThemesDepot/portfolio?ref=ThemesDepot" class="add-new-h2" target="_blank">'.__('Browse Premium WordPress Themes', 'easy-peasy-mailchimp').'</a>'; 
  185.  
  186. /** 
  187. * Prevents Plugin Activation if host is crap. 
  188. * Yes, my darling friends, php 5.2 was deprecated in 2011  
  189. * Run away from your host if you're still using php 5.2 
  190. * @since 1.0.4 
  191. */ 
  192. function plugin_activation_check() {  
  193. if (version_compare(PHP_VERSION, '5.3', '<')) {  
  194. deactivate_plugins(basename(__FILE__)); // Deactivate ourself  
  195. wp_die("Sorry, but you can't run this plugin, it requires PHP 5.3 or higher. Contact your host and request a php update.");  
  196. }  
  197.  
  198.  
  199. $GLOBALS['easy_peasy_mailchimp'] = new Easy_Peasy_MailChimp(); 
.