Wpcf7_Signature_Admin

The admin-specific functionality of the plugin.

Defined (1)

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

/admin/class-wpcf7-signature-admin.php  
  1. class Wpcf7_Signature_Admin { 
  2.  
  3. const WPCF7_SIGNATURE_JS_CALLBACK = "$('div.wpcf7 > form').wpcf7ClearSignatures();"; 
  4.  
  5. /** 
  6. * The ID of this plugin. 
  7. * @since 4.0.0 
  8. * @access private 
  9. * @var string $plugin_name The ID of this plugin. 
  10. */ 
  11. private $plugin_name; 
  12.  
  13. /** 
  14. * The version of this plugin. 
  15. * @since 4.0.0 
  16. * @access private 
  17. * @var string $version The current version of this plugin. 
  18. */ 
  19. private $version; 
  20.  
  21. /** 
  22. * Initialize the class and set its properties. 
  23. * @since 4.0.0 
  24. * @param string $plugin_name The name of this plugin. 
  25. * @param string $version The version of this plugin. 
  26. */ 
  27. public function __construct( $plugin_name, $version ) { 
  28.  
  29. $this->plugin_name = $plugin_name; 
  30. $this->version = $version; 
  31.  
  32.  
  33. /** 
  34. * Modify contact form properties for signatures 
  35. * @since 4.0.0 
  36. */ 
  37. public function contact_form_properties( $properties, $instance )  
  38. if (! is_array($properties)) { 
  39. return $properties; 
  40.  
  41. if (!class_exists('WPCF7_FormTagsManager')) { 
  42. return $properties; 
  43.  
  44. // We need to know if the current form has a signature field 
  45. $manager = WPCF7_FormTagsManager::get_instance(); 
  46. $scanned = $manager->scan( $properties['form'] ); 
  47.  
  48. if ( empty( $scanned ) ) 
  49. return $properties; 
  50.  
  51. for ( $i = 0, $size = count( $scanned ); $i < $size; $i++ ) { 
  52. if ( !empty( $scanned[$i]) && $scanned[$i]['basetype'] == "signature") { 
  53. // We got one ! 
  54. //Let's add the callback if needed 
  55. $WPCF7Callback = 'on_sent_ok: "'.$this::WPCF7_SIGNATURE_JS_CALLBACK.'"'; 
  56. $settings = $properties['additional_settings']; 
  57.  
  58. // No callback found, let's do this ! 
  59. if(!strstr($settings, addslashes($WPCF7Callback)) && !strstr($settings, $WPCF7Callback)) { 
  60.  
  61. if (strlen($settings) > 0) 
  62. $settings .= "\n"; 
  63.  
  64. $settings .= $WPCF7Callback."\n"; 
  65.  
  66. $properties['additional_settings'] = $settings; 
  67.  
  68. return $properties; 
  69.  
  70. /** 
  71. * Add a tag generator for the signature field type 
  72. * @since 4.0.0 
  73. */ 
  74. public function add_tag_generator() { 
  75.  
  76. if (class_exists('WPCF7_TagGenerator')) { 
  77. $tag_generator = WPCF7_TagGenerator::get_instance(); 
  78. $tag_generator->add( 'signature', __( 'signature', 'contact-form-7-signature-addon' ), array($this, 'tag_generator_signature') ); 
  79.  
  80.  
  81. /** 
  82. * Tag generator form 
  83. * @since 4.0.0 
  84. */ 
  85. public function tag_generator_signature( $contact_form, $args = '' ) { 
  86.  
  87. $args = wp_parse_args( $args, array() ); 
  88. $type = 'signature'; 
  89.  
  90. $description = __( "Generate a form-tag for a signature field.", 'contact-form-7' ); 
  91. ?> 
  92. <div class="control-box"> 
  93. <fieldset> 
  94. <legend><?php echo sprintf( esc_html( $description ) ); ?></legend> 
  95. <table class="form-table"> 
  96. <tbody> 
  97. <tr> 
  98. <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th> 
  99. <td> 
  100. <fieldset> 
  101. <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend> 
  102. <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label> 
  103. </fieldset> 
  104. </td> 
  105. </tr> 
  106.  
  107. <tr> 
  108. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th> 
  109. <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td> 
  110. </tr> 
  111.  
  112. <tr> 
  113. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th> 
  114. <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td> 
  115. </tr> 
  116.  
  117. <tr> 
  118. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th> 
  119. <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td> 
  120. </tr> 
  121.  
  122. <tr> 
  123. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-width' ); ?>"><?php echo esc_html( __( 'Width attribute', 'contact-form-7' ) ); ?></label></th> 
  124. <td><input type="number" name="cols" class="widthvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-width' ); ?>" /></td> 
  125. </tr> 
  126.  
  127. <tr> 
  128. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-height' ); ?>"><?php echo esc_html( __( 'Height attribute', 'contact-form-7' ) ); ?></label></th> 
  129. <td><input type="number" name="rows" class="heightvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-height' ); ?>" /></td> 
  130. </tr> 
  131.  
  132. <tr> 
  133. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-color' ); ?>"><?php echo esc_html( __( 'Color attribute', 'contact-form-7-signature-addon' ) ); ?></label></th> 
  134. <td><input type="text" name="color" class="heightvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-color' ); ?>" /></td> 
  135. </tr> 
  136.  
  137. <tr> 
  138. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-background' ); ?>"><?php echo esc_html( __( 'Background attribute', 'contact-form-7-signature-addon' ) ); ?></label></th> 
  139. <td><input type="text" name="background" class="heightvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-background' ); ?>" /></td> 
  140. </tr> 
  141.  
  142. </tbody> 
  143. </table> 
  144. </fieldset> 
  145. </div> 
  146.  
  147. <div class="insert-box"> 
  148. <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" /> 
  149.  
  150. <div class="submitbox"> 
  151. <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" /> 
  152. </div> 
  153.  
  154. <br class="clear" /> 
  155.  
  156. <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag into an image tag (<img src=\"%s\"/>)in the field on the Mail tab.", 'contact-form-7-signature-addon' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p> 
  157. </div> 
  158. <?php 
  159.  
  160. /** 
  161. * Remove old JS callback from properties when upgrading  
  162. * to 4.0 for the first time 
  163. * @since 4.0.0 
  164. */ 
  165. public function remove_v3_js_callback($new_ver, $old_ver) { 
  166.  
  167. if ( version_compare( $old_ver, '4.0-dev', '>=' ) ) { 
  168. return; 
  169.  
  170. // Looping through all forms 
  171. $posts = WPCF7_ContactForm::find( array( 
  172. 'post_status' => 'any',  
  173. 'posts_per_page' => -1,  
  174. ) ); 
  175.  
  176. $oldJSCallback = "sigFieldsClear();"; 
  177.  
  178. foreach ( $posts as $post ) { 
  179.  
  180. $props = $post->get_properties(); 
  181. $newProps = array(); 
  182. $needSave = false; 
  183.  
  184. foreach ( $props as $prop => $value ) { 
  185.  
  186. if ($prop == 'additional_settings') { 
  187. if(strstr($value, $oldJSCallback)) { 
  188. $oldJSCallback = 'on_sent_ok: "'.$oldJSCallback.'"'; 
  189. $value = str_replace($oldJSCallback, "", $value); 
  190. $needSave = true; 
  191.  
  192. $newProps[$prop] = $value; 
  193.  
  194. if ($needSave) { 
  195. $post->set_properties($newProps); 
  196. $post->save(); 
  197.