GFPDF_Major_Compatibility_Checks

Our initialisation class Check all the dependancy requirements are met, otherwise fallback and show appropriate user error.

Defined (1)

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

/pdf.php  
  1. class GFPDF_Major_Compatibility_Checks { 
  2.  
  3. /** 
  4. * The plugin's basename 
  5. * @var string 
  6. * @since 4.0 
  7. */ 
  8. private $basename; 
  9.  
  10. /** 
  11. * The path to the plugin 
  12. * @var string 
  13. * @since 4.0 
  14. */ 
  15. private $path; 
  16.  
  17. /** 
  18. * Holds any blocker error messages stopping plugin running 
  19. * @var array 
  20. * @since 4.0 
  21. */ 
  22. private $notices = array(); 
  23.  
  24. /** 
  25. * The plugin's required Gravity Forms version 
  26. * @var string 
  27. * @since 4.0 
  28. */ 
  29. public $required_gf_version = '1.9'; 
  30.  
  31. /** 
  32. * The plugin's required WordPress version 
  33. * @var string 
  34. * @since 4.0 
  35. */ 
  36. public $required_wp_version = '4.2'; 
  37.  
  38. /** 
  39. * The plugin's required PHP version 
  40. * Gravity PDF 4.0 is such a major release that we can afford to also bump up the version requirements. 
  41. * We really wanted to bump this up to an actively supported version of PHP (http://php.net/supported-versions.php) 
  42. * but with WordPress supporting PHP5.2+ (and making no moves to increase this) we had to strike a balance. 
  43. * The initial release will require PHP 5.4 which will strike a better balance. 
  44. * @var string 
  45. * @since 4.0 
  46. */ 
  47. public $required_php_version = '5.4'; 
  48.  
  49. /** 
  50. * Set our required variables for a fallback and attempt to initialise 
  51. * @param string $basename Plugin basename 
  52. * @param string $path The plugin path 
  53. * @since 4.0 
  54. */ 
  55. public function __construct( $basename = '', $path = '' ) { 
  56.  
  57. /** Set our class variables */ 
  58. $this->basename = $basename; 
  59. $this->path = $path; 
  60.  
  61. /** 
  62. * Load the plugin 
  63. * @return void 
  64. * @since 4.0 
  65. */ 
  66. public function init() { 
  67. add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); 
  68.  
  69. /** 
  70. * Check if dependancies are met and load plugin, otherwise display errors 
  71. * @return void 
  72. * @since 4.0 
  73. */ 
  74. public function plugins_loaded() { 
  75.  
  76. /** Check minimum requirements are met */ 
  77. $this->is_compatible_wordpress_version(); 
  78. $this->check_gravity_forms(); 
  79. $this->check_php(); 
  80. $this->check_mb_string(); 
  81. $this->check_mb_string_regex(); 
  82. $this->check_gd(); 
  83. $this->check_dom(); 
  84. $this->check_ram( ini_get( 'memory_limit' ) ); 
  85.  
  86. /** Check if any errors were thrown, enqueue them and exit early */ 
  87. if ( sizeof( $this->notices ) > 0 ) { 
  88. add_action( 'admin_notices', array( $this, 'display_notices' ) ); 
  89.  
  90. return null; 
  91.  
  92. require_once $this->path . 'src/bootstrap.php'; 
  93.  
  94. /** 
  95. * Check if WordPress version is compatible 
  96. * @return boolean Whether compatible or not 
  97. * @since 4.0 
  98. */ 
  99. public function is_compatible_wordpress_version() { 
  100. global $wp_version; 
  101.  
  102. /** WordPress version not compatible */ 
  103. if ( ! version_compare( $wp_version, $this->required_wp_version, '>=' ) ) { 
  104. $this->notices[] = sprintf( esc_html__( 'WordPress Version %s is required. %sGet more info%s.', 'gravity-forms-pdf-extended' ), $this->required_wp_version, '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#wordpress-version">', '</a>' ); 
  105.  
  106. return false; 
  107.  
  108. return true; 
  109.  
  110. /** 
  111. * Check if Gravity Forms version is compatible 
  112. * @return boolean Whether compatible or not 
  113. * @since 4.0 
  114. */ 
  115. public function check_gravity_forms() { 
  116.  
  117. /** Gravity Forms version not compatible */ 
  118. if ( ! class_exists( 'GFCommon' ) || ! version_compare( GFCommon::$version, $this->required_gf_version, '>=' ) ) { 
  119. $this->notices[] = sprintf( esc_html__( '%sGravity Forms%s Version %s is required. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://www.e-junkie.com/ecom/gb.php?cl=54585&c=ib&aff=235154">', '</a>', $this->required_gf_version, '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#gravityforms-version">', '</a>' ); 
  120.  
  121. return false; 
  122.  
  123. return true; 
  124.  
  125. /** 
  126. * Check if PHP version is compatible 
  127. * @return boolean Whether compatible or not 
  128. * @since 4.0 
  129. */ 
  130. public function check_php() { 
  131.  
  132. /** Check PHP version is compatible */ 
  133. if ( ! version_compare( phpversion(), $this->required_php_version, '>=' ) ) { 
  134. $this->notices[] = sprintf( esc_html__( 'You are running an %soutdated version of PHP%s. Contact your web hosting provider to update. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="http://www.wpupdatephp.com/update/">', '</a>', '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-version">', '</a>' ); 
  135.  
  136. return false; 
  137.  
  138. return true; 
  139.  
  140. /** 
  141. * Check if PHP MB String enabled 
  142. * @return boolean Whether compatible or not 
  143. * @since 4.0 
  144. */ 
  145. public function check_mb_string() { 
  146.  
  147. /** Check MB String is installed */ 
  148. if ( ! extension_loaded( 'mbstring' ) ) { 
  149. $this->notices[] = sprintf( esc_html__( 'The PHP Extension MB String could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-mbstring">', '</a>' ); 
  150.  
  151. return false; 
  152.  
  153. return true; 
  154.  
  155. /** 
  156. * Check if MB String Regex enabled 
  157. * @return boolean Whether compatible or not 
  158. * @since 4.0 
  159. */ 
  160. public function check_mb_string_regex() { 
  161.  
  162. /** Check MB String is compiled with regex capabilities */ 
  163. if ( extension_loaded( 'mbstring' ) && ! function_exists( 'mb_regex_encoding' ) ) { 
  164. $this->notices[] = sprintf( esc_html__( 'The PHP Extension MB String does not have MB Regex enabled. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-mbstring-regex">', '</a>' ); 
  165.  
  166. return false; 
  167.  
  168. return true; 
  169.  
  170. /** 
  171. * Check if PHP GD Library installed 
  172. * @return boolean Whether compatible or not 
  173. * @since 4.0 
  174. */ 
  175. public function check_gd() { 
  176.  
  177. /** Check GD Image Library is installed */ 
  178. if ( ! extension_loaded( 'gd' ) ) { 
  179. $this->notices[] = sprintf( esc_html__( 'The PHP Extension GD Image Library could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-gd">', '</a>' ); 
  180.  
  181. return false; 
  182.  
  183. return true; 
  184.  
  185. /** 
  186. * Check if PHP DOM / libxml installed 
  187. * @return boolean Whether compatible or not 
  188. * @since 4.0 
  189. */ 
  190. public function check_dom() { 
  191.  
  192. /** Check DOM Class is installed */ 
  193. if ( ! extension_loaded( 'dom' ) || ! class_exists( 'DOMDocument' ) ) { 
  194. $this->notices[] = sprintf( esc_html__( 'The PHP DOM Extension was not found. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-dom">', '</a>' ); 
  195.  
  196. return false; 
  197.  
  198. /** Check libxml is loaded */ 
  199. if ( ! extension_loaded( 'libxml' ) ) { 
  200. $this->notices[] = sprintf( esc_html__( 'The PHP Extension libxml could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v4/user-activation-errors/#php-xml">', '</a>' ); 
  201.  
  202. return false; 
  203.  
  204. return true; 
  205.  
  206. /** 
  207. * Check if minimum RAM requirements met 
  208. * @param string $ram The PHP RAM setting 
  209. * @return boolean Whether compatible or not 
  210. * @since 4.0 
  211. */ 
  212. public function check_ram( $ram ) { 
  213.  
  214. /** Check Minimum RAM requirements */ 
  215. $ram = $this->get_ram( $ram ); 
  216.  
  217. if ( $ram < 64 && $ram !== -1 ) { 
  218. $this->notices[] = sprintf( esc_html__( "You need %s128MB%s of WP Memory (RAM) but we only found %s available. %sTry these methods to increase your memory limit%s, otherwise contact your web hosting provider to fix.", 'gravity-forms-pdf-extended' ), '<strong>', '</strong>', $ram . 'MB', '<a href="https://gravitypdf.com/documentation/v4/user-increasing-memory-limit/">', '</a>' ); 
  219.  
  220. return false; 
  221.  
  222. return true; 
  223.  
  224.  
  225. /** 
  226. * Get the available system memory 
  227. * @param string $ram The PHP RAM setting 
  228. * @return integer The calculated RAM 
  229. * @since 4.0 
  230. */ 
  231. public function get_ram( $ram ) { 
  232.  
  233. /** Get memory in standardised bytes format */ 
  234. $memory_limit = $this->convert_ini_memory( $ram ); 
  235.  
  236. /** Convert to megabytes, or set to -1 if unlimited */ 
  237. return ( $memory_limit === '-1' ) ? -1 : floor( $memory_limit / 1024 / 1024 ); 
  238.  
  239. /** 
  240. * Convert .ini file memory to bytes 
  241. * @param string $memory The .ini memory limit 
  242. * @return integer The calculated memory limit in bytes 
  243. */ 
  244. public function convert_ini_memory( $memory ) { 
  245.  
  246. $convert = array( 'mb' => 'm', 'kb' => 'k', 'gb' => 'g' ); 
  247.  
  248. /** Standardise format */ 
  249. foreach ( $convert as $k => $v ) { 
  250. $memory = str_ireplace( $k, $v, $memory ); 
  251.  
  252. /** Check if memory allocation is in mb, kb or gb */ 
  253. switch ( strtolower( substr( $memory, -1 ) ) ) { 
  254. case 'm': 
  255. return (int) $memory * 1048576; 
  256. case 'k': 
  257. return (int) $memory * 1024; 
  258. case 'g': 
  259. return (int) $memory * 1073741824; 
  260.  
  261. return $memory; 
  262.  
  263.  
  264. /** 
  265. * Helper function to easily display error messages 
  266. * @return void 
  267. * @since 4.0 
  268. */ 
  269. public function display_notices() { 
  270. ?> 
  271. <div class="error"> 
  272. <p><strong><?php esc_html_e( 'Gravity PDF Installation Problem', 'gravity-forms-pdf-extended' ); ?></strong></p> 
  273.  
  274. <p><?php esc_html_e( 'The minimum requirements for Gravity PDF have not been met. Please fix the issue(s) below to continue:', 'gravity-forms-pdf-extended' ); ?></p> 
  275. <ul style="padding-bottom: 0.5em"> 
  276. <?php foreach ( $this->notices as $notice ) : ?> 
  277. <li style="padding-left: 20px;list-style: inside"><?php echo $notice; ?></li> 
  278. <?php endforeach; ?> 
  279. </ul> 
  280. </div> 
  281. <?php