Wpcf7_Signature

The core plugin class.

Defined (1)

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

/includes/class-wpcf7-signature.php  
  1. class Wpcf7_Signature { 
  2.  
  3. /** 
  4. * The loader that's responsible for maintaining and registering all hooks that power 
  5. * the plugin. 
  6. * @since 4.0.0 
  7. * @access protected 
  8. * @var Wpcf7_Signature_Loader $loader Maintains and registers all hooks for the plugin. 
  9. */ 
  10. protected $loader; 
  11.  
  12. /** 
  13. * The unique identifier of this plugin. 
  14. * @since 4.0.0 
  15. * @access protected 
  16. * @var string $plugin_name The string used to uniquely identify this plugin. 
  17. */ 
  18. protected $plugin_name; 
  19.  
  20. /** 
  21. * The current version of the plugin. 
  22. * @since 4.0.0 
  23. * @access protected 
  24. * @var string $version The current version of the plugin. 
  25. */ 
  26. protected $version; 
  27.  
  28. /** 
  29. * Define the core functionality of the plugin. 
  30. * Set the plugin name and the plugin version that can be used throughout the plugin. 
  31. * Load the dependencies, define the locale, and set the hooks for the admin area and 
  32. * the public-facing side of the site. 
  33. * @since 4.0.0 
  34. */ 
  35. public function __construct() { 
  36.  
  37. $this->plugin_name = WPCF7_SIGNATURE_PLUGIN_NAME; 
  38. $this->version = WPCF7_SIGNATURE_VERSION; 
  39.  
  40. $this->load_dependencies(); 
  41. $this->set_locale(); 
  42. $this->define_base_hooks(); 
  43. $this->define_admin_hooks(); 
  44. $this->define_public_hooks(); 
  45. $this->define_mail_hooks(); 
  46.  
  47.  
  48. /** 
  49. * Load the required dependencies for this plugin. 
  50. * Create an instance of the loader which will be used to register the hooks 
  51. * with WordPress. 
  52. * @since 4.0.0 
  53. * @access private 
  54. */ 
  55. private function load_dependencies() { 
  56.  
  57. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcf7-signature-loader.php'; 
  58.  
  59. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcf7-signature-i18n.php'; 
  60.  
  61. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpcf7-signature-mail.php'; 
  62.  
  63. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpcf7-signature-admin.php'; 
  64.  
  65. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpcf7-signature-public.php'; 
  66.  
  67. // Dependency management 
  68. require_once dirname( __FILE__ ) . '/class-tgm-plugin-activation.php'; 
  69.  
  70. $this->loader = new Wpcf7_Signature_Loader(); 
  71.  
  72.  
  73. /** 
  74. * Define the locale for this plugin for internationalization. 
  75. * Uses the Wpcf7_Signature_i18n class in order to set the domain and to register the hook 
  76. * with WordPress. 
  77. * @since 4.0.0 
  78. * @access private 
  79. */ 
  80. private function set_locale() { 
  81.  
  82. $plugin_i18n = new Wpcf7_Signature_i18n(); 
  83.  
  84. $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); 
  85.  
  86.  
  87. /** 
  88. * Register all of the hooks related to the plugin settings 
  89. * of the plugin. 
  90. * @since 4.0.0 
  91. * @access private 
  92. */ 
  93. private function define_base_hooks() { 
  94.  
  95. // Dependencies 
  96. $this->loader->add_action( 'tgmpa_register', $this, 'check_dependencies' ); 
  97.  
  98. // Plugin upgrade process 
  99. $this->loader->add_action( 'admin_init', $this, 'wpcf7_signature_upgrade', 10 ); 
  100.  
  101.  
  102. /** 
  103. * Register all of the hooks related to the admin area functionality 
  104. * of the plugin. 
  105. * @since 4.0.0 
  106. * @access private 
  107. */ 
  108. private function define_admin_hooks() { 
  109.  
  110. $plugin_admin = new Wpcf7_Signature_Admin( $this->get_plugin_name(), $this->get_version() ); 
  111.  
  112. // WPCF7 
  113. $this->loader->add_filter( 'wpcf7_contact_form_properties', $plugin_admin, 'contact_form_properties', 10, 2 ); 
  114. $this->loader->add_action( 'wpcf7_admin_init', $plugin_admin, 'add_tag_generator', 60 ); 
  115.  
  116. // Replace old JS callbacks 
  117. $this->loader->add_action( 'wpcf7_signature_upgrade', $plugin_admin, 'remove_v3_js_callback', 10, 2); 
  118.  
  119.  
  120. /** 
  121. * Register all of the hooks related to the public-facing functionality 
  122. * of the plugin. 
  123. * @since 4.0.0 
  124. * @access private 
  125. */ 
  126. private function define_public_hooks() { 
  127.  
  128. $plugin_public = new Wpcf7_Signature_Public( $this->get_plugin_name(), $this->get_version() ); 
  129.  
  130. // Scripts and styles 
  131. $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); 
  132. $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); 
  133.  
  134. // WPCF7 
  135. $this->loader->add_action( 'wpcf7_init', $plugin_public, 'add_signature_shortcode_handler' ); 
  136. $this->loader->add_filter( 'wpcf7_validate_signature', $plugin_public, 'signature_validation', 10, 2 ); 
  137. $this->loader->add_filter( 'wpcf7_validate_signature*', $plugin_public, 'signature_validation', 10, 2 ); 
  138.  
  139.  
  140. /** 
  141. * Register all of the hooks related to the mails sent by CF7 
  142. * @since 4.0.0 
  143. * @access private 
  144. */ 
  145. private function define_mail_hooks() { 
  146.  
  147. $plugin_mail = new Wpcf7_Signature_Mail( $this->get_plugin_name(), $this->get_version() ); 
  148.  
  149. $this->loader->add_filter( 'wpcf7_mail_components', $plugin_mail, 'modify_components' ); 
  150. $this->loader->add_filter( 'wpcf7_posted_data', $plugin_mail, 'manage_signature_data' ); 
  151.  
  152.  
  153. /** 
  154. * Run the loader to execute all of the hooks with WordPress. 
  155. * @since 4.0.0 
  156. */ 
  157. public function run() { 
  158. $this->loader->run(); 
  159.  
  160. /** 
  161. * The name of the plugin used to uniquely identify it within the context of 
  162. * WordPress and to define internationalization functionality. 
  163. * @since 4.0.0 
  164. * @return string The name of the plugin. 
  165. */ 
  166. public function get_plugin_name() { 
  167. return $this->plugin_name; 
  168.  
  169. /** 
  170. * The reference to the class that orchestrates the hooks with the plugin. 
  171. * @since 4.0.0 
  172. * @return Wpcf7_Signature_Loader Orchestrates the hooks of the plugin. 
  173. */ 
  174. public function get_loader() { 
  175. return $this->loader; 
  176.  
  177. /** 
  178. * Retrieve the version number of the plugin. 
  179. * @since 4.0.0 
  180. * @return string The version number of the plugin. 
  181. */ 
  182. public function get_version() { 
  183. return $this->version; 
  184.  
  185. /** 
  186. * Get option, stored as a meta 
  187. * @since 4.0.0 
  188. * @param string $name Option name 
  189. * @param string $default Default value 
  190. * @return string The option value 
  191. */ 
  192. public static function get_option( $name, $default = false ) { 
  193. $option = get_option( WPCF7_SIGNATURE_PLUGIN_NAME ); 
  194.  
  195. if ( false === $option ) { 
  196. return $default; 
  197.  
  198. if ( isset( $option[$name] ) ) { 
  199. return $option[$name]; 
  200. } else { 
  201. return $default; 
  202.  
  203. /** 
  204. * Store option as a meta 
  205. * @since 4.0.0 
  206. * @param string $name Option name 
  207. * @param string $value Option value 
  208. */ 
  209. public static function update_option( $name, $value ) { 
  210. $option = get_option( WPCF7_SIGNATURE_PLUGIN_NAME ); 
  211. $option = ( false === $option ) ? array() : (array) $option; 
  212. $option = array_merge( $option, array( $name => $value ) ); 
  213. update_option( WPCF7_SIGNATURE_PLUGIN_NAME, $option ); 
  214.  
  215. /** 
  216. * Check for plugin updates 
  217. * @since 4.0.0 
  218. */ 
  219. public function wpcf7_signature_upgrade() { 
  220. $old_ver = Wpcf7_Signature::get_option( 'version', '0' ); 
  221. $new_ver = WPCF7_SIGNATURE_VERSION; 
  222.  
  223. if ( $old_ver == $new_ver ) { 
  224. return; 
  225.  
  226. do_action( 'wpcf7_signature_upgrade', $new_ver, $old_ver ); 
  227.  
  228. Wpcf7_Signature::update_option( 'version', $new_ver ); 
  229.  
  230. /** 
  231. * Check if CF7 is installed 
  232. * @since 4.0.0 
  233. */ 
  234. public function check_dependencies() { 
  235.  
  236. $plugins = array( 
  237.  
  238. array( 
  239. 'name' => 'Contact Form 7',  
  240. 'slug' => 'contact-form-7',  
  241. 'required' => true,  
  242. 'version' => '4.6' 
  243. ),  
  244.  
  245. ); 
  246.  
  247. $config = array( 
  248. 'id' => 'contact-form-7-signature-addon',  
  249. 'default_path' => '',  
  250. 'menu' => 'tgmpa-install-plugins',  
  251. 'parent_slug' => 'plugins.php',  
  252. 'capability' => 'manage_options',  
  253. 'has_notices' => true,  
  254. 'dismissable' => true,  
  255. 'dismiss_msg' => '',  
  256. 'is_automatic' => false,  
  257. 'message' => '' 
  258. ); 
  259.  
  260. tgmpa( $plugins, $config ); 
  261.  
  262.