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?
- Using register_activation_hook in classes
- How to change the wp-login.php page title?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- Allow authors to post only in categories they create in WordPress
- How to Remove a Filter from the Admin List Table?
- Woocommerce, recognize the loop of related products
- Insert all post IDs in new database table
- Filter get_the_title to remove certain characters?
- Reposition Woocommerce Message
- Get posts with at least one category in common with current post?
- How Can I Call Up The Author’s Name on a Post
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- wp_loaded hook block script enquequing
- Change the site tagline (or similar) based on current page
- Custom filter in admin edit custom post type responding with invalid post type?
- How to pass arguments to add_action() or retrieve return value of called function?
- hook that when page is starting to load
- How to change home or site url using action hooks or filter?
- Add data attribute to each li in menu
- Ajax category filtering products default show all
- Add a specific part of current category page url to shortcode
- Remove metabox from WordPress menu editor page?
- Why ajax doesn’t work on certain wordpress hooks?
- Print last modified date only on posts
- Don’t insert if permalink is the same?
- Change tinyMCE editor to allow marked content when pasting from Word
- How to make modifications only to certain elements of an HTML string on the server-side?
- How to catch wordpress post ID when it’s published
- How to append to an array and return the results in a filter?
- How can I hook into the wp_mail function used by BackWPup?
- wrap a span tag around author’s post count
- How to hide the author box of a specific user?
- How to pass hook variable to function?
- How to Create custom block for displaying information in content section which act like shortcode
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Filter ‘comment_notification_text’ not working
- Restricting displayed posts to posts from only select authors
- Use wp_head hook on template page
- Adding custom field to product category and show it to shop/category shop page
- Remove span tags from WooCommerce Downloads page
- Add a top bar to a wordpress theme without editing the header.php file?
- Get original value in save_post action hooka
- get Woocommerce product format json for WP_Query
- Is there an option to execute javascript file only on plugin activation
- How to change href of a Widget menu item link?
- How do I remove an action hook inside a class that is called by another class?
- Reload page with a different shortcode when a user selects from a dropdown
- Help hooking into user_register
- WordPress Ajax filter: Create two loops for different output styles?
- How to display custom seo title before the loop?
- Hook into all password resets in WordPress and get password before hashing?
- Following/Followers Users list Using Ajax Pagination inside Author Profile
- How to remove title tag with this filter
- Why transition_post_type hook is called twice for the same post?
- Add custom filter to register data in array
- Get terms of the posts with one query
- Woocommerce Price Text
- Limit Taxonomy Parents
- WordPress HTML Helper
- Display a post based on its metabox selection
- dynamically filter by category via sub-menu
- Change Checkout “Place Order” text if cart has a specific product
- transition_post_status hook, works – but not if the post is new
- php was updated – critical error [closed]
- Woocommerce – add tracking code to another email template
- Custom Filtering date with newsletter