admin管理员组文章数量:1130349
I would like to display a page and all the hooks, classes, or php custom function inline with page content without var_dump.
The purpose of this would be to audit a seven year old site that has 18k pages and many developers coding and writing functions over the years (without documentation) to discern which functions are being used on which pages and if there are functions that are not being used on the site at all, deprecate them.
Thank you!
I would like to display a page and all the hooks, classes, or php custom function inline with page content without var_dump.
The purpose of this would be to audit a seven year old site that has 18k pages and many developers coding and writing functions over the years (without documentation) to discern which functions are being used on which pages and if there are functions that are not being used on the site at all, deprecate them.
Thank you!
Share Improve this question edited May 7, 2019 at 1:15 user3795286 asked May 6, 2019 at 14:02 user3795286user3795286 616 bronze badges 5 |1 Answer
Reset to default 2You're asking for more than one thing:
- Enumerate hooks: this can be found in the
$wp_filterglobal variable. If you're looking for just the names of the hooks, usearray_keys(). For some code examples, look here or there are plenty of other examples. - Enumerate classes: use the PHP function
get_declared_classes(). - Enumerate functions: similarly, use the PHP function
get_defined_functions(). This should give you an associative array-of-arrays and it sounds like you probably just want the ones under theuserkey. - Filter these lists: this is the tricker part. Probably you'd need to build a reference list of things you want to filter out, like all the WP custom functions (a long list). All of the above-referenced sources give you arrays, so
array_filter()is probably your best friend here. - Display your content: probably you will end up with one or more arrays containing the content that you want to display. Build your
foreachloops to dump the contents on the screen where and how you'd like. I'm not exactly sure what, "inline with page content," means but a few quick runs should help you sort things out and make it look as you prefer. Keep in mind that if you have an array of strings to dump to the screen in a delimited list,implode(', ', $array_of_strings)gives good results.
If you're looking for what gets called on a particular page as opposed to what's been defined, the classes and functions are hard without breaking into the PHP parser (or re-parsing the PHP file that was called). Hooks are relatively easy in this case, just use the all filter. This will give you what's being called, from end to end, in the rendering of the page.
If you're looking for what's defined in a PHP file, that's just an exercise in parsing or hooking into the PHP parser. Your bigger problem here is that a particular page load in WP has a very loose correlation to the number of PHP files that are loaded. There is no one-to-one correlation between the URL visited and a single PHP file loaded. For example, each of the support classes, like WP_Post and wpdb, are defined in a single PHP file, none of which may be responsible directly for any output to any page load, but all of which are essential to just about every page load.
Without more information on exactly what you're trying to accomplish (specifically, why), it's hard to say more. So... what are you trying to accomplish? Is this enough background information to help you accomplish your task?
I would like to display a page and all the hooks, classes, or php custom function inline with page content without var_dump.
The purpose of this would be to audit a seven year old site that has 18k pages and many developers coding and writing functions over the years (without documentation) to discern which functions are being used on which pages and if there are functions that are not being used on the site at all, deprecate them.
Thank you!
I would like to display a page and all the hooks, classes, or php custom function inline with page content without var_dump.
The purpose of this would be to audit a seven year old site that has 18k pages and many developers coding and writing functions over the years (without documentation) to discern which functions are being used on which pages and if there are functions that are not being used on the site at all, deprecate them.
Thank you!
Share Improve this question edited May 7, 2019 at 1:15 user3795286 asked May 6, 2019 at 14:02 user3795286user3795286 616 bronze badges 5- @jacobpeattie, reworded question to conform to rules. please remove on hold. – user3795286 Commented May 6, 2019 at 15:15
- @jackjohansson, reworded question to conform to rules. please remove on hold. – user3795286 Commented May 6, 2019 at 15:16
-
Are you looking to enumerate all of the hooks, classes and PHP functions used, or just the ones that are used on a particular page? If it's on a page, are you asking about the post type
pageor on a particular... template, core page (like archive or post), admin page, or... otherwise? – Stephan Samuel Commented May 6, 2019 at 16:42 - @StephanSamuel, Yes I am looking to enumerate all of the hooks, classes and php functions that used on each front-end page (post, page, cpt, etc), excluding admin. The functions should display inline with the content, not just a list. Thank you – user3795286 Commented May 6, 2019 at 17:45
- There are options in PHP, see this Stack Overflow thread: »Print PHP Call Stack«. – Nicolai Grossherr Commented May 6, 2019 at 17:54
1 Answer
Reset to default 2You're asking for more than one thing:
- Enumerate hooks: this can be found in the
$wp_filterglobal variable. If you're looking for just the names of the hooks, usearray_keys(). For some code examples, look here or there are plenty of other examples. - Enumerate classes: use the PHP function
get_declared_classes(). - Enumerate functions: similarly, use the PHP function
get_defined_functions(). This should give you an associative array-of-arrays and it sounds like you probably just want the ones under theuserkey. - Filter these lists: this is the tricker part. Probably you'd need to build a reference list of things you want to filter out, like all the WP custom functions (a long list). All of the above-referenced sources give you arrays, so
array_filter()is probably your best friend here. - Display your content: probably you will end up with one or more arrays containing the content that you want to display. Build your
foreachloops to dump the contents on the screen where and how you'd like. I'm not exactly sure what, "inline with page content," means but a few quick runs should help you sort things out and make it look as you prefer. Keep in mind that if you have an array of strings to dump to the screen in a delimited list,implode(', ', $array_of_strings)gives good results.
If you're looking for what gets called on a particular page as opposed to what's been defined, the classes and functions are hard without breaking into the PHP parser (or re-parsing the PHP file that was called). Hooks are relatively easy in this case, just use the all filter. This will give you what's being called, from end to end, in the rendering of the page.
If you're looking for what's defined in a PHP file, that's just an exercise in parsing or hooking into the PHP parser. Your bigger problem here is that a particular page load in WP has a very loose correlation to the number of PHP files that are loaded. There is no one-to-one correlation between the URL visited and a single PHP file loaded. For example, each of the support classes, like WP_Post and wpdb, are defined in a single PHP file, none of which may be responsible directly for any output to any page load, but all of which are essential to just about every page load.
Without more information on exactly what you're trying to accomplish (specifically, why), it's hard to say more. So... what are you trying to accomplish? Is this enough background information to help you accomplish your task?
本文标签:
版权声明:本文标题:plugins - How to display all functions (hooks, filters, or custom php) used on a page inline 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1745517974a2154168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


pageor on a particular... template, core page (like archive or post), admin page, or... otherwise? – Stephan Samuel Commented May 6, 2019 at 16:42