Guest User

Untitled

a guest
Jul 17th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. <?php
  2. /**
  3. * Performs necessary hooks to get things going in the admin
  4. *
  5. * @author Matt Martz <matt@sivel.net>
  6. * @package plugin-update-ignore
  7. * @subpackage admin
  8. * @since 1.0
  9. */
  10.  
  11. class PluginUpdateIgnoreAdmin extends PluginUpdateIgnore {
  12.  
  13. public $arrPluginCount = array(); // Plugin Count
  14.  
  15. /**
  16. * PHP4 style constructor.
  17. *
  18. * Calls the below PHP5 style constructor.
  19. *
  20. * @author Matt Martz <matt@sivel.net>
  21. * @since 1.0
  22. * @return none
  23. */
  24. function PluginUpdateIgnoreAdmin() {
  25. $this->__construct();
  26. }
  27.  
  28. /**
  29. * PHP5 style contructor
  30. *
  31. * Hooks into all of the necessary WordPress actions and filters needed
  32. * for this plugin to function
  33. *
  34. * @author Matt Martz <matt@sivel.net>
  35. * @since 1.0
  36. * @return none
  37. */
  38. function __construct() {
  39. PluginUpdateIgnore::__construct();
  40. add_action('admin_menu', array(&$this, 'add_options_page')) ;
  41. register_activation_hook($this->plugin_file, array(&$this, 'activation'));
  42. load_plugin_textdomain('plugin-update-ignore', false, $this->plugin_dir_basename . '/localization');
  43. }
  44.  
  45. /**
  46. * Action hook callback for activation
  47. *
  48. * Initializes the plugin for first time use
  49. *
  50. * @author Matt Martz <matt@sivel.net>
  51. * @since 1.0
  52. * @return none
  53. */
  54. function activation() {
  55. if ( ! is_array($this->ignores) )
  56. add_option('plugin_update_ignore', array());
  57. }
  58.  
  59. /**
  60. * Action hook callback to filter the plugin action links
  61. *
  62. * @author Matt Martz <matt@sivel.net>
  63. * @since 1.0
  64. * @return none
  65. */
  66. function add_options_page() {
  67. if ( current_user_can('update_plugins') ) {
  68. // Add the call to create a new plugin submenu here
  69. add_filter("plugin_action_links" ,array(&$this, 'filter_plugin_actions'), 10, 2);
  70. }
  71. }
  72.  
  73. /**
  74. * Action hook callback to populate update message show in below each plugin
  75. * requiring an update on plugins.php
  76. *
  77. * @author Matt Martz <matt@sivel.net>
  78. * @since 1.0
  79. * @param string $file plugin_basename of the current plugin the action was called for
  80. * @param array $plugin_data array of plugin information of the current plugin the action was called for
  81. * @return none
  82. */
  83. function wp_plugin_update_row($file, $plugin_data) {
  84.  
  85. //load plugin options
  86. $options_arr = get_option('pui_params');
  87. $pui_display_msg = $options_arr["pui_display_msg"];
  88.  
  89. $current = get_transient('update_plugins');
  90. if ( !isset($current->response[ $file ]) )
  91. return false;
  92.  
  93. if ( isset($this->ignores[$file]) ) {
  94. $this->arrPluginCount[] = $plugin_name;
  95. $r = $current->response[ $file ];
  96.  
  97. $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
  98. $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
  99.  
  100. $details_url = admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800');
  101.  
  102. //check if option is set to show update notices
  103. If ($pui_display_msg != "on") {
  104. echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message-ignore">';
  105. printf( __('The ability to update this plugin by automatic means has been disabled by the site administrator. However, it is reported that there is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a>.', 'plugin-update-ignore'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version );
  106. }
  107.  
  108. do_action( "in_plugin_update_message-$file", $plugin_data, $r );
  109.  
  110. echo '</div></td></tr>';
  111. } else {
  112. // If we are using WP < 2.9 we are replacing the after_plugin_row action for all plugins, so call the built in WP function, to keep from showing our custom message.
  113. wp_plugin_update_row($file, $plugin_data);
  114. }
  115. }
  116.  
  117. /**
  118. * Update Plugin Count
  119. *
  120. * @author Scott Basgaard <scott@webdevstudios.com>
  121. */
  122. function wds_plugin_count_add_js() {
  123. $update_plugins = get_transient( 'update_plugins' );
  124. $update_count = 0;
  125. if ( !empty($update_plugins->response) ) {
  126. $update_count = count( $update_plugins->response );
  127. }
  128. $lock_count = count($this->arrPluginCount);
  129. $total_update = $update_count - $lock_count;
  130. $js = array();
  131. if ($total_update <= 0) {
  132. $js[] = "\$('.plugin-count').remove();";
  133. } else if ($total_update > 0) {
  134. $js[] = "\$('.plugin-count').html(" . $total_update . ");";
  135. }
  136. if ( !empty($js) ) {
  137. $js = implode("\n", $js);
  138. echo '<script type="text/javascript">jQuery(document).ready(function($) { {'.$js.'} }); </script>';
  139. }
  140. }
  141.  
  142. /**
  143. * Filter hook callback to insert and modify plugin action links
  144. *
  145. * @author Matt Martz <matt@sivel.net>
  146. * @since 1.0
  147. * @param array $links array of current action links to be filtered
  148. * @param string $file plugin_basename of the current plugin the filter was called for
  149. * @return array array of plugin action links
  150. */
  151. function filter_plugin_actions($links, $file) {
  152. global $wp_version;
  153.  
  154. // Update Plugin Count
  155. add_action('admin_footer', array(&$this, 'wds_plugin_count_add_js'), 0);
  156.  
  157. // Remove the core update message action callback and use a custom one if this plugin is ignoring updates
  158. if ( isset($this->ignores[$file]) ) {
  159. if ( version_compare('2.9', preg_replace('/[a-z-]+/i', '', $wp_version), '<=') ) {
  160. remove_action("after_plugin_row_$file", 'wp_plugin_update_row', 10, 2);
  161. add_action("after_plugin_row_$file", array(&$this, 'wp_plugin_update_row'), 10, 2);
  162. } else {
  163. remove_action('after_plugin_row', 'wp_plugin_update_row', 10, 2);
  164. add_action('after_plugin_row', array(&$this, 'wp_plugin_update_row'), 10, 2);
  165. }
  166.  
  167. }
  168. $current = get_transient('update_plugins');
  169. $update_class = isset($current->response[ $file ]) ? 'update' : 'noupdate';
  170. $class = str_replace(array('/','.'), '-', $file);
  171. $linktext = isset($this->ignores[$file]) ? __('Un-Ignore Updates') : __('Ignore Updates');
  172. // The href here is only good for non JS calls, when we add an AJAX call we need to not include _wp_http_referer,
  173. // this is so we can degrade to nicely if JS isn't available
  174. $links[] = "<img class='{$class}-spin hidden' src='" . admin_url('images/wpspin_light.gif') . "' alt='" . __('Loading...', 'ajax-plugin-helper') . "' /><a class='plugin-update-ignore {$class}-switch {$update_class}' href='" . admin_url('admin-ajax.php?action=pluginupdateignoreswitch&plugin=' . $file . '&_wpnonce=' . wp_create_nonce() . "&_wp_http_referer=" . urlencode(stripslashes($_SERVER['REQUEST_URI']))) . "' rel='$file'>$linktext</a>";
  175. return $links;
  176. }
  177.  
  178. }
Add Comment
Please, Sign In to add comment