PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/code/cake/app/webroot/research/wp-content/plugins/debug-this/_inc/extensions.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 777 lines | 733 code | 42 blank | 2 comment | 45 complexity | 00193e2760120df89f1bbca514d6d4a3 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. if(!defined('ABSPATH')) die();
  3. class Debug_This_Extensions{
  4. public function __construct(){
  5. $version = get_bloginfo('version');
  6. add_debug_extension('actions', __('Actions', 'debug-this'), __('$wp_actions contains all active registered actions', 'debug-this'), array($this, 'actions'), 'Filters And Actions');
  7. add_debug_extension('apache', __('Apache Information', 'debug-this'), __('Apache version and list of modules', 'debug-this'), array($this, 'apache'), 'Server');
  8. add_debug_extension('attachments', __('Attachments', 'debug-this'), __('List of post attachments', 'debug-this'), array($this, 'attachments'), 'Media');
  9. add_debug_extension('author', __('Post Author', 'debug-this'), __('Current author data', 'debug-this'), array($this, 'author'), 'Users');
  10. add_debug_extension('backtrace', __('Backtrace', 'debug-this'), __('PHP Backtrace', 'debug-this'), array($this, 'backtrace'), 'PHP');
  11. add_debug_extension('bloginfo', __('Blog Info', 'debug-this'), __('Key/Values for get_bloginfo() or bloginfo()', 'debug-this'), array($this, 'bloginfo'));
  12. add_debug_extension('classes', __('Classes', 'debug-this'), __('Declared Classes', 'debug-this'), array($this, 'classes'), 'PHP');
  13. add_debug_extension('cache', __('Object Cache', 'debug-this'), __('Object Cache stats', 'debug-this'), array($this, 'cache'), 'Cache');
  14. add_debug_extension('constants', __('Constants', 'debug-this'), __('Defined Constants', 'debug-this'), array($this, 'constants'), 'PHP');
  15. add_debug_extension('constants-wp', __('Constants (WordPress)', 'debug-this'), __('Defined WordPress Constants', 'debug-this'), array($this, 'constants_wordpress'), 'PHP');
  16. add_debug_extension('content-width', __('Content Width', 'debug-this'), __('global $content_width', 'debug-this'), array($this, 'content_width'), 'Themes');
  17. add_debug_extension('context', __('Context', 'debug-this'), __('Conditional Context Tags', 'debug-this'), array($this, 'context'), 'Query');
  18. add_debug_extension('cron-schedules', __('WP Cron Schedules', 'debug-this'), __('WP Cron Schedules', 'debug-this'), array($this, 'cron_schedules'), 'Cron');
  19. add_debug_extension('cron-jobs', __('WP Cron Jobs', 'debug-this'), __('WP Cron Jobs', 'debug-this'), array($this, 'cron_jobs'), 'Cron');
  20. add_debug_extension('css', __('CSS', 'debug-this'), __('Rendered CSS', 'debug-this'), array($this, 'css'), 'Rendered HTML');
  21. add_debug_extension('dropins', __('Dropins', 'debug-this'), __('List of all dropins that replace core WP functionality', 'debug-this'), array($this, 'dropins'), 'Plugins');
  22. add_debug_extension('php-extensions', __('Extensions', 'debug-this'), __('List of all loaded PHP extensions', 'debug-this'), array($this, 'extensions'), 'PHP');
  23. add_debug_extension('file-permissions', __('File Permissions', 'debug-this'), __('Info about WP root, plugins and theme directories.', 'debug-this'), array($this, 'file_permissions'), 'Server');
  24. add_debug_extension('files', __('Files', 'debug-this'), __('All required and included files', 'debug-this'), array($this, 'files'), 'PHP');
  25. add_debug_extension('filters', __('Filters', 'debug-this'), __('$wp_filter contains all registered filters. Callback functions are contained in parentheses', 'debug-this'), array($this, 'filters'), 'Filters And Actions');
  26. add_debug_extension('filters-current', __('Current', 'debug-this'), __('Current Filters and Actions', 'debug-this'), array($this, 'filters_current'), 'Filters And Actions');
  27. add_debug_extension('functions', __('Functions', 'debug-this'), __('All defined user functions', 'debug-this'), array($this, 'functions'), 'PHP');
  28. add_debug_extension('images', __('Images', 'debug-this'), __('Rendered images on the current page/post', 'debug-this'), array($this, 'images'), 'Rendered HTML');
  29. add_debug_extension('imagesizes', __('Image Sizes', 'debug-this'), __('All registered image sizes. Uses get_intermediate_image_sizes() & global $_wp_additional_image_sizes', 'debug-this'), array($this, 'imagesizes'), 'Media');
  30. add_debug_extension('js', __('JavaScript', 'debug-this'), __('Rendered JS', 'debug-this'), array($this, 'js'), 'Rendered HTML');
  31. add_debug_extension('load-time', __('Load Time', 'debug-this'), __('True page load time (sans Debug This)', 'debug-this'), array($this, 'load_time'), 'Rendered HTML');
  32. add_debug_extension('menus', __('Registered Menus', 'debug-this'), __('All registered menus', 'debug-this'), array($this, 'menus'), 'Menus');
  33. add_debug_extension('menus_dynamic', __('Dynamic Menus', 'debug-this'), __('Dynamic Menus and Locations', 'debug-this'), array($this, 'menus_dynamic'), 'Menus');
  34. add_debug_extension('oembed', __('oEmbed', 'debug-this'), __('Registered oEmbed providers', 'debug-this'), array($this, 'oembed'), 'Media');
  35. add_debug_extension('options', __('Options', 'debug-this'), __('A list of all autoloaded options', 'debug-this'), array($this, 'options'));
  36. add_debug_extension('phpinfo', __('phpinfo()', 'debug-this'), __('phpinfo()', 'debug-this'), array($this, 'phpinfo'), 'PHP');
  37. add_debug_extension('phpini', __('php.ini', 'debug-this'), __('php.ini configuration', 'debug-this'), array($this, 'phpini'), 'PHP');
  38. add_debug_extension('plugins', __('Plugins', 'debug-this'), __('A list of all plugins', 'debug-this'), array($this, 'plugins'), 'Plugins');
  39. add_debug_extension('post', __('Post', 'debug-this'), __('Single post object', 'debug-this'), array($this, 'post'), 'Queried Object');
  40. add_debug_extension('post-meta', __('Post Meta', 'debug-this'), __('Post meta for the queried object.', 'debug-this'), array($this, 'post_meta'), 'Queried Object');
  41. add_debug_extension('posts', __('Post Objects', 'debug-this'), __('Archive post objects', 'debug-this'), array($this, 'posts'), 'Query');
  42. add_debug_extension('post-types', __('All Post Types', 'debug-this'), __('Lists all registered post types in WordPress', 'debug-this'), array($this, 'posttypes'), 'Post Types');
  43. add_debug_extension('post-type-current', __('Current Post Type', 'debug-this'), __('Post type for the queried object', 'debug-this'), array($this, 'posttype_current'), 'Post Types');
  44. add_debug_extension('queries', __('Saved Queries', 'debug-this'), __('All queries run on the current page load (sans Debug This)', 'debug-this'), array($this, 'queries'), 'Query');
  45. add_debug_extension('request', __('Request', 'debug-this'), __('Current request', 'debug-this'), array($this, 'request'), 'Query');
  46. add_debug_extension('rewrites', __('Rewrites', 'debug-this'), __('A list of all cached rewrites. To refresh the cache, visit Settings->Permalinks', 'debug-this'), array($this, 'rewrites'), 'Query');
  47. add_debug_extension('scripts', __('Scripts', 'debug-this'), __('List of registered scripts. Uses $wp_scripts', 'debug-this'), array($this, 'scripts'), 'Enqueue');
  48. add_debug_extension('server', __('$_SERVER', 'debug-this'), __('$_SERVER information', 'debug-this'), array($this, 'server'), 'Server');
  49. add_debug_extension('shortcodes', __('Shortcodes', 'debug-this'), __('List of all registered shortcodes', 'debug-this'), array($this, 'shortcodes'), 'Shortcodes');
  50. add_debug_extension('shortcodes-regex', __('Shortcodes Regex', 'debug-this'), __('Dynamically generated shortcode regex - get_shortcode_regex()', 'debug-this'), array($this, 'shortcodes_regex'), 'Shortcodes');
  51. add_debug_extension('sidebars-current', __('Current Sidebars', 'debug-this'), __('All instances of get_sidebar() and dynamic_sidebar() in the current template', 'debug-this'), array($this, 'sidebars_rendered'), 'Sidebar');
  52. add_debug_extension('sidebars', __('Registered Sidebars', 'debug-this'), __('All registered sidebars. Uses $wp_registered_sidebars', 'debug-this'), array($this, 'sidebars_registered'), 'Sidebar');
  53. add_debug_extension('styles', __('Styles', 'debug-this'), __('List of rendered and registered styles', 'debug-this'), array($this, 'styles'), 'Enqueue');
  54. add_debug_extension('taxonomies', __('Taxonomies', 'debug-this'), __('Lists all registered taxonomies in WordPress', 'debug-this'), array($this, 'taxonomies'), 'Taxonomy');
  55. add_debug_extension('template', __('Current Template', 'debug-this'), __('Current template file', 'debug-this'), array($this, 'template'), 'Themes');
  56. add_debug_extension('terms', __('Post Terms', 'debug-this'), __('All terms for the current single post/page', 'debug-this'), array($this, 'terms'), 'Taxonomy');
  57. add_debug_extension('terms-all', __('All Terms', 'debug-this'), __('A list of all terms', 'debug-this'), array($this, 'terms_all'), 'Taxonomy');
  58. if($version >= 3.4)
  59. add_debug_extension('themes', __('Themes', 'debug-this'), __('List of all WP_Theme objects', 'debug-this'), array($this, 'themes'), 'Themes');
  60. add_debug_extension('users', __('All Users', 'debug-this'), __('List of all users', 'debug-this'), array($this, 'users'), 'Users');
  61. add_debug_extension('variables', __('Variables', 'debug-this'), __('List of all defined variables', 'debug-this'), array($this, 'variables'), 'PHP');
  62. add_debug_extension('widgets', __('Widgets'), __('All registered widgets - uses $wp_widget_factor->widgets', 'debug-this'), array($this, 'widgets'), 'Sidebar');
  63. add_debug_extension('wp-debug', __('WP Debug'), __('Displays a list of notices rendered by WP_DEBUG mode', 'debug-this'), array($this, 'wp_debug'), 'PHP');
  64. add_debug_extension('wp_query', __('WP_Query'), __('Current WP_Query object - global $wp_query', 'debug-this'), array($this, 'wp_query'), 'Query');
  65. add_debug_extension('help', __('Debug This Menu', 'debug-this'), __('Modes Navigation', 'debug-this'), array($this, 'help'));
  66. }
  67. public function actions(){
  68. global $wp_actions;
  69. $wp_actions['shutdown'] = 1;
  70. $debug = print_r($wp_actions, true);
  71. return $debug;
  72. }
  73. public function attachments(){
  74. global $post;
  75. $args = array(
  76. 'post_type' => 'attachment',
  77. 'post_parent' => $post->ID,
  78. 'posts_per_page' => -1
  79. );
  80. $attachments = get_children($args);
  81. if($attachments){
  82. foreach($attachments as $attachment){
  83. $title = $attachment->post_title ? $attachment->post_title : __('No Title', 'debug-this');
  84. $debug .= "<h3 class='emphasize'>$title</h3><ul>";
  85. $debug .= '<li>'.sprintf(__('ID: %s', 'debug-this'), $attachment->ID).'</li>';
  86. $debug .= '<li>'.sprintf(__('Mime Type: %s', 'debug-this'), $attachment->post_mime_type).'</li>';
  87. $url = wp_get_attachment_url($attachment->ID);
  88. $debug .= '<li>'. __('URL: ', 'debug-this')."<a href='$url'>$url</a></li>";
  89. if($attachment->post_content)
  90. $debug .= '<li>'.sprintf(__('Description: %s', 'debug-this'), $attachment->post_content);
  91. $debug .= '</ul>';
  92. }
  93. }
  94. else
  95. $debug = __('No attachments found.', 'debug-this');
  96. return $debug;
  97. }
  98. public function apache(){
  99. if(!preg_match('/[Aa]pache/', $_SERVER["SERVER_SOFTWARE"]))
  100. return __('This extension only works on Apache.', 'debug-this');
  101. $debug = '<h3 class="emphasize">'.__('Version', 'debug-this').'</h3>';
  102. $debug .= apache_get_version();
  103. $debug .= '<h3 class="emphasize">'.__('Modules', 'debug-this').'</h3>';
  104. $debug .= print_r(apache_get_modules(), true);
  105. if(!$debug)
  106. $debug = __("No modules were found. This could be a symptom of running PHP as CGI.", 'debug-this');
  107. return $debug;
  108. }
  109. public function author(){
  110. if(!is_singular())
  111. return __('This mode can only be used on a single post/page.', 'debug-this');
  112. global $post, $authordata;
  113. setup_postdata($post);
  114. $debug = print_r($authordata, true);
  115. return $debug;
  116. }
  117. public function backtrace(){
  118. $version = get_bloginfo('version');
  119. if($version >= 3.4){
  120. $debug = '<h3>'.__('Backtrace Summary', 'debug-this').'</h3>';
  121. $debug .= print_r(explode(', ', wp_debug_backtrace_summary()),true);
  122. }
  123. $debug .= '<h3>'.__('debug_backtrace()', 'debug-this').'</h3>';
  124. $debug .= htmlentities(print_r(debug_backtrace(), true));
  125. return $debug;
  126. }
  127. public function bloginfo(){
  128. global $wp_version;
  129. $bloginfo = array(
  130. 'url' => get_bloginfo('url'),
  131. 'wpurl' => get_bloginfo('wpurl'),
  132. 'description' => get_bloginfo('description'),
  133. 'rdf_url' => get_bloginfo('rdf_url'),
  134. 'rss_url' => get_bloginfo('rss_url'),
  135. 'rss2_url' => get_bloginfo('rss2_url'),
  136. 'atom_url' => get_bloginfo('atom_url'),
  137. 'comments_atom_url' => get_bloginfo('comments_atom_url'),
  138. 'comments_rss2_url' => get_bloginfo('comments_rss2_url'),
  139. 'pingback_url' => get_bloginfo('pingback_url'),
  140. 'stylesheet_url' => get_bloginfo('stylesheet_url'),
  141. 'stylesheet_directory' => get_bloginfo('stylesheet_directory'),
  142. 'template_directory' => get_bloginfo('template_directory'),
  143. 'template_url' => get_bloginfo('template_url'),
  144. 'admin_email' => get_bloginfo('admin_email'),
  145. 'charset' => get_bloginfo('charset'),
  146. 'html_type' => get_bloginfo('html_type'),
  147. 'version' => get_bloginfo('version'),
  148. 'language' => get_bloginfo('language'),
  149. 'name' => get_bloginfo('name')
  150. );
  151. $debug = print_r($bloginfo, true);
  152. return $debug;
  153. }
  154. public function cache(){
  155. # Appropriated from WP Debug Bar Plugin - class-debug-bar-object-cache.php
  156. global $wp_object_cache;
  157. ob_start();
  158. $wp_object_cache->stats();
  159. $debug = ob_get_contents();
  160. ob_end_clean();
  161. return $debug;
  162. }
  163. public function classes(){
  164. $debug = print_r(get_declared_classes(), true);
  165. return $debug;
  166. }
  167. public function constants(){
  168. $constants = get_defined_constants();
  169. foreach($constants as $constant => $value)
  170. if($value === false)
  171. $constants[$constant] = '<span class="error">'.__('false', 'debug-this').'</span>';
  172. elseif($value === '')
  173. $constants[$constant] = '<span class="error">'.__('empty string', 'debug-this').'</span>';
  174. $debug = print_r($constants, true);
  175. return $debug;
  176. }
  177. public function constants_wordpress(){
  178. $wp_constants = array('AUTOSAVE_INTERVAL', 'CORE_UPGRADE_SKIP_NEW_BUNDLED', 'DISABLE_WP_CRON', 'EMPTY_TRASH_DAYS', 'IMAGE_EDIT_OVERWRITE', 'MEDIA_TRASH', 'WPLANG', 'WP_DEFAULT_THEME', 'WP_CRON_LOCK_TIMEOUT', 'WP_MAIL_INTERVAL', 'WP_POST_REVISIONS', 'WP_MAX_MEMORY_LIMIT', 'WP_MEMORY_LIMIT', 'APP_REQUEST', 'COMMENTS_TEMPLATE', 'DOING_AJAX', 'DOING_AUTOSAVE', 'DOING_CRON', 'IFRAME_REQUEST', 'IS_PROFILE_PAGE', 'SHORTINIT', 'WP_ADMIN', 'WP_BLOG_ADMIN', 'WP_IMPORTING', 'WP_INSTALLING', 'WP_LOAD_IMPORTERS', 'WP_NETWORK_ADMIN', 'WP_REPAIRING', 'WP_SETUP_CONFIG', 'WP_UNINSTALL_PLUGIN', 'WP_USER_ADMIN', 'XMLRPC_REQUEST', 'ABSPATH', 'WPINC', 'WP_LANG_DIR', 'WP_PLUGIN_DIR', 'WP_PLUGIN_URL', 'WP_CONTENT_DIR', 'WP_CONTENT_URL', 'WP_HOME', 'WP_SITEURL', 'WP_TEMP_DIR', 'WPMU_PLUGIN_DIR', 'WPMU_PLUGIN_URL', 'DB_CHARSET', 'DB_COLLATE', 'DB_HOST', 'DB_NAME', 'DB_PASSWORD', 'DB_USER', 'WP_ALLOW_REPAIR', 'CUSTOM_USER_TABLE', 'CUSTOM_USER_META_TABLE', 'ALLOW_SUBDIRECTORY_INSTALL', 'BLOGUPLOADDIR', 'BLOG_ID_CURRENT_SITE', 'DOMAIN_CURRENT_SITE', 'DIEONDBERROR', 'ERRORLOGFILE', 'MULTISITE', 'NOBLOGREDIRECT', 'PATH_CURRENT_SITE', 'UPLOADBLOGSDIR', 'SITE_ID_CURRENT_SITE', 'SUBDOMAIN_INSTALL', 'SUNRISE', 'UPLOADS', 'WPMU_ACCEL_REDIRECT', 'WPMU_SENDFILE', 'WP_ALLOW_MULTISITE', 'WP_CACHE', 'COMPRESS_CSS', 'COMPRESS_SCRIPTS', 'CONCATENATE_SCRIPTS', 'ENFORCE_GZIP', 'FS_CHMOD_DIR', 'FS_CHMOD_FILE', 'FS_CONNECT_TIMEOUT', 'FS_METHOD', 'FS_TIMEOUT', 'FTP_BASE', 'FTP_CONTENT_DIR', 'FTP_HOST', 'FTP_LANG_DIR', 'FTP_PASS', 'FTP_PLUGIN_DIR', 'FTP_PRIKEY', 'FTP_PUBKEY', 'FTP_SSH', 'FTP_SSL', 'FTP_USER', 'WP_PROXY_BYPASS_HOSTS', 'WP_PROXY_HOST', 'WP_PROXY_PASSWORD', 'WP_PROXY_PORT', 'WP_PROXY_USERNAME', 'WP_HTTP_BLOCK_EXTERNAL', 'WP_ACCESSIBLE_HOSTS', 'BACKGROUND_IMAGE', 'HEADER_IMAGE', 'HEADER_IMAGE_HEIGHT', 'HEADER_IMAGE_WIDTH', 'HEADER_TEXTCOLOR', 'NO_HEADER_TEXT', 'STYLESHEETPATH', 'TEMPLATEPATH', 'WP_USE_THEMES', 'SAVEQUERIES', 'SCRIPT_DEBUG', 'WP_DEBUG', 'WP_DEBUG_DISPLAY', 'WP_DEBUG_LOG', 'ADMIN_COOKIE_PATH', 'ALLOW_UNFILTERED_UPLOADS', 'AUTH_COOKIE', 'AUTH_KEY', 'AUTH_SALT', 'COOKIEHASH', 'COOKIEPATH', 'COOKIE_DOMAIN', 'CUSTOM_TAGS', 'DISALLOW_FILE_EDIT', 'DISALLOW_FILE_MODS', 'DISALLOW_UNFILTERED_HTML', 'FORCE_SSL_ADMIN', 'FORCE_SSL_LOGIN', 'LOGGED_IN_COOKIE', 'LOGGED_IN_KEY', 'LOGGED_IN_SALT', 'NONCE_KEY', 'NONCE_SALT', 'PASS_COOKIE', 'PLUGINS_COOKIE_PATH', 'SECURE_AUTH_COOKIE', 'SECURE_AUTH_KEY', 'SECURE_AUTH_SALT', 'SITECOOKIEPATH', 'TEST_COOKIE', 'USER_COOKIE');
  179. ksort($wp_constants);
  180. $defined_constants = array();
  181. $undefined_constants = array();
  182. foreach($wp_constants as $constant){
  183. if(!defined($constant)){
  184. unset($wp_constants[$constant]);
  185. $undefined_constants[] = $constant;
  186. }
  187. else{
  188. $value = constant($constant);
  189. if($value === false)
  190. $defined_constants[$constant] = '<span class="error">'.__('false', 'debug-this').'</span>';
  191. elseif($value === '')
  192. $defined_constants[$constant] = '<span class="error">'.__('empty string', 'debug-this').'</span>';
  193. else
  194. $defined_constants[$constant] = $value;
  195. }
  196. }
  197. ksort($undefined_constants);
  198. $debug = '<h3 class="emphasize">'.__('Defined Constants', 'debug-this').'</h3>';
  199. $debug .= print_r($defined_constants, true);
  200. $debug .= '<h3 class="emphasize">'.__('Undefined Constants', 'debug-this').'</h3>';
  201. $debug .= print_r($undefined_constants, true);
  202. return $debug;
  203. }
  204. public function content_width(){
  205. global $content_width;
  206. return $content_width;
  207. }
  208. public function cron_schedules(){
  209. $schedules = wp_get_schedules();
  210. $debug = print_r($schedules, true);
  211. return $debug;
  212. }
  213. public function cron_jobs(){
  214. $jobs = _get_cron_array();
  215. if($jobs)
  216. $debug = print_r($jobs, true);
  217. else
  218. $debug = __('No cron jobs found.', 'debug-this');
  219. return $debug;
  220. }
  221. public function context(){
  222. global $wp_query;
  223. $conditionals = array(
  224. 'is_single',
  225. 'is_preview',
  226. 'is_page',
  227. 'is_archive',
  228. 'is_date',
  229. 'is_year',
  230. 'is_month',
  231. 'is_day',
  232. 'is_time',
  233. 'is_author',
  234. 'is_category',
  235. 'is_tag',
  236. 'is_tax',
  237. 'is_search',
  238. 'is_feed',
  239. 'is_comment_feed',
  240. 'is_trackback',
  241. 'is_home',
  242. 'is_404',
  243. 'is_comments_popup',
  244. 'is_paged',
  245. 'is_admin',
  246. 'is_attachment',
  247. 'is_singular',
  248. 'is_robots',
  249. 'is_posts_page',
  250. 'is_post_type_archive'
  251. );
  252. $debug = "<ul>";
  253. foreach($conditionals as $conditional){
  254. if($wp_query->$conditional)
  255. $debug .= "<li>$conditional</li>";
  256. }
  257. $debug .= "</ul>";
  258. $debug = apply_filters('debug_context', $debug);
  259. return $debug;
  260. }
  261. public function css($buffer, $template){
  262. //Make backwards compatible for no pretty permalinks
  263. global $wp;
  264. $debug = sprintf(__('Template: %s', 'debug-this'), $template)."\n";
  265. $debug .= sprintf(__('URL: %s', 'debug-this'), get_bloginfo('url').'/'.$wp->request)."\n";
  266. $debug .= '<h3 class="emphasize">'.__('Stylesheets', 'debug-this').'</h3>';
  267. preg_match_all('/(http.+\.css)/', $buffer, $matches);
  268. $debug .= print_r($matches[0], true);
  269. return $debug;
  270. }
  271. public function dropins(){
  272. include_once ABSPATH.'/wp-admin/includes/plugin.php';
  273. $dropins = get_dropins();
  274. if($dropins)
  275. $debug = print_r($dropins, true);
  276. else
  277. $debug = sprintf(__("No dropins found. To learn more, please see: %s", 'debug-this'), "<a href='http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/'>http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/</a>");
  278. return $debug;
  279. }
  280. public function extensions(){
  281. $debug = print_r(get_loaded_extensions(), true);
  282. return $debug;
  283. }
  284. public function file_permissions(){
  285. if(!preg_match('/[Aa]pache/', $_SERVER["SERVER_SOFTWARE"]))
  286. return __('This extension has only been tested on Apache.', 'debug-this');
  287. function debug_this_file_info($file, $recommended_perms, $current){
  288. $output = "<h3 class='emphasize'>$file</h3>";
  289. $perms = debug_this_get_file_perms($file);
  290. if($perms){
  291. $perms_output = '';
  292. $rwx = debug_this_convert_perms_to_rwx($perms, $file);
  293. if($perms !== $recommended_perms)
  294. $perms_output = '<span class="error">'.sprintf(__('%s %s Recommended: %s - To change, run: chmod %s %s', 'debug-this'), $perms, $rwx, $recommended_perms, $recommended_perms, $file)."</span>";
  295. $perms .= " $rwx";
  296. $output .= sprintf(__('Permissions: %s', 'debug-this'), $perms_output ? $perms_output : $perms)."\n";
  297. }
  298. $own = debug_this_get_file_ownership($file);
  299. if($own){
  300. $user_perm = $perms[1];
  301. $group_perm = $perms[2];
  302. if($current['user']['name'] === $own['user']['name'] && (int)$user_perm < 4)
  303. $user = "<span class='error'>{$own['user']['name']}</span>";
  304. else
  305. $user = "<span class='okay'>{$own['user']['name']}</span>";
  306. if($current['group']['name'] === $own['group']['name'] && (int)$group_perm < 4)
  307. $group = "<span class='error'>{$own['group']['name']}</span>";
  308. else
  309. $group = "<span class='okay'>{$own['group']['name']}</span>";
  310. if($current['group']['name'] !== $own['group']['name'] && $current['user']['name'] !== $own['user']['name'])
  311. $output .= '<span class="error">'.__('The current WordPress user might not have access to this file/folder.', 'debug-this')."</span>\n";
  312. $output .= sprintf(__('Owner/Group: %s:%s', 'debug-this'), $user, $group)."\n";
  313. }
  314. return $output;
  315. }
  316. $legend = '<span class="okay">'.__('access', 'debug-this').'</span> - <span class="error">'.__('no access', 'debug-this')."</span>";
  317. $debug = sprintf(__('Rubric: %s', 'debug-this'), $legend);
  318. $user = posix_getpwuid(getmyuid());
  319. $group = posix_getgrgid(getmygid());
  320. $current_user = compact('user', 'group');
  321. $debug .= '<h3 class="emphasize">'.__('WordPress User', 'debug-this').'</h3>';
  322. $debug .= sprintf(__('User: %s', 'debug-this'), $user['name'])."\n";
  323. $debug .= sprintf(__('Group: %s', 'debug-this'), $group['name']);
  324. $debug .= debug_this_file_info(ABSPATH, '0755', $current_user);
  325. if(file_exists(ABSPATH.'.htaccess'))
  326. $debug .= debug_this_file_info(ABSPATH.'.htaccess', '0604', $current_user);
  327. if(file_exists(ABSPATH.'php.ini'))
  328. $debug .= debug_this_file_info(ABSPATH.'php.ini', '0600', $current_user);
  329. if(file_exists(ABSPATH.'wp-config.php'))
  330. $debug .= debug_this_file_info(ABSPATH.'wp-config.php', '0600', $current_user);
  331. else{
  332. $parts = explode('/', trim(ABSPATH, '/'));
  333. array_pop($parts);
  334. $one_below = '/'.implode('/', $parts).'/wp-config.php';
  335. if(file_exists($one_below))
  336. $debug .= debug_this_file_info($one_below, '0600', $current_user);
  337. else{
  338. $debug .= "<h3 class='emphasize error'>wp-config.php</h3>";
  339. $debug .= '<span class="error">'.__("Couldn't find wp-config.php!", 'debug-this').'</span>';
  340. }
  341. }
  342. $debug .= debug_this_file_info(WP_CONTENT_DIR, '0755', $current_user);
  343. $debug .= debug_this_file_info(WP_PLUGIN_DIR, '0755', $current_user);
  344. $debug .= debug_this_file_info(get_theme_root(), '0755', $current_user);
  345. $uploads = wp_upload_dir();
  346. $debug .= debug_this_file_info($uploads['basedir'], '0755', $current_user);
  347. return $debug;
  348. }
  349. public function files(){
  350. $debug = '<h3 class="emphasize">'.__('Required Files', 'debug-this').'</h3>';
  351. $debug .= print_r(get_required_files(), true);
  352. $debug .= '<h3 class="emphasize">'.__('Included Files', 'debug-this').'</h3>';
  353. $debug .= print_r(get_included_files(), true);
  354. return $debug;
  355. }
  356. public function filters(){
  357. global $wp_filter;
  358. $debug = '';
  359. foreach($wp_filter as $id => $groups){
  360. $debug .= "<h3 class='emphasize'>$id</h3>\n<ul>";
  361. foreach($groups as $filters){
  362. foreach($filters as $filter => $values){
  363. $callback = is_string($values['function']) ? $values['function'] : '(object)';
  364. $debug .= "<li>$filter ({$callback})</li>\n";
  365. }
  366. }
  367. $debug .= '</ul>';
  368. }
  369. return $debug;
  370. }
  371. public function filters_current(){
  372. global $debug_this_current_filter;
  373. $debug = print_r($debug_this_current_filter, true);
  374. return $debug;
  375. }
  376. public function functions(){
  377. $functions = get_defined_functions();
  378. $debug = print_r($functions['user'], true);
  379. return $debug;
  380. }
  381. public function images($buffer){;
  382. preg_match_all('/src=[\'"](http.+\.(jpg|jpeg|png|svg))\'?"?/', $buffer, $matches);
  383. $debug = print_r($matches[1], true);
  384. return $debug;
  385. }
  386. public function imagesizes(){
  387. global $_wp_additional_image_sizes;
  388. $sizes = get_intermediate_image_sizes();
  389. $debug = '<h3>'.__('Registered Sizes Names', 'debug-this').'</h3>';
  390. $debug .= print_r($sizes, true);
  391. $debug .= '<h3>'.__('Registered Size Definitions', 'debug-this').'</h3>';
  392. $debug .= print_r($_wp_additional_image_sizes, true);
  393. return $debug;
  394. }
  395. public function js($buffer, $template){
  396. //make backwards compatible for no permalinks
  397. global $wp;
  398. $debug = sprintf(__('Template: %s', 'debug-this'), $template)."\n";
  399. $debug .= sprintf(__('URL: %s', 'debug-this'), get_bloginfo('url').'/'.$wp->request)."\n";
  400. $debug .= '<h3 class="emphasize">'.__('JavaScript Files', 'debug-this').'</h3>';
  401. preg_match_all('/(http.+\.js)/', $buffer, $matches);
  402. $debug .= print_r($matches[0], true);
  403. return $debug;
  404. }
  405. public function load_time($buffer, $template){
  406. //make backwards compatible for no permalinks
  407. global $wp;
  408. $debug = sprintf(__('Template: %s', 'debug-this'), $template)."\n";
  409. $debug .= sprintf(__('URL: %s', 'debug-this'), get_bloginfo('url').'/'.$wp->request)."\n";
  410. $debug .= sprintf(__('Execution Time: %s', 'debug-this'), Debug_This::$execution_time . ' ' .__('seconds', 'debug-this'));
  411. return $debug;
  412. }
  413. public function menus(){
  414. $debug = print_r(get_registered_nav_menus(), true);
  415. return $debug;
  416. }
  417. public function menus_dynamic(){
  418. $debug = '<h3>'.__('Dynamic Menu Locations', 'debug-this').'</h3>';
  419. $debug .= print_r(get_nav_menu_locations(), true);
  420. $debug .= '<h3>'.__('Dynamic Menus', 'debug-this').'</h3>';
  421. $menus = wp_get_nav_menus(array('orderby' => 'name'));
  422. foreach($menus as $id => $menu)
  423. $menus[$id]->items = wp_get_nav_menu_items($menu->term_id);
  424. $debug .= print_r($menus, true);
  425. return $debug;
  426. }
  427. public function oembed(){
  428. include_once ABSPATH . '/wp-includes/class-oembed.php';
  429. $debug = print_r(_wp_oembed_get_object(), true);
  430. return $debug;
  431. }
  432. public function options(){
  433. $debug = htmlentities(print_r(wp_load_alloptions(), true));
  434. return $debug;
  435. }
  436. public function phpinfo(){
  437. ob_start();
  438. phpinfo();
  439. $debug = ob_get_contents();
  440. ob_end_clean();
  441. Debug_This::$no_pre = true;
  442. return $debug;
  443. }
  444. public function phpini(){
  445. $debug = print_r(ini_get_all(), true);
  446. return $debug;
  447. }
  448. public function plugins(){
  449. include_once ABSPATH.'/wp-admin/includes/plugin.php';
  450. $debug = htmlentities(print_r(get_plugins(), true));
  451. return $debug;
  452. }
  453. public function post(){
  454. if(is_singular()){
  455. global $post;
  456. $debug = htmlentities(print_r($post, true));
  457. }
  458. else
  459. $debug = __('This mode only works for single posts/pages', 'debug-this');
  460. return $debug;
  461. }
  462. public function posts(){
  463. if(!is_singular()){
  464. global $wp_query;
  465. $posts_count = count($wp_query->posts);
  466. $debug = sprintf(__('Number of Posts: %d'), $posts_count)."\n\n";
  467. $debug .= htmlentities(print_r($wp_query->posts, true));
  468. }
  469. else
  470. $debug = __('This mode only works for archive/home pages', 'debug-this');
  471. return $debug;
  472. }
  473. public function post_meta(){
  474. if(!is_singular())
  475. return __('This mode only works for single posts/pages', 'debug-this');
  476. global $post;
  477. $debug = print_r(get_post_custom($post->ID), true);
  478. return $debug;
  479. }
  480. public function posttypes(){
  481. global $post;
  482. $post_types = get_post_types('', 'objects');
  483. $debug = print_r($post_types, true);
  484. return $debug;
  485. }
  486. public function posttype_current(){
  487. global $wp_query;
  488. if($wp_query->queried_object)
  489. $post = $wp_query->queried_object;
  490. $post_types = get_post_types('', 'objects');
  491. $debug = print_r(array($post->post_type => $post_types[$post->post_type]), true)."\n\n";
  492. return $debug;
  493. }
  494. public function queries(){
  495. if(Debug_This::$queries)
  496. $debug = print_r(Debug_This::$queries, true);
  497. else
  498. $debug = '<span class="error">'.__('Please set define("SAVEQUERIES", true); in wp-config.php to see saved queries. Please disable when completed as this can be a large performance hit.', 'debug-this').'</span>';
  499. return $debug;
  500. }
  501. public function request(){
  502. global $wp;
  503. $wp->matched_rule = "<a href='?debug=rewrites'>$wp->matched_rule</a>";
  504. $debug = print_r($wp, true);
  505. return $debug;
  506. }
  507. public function rewrites(){
  508. global $wp_rewrite, $wp;
  509. $permalink_structure = get_option('permalink_structure');
  510. if(!$permalink_structure)
  511. return __('Pretty permalinks must be enabled to use this mode. To set a permalink structure, go to Settings->Permalinks in wp-admin.', 'debug-this');
  512. $debug = '<h3>'.__('Current Rewrite', 'debug-this').'</h3>';
  513. $debug .= __('Matched Rule', 'debug-this').": <span class='current'>$wp->matched_rule</span>\n";
  514. $debug .= __('Matched Query', 'debug-this').": $wp->matched_query\n";
  515. $debug .= __('Query String', 'debug-this').": $wp->query_string\n\n";
  516. $debug .= '<h3>'.__('Rewrite Rules', 'debug-this').'</h3>';
  517. if(!empty($wp_rewrite->rules)){
  518. $debug .= '<table><thead><tr>';
  519. $debug .= '<td><strong>'.__('Rule', 'debug-this').'</strong></td><td><strong>'.__('Rewrite', 'debug-this').'</strong></td>';
  520. $debug .= '</tr></thead><tbody>';
  521. foreach($wp_rewrite->rules as $rule => $rewrite){
  522. $class = $wp->matched_rule === $rule ? 'class="current"' : '';
  523. $debug .= '<tr><td '.$class.'>'.$rule.'</td><td '.$class.'>'.$rewrite.'</td></tr>';
  524. }
  525. $debug .= '</tbody></table>';
  526. }
  527. else
  528. echo __('No rules defined.', 'debug-this');
  529. return $debug;
  530. }
  531. public function scripts(){
  532. global $wp_scripts;
  533. $debug = print_r($wp_scripts->registered, true);
  534. return $debug;
  535. }
  536. public function server(){
  537. $debug = print_r($_SERVER, true);
  538. return $debug;
  539. }
  540. public function shortcodes(){
  541. global $shortcode_tags;
  542. $debug = htmlentities(print_r($shortcode_tags, true));
  543. return $debug;
  544. }
  545. public function shortcodes_regex(){
  546. $regex = get_shortcode_regex();
  547. $debug = htmlentities(print_r($regex, true));
  548. return $debug;
  549. }
  550. public function sidebars_rendered($buffer, $template){
  551. global $wp_registered_sidebars;
  552. $template_contents = file_get_contents($template);
  553. preg_match_all('/(get_sidebar|dynamic_sidebar).+\)/', $template_contents, $matches);
  554. $sidebars = array();
  555. foreach($matches[0] as $sidebar){
  556. if($sidebar === 'get_sidebar()')
  557. $sidebars[] = 'get_sidebar() ' . locate_template('sidebar.php');
  558. else{
  559. preg_match_all('/\(.+\)/', $sidebar, $parts);
  560. foreach($parts[0] as $part){
  561. $sidebar_name = trim($part, ' )(\'"');
  562. if(preg_match('/dynamic/', $sidebar))
  563. $sidebars[] = sprintf(__('Dynamic Sidebar: %s'), $sidebar_name);
  564. else{
  565. $path = locate_template("$sidebar_name.php");
  566. $path = $path ? $path : sprintf(__('Missing sidebar template for %s.php', 'debug-this'), $sidebar_name);
  567. $sidebars[] = "get_sidebar('$sidebar_name') $path";
  568. }
  569. }
  570. }
  571. }
  572. $debug = sprintf(__('Current Template: %s', 'debug-this'), $template)."\n\n";
  573. if($sidebars)
  574. $debug .= htmlentities(print_r($sidebars, true))."\n";
  575. else
  576. $debug .= __('No sidebars were found in this template.', 'debug-this');
  577. return $debug;
  578. }
  579. public function sidebars_registered(){
  580. global $wp_registered_sidebars;
  581. $debug = '<h3>'.__('Registered Sidebars', 'debug-this').'</h3>';
  582. $debug .= htmlentities(print_r($wp_registered_sidebars, true));
  583. return $debug;
  584. }
  585. public function styles(){
  586. global $wp_styles;
  587. $debug = print_r($wp_styles->registered, true);
  588. return $debug;
  589. }
  590. public function taxonomies(){
  591. $debug = print_r(get_taxonomies('', 'objects'), true);
  592. return $debug;
  593. }
  594. public function template(){
  595. global $template;
  596. $template = $template;
  597. $debug = print_r($template, true);
  598. return $debug;
  599. }
  600. public function terms_all(){
  601. $taxonomies = get_taxonomies('', 'names');
  602. $debug = print_r(get_terms($taxonomies), true);
  603. return $debug;
  604. }
  605. public function terms(){
  606. global $post;
  607. if(is_singular()){
  608. $debug = '';
  609. $taxonomies = get_taxonomies('','names');
  610. foreach($taxonomies as $taxonomy){
  611. $terms = wp_get_post_terms($post->ID, $taxonomy);
  612. if($terms){
  613. $debug .= "<h3 class='emphasize'>$taxonomy</h3><ul>";
  614. foreach($terms as $term)
  615. $debug .= '<li>'.sprintf(__('Term ID #%s - %s - %s', 'debug-this'), $term->term_id, $term->slug, $term->name).'</li>';
  616. $debug .= '</ul>';
  617. }
  618. }
  619. }
  620. else
  621. $debug = '<span class="error">'.__('This mode only works on single pages/posts.', 'debug-this').'</span>';
  622. return $debug;
  623. }
  624. public function themes(){
  625. $debug = '<h3>'.__('Current Theme', 'debug-this').'</h3>';
  626. $debug .= print_r(get_current_theme(), true)."\n\n";
  627. $themes = wp_get_themes();
  628. $debug .= '<h3>'.__('Themes', 'debug-this').'</h3>';
  629. $debug .= print_r(wp_get_themes(), true);
  630. return $debug;
  631. }
  632. public function users(){
  633. $users = get_users();
  634. $debug = '';
  635. foreach($users as $user){
  636. $login = property_exists($user, 'data') ? $user->data->user_login : $user->user_login;
  637. $debug .= "<h3 class='emphasize'>{$login}</h3>";
  638. $debug .= print_r($user, true);
  639. }
  640. return $debug;
  641. }
  642. public function variables(){
  643. $debug = '';
  644. foreach($GLOBALS as $id => $values){
  645. if($id === 'GLOBALS' || $id === 'html')
  646. continue;
  647. if(is_array($values) && !empty($values)){
  648. $debug .= "<h3>$id</h3>";
  649. $debug .= htmlentities(print_r(array_keys($values), true));
  650. }
  651. elseif(is_string($values)){
  652. $debug .= "<h3>$id</h3>";
  653. $debug .= htmlentities("$values\n\n");
  654. }
  655. }
  656. return $debug;
  657. }
  658. public function widgets(){
  659. global $wp_widget_factory;
  660. $debug = print_r($wp_widget_factory->widgets, true);
  661. return $debug;
  662. }
  663. public function wp_debug(){
  664. if(defined('WP_DEBUG') && WP_DEBUG === true && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG === true){
  665. $path = WP_CONTENT_DIR.'/debug.log';
  666. $debug = '';
  667. if(file_exists($path) && is_writeable($path)){
  668. add_debug_header_link(Debug_This::get_current_debug_url().'&clear-debug-log=true', __('Reset log file', 'debug-this'));
  669. if(isset($_GET['clear-debug-log'])){
  670. if(file_put_contents($path, '') === 0)
  671. $debug .= __('Debug log was successfully cleared.', 'debug-this');
  672. else
  673. $debug .= __('Debug log could not be reset. Please try again', 'debug-this');
  674. }
  675. $debug .= file_get_contents($path);
  676. if(!$debug)
  677. $debug .= __('Looking good! No notices were logged.', 'debug-this');
  678. }
  679. elseif(touch($path))
  680. $debug = __('Looking good! No notices were logged.', 'debug-this'); #Better reporting. If nothing was found, it's not a file perms error.
  681. else
  682. $debug = __('Could not open debug.log. Please make sure your wp-content folder is writeable by the web server user.', 'debug-this');
  683. return $debug;
  684. }
  685. else{
  686. $debug = __("Please add the following to wp-config.php to use this mode.\ndefine('WP_DEBUG', true);\ndefine('WP_DEBUG_LOG', true);\ndefine('WP_DEBUG_DISPLAY', false);", 'debug-this');
  687. return $debug;
  688. }
  689. }
  690. public function wp_query(){
  691. global $wp_query;
  692. $debug = htmlentities(print_r($wp_query, true));
  693. return $debug;
  694. }
  695. }
  696. new Debug_This_Extensions;