You can determine the calling files using debug_backtrace
in PHP, which will give you the backtrace of the functions called and the file called from. WP core provides wp_debug_backtrace_summary, which makes doing things like this easier. Using the condition stated in your question of being called from my_file.php
you could do something like this:
add_filter( 'the_author', 'change_author' );
function change_author($author) {
if ( false !== strpos( wp_debug_backtrace_summary(), 'my_file.php' ) ) {
$author = "NEW AUTHOR!";
}
return $author;
}
By not passing any args to wp_debug_backtrace_summary
it will output the summary as a string. Then we just use strpos
to check if my_file.php
is included in the output as a calling file and do the changes.
As mentioned by others, this might not be the best approach, but it is easily doable.
Related Posts:
- Assign new post author IF another user in custom field on post transition
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Find variables available at a given hook
- Getting my head round WordPress filter
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How to set a custom path, for ajax image upload folder in admin?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- How to call function at the bottom of post using plugin?
- Handling Body class based on Template
- Edit incorrect password message WordPress
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Remove a div from RSS feed
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- edit_comment_link is not showing for comment author
- How to have different site identity logos on each page on Astra Theme [closed]
- Must filter functions receive all arguments passed to them?
- How to sort WooCommerce products page by latest in-stock items first?
- Filter wordpress posts without searching the keywords in the post content
- Variation prices breakdown only for single product page
- Remove Author Links
- How to edit post meta data before publishing the post it self wordpress?
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- add_filter() inside another add_filter()
- Add class to all meta boxes for a custom post type
- How to add custom checkout field in user details mail template
- For each loop will not append to the_content hook
- Is there a hook that I can use when a fatal error occurs?
- how to append ACF field data using one of the following filter/ hooks
- How can I remove a function that has been added to wordpress with add_filter?
- Sending data from custom inputs in WordPress comment form in the admin notification email
- How to control WordPress image metadata (using Imagick)?
- How do I add custom bulk actions to multiple custom post types?
- Add data attribute to each li in menu
- Show prices with tax in Woocommerce Mini Cart [closed]
- Ajax category filtering products default show all
- Add a specific part of current category page url to shortcode
- Why does my callback function not work with this custom filter hook?
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Removing “wpautop” (auto tags) only on certain pages?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- Add a product to checkout via form
- Add filter when image is uploaded?
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove the first 5 characters of the_title and orderby that
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- user_profile_update_errors hook not executing
- Set meta field to publish date + 2 weeks
- Error in custom php function doesn’t exist
- Don’t insert if permalink is the same?
- Return a numerical function value in Customizer controls
- Adding widgets to my plugin page instead of WordPress dashboard
- Unique icons next to each WordPress menu item
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- Remove author link wherever author’s name is display
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- Hide Featured Image Meta Box on Editor Screen
- Add item to top of menu using a filter in functions.php
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Add filter multiple times using only one master function
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- Run a code only on theme activation only during first activation
- Theme activation hook in php class
- Filtering a function’ output for a new continued function
- Deleting Certain terms from appearing on the front end as links
- Theme not calling Jquery properly
- Content filter won’t work
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Get access to variable from previous pageview, excluding ajax-calls
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Create page template via functions.php?
- Add meta tags to a custom header