/wp-content/plugins/ml-slider/inc/metaslider.systemcheck.class.php

https://gitlab.com/thisishayat/itv-2016 · PHP · 156 lines · 99 code · 26 blank · 31 comment · 32 complexity · 8d46f8c8a38ceac15c06a50f7528be87 MD5 · raw file

  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // disable direct access
  4. }
  5. /**
  6. * Check for common issues with the server environment and WordPress install.
  7. */
  8. class MetaSliderSystemCheck {
  9. var $options = array();
  10. /**
  11. * Constructor
  12. */
  13. public function __construct() {
  14. $this->options = get_site_option( 'metaslider_systemcheck' );
  15. }
  16. /**
  17. * Check the system
  18. */
  19. public function check() {
  20. $this->dismissMessages();
  21. $this->checkWordPressVersion();
  22. $this->checkImageLibrary();
  23. $this->checkRoleScoper();
  24. //$this->checkWpFooter();
  25. $this->updateSystemCheck();
  26. }
  27. /**
  28. * Disable a message
  29. */
  30. private function dismissMessages() {
  31. if ( isset( $_REQUEST['dismissMessage'] ) && isset( $_REQUEST['_wpnonce'] ) ) {
  32. $nonce = $_REQUEST['_wpnonce'];
  33. $key = $_REQUEST['dismissMessage'];
  34. if ( wp_verify_nonce( $nonce, "metaslider-dismiss-{$key}" ) ) {
  35. $this->options[$key] = false;
  36. update_site_option( 'metaslider_systemcheck', $this->options );
  37. }
  38. }
  39. }
  40. /**
  41. * Update our stored messages
  42. */
  43. private function updateSystemCheck() {
  44. update_site_option( 'metaslider_systemcheck', $this->options );
  45. }
  46. /**
  47. * Check the WordPress version.
  48. */
  49. private function checkWordPressVersion() {
  50. if ( isset( $this->options['wordPressVersion'] ) && $this->options['wordPressVersion'] === false ) {
  51. return;
  52. }
  53. if ( !function_exists( 'wp_enqueue_media' ) ) {
  54. $error = "Meta Slider requires WordPress 3.5 or above. Please upgrade your WordPress installation.";
  55. $this->printMessage( $error, 'wordPressVersion' );
  56. } else {
  57. $this->options['wordPressVersion'] = false;
  58. }
  59. }
  60. /**
  61. * Check GD or ImageMagick library exists
  62. */
  63. private function checkImageLibrary() {
  64. if ( isset( $this->options['imageLibrary'] ) && $this->options['imageLibrary'] === false ) {
  65. return;
  66. }
  67. if ( ( !extension_loaded( 'gd' ) || !function_exists( 'gd_info' ) ) && ( !extension_loaded( 'imagick' ) || !class_exists( 'Imagick' ) || !class_exists( 'ImagickPixel' ) ) ) {
  68. $error = "Meta Slider requires the GD or ImageMagick PHP extension. Please contact your hosting provider";
  69. $this->printMessage( $error, 'imageLibrary' );
  70. } else {
  71. $this->options['imageLibrary'] = false;
  72. }
  73. }
  74. /**
  75. * Detect the role scoper plugin
  76. */
  77. private function checkRoleScoper() {
  78. if ( isset( $this->options['roleScoper'] ) && $this->options['roleScoper'] === false ) {
  79. return;
  80. }
  81. if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'role-scoper/role-scoper.php' ) ) {
  82. $access_types = get_option( 'scoper_disabled_access_types' );
  83. if ( isset( $access_types['front'] ) && !$access_types['front'] ) {
  84. $error = 'Role Scoper Plugin Detected. Please go to Roles > Options. Click the Realm Tab, scroll down to "Access Types" and uncheck the "Viewing content (front-end)" setting.';
  85. $this->printMessage( $error, 'roleScoper' );
  86. }
  87. }
  88. }
  89. /**
  90. * Check the theme has a call to 'wp_footer'
  91. */
  92. private function checkWpFooter() {
  93. $current_theme = wp_get_theme();
  94. $theme_name = $current_theme->Template;
  95. $key = 'wpFooter:' . $theme_name;
  96. if ( isset( $this->options[$key] ) && $this->options[$key] === false ) {
  97. return;
  98. }
  99. $child_footer = get_stylesheet_directory() . '/footer.php';
  100. $parent_footer = TEMPLATEPATH . '/footer.php';
  101. $theme_type = 'parent';
  102. if ( file_exists( $child_footer ) ) {
  103. $theme_type = 'child';
  104. $footer_file = file_get_contents( $child_footer );
  105. if ( strpos( $footer_file, 'wp_footer()' ) ) {
  106. return;
  107. }
  108. } else if ( file_exists( $parent_footer . '/footer.php' ) ) {
  109. $theme_type = 'parent';
  110. $footer_file = file_get_contents( $parent_footer . '/footer.php' );
  111. if ( strpos( $footer_file, 'wp_footer()' ) ) {
  112. return;
  113. }
  114. }
  115. if ( $theme_type == 'parent' ) {
  116. $file_path = $parent_footer;
  117. } else {
  118. $file_path = $child_footer;
  119. }
  120. $error = "Required call to wp_footer() not found in file <b>{$file_path}</b>. <br /><br />Please check the <a href='http://codex.wordpress.org/Function_Reference/wp_footer'>wp_footer()</a> documentation and make sure your theme has a call to wp_footer() just above the closing </body> tag.";
  121. $this->printMessage( $error, $key );
  122. }
  123. /**
  124. * Print a warning message to the screen
  125. */
  126. private function printMessage( $message, $key ) {
  127. $nonce = wp_create_nonce( "metaslider-dismiss-{$key}" );
  128. echo "<div id='message' class='updated'><p><b>Warning:</b> {$message}<br /><br /><a class='button' href='?page=metaslider&dismissMessage={$key}&_wpnonce={$nonce}'>Hide</a></p></div>";
  129. }
  130. }