GFCPTAddon

The Gravity Forms + Custom Post Types GFCPTAddon class.

Defined (1)

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

/gfcptaddon.php  
  1. class GFCPTAddon { 
  2.  
  3. private static $name = 'Gravity Forms + Custom Post Types'; 
  4. private static $slug = 'GFCPTAddon'; 
  5. private static $version = '2.0'; 
  6. private static $min_gravityforms_version = '1.5'; 
  7.  
  8. //Plugin starting point. Will load appropriate files 
  9. public static function init() { 
  10.  
  11. if(self::is_gravityforms_installed()) { 
  12.  
  13. global $gf_cpt_addon; 
  14.  
  15. //include the base class 
  16. require_once(self::get_base_path() . '/gfcptaddonbase.php'); 
  17.  
  18. //only supports 1.5 and over 
  19. require_once(self::get_base_path() . '/gfcptaddon_1-5.php'); 
  20. $gf_cpt_addon = new GFCPTAddon1_5(); 
  21.  
  22. //start me up! 
  23. $gf_cpt_addon->init(__FILE__); 
  24.  
  25. //display admin warnings if GF is not the correct version or GF is not installed 
  26. public static function admin_warnings() { 
  27. if ( !self::is_gravityforms_installed() ) { 
  28. $message = __('requires Gravity Forms to be installed.', self::$slug); 
  29. } else if ( !self::is_gravityforms_supported() ) { 
  30. $message = __('requires a minimum Gravity Forms version of ', self::$slug) . self::$min_gravityforms_version; 
  31.  
  32. if (empty($message)) { 
  33. return; 
  34. ?> 
  35. <div class="error"> 
  36. <p> 
  37. <?php _e('The plugin ', self::$slug); ?><strong><?php echo self::$name; ?></strong> <?php echo $message; ?><br /> 
  38. <?php _e('Please ', self::$slug); ?><a href="http://bit.ly/getgravityforms"><?php _e(' download the latest version ', self::$slug); ?></a><?php _e(' of Gravity Forms and try again.', self::$slug) ?> 
  39. </p> 
  40. </div> 
  41. <?php 
  42.  
  43. /** 
  44. * Check if GF is installed 
  45. */ 
  46. private static function is_gravityforms_installed() { 
  47. return class_exists( 'RGForms' ); 
  48.  
  49. /** 
  50. * Check if the installed version of GF is supported 
  51. */ 
  52. private static function is_gravityforms_supported() { 
  53. return self::check_gravityforms_version( self::$min_gravityforms_version, '>=' ); 
  54.  
  55. /** 
  56. * Do a GF version compare 
  57. */ 
  58. private static function check_gravityforms_version($version, $operator) { 
  59. if(class_exists('GFCommon')) { 
  60. return version_compare( GFCommon::$version, $version, $operator ); 
  61. return false; 
  62.  
  63. /** 
  64. * Returns the url of the plugin's root folder 
  65. */ 
  66. protected function get_base_url() { 
  67. return plugins_url(null, __FILE__); 
  68.  
  69. /** 
  70. * Returns the physical path of the plugin's root folder 
  71. */ 
  72. protected function get_base_path() { 
  73. $folder = basename(dirname(__FILE__)); 
  74. return WP_PLUGIN_DIR . '/' . $folder; 
  75.  
  76. /** 
  77. * starts_with 
  78. * Tests if a text starts with an given string. 
  79. * @param string 
  80. * @param string 
  81. * @return bool 
  82. */ 
  83. public static function starts_with($haystack, $needle) { 
  84. return strpos($haystack, $needle) === 0; 
  85.  
  86. /** 
  87. * returns true if a needle can be found in a haystack 
  88. */ 
  89. public static function str_contains($haystack, $needle) { 
  90. if (empty($haystack) || empty($needle)) 
  91. return false; 
  92.  
  93. $pos = strpos(strtolower($haystack), strtolower($needle)); 
  94.  
  95. if ($pos === false) 
  96. return false; 
  97. else 
  98. return true;