PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/commentpress-multisite/commentpress-mu.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 219 lines | 54 code | 80 blank | 85 comment | 9 complexity | e6dcf8b2d5d3479291597cfb7bf5525e MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php /*
  2. ================================================================================
  3. CommentPress for Multisite
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. =====
  9. This used to be the CommentPress for Multisite plugin, but is now merged into
  10. a unified plugin that covers all situations.
  11. --------------------------------------------------------------------------------
  12. */
  13. // define version
  14. define( 'COMMENTPRESS_MU_PLUGIN_VERSION', '1.0' );
  15. /*
  16. --------------------------------------------------------------------------------
  17. Init Multisite plugin
  18. --------------------------------------------------------------------------------
  19. */
  20. // do we have our class?
  21. if ( !class_exists( 'CommentpressMultisiteLoader' ) ) {
  22. // define filename
  23. $class_file = 'commentpress-multisite/class_commentpress_mu_loader.php';
  24. // get path
  25. $class_file_path = commentpress_file_is_present( $class_file );
  26. // we're fine, include class definition
  27. require_once( $class_file_path );
  28. // define as global
  29. global $commentpress_mu;
  30. // instantiate it
  31. $commentpress_mu = new CommentpressMultisiteLoader;
  32. }
  33. /*
  34. --------------------------------------------------------------------------------
  35. Misc Utility Functions
  36. --------------------------------------------------------------------------------
  37. */
  38. /**
  39. * @description: get WP plugin reference by name (since we never know for sure what the enclosing
  40. * directory is called)
  41. * @todo:
  42. *
  43. */
  44. function commentpress_mu_find_plugin_by_name( $plugin_name = '' ) {
  45. // kick out if no param supplied
  46. if ( $plugin_name == '' ) { return false; }
  47. // init path
  48. $path_to_plugin = false;
  49. // get plugins
  50. $plugins = get_plugins();
  51. //print_r( $plugins ); die();
  52. // because the key is the path to the plugin file, we have to find the
  53. // key by iterating over the values (which are arrays) to find the
  54. // plugin with the desired name. Doh!
  55. foreach( $plugins AS $key => $plugin ) {
  56. // is it ours?
  57. if ( $plugin['Name'] == $plugin_name ) {
  58. // now get the key, which is our path
  59. $path_to_plugin = $key;
  60. break;
  61. }
  62. }
  63. // --<
  64. return $path_to_plugin;
  65. }
  66. /*
  67. --------------------------------------------------------------------------------
  68. Force a plugin to activate: adapted from https://gist.github.com/1966425
  69. Audited with reference to activate_plugin() with extra commenting inline
  70. --------------------------------------------------------------------------------
  71. */
  72. /**
  73. * @description: Helper to activate a plugin on another site without causing a
  74. * fatal error by including the plugin file a second time
  75. * Based on activate_plugin() in wp-admin/includes/plugin.php
  76. * $buffer option is used for plugins which send output
  77. * @todo:
  78. *
  79. */
  80. function commentpress_mu_activate_plugin( $plugin, $buffer = false ) {
  81. // find our already active plugins
  82. $current = get_option( 'active_plugins', array() );
  83. // no need to validate it...
  84. // check that the plugin isn't already active
  85. if ( !in_array( $plugin, $current ) ) {
  86. // no need to redirect...
  87. // open buffer if required
  88. if ( $buffer ) { ob_start(); }
  89. // safe include
  90. // Note: this a valid use of WP_PLUGIN_DIR since there is no plugins_dir()
  91. include_once( WP_PLUGIN_DIR . '/' . $plugin );
  92. // no need to check silent activation, just go ahead...
  93. do_action( 'activate_plugin', $plugin );
  94. do_action( 'activate_' . $plugin );
  95. // housekeeping
  96. $current[] = $plugin;
  97. sort( $current );
  98. update_option( 'active_plugins', $current );
  99. do_action( 'activated_plugin', $plugin );
  100. // close buffer if required
  101. if ( $buffer ) { ob_end_clean(); }
  102. }
  103. }
  104. /**
  105. * @description: utility to show theme environment
  106. * @todo:
  107. *
  108. */
  109. function _commentpress_mu_environment() {
  110. // don't show in admin
  111. if ( !is_admin() ) {
  112. // dump our environment
  113. echo '<strong>TEMPLATEPATH</strong><br />'.TEMPLATEPATH.'<br /><br />';
  114. echo '<strong>STYLESHEETPATH</strong><br />'.STYLESHEETPATH.'<br /><br />';
  115. echo '<strong>template_directory</strong><br />'.get_bloginfo('template_directory').'<br /><br />';
  116. echo '<strong>stylesheet_directory</strong><br />'.get_bloginfo('stylesheet_directory').'<br /><br />';
  117. echo '<strong>template_url</strong><br />'.get_bloginfo('template_url').'<br /><br />';
  118. echo '<strong>stylesheet_url</strong><br />'.get_bloginfo('stylesheet_url').'<br /><br />';
  119. echo '<strong>get_template_directory</strong><br />'.get_template_directory().'<br /><br />';
  120. echo '<strong>get_stylesheet_directory</strong><br />'.get_stylesheet_directory().'<br /><br />';
  121. echo '<strong>get_stylesheet_directory_uri</strong><br />'.get_stylesheet_directory_uri().'<br /><br />';
  122. echo '<strong>get_template_directory_uri</strong><br />'.get_template_directory_uri().'<br /><br />';
  123. echo '<strong>locate_template</strong><br />'.locate_template( array( 'style/js/cp_js_common.js' ), false ).'<br /><br />';
  124. die();
  125. }
  126. }
  127. //add_action( 'template_redirect', '_commentpress_mu_environment' );
  128. /**
  129. * @description: utility to show tests
  130. * @todo:
  131. *
  132. */
  133. function _commentpress_mu_test() {
  134. global $commentpress_core;
  135. //print_r( $commentpress_core ); die();
  136. }
  137. //add_action( 'wp_head', '_commentpress_mu_test' );