MS_Helper_Shortcode

This Helper creates utility functions for working with shortcodes.

Defined (1)

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

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