/app/helper/class-ms-helper-shortcode.php

  1. <?php 
  2. /** 
  3. * This Helper creates utility functions for working with shortcodes. 
  4. * 
  5. * @since 1.0.0 
  6. * @package Membership2 
  7. * @subpackage Controller 
  8. */ 
  9. class MS_Helper_Shortcode extends MS_Helper { 
  10.  
  11. const SCODE_REGISTER_USER = 'ms-membership-register-user'; 
  12.  
  13. const SCODE_SIGNUP = 'ms-membership-signup'; 
  14.  
  15. const SCODE_MS_TITLE = 'ms-membership-title'; 
  16.  
  17. const SCODE_MS_DETAILS = 'ms-membership-details'; 
  18.  
  19. const SCODE_MS_PRICE = 'ms-membership-price'; 
  20.  
  21. const SCODE_MS_BUY = 'ms-membership-buy'; 
  22.  
  23. const SCODE_PROTECTED = 'ms-protection-message'; 
  24.  
  25. const SCODE_LOGIN = 'ms-membership-login'; 
  26.  
  27. const SCODE_LOGOUT = 'ms-membership-logout'; 
  28.  
  29. const SCODE_MS_ACCOUNT = 'ms-membership-account'; 
  30.  
  31. const SCODE_MS_ACCOUNT_LINK = 'ms-membership-account-link'; 
  32.  
  33. const SCODE_MS_INVOICE = 'ms-invoice'; 
  34.  
  35. const SCODE_NOTE = 'ms-note'; 
  36.  
  37. const SCODE_USER = 'ms-user'; 
  38.  
  39. const SCODE_MEMBER_INFO = 'ms-member-info'; 
  40.  
  41. // deprecated, replaced by SCODE_NOTE 
  42. const SCODE_GREEN_NOTE = 'ms-green-note'; 
  43.  
  44. // deprecated, replaced by SCODE_NOTE 
  45. const SCODE_RED_NOTE = 'ms-red-note'; 
  46.  
  47. /** 
  48. * Holds an array of all replaced Membership2 shortcodes. 
  49. * 
  50. * @since 1.0.0 
  51. * 
  52. * @var array 
  53. */ 
  54. protected static $did_shortcodes = array(); 
  55.  
  56.  
  57. /** 
  58. * This function searches content for the presence of a given short code. 
  59. * 
  60. * Returns 'true' if shortcode is found or 'false' if the shortcode is not found. 
  61. * 
  62. * @since 1.0.0 
  63. * @param string $shortcode The shortcode to find. 
  64. * @param string $content The string to search. 
  65. * @return boolean 
  66. */ 
  67. public static function has_shortcode( $shortcode, $content ) { 
  68. $result = false; 
  69.  
  70. if ( isset( self::$did_shortcodes[$shortcode] ) ) { 
  71. $result = self::$did_shortcodes[$shortcode]; 
  72. } else { 
  73. // Use WP core function `has_shortcode` instead of own logic. 
  74. $result = has_shortcode( $content, $shortcode ); 
  75.  
  76. return $result; 
  77.  
  78. /** 
  79. * Resets the shortcode-memory. 
  80. * 
  81. * This is required when a page has multiple calls to the_content - if the 
  82. * usage would not be reset, then only the first call to the_content would 
  83. * actually add certain shortcodes. 
  84. * 
  85. * @since 1.0.0 
  86. */ 
  87. public static function reset_shortcode_usage() { 
  88. self::$did_shortcodes = array(); 
  89.  
  90. /** 
  91. * Remembers that a shortcode was inserted already. 
  92. * 
  93. * @since 1.0.0 
  94. * @param string $shortcode The Membership2 shortcode. 
  95. */ 
  96. public static function did_shortcode( $shortcode ) { 
  97. self::$did_shortcodes[$shortcode] = true; 
  98.  
  99. /** 
  100. * Get all membership plugin shortcodes 
  101. * 
  102. * @since 1.0.0 
  103. * @return string[] 
  104. */ 
  105. public static function get_membership_shortcodes() { 
  106. return apply_filters( 
  107. 'ms_helper_shortcode_get_membership_shortcodes',  
  108. array( 
  109. self::SCODE_REGISTER_USER,  
  110. self::SCODE_SIGNUP,  
  111. self::SCODE_MS_TITLE,  
  112. self::SCODE_MS_DETAILS,  
  113. self::SCODE_MS_PRICE,  
  114. self::SCODE_MS_BUY,  
  115. self::SCODE_PROTECTED,  
  116. self::SCODE_LOGIN,  
  117. self::SCODE_LOGOUT,  
  118. self::SCODE_MS_ACCOUNT,  
  119. self::SCODE_MS_ACCOUNT_LINK,  
  120. self::SCODE_MS_INVOICE,  
  121. self::SCODE_NOTE,  
  122. self::SCODE_USER,  
  123. self::SCODE_GREEN_NOTE /** deprecated, replaced by SCODE_NOTE */,  
  124. self::SCODE_RED_NOTE /** deprecated, replaced by SCODE_NOTE */,  
  125. ); 
.