php在wordpress上进行php调试的少数功能(代码片段)

author author     2022-12-10     637

关键词:

<?php

/**
* Plugin Name: Debugging WordPress
* Plugin URI: https://premium.wpmudev.org/
* Description: Handy functions for PHP debugging on WordPress
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/

if ( ! defined( 'ABSPATH' ) ) 
	exit;




// See clearly what's going on and where is the debug data. Also it has to accommodate with the current styles and not fall behind or get mixed with other text etc.
// This snippet will provide real debug notices in a flashy table:
// - complete backtrace of calls on the left with line numbers
// - arguments content on the right, with the variable name and coloring per variable type
// Uses: error_log_full($arg1, $arg2,..);

if ( ! function_exists('error_log_full') ) 

	function error_log_full() 
		error_reporting(E_ALL);
		$args = func_get_args();
		$backtrace = debug_backtrace();
		$file = file($backtrace[0]['file']);
		$src  = $file[$backtrace[0]['line']-1];  // select debug($varname) line where it has been called
		$pat  = '#(.*)'.__FUNCTION__.' *?\( *?\$(.*) *?\)(.*)#i';  // search pattern for wtf(parameter)
		$arguments  = trim(preg_replace($pat, '$2', $src));  // extract arguments pattern
		$args_arr = array_map('trim', explode(',', $arguments));

		print '<style>
			div.debug visible; clear: both; display: table; width: 100%; font-family: Courier,monospace; border: medium solid red; background-color: yellow; border-spacing: 5px; z-index: 999;
			div.debug > div display: unset; margin: 5px; border-spacing: 5px; padding: 5px;
			div.debug .cell display: inline-flex; padding: 5px; white-space: pre-wrap;
			div.debug .left-cell float: left; background-color: Violet;
			div.debug .array color: RebeccaPurple; background-color: Violet;
			div.debug .object pre color: DodgerBlue; background-color: PowderBlue;
			div.debug .variable pre color: RebeccaPurple; background-color: LightGoldenRodYellow;
			div.debug pre white-space: pre-wrap;
		</style>'.PHP_EOL;

		print '<div class="debug">'.PHP_EOL;
			foreach ($args as $key => $arg) 
				print '<div><div class="left-cell cell"><b>';
				array_walk(debug_backtrace(),create_function('$a,$b','print "$a[\'function\']()(".basename($a[\'file\']).":$a[\'line\'])<br> ";'));
				print '</b></div>'.PHP_EOL;
					if (is_array($arg)) 
						print '<div class="cell array"><b>'.$args_arr[$key].' = </b>';
							print_r(htmlspecialchars(print_r($arg)), ENT_COMPAT, 'UTF-8');
						print '</div>'.PHP_EOL;
					 elseif (is_object($arg)) 
						print '<div class="cell object"><pre><b>'.$args_arr[$key].' = </b>';
							print_r(htmlspecialchars(print_r(var_dump($arg))), ENT_COMPAT, 'UTF-8');
						print '</pre></div>'.PHP_EOL;
					 else 
						print '<div class="cell variable"><pre><b>'.$args_arr[$key].' = </b>&gt;';
							print_r(htmlspecialchars($arg, ENT_COMPAT, 'UTF-8').'&lt;');
						print '</pre></div>'.PHP_EOL;
					
				print '</div>'.PHP_EOL;
			
		print '</div>'.PHP_EOL;
	





// Log something in the browser console.log
// Uses: console_log( $data );

if ( ! function_exists('console_log') ) 

	function console_log( $data ) 
		echo '<script>';
		echo 'console.log('. json_encode( $data ) .')';
		echo '</script>';
	





// Log anything in the debug.log
// Uses: write_log( $data );

if ( ! function_exists('write_log') ) 

	function write_log( $data ) 
		error_log( print_r( $data, true ) );
	






// Simple log view with enabling <pre> tag.
// Uses: debug_view( $data );

if ( ! function_exists('debug_view') ) 

	function debug_view( $data ) 
		echo '<pre>';
			if ( is_array( $data ) )  
				print_r ( $data );
			 else 
				var_dump ( $data );
			
		echo '</pre>';
	


在 Windows 上进行本机调试

】在Windows上进行本机调试【英文标题】:Reactnativedebugonwindows【发布时间】:2017-01-1819:31:44【问题描述】:我有一个reactnativeandroid应用程序,我目前正在使用android模拟器在windows机器上进行调试。我可以打http://localhost:8081/debugger-u... 查看详情

试图让一个无头 WordPress 在纱线启动命令上进行热重载

】试图让一个无头WordPress在纱线启动命令上进行热重载【英文标题】:TryingtogetaheadlessWordPresstodohotreloadingonyarnstartcommand【发布时间】:2019-05-2321:48:15【问题描述】:我正在运行这个项目https://github.com/postlight/headless-wp-starter。我已... 查看详情

关于browser-sync(在多个设备上进行网页调试)的问题点总结

...站的开发视频,其中有一部分非常有用,就是在多个设备上进行网页调试,通过使用browser-sync来实现,具体的步骤可以参照官网(http://www.browsersync.cn/)按照步骤操作就可以了,当然电脑必须安装了node.js,在这里我主要说一下我... 查看详情

如何在使用 Xamarin for Visual Studio 的真实 Android 设备上进行调试?

】如何在使用XamarinforVisualStudio的真实Android设备上进行调试?【英文标题】:HowdoIdebugonarealAndroiddeviceusingXamarinforVisualStudio?【发布时间】:2014-10-0106:55:30【问题描述】:我找到了一些链接,但他们没有解释这是如何完成的。我可... 查看详情

我可以使用中文 iphone 在 xcode 上进行调试吗? [关闭]

】我可以使用中文iphone在xcode上进行调试吗?[关闭]【英文标题】:CanIusechineseiphonefordebuggingonxcode?[closed]【发布时间】:2017-06-1021:31:00【问题描述】:有没有办法在开发应用程序时使用运行ios的中国iPhone在xcode上调试而不是更昂贵... 查看详情

Eclipse Kepler 不允许在三星 Galaxy S4 上进行调试

】EclipseKepler不允许在三星GalaxyS4上进行调试【英文标题】:EclipseKeplerdoesnotallowdebuggingonSamsungGalaxyS4【发布时间】:2014-04-1404:09:02【问题描述】:我正在使用三星GalaxyS4I9505(JellyBean4.3)作为我的调试目标,并且我已经完成了初步步骤... 查看详情

text在真实设备上进行离子调试(代码片段)

查看详情

php打印错误以在drupal中的默认php5上进行筛选(代码片段)

查看详情

如何安装部署wordpress?

WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的,用户可以在支持PHP和MySQL数据库的服务器上使用自己的博客。WordPress在软件设计方面有很多优秀特点,故能被广泛使用。... 查看详情

更改 Xamarin.Forms 项目代码后,我无法在 Iphone 上进行调试

】更改Xamarin.Forms项目代码后,我无法在Iphone上进行调试【英文标题】:IcantdebugonmyIphoneonceIhavechangedmyXamarin.Formsproject´scode【发布时间】:2021-06-1217:28:11【问题描述】:我正在尝试使用VisualStudioformac在我的物理IOS设备(iPhone7)上... 查看详情

VS2019 - 使用 Cmake 项目在 Linux 上进行 Sudo 远程调试

】VS2019-使用Cmake项目在Linux上进行Sudo远程调试【英文标题】:VS2019-SudoRemoteDebuggingonLinuxwithCmakeproject【发布时间】:2020-06-1205:50:48【问题描述】:我有一个使用Windows计算机远程调试的cmakec++Linux项目。该程序访问Raspberrypi上的GPIO引... 查看详情

php启用wordpress错误日志调试输出到文件(代码片段)

查看详情

我目前在 Eclipse MacOS Big Sur 上进行 GDB 调试时遇到错误

】我目前在EclipseMacOSBigSur上进行GDB调试时遇到错误【英文标题】:I\'mcurrentlyexperiencinganerrorwithGDBdebuggingonEclipseMacOSBigSur【发布时间】:2021-04-2805:30:37【问题描述】:通过Homebrew在BigSur上安装GDB后,我目前遇到了一个奇怪的错误。... 查看详情

wordpress 中的 tinyMCE 不能在少数计算机上运行,​​并且只能在少数计算机上运行

】wordpress中的tinyMCE不能在少数计算机上运行,​​并且只能在少数计算机上运行【英文标题】:tinyMCEinwordpressisnotworkinginfewcomputersandworkinginfew【发布时间】:2013-04-1510:23:26【问题描述】:我有一个很奇怪的问题,在我的办公室里... 查看详情

php[wordpress-常规]显示其他服务器信息。用于调试网站。(代码片段)

查看详情

php[debugenqueuescripts]快速调试,列出所有入队脚本。#wordpress#enqueue(代码片段)

查看详情

php[wordpress-常规]显示其他服务器信息。用于调试网站。(代码片段)

查看详情

如何在自定义 PHP 脚本中调用 WordPress 函数

】如何在自定义PHP脚本中调用WordPress函数【英文标题】:HowtocallWordPressfunctionsinacustomPHPscript【发布时间】:2011-01-0616:26:05【问题描述】:我有一个PHP脚本,我想用它在WPMU中创建一个新博客。我无法调用像wpmu_create_user和wpmu_create_b... 查看详情