ddw_wcde_do_string_swaps

Passing an array of labels to our helper function to do string swaps.

Description

ddw_wcde_do_string_swaps(); 

NOTE: Most of the used strings are currently not filterable by itself. So using translations global variable and merging to the MO object is the only way. AND, we avoid the gettext filter with that, which is by intention, and a must performance-wise!


Usage

  1. if ( !function_exists( 'ddw_wcde_do_string_swaps' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-german-de_de/includes/wcde-string-swaps.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ddw_wcde_do_string_swaps(); 
  7.  

Defined (1)

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

/includes/wcde-string-swaps.php  
  1. function ddw_wcde_do_string_swaps() { 
  2.  
  3. /** Bail early if is not frontend or option is not set */ 
  4. if ( is_admin() 
  5. || 'no' === get_option( 'wcde_load_string_swaps' ) 
  6. ) { 
  7.  
  8. return; 
  9.  
  10. } // end if 
  11.  
  12. /** 
  13. * Helper filter, allows for custom disabling of string swaps. 
  14. * Usage: add_filter( 'wcde_filter_do_string_swaps', '__return_false' ); 
  15. */ 
  16. $wcde_do_string_swaps = (bool) apply_filters( 'wcde_filter_do_string_swaps', '__return_true' ); 
  17.  
  18. /** 
  19. * Bail early if our helper filter returns false, if we are not in German 
  20. * context within WPML (premium plugin), or, if no German-based locale is 
  21. * to be found for 'WPLANG'. 
  22. * NOTE: This is very important for multilingual sites and/or Multisite 
  23. * installs. 
  24. */ 
  25. if ( ! $wcde_do_string_swaps || ! wcde_is_german() ) { 
  26.  
  27. return; 
  28.  
  29. } // end if 
  30.  
  31.  
  32. /** 
  33. * New string labels: backwards compatible with our former 'gettext' approach. 
  34. * NOTE I: Kept filter names from v3.0.0+ to ensure backwards compatibility! 
  35. * NOTE II: Both filters WON'T work for WooCommerce v2.1.6+ ! 
  36. */ 
  37. $wcde_read_accept_string = apply_filters( 
  38. 'wcde_filter_gettext_read_accept_string',  
  39. 'Bedingungen gelesen und zur Kenntnis genommen:' 
  40. ); 
  41.  
  42. $wcde_terms_string = apply_filters( 
  43. 'wcde_filter_gettext_terms_string',  
  44. 'Liefer- und Zahlungsbedingungen (AGB)' 
  45. ); 
  46.  
  47.  
  48. /** 
  49. * New string labels: for strings of WooCommerce v2.1.6 or onwards! 
  50. * @since 3.1.5 
  51. */ 
  52. $wcde_terms_conditions_translation = 'Bedingungen gelesen und zur Kenntnis genommen: <a href="%s" target="_blank">Liefer- und Zahlungsbedingungen (AGB)</a>'; 
  53.  
  54. $wcde_terms_conditions_string = apply_filters( 
  55. 'wcde_filter_terms_conditions_string',  
  56. $wcde_terms_conditions_translation 
  57. ); 
  58.  
  59.  
  60. /** Set up our array of planned string swap keys/ strings */ 
  61. $wcde_labels = array( 
  62.  
  63. /** Read/accept string */ 
  64. 'read_accept_string' => array( 
  65. 'option_key' => 'read_accept_string',  
  66. 'strings' => array( 
  67. 'I have read and accept the',  
  68. 'I accept the' 
  69. ),  
  70. 'translation' => esc_attr__( $wcde_read_accept_string ),  
  71. ),  
  72.  
  73. /** Terms string */ 
  74. 'terms_string' => array( 
  75. 'option_key' => 'term_string',  
  76. 'strings' => array( 'terms & conditions' ),  
  77. 'translation' => esc_attr__( $wcde_terms_string ),  
  78. ),  
  79.  
  80. /** Terms & Conditions string */ 
  81. 'terms_conditions_string' => array( 
  82. 'option_key' => 'terms_conditions_string',  
  83. 'strings' => array( 'I’ve read and accept the <a href="%s" target="_blank">terms & conditions</a>' ),  
  84. 'translation' => $wcde_terms_conditions_string,  
  85.  
  86. ); // end of array 
  87.  
  88. /** Apply our string swapper for each string or our array */ 
  89. foreach ( $wcde_labels as $wcde_label => $label_id ) { 
  90.  
  91. /** Actually load the various new label strings for display */ 
  92. $label_id[ 'option_key' ],  
  93. (array) $label_id[ 'strings' ],  
  94. $label_id[ 'translation' ] 
  95. ); 
  96.  
  97. } // end foreach 
  98.  
  99. } // end of function ddw_wcde_do_string_swaps