Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Yikes_Inc_Easy_Mailchimp_Forms_Admin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Yikes_Inc_Easy_Mailchimp_Forms_Admin, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Yikes_Inc_Easy_Mailchimp_Forms_Admin {
|
||
| 13 | |||
| 14 | /** |
||
| 15 | * The ID of this plugin. |
||
| 16 | * |
||
| 17 | * @since 1.0.0 |
||
| 18 | * @access private |
||
| 19 | * @var string $yikes_inc_easy_mailchimp_extender The ID of this plugin. |
||
| 20 | */ |
||
| 21 | private $yikes_inc_easy_mailchimp_extender; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The version of this plugin. |
||
| 25 | * |
||
| 26 | * @since 1.0.0 |
||
| 27 | * @access private |
||
| 28 | * @var string $version The current version of this plugin. |
||
| 29 | */ |
||
| 30 | private $version; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Our form interface instance. |
||
| 34 | * |
||
| 35 | * @var Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface |
||
| 36 | */ |
||
| 37 | private $form_interface; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Initialize the class and set its properties. |
||
| 41 | * |
||
| 42 | * @since 1.0.0 |
||
| 43 | * |
||
| 44 | * @param string $yikes_inc_easy_mailchimp_extender The name of this plugin. |
||
| 45 | * @param string $version The version of this plugin. |
||
| 46 | * @param Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface $form_interface |
||
| 47 | */ |
||
| 48 | public function __construct( |
||
| 49 | $yikes_inc_easy_mailchimp_extender, |
||
| 50 | $version, |
||
| 51 | Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface $form_interface |
||
| 52 | ) {
|
||
| 53 | $this->yikes_inc_easy_mailchimp_extender = $yikes_inc_easy_mailchimp_extender; |
||
| 54 | $this->version = $version; |
||
| 55 | $this->form_interface = $form_interface; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Our admin hooks. |
||
| 60 | * |
||
| 61 | * @author Jeremy Pry |
||
| 62 | */ |
||
| 63 | public function hooks() {
|
||
| 252 | |||
| 253 | /** |
||
| 254 | * Add custom action links on plugins.php |
||
| 255 | * @ param array $links Pre-existing plugin action links |
||
| 256 | * @ return array $links New array of plugin actions |
||
| 257 | */ |
||
| 258 | public function easy_forms_plugin_action_links( $links ) {
|
||
| 259 | $links[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=yikes-inc-easy-mailchimp-settings') ) .'">' . __( 'Settings', 'yikes-inc-easy-mailchimp-extender' ) . '</a>'; |
||
| 260 | $links[] = '<a href="' . esc_url( 'http://www.yikesplugins.com?utm_source=plugins-page&utm_medium=plugin-row&utm_campaign=admin' ) . '" target="_blank">' . __( 'More plugins by YIKES, Inc.', 'yikes-inc-easy-mailchimp-extender' ) . '</a>'; |
||
| 261 | return $links; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Add a disclaimer to the admin footer for all YIKES pages to ensure that users understand there is no correlation between this plugin and Mailchimp. |
||
| 266 | * This plugin simply provides the service of linking Mailchimp with your site. |
||
| 267 | * |
||
| 268 | * @since 6.0 |
||
| 269 | * |
||
| 270 | * @param string $footer_text The existing footer text. |
||
| 271 | * |
||
| 272 | * @return string |
||
| 273 | */ |
||
| 274 | public function yikes_easy_forms_admin_disclaimer( $footer_text ) {
|
||
| 275 | $page = get_current_screen(); |
||
| 276 | $base = $page->base; |
||
| 277 | if ( strpos( $base, 'yikes-inc-easy-mailchimp' ) !== false || strpos( $base, 'yikes-mailchimp' ) !== false ) {
|
||
| 278 | $disclaimer_text = sprintf( '<em>' . __( 'Disclaimer: <strong>Easy Forms for Mailchimp</strong> is in no way endorsed, affiliated or backed by Mailchimp, or its parent company Rocket Science Group.', 'yikes-inc-easy-mailchimp-extender' ), '<a href="https://wordpress.org/support/view/plugin-reviews/give?filter=5#postform" target="_blank" class="give-rating-link" data-rated="' . __( 'Thanks :)', 'yikes-inc-easy-mailchimp-extender' ) . '">', '</a></em>' ); |
||
| 279 | return $disclaimer_text; |
||
| 280 | } else {
|
||
| 281 | return $footer_text; |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | /* |
||
| 286 | * Parse our default tag into dynamic data |
||
| 287 | * to be passed to Mailchimp |
||
| 288 | * |
||
| 289 | * @since 6.0.0 |
||
| 290 | * @return parsed tag content |
||
| 291 | */ |
||
| 292 | public function parse_mailchimp_default_tag( $default_tag ) {
|
||
| 293 | if ( ! $default_tag || $default_tag == '' ) {
|
||
| 294 | return $default_tag; |
||
| 295 | } |
||
| 296 | global $post; |
||
| 297 | // page title. |
||
| 298 | if ( $default_tag == '{page_title}' ) {
|
||
| 299 | $default_tag = get_the_title( $post->ID ); |
||
| 300 | } |
||
| 301 | // page id. |
||
| 302 | if ( $default_tag == '{page_id}' ) {
|
||
| 303 | $default_tag = $post->ID; |
||
| 304 | } |
||
| 305 | // page url. |
||
| 306 | if ( $default_tag == '{page_url}' ) {
|
||
| 307 | $default_tag = get_permalink( $post->ID ); |
||
| 308 | } |
||
| 309 | // blog name. |
||
| 310 | if ( $default_tag == '{blog_name}' ) {
|
||
| 311 | $default_tag = get_bloginfo( 'name' ); |
||
| 312 | } |
||
| 313 | // is user logged in. |
||
| 314 | if ( $default_tag == '{user_logged_in}' ) {
|
||
| 315 | if ( is_user_logged_in() ) {
|
||
| 316 | $default_tag = 'Registered User'; |
||
| 317 | } else {
|
||
| 318 | $default_tag = 'Guest User'; |
||
| 319 | } |
||
| 320 | } |
||
| 321 | /* Return our filtered tag */ |
||
| 322 | return apply_filters( 'yikes-mailchimp-parse-custom-default-value', $default_tag ); |
||
| 323 | } |
||
| 324 | |||
| 325 | /* |
||
| 326 | * Delete the contents of our error log |
||
| 327 | * |
||
| 328 | * When a user clicks 'Clear Log' on the debug settings page, this funciton |
||
| 329 | * is used to clear the data out of our php file. |
||
| 330 | */ |
||
| 331 | public function yikes_easy_mailchimp_clear_error_log() {
|
||
| 332 | |||
| 333 | // Get our error log class. |
||
| 334 | $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
||
| 335 | |||
| 336 | // file put contents $returned error + other data. |
||
| 337 | if ( file_exists( $error_logging->error_log_file_path ) ) {
|
||
| 338 | |||
| 339 | $clear_log = file_put_contents( $error_logging->error_log_file_path, '' ); |
||
| 340 | |||
| 341 | if ( $clear_log === false ) {
|
||
| 342 | |||
| 343 | // redirect the user to the manage forms page, display error message. |
||
| 344 | wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings§ion=debug-settings&error-log-cleared=false' ) ) ); |
||
| 345 | } else {
|
||
| 346 | |||
| 347 | // redirect the user to the manage forms page, display confirmation. |
||
| 348 | wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings§ion=debug-settings&error-log-cleared=true' ) ) ); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
||
| 352 | |||
| 353 | /* |
||
| 354 | * Custom export function to export all or specific forms |
||
| 355 | * to allow for easy transpot to other sites |
||
| 356 | * @since 6.0.0 |
||
| 357 | * @return CSV export file |
||
| 358 | */ |
||
| 359 | public function yikes_easy_mailchimp_export_forms() {
|
||
| 360 | // grab our nonce. |
||
| 361 | $nonce = $_REQUEST['nonce']; |
||
| 362 | // grab the forms. |
||
| 363 | $forms = isset( $_REQUEST['yikes_export_forms'] ) ? $_REQUEST['yikes_export_forms'] : array(); |
||
| 364 | // validate nonce. |
||
| 365 | View Code Duplication | if ( ! wp_verify_nonce( $nonce, 'export-forms' ) ) {
|
|
|
|
|||
| 366 | wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) ); |
||
| 367 | } |
||
| 368 | |||
| 369 | // run the export function. |
||
| 370 | // parameters: ( $table_name, $form_ids, $file_name ). |
||
| 371 | Yikes_Inc_Easy_Mailchimp_Export_Class::yikes_mailchimp_form_export('Yikes-Inc-Easy-Mailchimp-Forms-Export', $forms );
|
||
| 372 | // re-direct the user back to the page. |
||
| 373 | wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings§ion=import-export-forms' ) ) ); |
||
| 374 | die(); |
||
| 375 | } |
||
| 376 | |||
| 377 | /* |
||
| 378 | * Custom export function to export YIKES Easy Forms for Mailchimp Plugin Settings |
||
| 379 | * to allow for easy transpot to other sites |
||
| 380 | * @since 6.0.0 |
||
| 381 | * @return CSV export file |
||
| 382 | */ |
||
| 383 | public function yikes_easy_mailchimp_export_plugin_settings() {
|
||
| 384 | // grab our nonce |
||
| 385 | $nonce = $_REQUEST['nonce']; |
||
| 386 | // validate nonce. |
||
| 387 | View Code Duplication | if ( ! wp_verify_nonce( $nonce, 'export-settings' ) ) {
|
|
| 388 | wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) ); |
||
| 389 | } |
||
| 390 | |||
| 391 | // run the export function. |
||
| 392 | // parameters: ( $table_name, $form_ids, $file_name ). |
||
| 393 | Yikes_Inc_Easy_Mailchimp_Export_Class::yikes_mailchimp_settings_export( 'Yikes-Inc-Easy-Mailchimp-Settings-Export' ); |
||
| 394 | // re-direct the user back to the page. |
||
| 395 | wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings§ion=import-export-forms' ) ) ); |
||
| 396 | die(); |
||
| 397 | } |
||
| 398 | |||
| 399 | /* |
||
| 400 | * Custom import function to import all or specific forms |
||
| 401 | * @since 6.0.0 |
||
| 402 | */ |
||
| 403 | public function yikes_easy_mailchimp_import_forms() {
|
||
| 404 | // grab our nonce. |
||
| 405 | $nonce = $_REQUEST['nonce']; |
||
| 406 | // validate nonce. |
||
| 407 | View Code Duplication | if ( ! wp_verify_nonce( $nonce, 'import-forms' ) ) {
|
|
| 408 | wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) ); |
||
| 409 | } |
||
| 410 | // include the export class. |
||
| 411 | if ( ! class_exists( 'Yikes_Inc_Easy_Mailchimp_Import_Class' ) ) {
|
||
| 412 | include_once( YIKES_MC_PATH . 'includes/import-export/yikes-easy-mailchimp-import.class.php' ); |
||
| 413 | } |
||
| 414 | // run the import function. |
||
| 415 | // parameters: ( $_FILES ). |
||
| 416 | Yikes_Inc_Easy_Mailchimp_Import_Class::yikes_mailchimp_import_forms( $_FILES ); |
||
| 417 | $import_query_arg = Yikes_Inc_Easy_Mailchimp_Import_Class::yikes_mailchimp_import_type( $_FILES ); |
||
| 418 | // re-direct the user back to the page. |
||
| 419 | wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings§ion=import-export-forms&' . $import_query_arg . '=true' ) ) ); |
||
| 420 | die(); |
||
| 421 | } |
||
| 422 | |||
| 423 | /* |
||
| 424 | * Premium Support Request |
||
| 425 | * @since 6.0.0 |
||
| 426 | */ |
||
| 427 | public function yikes_easy_mailchimp_premium_support_request() {
|
||
| 428 | |||
| 429 | if ( isset( $_POST['action'] ) && $_POST['action'] != 'yikes-support-request' ) {
|
||
| 430 | return __( 'We encountered an error. Please contact the YIKES Inc. support team.', 'yikes-inc-easy-mailchimp-extender' ); |
||
| 431 | } |
||
| 432 | |||
| 433 | $email = isset( $_POST['user-email'] ) ? $_POST['user-email'] : ''; |
||
| 434 | $topic = isset( $_POST['support-topic'] ) ? $_POST['support-topic'] : ''; |
||
| 435 | $issue = isset( $_POST['support-content'] ) ? $_POST['support-content'] : ''; |
||
| 436 | $priority = isset( $_POST['support-priority'] ) ? $_POST['support-priority'] : 1; |
||
| 437 | $license = isset( $_POST['license_key'] ) ? $_POST['license_key'] : ''; |
||
| 438 | $plugin_name = isset( $_POST['plugin-name'] ) ? $_POST['plugin-name'] : ''; |
||
| 439 | $plugin_slug = isset( $_POST['plugin-slug'] ) ? $_POST['plugin-slug'] : ''; |
||
| 440 | $name = isset( $_POST['user-name'] ) ? $_POST['user-name'] : 'Mailchimp Support'; |
||
| 441 | |||
| 442 | $edd_item_id = $this->get_premium_license( $plugin_slug ); |
||
| 443 | |||
| 444 | $ticket_array = array( |
||
| 445 | 'action' => 'yikes-support-request', |
||
| 446 | 'license_key' => base64_encode( $license ), |
||
| 447 | 'plugin_name' => $plugin_name, |
||
| 448 | 'edd_item_id' => $edd_item_id, |
||
| 449 | 'user_email' => $email, |
||
| 450 | 'site_url' => esc_url( home_url() ), |
||
| 451 | 'support_name' => $name, |
||
| 452 | 'support_topic' => $topic, |
||
| 453 | 'support_priority' => $priority, |
||
| 454 | 'support_content' => $issue, |
||
| 455 | 'api_version' => '2' |
||
| 456 | ); |
||
| 457 | |||
| 458 | $response = wp_remote_post( 'https://yikesplugins.com', array( |
||
| 459 | 'timeout' => 30, |
||
| 460 | 'sslverify' => false, |
||
| 461 | 'body' => $ticket_array |
||
| 462 | ) ); |
||
| 463 | |||
| 464 | // Catch the error. |
||
| 465 | if ( is_wp_error( $response ) ) {
|
||
| 466 | wp_send_json_error( $response->getMessage() ); |
||
| 467 | } |
||
| 468 | |||
| 469 | // Retrieve our body. |
||
| 470 | $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
||
| 471 | } |
||
| 472 | |||
| 473 | public function get_premium_license( $plugin_slug ) {
|
||
| 490 | |||
| 491 | /** |
||
| 492 | * Error logging class |
||
| 493 | * |
||
| 494 | * This is our main error logging class file, used to log errors to the error log. |
||
| 495 | * |
||
| 496 | * @since 6.0.0 |
||
| 497 | */ |
||
| 498 | View Code Duplication | public function load_error_logging_class() {
|
|
| 499 | if ( get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) {
|
||
| 506 | |||
| 507 | /** |
||
| 508 | * yikes_easy_mailchimp_check_installation_date() |
||
| 509 | * checks the user installation date, and adds our action |
||
| 510 | * - if it's past 2 weeks we ask the user for a review :) |
||
| 511 | * |
||
| 512 | * @since v6.0.0 |
||
| 513 | */ |
||
| 514 | public function yikes_easy_mailchimp_check_installation_date() {
|
||
| 534 | |||
| 535 | /* |
||
| 536 | Display our admin notification |
||
| 537 | asking for a review, and for user feedback |
||
| 538 | @since v6.0.0 |
||
| 539 | */ |
||
| 540 | public function yikes_easy_mailchimp_display_review_us_notice() {
|
||
| 579 | |||
| 580 | /** |
||
| 581 | yikes_easy_mailchimp_stop_bugging_me() |
||
| 582 | Remove the Review us notification when user clicks 'Dismiss' |
||
| 583 | @since v3.1.1 |
||
| 584 | */ |
||
| 585 | public function yikes_easy_mailchimp_stop_bugging_me() {
|
||
| 590 | |||
| 591 | /* End Two Week Notification */ |
||
| 592 | |||
| 593 | /* Display a warning users who are using PHP < 5.3 */ |
||
| 594 | public function display_php_warning() {
|
||
| 598 | |||
| 599 | /** |
||
| 600 | * |
||
| 601 | * TinyMCE Functions |
||
| 602 | */ |
||
| 603 | // load our button and pass in the JS form data variable. |
||
| 604 | public function add_tinyMCE_buttons() {
|
||
| 613 | |||
| 614 | // Add the button key for address via JS. |
||
| 615 | public function yks_mc_add_tinymce_button( $buttons ) {
|
||
| 620 | |||
| 621 | // inlcude the js for tinymce. |
||
| 622 | public function yks_mc_add_tinymce_plugin( $plugin_array ) {
|
||
| 628 | |||
| 629 | /** |
||
| 630 | * Localize Script |
||
| 631 | * Pass our imported list data, to the JS file |
||
| 632 | * to build the drop down list in the modal |
||
| 633 | */ |
||
| 634 | public function tinymce_yikes_easy_mc() {
|
||
| 670 | /* End TinyMCE Functions */ |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Fix the Mailchimp icon spacing in the admin menu. |
||
| 674 | */ |
||
| 675 | public function fix_menu_icon_spacing() {
|
||
| 684 | |||
| 685 | /** |
||
| 686 | * Register the stylesheets for the admin area. |
||
| 687 | * |
||
| 688 | * @since 6.0.0 |
||
| 689 | */ |
||
| 690 | public function enqueue_styles() {
|
||
| 703 | /** |
||
| 704 | * Register the JavaScript for the admin area. |
||
| 705 | * |
||
| 706 | * @since 6.0.0 |
||
| 707 | */ |
||
| 708 | public function enqueue_scripts() {
|
||
| 767 | |||
| 768 | /** |
||
| 769 | * Convert the php date format string to a js date format |
||
| 770 | */ |
||
| 771 | public function yikes_jQuery_datepicker_date_format_php_to_js( $sFormat, $type ) {
|
||
| 824 | |||
| 825 | /** |
||
| 826 | * Convert the php date format string to a js date format |
||
| 827 | */ |
||
| 828 | public function yikes_jQuery_datepicker_date_format( $site_option ) {
|
||
| 844 | |||
| 845 | /** |
||
| 846 | * Register our admin pages |
||
| 847 | * used to display data back to the user |
||
| 848 | **/ |
||
| 849 | public function register_admin_pages() {
|
||
| 956 | |||
| 957 | /* |
||
| 958 | * Redirect a user to an external page |
||
| 959 | * when they click 'Go Pro' in the admin menu |
||
| 960 | * to do: populate with sales URL |
||
| 961 | */ |
||
| 962 | public function generateAddOnsPage() {
|
||
| 965 | |||
| 966 | /** |
||
| 967 | * Generate Us Easy Mailchimp Manage Forms Page |
||
| 968 | * |
||
| 969 | * @since 1.0.0 |
||
| 970 | */ |
||
| 971 | function generateManageFormsPage() {
|
||
| 974 | |||
| 975 | /** |
||
| 976 | * Generate Us Easy Mailchimp Manage Lists Page |
||
| 977 | * |
||
| 978 | * @since 1.0.0 |
||
| 979 | */ |
||
| 980 | function generateManageListsPage() {
|
||
| 983 | |||
| 984 | /** |
||
| 985 | * Generate Us Easy Mailchimp Support Page |
||
| 986 | * |
||
| 987 | * @since 1.0.0 |
||
| 988 | */ |
||
| 989 | function generateSupportPage() {
|
||
| 994 | |||
| 995 | /** |
||
| 996 | * Generate Us Easy Mailchimp Edit Form Page |
||
| 997 | * |
||
| 998 | * @since 1.0.0 |
||
| 999 | */ |
||
| 1000 | function generateEditFormPage() {
|
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Generate Us Easy Mailchimp View List Page |
||
| 1006 | * |
||
| 1007 | * @since 1.0.0 |
||
| 1008 | */ |
||
| 1009 | function generateViewListPage() {
|
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Generate Us Easy Mailchimp View User Page |
||
| 1015 | * |
||
| 1016 | * @since 1.0.0 |
||
| 1017 | */ |
||
| 1018 | function generateViewUserPage() {
|
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Register our plugin settings, and display them on our settings page |
||
| 1024 | * |
||
| 1025 | * @since v.5.4 |
||
| 1026 | **/ |
||
| 1027 | function yikes_easy_mc_settings_init() {
|
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Options Sanitization & Validation |
||
| 1171 | * @since complete re-write |
||
| 1172 | **/ |
||
| 1173 | function yikes_mc_validate_api_key( $input ) {
|
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * Generate Us Easy Forms for Mailchimp Options Page |
||
| 1205 | * |
||
| 1206 | * @since 1.0.0 |
||
| 1207 | */ |
||
| 1208 | function generatePageOptions() {
|
||
| 1211 | |||
| 1212 | /** |
||
| 1213 | * Check if users API key is valid, if not |
||
| 1214 | * this function will apply a disabled attribute |
||
| 1215 | * to form fields. (input, dropdowns, buttons etc.) |
||
| 1216 | * @since v5.5 re-write |
||
| 1217 | **/ |
||
| 1218 | public function is_user_mc_api_valid_form( $echo = true ) {
|
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Admin Notices |
||
| 1234 | * - Notifications displayed at the top of admin pages, back to the user |
||
| 1235 | */ |
||
| 1236 | |||
| 1237 | /* |
||
| 1238 | * Search through multi dimensional array |
||
| 1239 | * and return the index ( used to find the list name assigned to a form ) |
||
| 1240 | * - http://stackoverflow.com/questions/6661530/php-multi-dimensional-array-search |
||
| 1241 | */ |
||
| 1242 | function findMCListID($id, $array) {
|
||
| 1250 | |||
| 1251 | /* |
||
| 1252 | * generate_options_pages_sidebar_menu(); |
||
| 1253 | * Render our sidebar menu on all of the setings pages (general, form, checkbox, recaptcha, popup, debug etc. ) |
||
| 1254 | * @since v5.6 - complete re-write |
||
| 1255 | */ |
||
| 1256 | public function generate_options_pages_sidebar_menu() {
|
||
| 1304 | |||
| 1305 | /* |
||
| 1306 | * generate_manage_forms_sidebar(); |
||
| 1307 | * Render our sidebar menu on all of the setings pages (general, form, checkbox, recaptcha, popup, debug etc. ) |
||
| 1308 | * @since v5.6 - complete re-write |
||
| 1309 | */ |
||
| 1310 | public function generate_manage_forms_sidebar( $lists ) {
|
||
| 1409 | |||
| 1410 | /* |
||
| 1411 | * Generate a dropdown of post and pages |
||
| 1412 | * so the user can send the user to on form submission |
||
| 1413 | */ |
||
| 1414 | public function generate_page_redirect_dropdown( $redirect, $redirect_page, $custom_redirect_url ) {
|
||
| 1480 | |||
| 1481 | /* |
||
| 1482 | * generate_show_some_love_container() |
||
| 1483 | * Generate a container, with some author info |
||
| 1484 | * |
||
| 1485 | * Displayed in sidebars |
||
| 1486 | */ |
||
| 1487 | public function generate_show_some_love_container() {
|
||
| 1565 | |||
| 1566 | /* |
||
| 1567 | * generate_form_editor( $list_id ) |
||
| 1568 | * Submit an API request to get our merge variables, and build up a small form editor |
||
| 1569 | * for users to 'customize' their form |
||
| 1570 | * - |
||
| 1571 | * @parameters - $list_id - pass in the list ID to retreive merge variables from |
||
| 1572 | */ |
||
| 1573 | public function generate_form_editor( $form_fields, $list_id, $merge_variables, $interest_groups ) {
|
||
| 1574 | |||
| 1575 | // if no list id, die! |
||
| 1576 | if ( ! $list_id ) {
|
||
| 1577 | wp_die( __( "We've encountered an error. No list ID was sent." , 'yikes-inc-easy-mailchimp-extender' ) ); |
||
| 1578 | } |
||
| 1579 | |||
| 1580 | if ( ! $merge_variables ) {
|
||
| 1581 | wp_die( __( "We've encountered an error. Reload the page and try again. If the error persists, please reach out to support." , 'yikes-inc-easy-mailchimp-extender' ) ); |
||
| 1582 | } |
||
| 1583 | |||
| 1584 | if ( ! empty( $form_fields ) ) {
|
||
| 1585 | |||
| 1586 | // find any fields that are assigned to this form, that don't exist in Mailchimp |
||
| 1587 | // or else were going to run into issues when we submit the form |
||
| 1588 | $available_merge_variables = array(); |
||
| 1589 | $available_interest_groups = array(); |
||
| 1590 | |||
| 1591 | // Default variables as arrays - these are used for holding the Mailchimp merge field ID |
||
| 1592 | $merge_field_ids = array(); |
||
| 1593 | $mailchimp_merge_field_ids = array(); |
||
| 1594 | |||
| 1595 | // loop over merge variables |
||
| 1596 | if ( ! empty( $merge_variables['merge_fields'] ) ) {
|
||
| 1597 | $available_merge_variables = wp_list_pluck( $merge_variables['merge_fields'], 'tag' ); |
||
| 1598 | $mailchimp_merge_field_ids = wp_list_pluck( $merge_variables['merge_fields'], 'merge_id' ); |
||
| 1599 | |||
| 1600 | // Array will look like $merge_tag => $merge_id |
||
| 1601 | foreach( $available_merge_variables as $index => $merge_tag ) {
|
||
| 1602 | $merge_field_ids[$merge_tag] = $mailchimp_merge_field_ids[$index]; |
||
| 1603 | } |
||
| 1604 | } |
||
| 1605 | |||
| 1606 | // loop over interest groups |
||
| 1607 | if ( ! empty( $interest_groups ) ) {
|
||
| 1608 | $available_interest_groups = array_keys( $interest_groups ); |
||
| 1609 | } |
||
| 1610 | |||
| 1611 | // build our assigned fields |
||
| 1612 | $assigned_fields = array_keys( $form_fields ); |
||
| 1613 | $merged_fields = array_merge( $available_merge_variables, $available_interest_groups ); |
||
| 1614 | $excluded_fields = array_diff( $assigned_fields, $merged_fields ); |
||
| 1615 | |||
| 1616 | $i = 1; |
||
| 1617 | foreach( $form_fields as $field ) {
|
||
| 1618 | |||
| 1619 | if ( isset( $field['merge'] ) ) {
|
||
| 1620 | // @todo: don't use in_array() |
||
| 1621 | $excluded_field = in_array( $field['merge'], $excluded_fields, true ); |
||
| 1622 | ?> |
||
| 1623 | <section class="draggable" id="<?php echo $field['merge']; ?>"> |
||
| 1624 | <!-- top --> |
||
| 1625 | <a class="expansion-section-title settings-sidebar"> |
||
| 1626 | <span class="dashicons dashicons-plus yikes-mc-expansion-toggle"></span> |
||
| 1627 | <span class="yikes-mc-expansion-section-field-label"> <?php echo stripslashes( $field['label'] ); ?> </span> |
||
| 1628 | <?php if ( $excluded_field ) { ?>
|
||
| 1629 | <img src="<?php echo YIKES_MC_URL . 'includes/images/warning.svg'; ?>" class="field-doesnt-exist-notice" title="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>" alt="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>"> |
||
| 1630 | <?php } ?> |
||
| 1631 | <input maxlength="50" type="text" class="yikes-mc-edit-field-label-input" value="<?php echo stripslashes( $field['label'] ); ?>" /> |
||
| 1632 | <span class="dashicons dashicons-yes yikes-mc-save-field-label-edits-icon" title="<?php _e( 'Click to save changes.', 'yikes-inc-easy-mailchimp-extender' ); ?>"></span> |
||
| 1633 | <span class="dashicons dashicons-edit yikes-mc-edit-field-label-icon" title="<?php _e( 'Click to edit the label', 'yikes-inc-easy-mailchimp-extender' ); ?>"></span> |
||
| 1634 | <span class="yikes-mc-edit-field-label-message"></span> |
||
| 1635 | <span class="field-type-text"><small><?php echo __( 'type', 'yikes-inc-easy-mailchimp-extender' ) . ' : ' . $field['type']; ?></small></span> |
||
| 1636 | </a> |
||
| 1637 | <!-- expansion section --> |
||
| 1638 | <div class="yikes-mc-settings-expansion-section"> |
||
| 1639 | |||
| 1640 | <?php if ( $excluded_field ) { ?>
|
||
| 1641 | <p class="yikes-mc-warning-message"><?php _e( "This field no longer exists in this list. Delete this field from the form to prevent issues on your website." , 'yikes-inc-easy-mailchimp-extender' ); ?></p> |
||
| 1642 | <?php } ?> |
||
| 1643 | |||
| 1644 | <!-- store field data --> |
||
| 1645 | <input type="hidden" class="yikes-mc-merge-field-label" name="field[<?php echo $field['merge']; ?>][label]" value="<?php echo htmlspecialchars( $field['label'] ); ?>" /> |
||
| 1646 | <input type="hidden" class="yikes-mc-merge-field-type" name="field[<?php echo $field['merge']; ?>][type]" value="<?php echo $field['type']; ?>" /> |
||
| 1647 | <input type="hidden" class="yikes-mc-merge-field-tag" name="field[<?php echo $field['merge']; ?>][merge]" value="<?php echo $field['merge']; ?>" /> |
||
| 1648 | <input type="hidden" class="field-<?php echo $field['merge']; ?>-position position-input" name="field[<?php echo $field['merge']; ?>][position]" value="<?php echo $i++; ?>" /> |
||
| 1649 | <?php if ( isset( $merge_field_ids[ $field['merge'] ] ) && is_int( $merge_field_ids[ $field['merge'] ] ) ) { ?>
|
||
| 1650 | <input type="hidden" class="yikes-mc-merge-field-id" name="field[<?php echo $field['merge']; ?>][id]" value="<?php echo $merge_field_ids[ $field['merge'] ] ?>" /> |
||
| 1651 | <?php } ?> |
||
| 1652 | |||
| 1653 | <?php if ( $field['type'] == 'radio' || $field['type'] == 'dropdown' || $field['type'] == 'select' ) {
|
||
| 1654 | $choices = json_decode( $field['choices'], true ); |
||
| 1655 | ?> |
||
| 1656 | <input type="hidden" name="field[<?php echo $field['merge']; ?>][choices]" value='<?php echo esc_attr( json_encode( $choices ) ); ?>' /> |
||
| 1657 | <?php } ?> |
||
| 1658 | |||
| 1659 | <!-- Single or Double Opt-in --> |
||
| 1660 | <p class="type-container"><!-- necessary to prevent skipping on slideToggle(); --> |
||
| 1661 | |||
| 1662 | <table class="form-table form-field-container"> |
||
| 1663 | |||
| 1664 | <!-- Merge Tag --> |
||
| 1665 | <tr valign="top"> |
||
| 1666 | <td scope="row"> |
||
| 1667 | <label for="merge-tag"> |
||
| 1668 | <?php _e( 'Merge Tag', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1669 | </label> |
||
| 1670 | </td> |
||
| 1671 | <td> |
||
| 1672 | <input class="widefat merge-tag-text" type="text" readonly value="<?php echo $field['merge']; ?>"> |
||
| 1673 | </td> |
||
| 1674 | </tr> |
||
| 1675 | |||
| 1676 | <!-- Placeholder Value --> |
||
| 1677 | <?php switch( $field['type'] ) {
|
||
| 1678 | |||
| 1679 | case 'text': |
||
| 1680 | case 'email': |
||
| 1681 | case 'url': |
||
| 1682 | case 'number'; |
||
| 1683 | case 'birthday': |
||
| 1684 | case 'date': |
||
| 1685 | case 'zip': |
||
| 1686 | View Code Duplication | case 'phone': |
|
| 1687 | ?> |
||
| 1688 | <!-- Placeholder --> |
||
| 1689 | <tr valign="top"> |
||
| 1690 | <td scope="row"> |
||
| 1691 | <label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1692 | <?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1693 | </label> |
||
| 1694 | </td> |
||
| 1695 | <td> |
||
| 1696 | <input type="text" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="<?php echo isset( $field['placeholder'] ) ? $field['placeholder'] : '' ; ?>" /> |
||
| 1697 | <p class="description"><small><?php _e( "Assign a placeholder value to this field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1698 | </td> |
||
| 1699 | </tr> |
||
| 1700 | <?php |
||
| 1701 | break; |
||
| 1702 | |||
| 1703 | // Custom address placeholder field |
||
| 1704 | View Code Duplication | case 'address': |
|
| 1705 | ?> |
||
| 1706 | <tr valign="top"> |
||
| 1707 | <td scope="row"> |
||
| 1708 | <label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1709 | <?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1710 | </label> |
||
| 1711 | </td> |
||
| 1712 | <td> |
||
| 1713 | <input type="checkbox" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="1" <?php echo isset( $field['placeholder'] ) && ! empty( $field['placeholder'] ) ? 'checked="checked"' : '' ; ?> /> |
||
| 1714 | <span class="description"><small><?php _e( "Use placeholders for this field (these will be automatically filled in with field names).", 'yikes-inc-easy-mailchimp-extender' );?></small></span> |
||
| 1715 | </td> |
||
| 1716 | </tr> |
||
| 1717 | <?php |
||
| 1718 | break; |
||
| 1719 | |||
| 1720 | } |
||
| 1721 | ?> |
||
| 1722 | |||
| 1723 | <!-- Default Value --> |
||
| 1724 | <?php switch( $field['type'] ) {
|
||
| 1725 | default: |
||
| 1726 | case 'text': |
||
| 1727 | case 'number': |
||
| 1728 | case 'url': |
||
| 1729 | ?> |
||
| 1730 | <tr valign="top"> |
||
| 1731 | <td scope="row"> |
||
| 1732 | <label for="default_value_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1733 | <?php _e( 'Default Value', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1734 | </label> |
||
| 1735 | </td> |
||
| 1736 | <td> |
||
| 1737 | View Code Duplication | <input id="default_value_<?php echo esc_attr( $field['merge'] ); ?>" <?php if ( $field['type'] != 'number' ) { ?> type="text" <?php } else { ?> type="number" <?php } ?> class="widefat" name="field[<?php echo $field['merge']; ?>][default]" <?php if ( $field['type'] != 'url' ) { ?> value="<?php echo isset( $field['default'] ) ? stripslashes( wp_strip_all_tags( $field['default'] ) ) : ''; ?>" <?php } else { ?> value="<?php echo isset( $field['default'] ) ? stripslashes( wp_strip_all_tags( esc_url_raw( $field['default'] ) ) ) : ''; ?>" <?php } ?> />
|
|
| 1738 | <p class="description"><small><?php _e( "Assign a default value to populate this field with on initial page load.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1739 | <?php |
||
| 1740 | switch( $field['type'] ) {
|
||
| 1741 | case 'text': |
||
| 1742 | ?> |
||
| 1743 | <p><small class="pre-defined-tag-link"><a href="#TB_inline?width=600&height=550&inlineId=pre-defined-tag-container" onclick="storeGlobalClicked( jQuery( this ) );" class="thickbox"><?php _e( 'View Pre-Defined Tags', 'yikes-inc-easy-mailchimp-extender' ); ?></a></small></p> |
||
| 1744 | <?php |
||
| 1745 | break; |
||
| 1746 | } ?> |
||
| 1747 | </td> |
||
| 1748 | </tr> |
||
| 1749 | <?php |
||
| 1750 | break; |
||
| 1751 | |||
| 1752 | case 'radio': |
||
| 1753 | ?> |
||
| 1754 | <tr valign="top"> |
||
| 1755 | <td scope="row"> |
||
| 1756 | <label for="placeholder"> |
||
| 1757 | <?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1758 | </label> |
||
| 1759 | </td> |
||
| 1760 | <td> |
||
| 1761 | <?php |
||
| 1762 | $field['default_choice'] = ! isset( $field['default_choice'] ) ? 'no-default' : $field['default_choice']; |
||
| 1763 | $x = 0; |
||
| 1764 | ?> |
||
| 1765 | <label for="<?php echo $field['merge'] . '-no-default'; ?>"> |
||
| 1766 | <input id="<?php echo $field['merge'] . '-no-default'; ?>" |
||
| 1767 | type="radio" |
||
| 1768 | name="field[<?php echo $field['merge']; ?>][default_choice]" |
||
| 1769 | value="no-default" <?php checked( $field['default_choice'], 'no-default' ); ?> |
||
| 1770 | > |
||
| 1771 | No Default |
||
| 1772 | </label> |
||
| 1773 | <?php |
||
| 1774 | foreach ( $choices as $choice => $value ) { ?>
|
||
| 1775 | <label for="<?php echo $field['merge'].'-'.$x; ?>"> |
||
| 1776 | <input id="<?php echo $field['merge'].'-'.$x; ?>" |
||
| 1777 | type="radio" |
||
| 1778 | name="field[<?php echo $field['merge']; ?>][default_choice]" |
||
| 1779 | value="<?php echo $x; ?>" <?php checked( $field['default_choice'], $x ); ?>> |
||
| 1780 | <?php echo $value; ?> |
||
| 1781 | </label> |
||
| 1782 | <?php $x++; } ?> |
||
| 1783 | <p class="description"><small><?php _e( "Select the option that should be selected by default.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1784 | </td> |
||
| 1785 | </tr> |
||
| 1786 | |||
| 1787 | <?php |
||
| 1788 | break; |
||
| 1789 | |||
| 1790 | case 'dropdown': |
||
| 1791 | ?> |
||
| 1792 | <tr valign="top"> |
||
| 1793 | <td scope="row"> |
||
| 1794 | <label for="placeholder"> |
||
| 1795 | <?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1796 | </label> |
||
| 1797 | </td> |
||
| 1798 | <td> |
||
| 1799 | <select type="default" name="field[<?php echo $field['merge']; ?>][default_choice]"> |
||
| 1800 | <option value="no-default" <?php selected( $field['default_choice'] , 'no-default' ); ?>>No Default</option> |
||
| 1801 | <?php foreach( json_decode( $field['choices'], true ) as $choice => $value ) { ?>
|
||
| 1802 | <option value="<?php echo $choice; ?>" <?php selected( $field['default_choice'] , $choice ); ?>><?php echo $value; ?></option> |
||
| 1803 | <?php } ?> |
||
| 1804 | </select> |
||
| 1805 | <p class="description"><small><?php _e( "Which option should be selected by default?", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1806 | </td> |
||
| 1807 | </tr> |
||
| 1808 | |||
| 1809 | <?php |
||
| 1810 | View Code Duplication | if ( $default_selected === 'no-default' ) {
|
|
| 1811 | ?> |
||
| 1812 | <!-- Placeholder --> |
||
| 1813 | <tr valign="top"> |
||
| 1814 | <td scope="row"> |
||
| 1815 | <label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1816 | <?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1817 | </label> |
||
| 1818 | </td> |
||
| 1819 | <td> |
||
| 1820 | <input type="text" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="<?php echo isset( $field['placeholder'] ) ? $field['placeholder'] : '' ; ?>" /> |
||
| 1821 | <p class="description"><small><?php _e( "Assign a placeholder value to this field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1822 | </td> |
||
| 1823 | </tr> |
||
| 1824 | <?php |
||
| 1825 | } |
||
| 1826 | ?> |
||
| 1827 | <?php |
||
| 1828 | break; |
||
| 1829 | |||
| 1830 | case "birthday": |
||
| 1831 | case "address": |
||
| 1832 | break; |
||
| 1833 | |||
| 1834 | } // end Default Value ?> |
||
| 1835 | |||
| 1836 | |||
| 1837 | <!-- Field Description --> |
||
| 1838 | <tr valign="top"> |
||
| 1839 | <td scope="row"> |
||
| 1840 | <label for="description_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1841 | <?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1842 | </label> |
||
| 1843 | </td> |
||
| 1844 | <td> |
||
| 1845 | <textarea class="widefat field-description-input" id="description_<?php echo esc_attr( $field['merge'] ); ?>" name="field[<?php echo $field['merge']; ?>][description]"><?php echo isset( $field['description'] ) ? stripslashes( esc_html( $field['description'] ) ) : '' ; ?></textarea> |
||
| 1846 | <p class="description"><small><?php _e( "Enter the description for the form field. This will be displayed to the user and will provide some direction on how the field should be filled out or selected.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1847 | </td> |
||
| 1848 | </tr> |
||
| 1849 | <!-- Description Above Field --> |
||
| 1850 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 1851 | <td scope="row"> |
||
| 1852 | <label for="description_above_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1853 | <?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1854 | </label> |
||
| 1855 | </td> |
||
| 1856 | <td> |
||
| 1857 | <input type="checkbox" id="description_above_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat field-description-input" name="field[<?php echo $field['merge']; ?>][description_above]" value="1" <?php echo isset( $field['description_above'] ) && $field['description_above'] === '1' ? 'checked="checked"' : ''; ?> /> |
||
| 1858 | <p class="description"><small><?php _e( "By default the description will appear undearneath the field. Check this box if you'd like the description to appear above the field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1859 | </td> |
||
| 1860 | </tr> |
||
| 1861 | <!-- Additional Classes --> |
||
| 1862 | <tr valign="top"> |
||
| 1863 | <td scope="row"> |
||
| 1864 | <label for="classes_<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1865 | <?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1866 | </label> |
||
| 1867 | </td> |
||
| 1868 | <td> |
||
| 1869 | <input type="text" id="classes_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][additional-classes]" value="<?php echo isset( $field['additional-classes'] ) ? stripslashes( wp_strip_all_tags( $field['additional-classes'] ) ) : '' ; ?>" /> |
||
| 1870 | <p class="description"><small><?php printf( __( "Assign additional classes to this field. %s.", 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/bundled-css-classes/' ) . '">' . __( 'View bundled classes', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' );?></small></p> |
||
| 1871 | </td> |
||
| 1872 | </tr> |
||
| 1873 | <!-- Required Toggle --> |
||
| 1874 | <tr valign="top" class="yikes-checkbox-container yikes-checkbox-container-first"> |
||
| 1875 | <td scope="row"> |
||
| 1876 | <label for="field-required-<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1877 | <?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1878 | </label> |
||
| 1879 | </td> |
||
| 1880 | <td> |
||
| 1881 | <?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?> |
||
| 1882 | <input id="field-required-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" class="widefat" value="1" name="field[<?php echo $field['merge']; ?>][require]" <?php checked( $checked , 1 ); ?> <?php if ( $field['merge'] == 'EMAIL' ) { ?> disabled="disabled" checked="checked" title="<?php echo __( 'Email is a required field.', 'yikes-inc-easy-mailchimp-extender' ); } ?>">
|
||
| 1883 | <p class="description"><small><?php _e( "Require this field to be filled in before the form can be submitted.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1884 | </td> |
||
| 1885 | </tr> |
||
| 1886 | <!-- Visible Toggle --> |
||
| 1887 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 1888 | <td scope="row"> |
||
| 1889 | <label for="hide-field-<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1890 | <?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1891 | </label> |
||
| 1892 | </td> |
||
| 1893 | <td> |
||
| 1894 | <?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?> |
||
| 1895 | <input id="hide-field-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" class="widefat" value="1" name="field[<?php echo $field['merge']; ?>][hide]" <?php checked( $hide , 1 ); ?> <?php if ( $field['merge'] == 'EMAIL' ) { ?> disabled="disabled" title="<?php echo __( 'Cannot toggle email field visibility.', 'yikes-inc-easy-mailchimp-extender' ); } ?>">
|
||
| 1896 | <p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1897 | </td> |
||
| 1898 | </tr> |
||
| 1899 | <!-- Toggle Field Label Visibility --> |
||
| 1900 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 1901 | <td scope="row"> |
||
| 1902 | <label for="hide-label-<?php echo esc_attr( $field['merge'] ); ?>"> |
||
| 1903 | <?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 1904 | </label> |
||
| 1905 | </td> |
||
| 1906 | <td> |
||
| 1907 | <?php $hide_label = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?> |
||
| 1908 | <input id="hide-label-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" name="field[<?php echo $field['merge']; ?>][hide-label]" value="1" <?php checked( $hide_label , 1 ); ?>/> |
||
| 1909 | <p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 1910 | </td> |
||
| 1911 | </tr> |
||
| 1912 | <!-- Display Phone/Date Formats back to the user --> |
||
| 1913 | <!-- Phone Format Initial Load --> |
||
| 1914 | <?php |
||
| 1915 | switch( $field['type'] ) {
|
||
| 1916 | /* Store the phone format, for properly regex pattern */ |
||
| 1917 | case 'phone': |
||
| 1918 | case 'birthday': |
||
| 1919 | case 'date': |
||
| 1920 | ?> |
||
| 1921 | <tr valign="top"> |
||
| 1922 | <td scope="row"> |
||
| 1923 | <label for="placeholder"> |
||
| 1924 | <?php |
||
| 1925 | switch( $field['type'] ) {
|
||
| 1926 | default: |
||
| 1927 | View Code Duplication | case 'birthday': |
|
| 1928 | $type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' ); |
||
| 1929 | $format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD'; |
||
| 1930 | $format_name = 'date_format'; |
||
| 1931 | break; |
||
| 1932 | |||
| 1933 | View Code Duplication | case 'date': |
|
| 1934 | $type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' ); |
||
| 1935 | $format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD/YYYY'; |
||
| 1936 | $format_name = 'date_format'; |
||
| 1937 | break; |
||
| 1938 | |||
| 1939 | case 'phone': |
||
| 1940 | $type = __( 'Phone Format', 'yikes-inc-easy-mailchimp-extender' ); |
||
| 1941 | $format = isset( $field['phone_format'] ) && ! empty( $field['phone_format'] ) ? $field['phone_format'] : __( 'International', 'yikes-inc-easy-mailchimp-extender' ); |
||
| 1942 | $format_name = 'phone_format'; |
||
| 1943 | break; |
||
| 1944 | } |
||
| 1945 | echo $type; |
||
| 1946 | ?> |
||
| 1947 | </label> |
||
| 1948 | </td> |
||
| 1949 | <td> |
||
| 1950 | <strong><?php echo $format; ?></strong> |
||
| 1951 | <input type="hidden" name="field[<?php echo $field['merge']; ?>][<?php echo $format_name; ?>]" value="<?php echo $format; ?>" /> |
||
| 1952 | <p class="description"><small> |
||
| 1953 | <?php printf( __( 'To change the %s please head over to <a href="%s" title="Mailchimp" target="_blank">Mailchimp</a>. If you alter the format, you should re-import this field.', 'yikes-inc-easy-mailchimp-extender' ), strtolower( $type ), esc_url( 'http://www.mailchimp.com' ) ); ?> |
||
| 1954 | </small></p> |
||
| 1955 | </td> |
||
| 1956 | </tr> |
||
| 1957 | <?php |
||
| 1958 | break; |
||
| 1959 | // others.. |
||
| 1960 | default: |
||
| 1961 | break; |
||
| 1962 | } |
||
| 1963 | ?> |
||
| 1964 | <!-- End Date/Phone Formats --> |
||
| 1965 | <!-- Toggle Buttons --> |
||
| 1966 | <tr valign="top"> |
||
| 1967 | <td scope="row"> |
||
| 1968 | |
||
| 1969 | </td> |
||
| 1970 | <td> |
||
| 1971 | <span class="toggle-container"> |
||
| 1972 | <a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> | |
||
| 1973 | <a href="#" class="remove-field" alt="<?php echo $field['merge']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
||
| 1974 | </span> |
||
| 1975 | </td> |
||
| 1976 | </tr> |
||
| 1977 | </table> |
||
| 1978 | </p> |
||
| 1979 | |||
| 1980 | </div> |
||
| 1981 | </section> |
||
| 1982 | <?php |
||
| 1983 | |||
| 1984 | |||
| 1985 | |||
| 1986 | } else {
|
||
| 1987 | |||
| 1988 | /**** Interest Group ****/ |
||
| 1989 | |||
| 1990 | ?> |
||
| 1991 | <section class="draggable" id="<?php echo $field['group_id']; ?>"> |
||
| 1992 | <!-- top --> |
||
| 1993 | <a href="#" class="expansion-section-title settings-sidebar"> |
||
| 1994 | <span class="dashicons dashicons-plus yikes-mc-expansion-toggle"></span><?php echo stripslashes( $field['label'] ); ?> |
||
| 1995 | <?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
|
||
| 1996 | <img src="<?php echo YIKES_MC_URL . 'includes/images/warning.svg'; ?>" class="field-no-longer-exists-warning" title="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>" alt="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>"> |
||
| 1997 | <?php } ?> |
||
| 1998 | <span class="field-type-text"><small><?php echo __( 'type', 'yikes-inc-easy-mailchimp-extender' ) . ' : ' . $field['type']; ?></small></span> |
||
| 1999 | </a> |
||
| 2000 | <!-- expansion section --> |
||
| 2001 | <div class="yikes-mc-settings-expansion-section"> |
||
| 2002 | |||
| 2003 | <!-- check if this field exists in the available interest group array --> |
||
| 2004 | <?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
|
||
| 2005 | <p class="yikes-mc-warning-message"><?php _e( "This field no longer exists in this list. Delete this field from the form to prevent issues on the front end." , 'yikes-inc-easy-mailchimp-extender' ); ?></p> |
||
| 2006 | <?php } ?> |
||
| 2007 | |||
| 2008 | <!-- store the label --> |
||
| 2009 | <input type="hidden" name="field[<?php echo $field['group_id']; ?>][label]" value="<?php echo htmlspecialchars( $field['label'] ); ?>" /> |
||
| 2010 | <input type="hidden" name="field[<?php echo $field['group_id']; ?>][type]" value="<?php echo $field['type']; ?>" /> |
||
| 2011 | <input type="hidden" name="field[<?php echo $field['group_id']; ?>][group_id]" value="<?php echo $field['group_id']; ?>" /> |
||
| 2012 | <input type="hidden" name="field[<?php echo $field['group_id']; ?>][groups]" value='<?php echo esc_attr( json_encode( json_decode( $field['groups'], true ) ) ); ?>' /> |
||
| 2013 | |||
| 2014 | <!-- Single or Double Opt-in --> |
||
| 2015 | <p class="type-container"><!-- necessary to prevent skipping on slideToggle(); --> |
||
| 2016 | |||
| 2017 | <table class="form-table form-field-container"> |
||
| 2018 | <!-- Default Value --> |
||
| 2019 | <?php switch( $field['type'] ) {
|
||
| 2020 | default: |
||
| 2021 | case 'radio': |
||
| 2022 | case 'checkboxes': |
||
| 2023 | ?> |
||
| 2024 | <tr valign="top"> |
||
| 2025 | <td scope="row"> |
||
| 2026 | <label for="placeholder"> |
||
| 2027 | <?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2028 | </label> |
||
| 2029 | </td> |
||
| 2030 | <td> |
||
| 2031 | <?php |
||
| 2032 | $field['default_choice'] = isset( $field['default_choice'] ) ? $field['default_choice'] : ''; |
||
| 2033 | |||
| 2034 | $default_shown = false; |
||
| 2035 | |||
| 2036 | foreach ( json_decode( $field['groups'], true ) as $id => $group ) {
|
||
| 2037 | $field_id = "{$field['group_id']}-{$id}";
|
||
| 2038 | $field_type = 'hidden' == $field['type'] ? 'checkbox' : $field['type']; |
||
| 2039 | $field_type = 'checkboxes' == $field_type ? 'checkbox' : $field_type; |
||
| 2040 | $field_name = "field[{$field['group_id']}][default_choice]";
|
||
| 2041 | $field_name = 'checkbox' == $field_type ? $field_name . '[]' : $field_name; |
||
| 2042 | |||
| 2043 | // Determine if the current group is checked. |
||
| 2044 | $checked = ''; |
||
| 2045 | switch ( $field_type ) {
|
||
| 2046 | case 'radio': |
||
| 2047 | default: |
||
| 2048 | $default = is_array( $field['default_choice'] ) ? current( $field['default_choice'] ) : $field['default_choice']; |
||
| 2049 | $checked = is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), $id, false ) : checked( $field['default_choice'], $id, false ); |
||
| 2050 | break; |
||
| 2051 | |||
| 2052 | case 'checkbox': |
||
| 2053 | case 'hidden': |
||
| 2054 | if ( is_array( $field['default_choice'] ) && in_array( $id, $field['default_choice'] ) ) {
|
||
| 2055 | $checked = checked( true, true, false ); |
||
| 2056 | } |
||
| 2057 | break; |
||
| 2058 | } |
||
| 2059 | |||
| 2060 | // Allow users to not set a default choice for radio buttons. |
||
| 2061 | if ( $field_type === 'radio' && $default_shown === false ) {
|
||
| 2062 | $default_shown = true; |
||
| 2063 | ?> |
||
| 2064 | <label for="<?php echo $field_id . 'no-default'; ?>"> |
||
| 2065 | <input id="<?php echo $field_id . 'no-default'; ?>" |
||
| 2066 | type="<?php echo $field_type; ?>" |
||
| 2067 | name="<?php echo $field_name; ?>" |
||
| 2068 | value="no-default" |
||
| 2069 | <?php is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), 'no-default' ) : checked( $field['default_choice'], 'no-default' ); ?>> |
||
| 2070 | No Default |
||
| 2071 | </label> |
||
| 2072 | <?php |
||
| 2073 | } |
||
| 2074 | |||
| 2075 | ?> |
||
| 2076 | <label for="<?php echo $field_id; ?>"> |
||
| 2077 | <input id="<?php echo $field_id; ?>" |
||
| 2078 | type="<?php echo $field_type; ?>" |
||
| 2079 | name="<?php echo $field_name; ?>" |
||
| 2080 | value="<?php echo $id; ?>" <?php echo $checked; ?>> |
||
| 2081 | <?php echo stripslashes( str_replace( '\'', '', $group ) ); ?> |
||
| 2082 | </label> |
||
| 2083 | <?php |
||
| 2084 | } ?> |
||
| 2085 | <p class="description"><small><?php _e( "Select the option that should be selected by default.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2086 | </td> |
||
| 2087 | </tr> |
||
| 2088 | |||
| 2089 | <?php |
||
| 2090 | break; |
||
| 2091 | |||
| 2092 | case 'dropdown': |
||
| 2093 | ?> |
||
| 2094 | <tr valign="top"> |
||
| 2095 | <td scope="row"> |
||
| 2096 | <label for="placeholder"> |
||
| 2097 | <?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2098 | </label> |
||
| 2099 | </td> |
||
| 2100 | <td> |
||
| 2101 | <select type="default" name="field[<?php echo $field['group_id']; ?>][default_choice]"> |
||
| 2102 | <option value="no-default">No Default</option> |
||
| 2103 | <?php foreach( json_decode( stripslashes_deep( $field['groups'] ) , true ) as $id => $group ) { ?>
|
||
| 2104 | <option value="<?php echo $id; ?>" <?php selected( $field['default_choice'] , $id ); ?>><?php echo stripslashes( $group ); ?></option> |
||
| 2105 | <?php } ?> |
||
| 2106 | </select> |
||
| 2107 | <p class="description"><small><?php _e( "Which option should be selected by default?", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2108 | </td> |
||
| 2109 | </tr> |
||
| 2110 | |||
| 2111 | <?php |
||
| 2112 | break; |
||
| 2113 | ?> |
||
| 2114 | |||
| 2115 | <?php } // end Default Value ?> |
||
| 2116 | |||
| 2117 | <!-- Field Description --> |
||
| 2118 | <tr valign="top"> |
||
| 2119 | <td scope="row"> |
||
| 2120 | <label for="description_<?php echo esc_attr( $field['group_id'] ); ?>"> |
||
| 2121 | <?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2122 | </label> |
||
| 2123 | </td> |
||
| 2124 | <td> |
||
| 2125 | <textarea id="description_<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat field-description-input" name="field[<?php echo $field['group_id']; ?>][description]"><?php echo isset( $field['description'] ) ? stripslashes( esc_html( $field['description'] ) ) : '' ; ?></textarea> |
||
| 2126 | <p class="description"><small><?php _e( "Enter the description for the form field. This will be displayed to the user and provide some direction on how the field should be filled out or selected.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2127 | </td> |
||
| 2128 | </tr> |
||
| 2129 | |||
| 2130 | <!-- Description Above Field --> |
||
| 2131 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 2132 | <td scope="row"> |
||
| 2133 | <label for="description_above_<?php echo $field['group_id']; ?>"> |
||
| 2134 | <?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2135 | </label> |
||
| 2136 | </td> |
||
| 2137 | <td> |
||
| 2138 | <input type="checkbox" id="description_above_<?php echo $field['group_id']; ?>" class="widefat field-description-input" name="field[<?php echo $field['group_id']; ?>][description_above]" value="1" <?php echo isset( $field['description_above'] ) && $field['description_above'] === '1' ? 'checked="checked"' : ''; ?> /> |
||
| 2139 | <p class="description"><small><?php _e( "By default the description will appear undearneath the field. Check this box if you'd like the description to appear above the field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2140 | </td> |
||
| 2141 | </tr> |
||
| 2142 | |||
| 2143 | <!-- Additional Classes --> |
||
| 2144 | <tr valign="top"> |
||
| 2145 | <td scope="row"> |
||
| 2146 | <label for="classes_<?php echo esc_attr( $field['group_id'] ); ?>"> |
||
| 2147 | <?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2148 | </label> |
||
| 2149 | </td> |
||
| 2150 | <td> |
||
| 2151 | <input type="text" id="classes_<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" name="field[<?php echo $field['group_id']; ?>][additional-classes]" value="<?php echo isset( $field['additional-classes'] ) ? stripslashes( wp_strip_all_tags( $field['additional-classes'] ) ) : '' ; ?>" /> |
||
| 2152 | <p class="description"><small><?php printf( __( "Assign additional classes to this field. %s.", 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/bundled-css-classes/' ) . '">' . __( 'View bundled classes', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' );?></small></p> |
||
| 2153 | </td> |
||
| 2154 | </tr> |
||
| 2155 | <!-- Required Toggle --> |
||
| 2156 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 2157 | <td scope="row"> |
||
| 2158 | <label for="field-required-<?php echo esc_attr( $field['group_id'] ); ?>"> |
||
| 2159 | <?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2160 | </label> |
||
| 2161 | </td> |
||
| 2162 | <td> |
||
| 2163 | <?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?> |
||
| 2164 | <input type="checkbox" id="field-required-<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" value="1" name="field[<?php echo $field['group_id']; ?>][require]" <?php checked( $checked , 1 ); ?>> |
||
| 2165 | <p class="description"><small><?php _e( "Require this field to be filled in before the form can be submitted.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2166 | </td> |
||
| 2167 | </tr> |
||
| 2168 | <!-- Visible Toggle --> |
||
| 2169 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 2170 | <td scope="row"> |
||
| 2171 | <label for="hide-field-<?php echo esc_attr( $field['group_id'] ); ?>"> |
||
| 2172 | <?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2173 | </label> |
||
| 2174 | </td> |
||
| 2175 | <td> |
||
| 2176 | <?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?> |
||
| 2177 | <input type="checkbox" id="hide-field-<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" value="1" name="field[<?php echo $field['group_id']; ?>][hide]" <?php checked( $hide , 1 ); ?>> |
||
| 2178 | <p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2179 | </td> |
||
| 2180 | </tr> |
||
| 2181 | <!-- Toggle Field Label Visibility --> |
||
| 2182 | <tr valign="top" class="yikes-checkbox-container"> |
||
| 2183 | <td scope="row"> |
||
| 2184 | <label for="hide-label-<?php echo esc_attr( $field['group_id'] ); ?>"> |
||
| 2185 | <?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?> |
||
| 2186 | </label> |
||
| 2187 | </td> |
||
| 2188 | <td> |
||
| 2189 | <?php $hide = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?> |
||
| 2190 | <input type="checkbox" id="hide-label-<?php echo esc_attr( $field['group_id'] ); ?>" name="field[<?php echo $field['group_id']; ?>][hide-label]" value="1" <?php checked( $hide , 1 ); ?>/> |
||
| 2191 | <p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p> |
||
| 2192 | </td> |
||
| 2193 | </tr> |
||
| 2194 | <!-- Toggle Buttons --> |
||
| 2195 | <tr valign="top"> |
||
| 2196 | <td scope="row"> |
||
| 2197 | |
||
| 2198 | </td> |
||
| 2199 | <td> |
||
| 2200 | <span class="toggle-container"> |
||
| 2201 | <a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> | |
||
| 2202 | <a href="#" class="remove-field" alt="<?php echo $field['group_id']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
||
| 2203 | </span> |
||
| 2204 | </td> |
||
| 2205 | </tr> |
||
| 2206 | </table> |
||
| 2207 | </p> |
||
| 2208 | |||
| 2209 | </div> |
||
| 2210 | </section> |
||
| 2211 | <?php |
||
| 2212 | } |
||
| 2213 | } |
||
| 2214 | } else {
|
||
| 2215 | ?> |
||
| 2216 | <h4 class="no-fields-assigned-notice non-draggable-yikes"><em><?php _e( 'No fields are assigned to this form. Select fields from the right hand column to add to this form.', 'yikes-inc-easy-mailchimp-extender' ); ?></em></h4> |
||
| 2217 | <?php |
||
| 2218 | } |
||
| 2219 | /* Pre Defined Merge Tag Container - Always rendered so the modal appears and links are clickable on initial page load */ |
||
| 2220 | add_thickbox(); |
||
| 2221 | // enqueue jquery qtip for our tooltip |
||
| 2222 | wp_enqueue_script( 'jquery-qtip-tooltip', YIKES_MC_URL . 'admin/js/min/jquery.qtip.min.js', array( 'jquery' ) ); |
||
| 2223 | wp_enqueue_style( 'jquery-qtip-style', YIKES_MC_URL . 'admin/css/jquery.qtip.min.css' ); |
||
| 2224 | $available_tags = array( |
||
| 2225 | array( |
||
| 2226 | 'tag' => '{page_title}',
|
||
| 2227 | 'description' => '<h4 class="tooltip-title">' . __( 'Page Title', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_title}</small></h4><hr />' . __( 'Pre-populate the field with the current page or post title that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
|
||
| 2228 | 'title' => __( 'Page Title', 'yikes-inc-easy-mailchimp-extender' ) |
||
| 2229 | ), |
||
| 2230 | array( |
||
| 2231 | 'tag' => '{page_id}',
|
||
| 2232 | 'description' => '<h4 class="tooltip-title">' . __( 'Page ID', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_id}</small></h4><hr />' . __( 'Pre-populate the field with the current page or post ID that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
|
||
| 2233 | 'title' => __( 'Page ID', 'yikes-inc-easy-mailchimp-extender' ) |
||
| 2234 | ), |
||
| 2235 | array( |
||
| 2236 | 'tag' => '{page_url}',
|
||
| 2237 | 'description' => '<h4 class="tooltip-title">' . __( 'Page URL', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_url}</small></h4><hr />' . __( 'Pre-populate the field with the current page URL that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
|
||
| 2238 | 'title' => __( 'Page URL', 'yikes-inc-easy-mailchimp-extender' ) |
||
| 2239 | ), |
||
| 2240 | array( |
||
| 2241 | 'tag' => '{blog_name}',
|
||
| 2242 | 'description' => '<h4 class="tooltip-title">' . __( 'Blog Name', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{blog_name}</small></h4><hr />' . __( 'Pre-populate the field with the current blog name that the user is on when opting in to your mailing list. This is especially helpful for multi-site networks.', 'yikes-inc-easy-mailchimp-extender' ),
|
||
| 2243 | 'title' => __( 'Blog Name', 'yikes-inc-easy-mailchimp-extender' ) |
||
| 2244 | ), |
||
| 2245 | array( |
||
| 2246 | 'tag' => '{user_logged_in}',
|
||
| 2247 | 'description' => '<h4 class="tooltip-title">' . __( 'User Logged In', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{user_logged_in}</small></h4><hr />' . __( 'Detects if a user is logged in and pre-populates the field with an appropriate value.', 'yikes-inc-easy-mailchimp-extender' ),
|
||
| 2248 | 'title' => __( 'User Logged In', 'yikes-inc-easy-mailchimp-extender' ) |
||
| 2249 | ), |
||
| 2250 | ); |
||
| 2251 | ?> |
||
| 2252 | <!-- tooltips --> |
||
| 2253 | <script type="text/javascript"> |
||
| 2254 | /* Initialize Qtip tooltips for pre-defined tags */ |
||
| 2255 | jQuery( document ).ready( function() {
|
||
| 2256 | jQuery( '.dashicons-editor-help' ).each( function() {
|
||
| 2257 | jQuery( this ).qtip({
|
||
| 2258 | content: {
|
||
| 2259 | text: jQuery( this ).next( '.tooltiptext' ), |
||
| 2260 | style: {
|
||
| 2261 | def: false |
||
| 2262 | } |
||
| 2263 | } |
||
| 2264 | }); |
||
| 2265 | }); |
||
| 2266 | jQuery( '.qtip' ).each( function() {
|
||
| 2267 | jQuery( this ).removeClass( 'qtip-default' ); |
||
| 2268 | }); |
||
| 2269 | }); |
||
| 2270 | </script> |
||
| 2271 | |||
| 2272 | <div id="pre-defined-tag-container"> |
||
| 2273 | <input type="hidden" value="" class="clicked-input"> |
||
| 2274 | <div id="pre-defined-tag-interior-container"> |
||
| 2275 | <h3><?php _e( 'Pre Defined Tags', 'yikes-inc-easy-mailchimp-extender' ); ?></h3> |
||
| 2276 | <p class="description"><?php _e( 'You can use any of the following tags to populate a Mailchimp text field with dynamic content. This can be used to determine which page the user signed up on, if the user was logged in and more.', 'yikes-inc-easy-mailchimp-extender' ); ?></p> |
||
| 2277 | <ul> |
||
| 2278 | <?php foreach( apply_filters( 'yikes-mailchimp-custom-default-value-tags', $available_tags ) as $tag ) { ?>
|
||
| 2279 | <li class="tooltop-tag"> |
||
| 2280 | <!-- link/tag --> |
||
| 2281 | <a href="#" onclick="populateDefaultValue( '<?php echo $tag['tag']; ?>' );return false;" data-attr-tag="<?php echo $tag['tag']; ?>" title="<?php echo $tag['title']; ?>"><?php echo $tag['title']; ?></a> |
||
| 2282 | <!-- help icon --> |
||
| 2283 | <span class="dashicons dashicons-editor-help"></span> |
||
| 2284 | <!-- tooltip --> |
||
| 2285 | <div class="tooltiptext qtip-bootstrap yikes-easy-mc-hidden"><?php echo $tag['description']; ?></div> |
||
| 2286 | </li> |
||
| 2287 | <?php } ?> |
||
| 2288 | </ul> |
||
| 2289 | </div> |
||
| 2290 | </div> |
||
| 2291 | <?php |
||
| 2292 | } |
||
| 2293 | |||
| 2294 | /** |
||
| 2295 | * build_available_merge_vars( $list_id ) |
||
| 2296 | * Submit an API request to get our merge variables, and build up a small form editor |
||
| 2297 | * for users to 'customize' their form |
||
| 2298 | * - |
||
| 2299 | * @parameters - $list_id - pass in the list ID to retreive merge variables from |
||
| 2300 | */ |
||
| 2301 | public function build_available_merge_vars( $form_fields, $available_merge_variables ) {
|
||
| 2342 | |||
| 2343 | /** |
||
| 2344 | * build_available_interest_groups( $form_fields , $available_interest_groups ) |
||
| 2345 | * Submit an API request to get our merge variables, and build up a small form editor |
||
| 2346 | * for users to 'customize' their form |
||
| 2347 | * - |
||
| 2348 | * @parameters - $list_id - pass in the list ID to retreive merge variables from |
||
| 2349 | */ |
||
| 2350 | public function build_available_interest_groups( $form_fields, $available_interest_groups, $list_id ) {
|
||
| 2391 | |||
| 2392 | /** |
||
| 2393 | * Smt. |
||
| 2394 | */ |
||
| 2395 | public function build_available_tags( $form_tags, $tags, $list_id ) {
|
||
| 2422 | |||
| 2423 | /* |
||
| 2424 | * Create A New Form! |
||
| 2425 | * Probably Move these to its own file, |
||
| 2426 | * and include it here for easy maintenance |
||
| 2427 | * - must clean up db tables , ensure what data is going in and what is needed... |
||
| 2428 | */ |
||
| 2429 | public function yikes_easy_mailchimp_create_form() {
|
||
| 2454 | |||
| 2455 | /* |
||
| 2456 | * Delete A Form ! |
||
| 2457 | * Probably Move these to its own file, |
||
| 2458 | * and include it here for easy maintenance |
||
| 2459 | * - must clean up db tables , ensure what data is going in and what is needed... |
||
| 2460 | */ |
||
| 2461 | public function yikes_easy_mailchimp_delete_form() {
|
||
| 2476 | |||
| 2477 | /* |
||
| 2478 | * Duplicate an entire form ! |
||
| 2479 | * Probably Move these to its own file, |
||
| 2480 | */ |
||
| 2481 | public function yikes_easy_mailchimp_duplicate_form() {
|
||
| 2520 | |||
| 2521 | /* |
||
| 2522 | * Reset a forms impression stats |
||
| 2523 | */ |
||
| 2524 | public function yikes_easy_mailchimp_reset_impression_stats() {
|
||
| 2551 | |||
| 2552 | /* |
||
| 2553 | * Update an entire form ! |
||
| 2554 | * Probably Move these to its own file, |
||
| 2555 | */ |
||
| 2556 | public function yikes_easy_mailchimp_update_form() {
|
||
| 2674 | |||
| 2675 | public static function generate_default_email_body() {
|
||
| 2696 | |||
| 2697 | /* Unsubscribe a given user from our list */ |
||
| 2698 | public function yikes_easy_mailchimp_unsubscribe_user() {
|
||
| 2721 | |||
| 2722 | public function yikes_easy_mailchimp_create_missing_error_log() {
|
||
| 2741 | |||
| 2742 | /* |
||
| 2743 | * Clear Transient Data ! |
||
| 2744 | * Probably Move these to its own file, |
||
| 2745 | */ |
||
| 2746 | public function yikes_easy_mailchimp_clear_transient_data() {
|
||
| 2772 | |||
| 2773 | /** |
||
| 2774 | * Return an array of Mailchimp lists associated with this account |
||
| 2775 | * |
||
| 2776 | * Used when deleting the sites Mailchimp cache stored |
||
| 2777 | * |
||
| 2778 | * @since 6.0.2 |
||
| 2779 | * @return $list_id_array - array of list id's to loop over |
||
| 2780 | */ |
||
| 2781 | public function get_mailchimp_list_ids_on_account() {
|
||
| 2799 | |||
| 2800 | /** |
||
| 2801 | * Include our main Helper class file |
||
| 2802 | * |
||
| 2803 | * @since 6.0 |
||
| 2804 | */ |
||
| 2805 | public function yikes_mailchimp_load_helper_class() {
|
||
| 2812 | |||
| 2813 | /** |
||
| 2814 | * Alter the color scheme based on the current user selection (this is done to help integrate the plugin into the dashboard more seamlessly) |
||
| 2815 | * |
||
| 2816 | * @since 0.1 |
||
| 2817 | * @order requires that yikes-inc-easy-mailchimp-extender-admin.min.css be enqueued, so we can override the defaults (handle: yikes-inc-easy-mailchimp-extender-admin) |
||
| 2818 | * @return print out custom styles to the admin header to alter the default blue color |
||
| 2819 | */ |
||
| 2820 | public function alter_yikes_easy_mc_color_scheme() {
|
||
| 2868 | |||
| 2869 | /** |
||
| 2870 | * Display premium support page if any add-ons are installed, otherwise display free support page |
||
| 2871 | */ |
||
| 2872 | public function display_support_page_content() {
|
||
| 2887 | |||
| 2888 | /** |
||
| 2889 | * Check the users version number, and display a notice to upgrade the database if needed |
||
| 2890 | * |
||
| 2891 | * @since 6.0.4 |
||
| 2892 | */ |
||
| 2893 | public function check_yikes_mc_table_version() {
|
||
| 2902 | |||
| 2903 | /** |
||
| 2904 | * Process [yikes-mailchimp-form-description] into the shortcode |
||
| 2905 | * |
||
| 2906 | * @since 6.0.4.4 |
||
| 2907 | */ |
||
| 2908 | public function process_subscriber_count_shortcode_in_form_descriptions( $form_description, $form_id ) {
|
||
| 2912 | |||
| 2913 | /** |
||
| 2914 | * Generate the sidebar advertisement on the 'Edit Form' page |
||
| 2915 | * |
||
| 2916 | * @since 6.0.3 |
||
| 2917 | */ |
||
| 2918 | public function generate_edit_forms_upsell_ad() {
|
||
| 2930 | |||
| 2931 | /*** |
||
| 2932 | * Helper function to clear out transients stored by this plugin |
||
| 2933 | * |
||
| 2934 | * Mainly used when the API key is altered, changed or removed. |
||
| 2935 | * @since 6.1.3 |
||
| 2936 | */ |
||
| 2937 | public function delete_yikes_mailchimp_transients() {
|
||
| 2957 | |||
| 2958 | /** |
||
| 2959 | * Register the Opt-in widget. |
||
| 2960 | * |
||
| 2961 | * @author Jeremy Pry |
||
| 2962 | */ |
||
| 2963 | public function register_optin_widget() {
|
||
| 2966 | } |
||
| 2967 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.