In my plugin, I have this statement
add_filter( 'comment_edit_redirect', 'mcd_return_link');
and this function
function mcd_return_link {
return "edit-comments.php";
}
Inside the comments.php (core file), is this section of code (within the section to edit comments, around line 310) (version 4.720
$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
/**
* Filters the URI the user is redirected to after editing a comment in the admin.
*
* @since 2.1.0
*
* @param string $location The URI the user will be redirected to.
* @param int $comment_id The ID of the comment being edited.
*/
$location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
wp_redirect( $location );
The intent of the add_filter
is to change the $location
value in the comments.php file to return back to the comment lists screen (in admin).
So my plugin uses a shortcode that is entered on a page
- the shortcode creates a list of comments, each comment with a link to that comment's edit screen (it does)
- have links to the edit comments screen for a specific comment (it does)
- clicking on that link gets me to the comment's edit screen (it does)
- clicking on the 'update' button should return me to the edit-comments.php page (it doesn't).
To check if the filter is being applied, on my test system, I added code before and after the apply_filters
line in core comments.php to echo the $location
value.
Both values (before and after) show the calling page (my page that displays comments with edit links). It does not redirect to the 'edit-comments.php' page, so it appears that the filter is not being applied.
I have tried changing the priority of the add_filter
to 7 and 15, with no effect.
I have also dumped the $wp_filter
global variable to ensure that the filter was recognized (it was).
Why is the filter not being applied?
** (Edited 6 Feb after suggested answers) **
I added an echo statement and a wp_die() inside the filter function. I also did further testing of this issue on my test multisite.
- The shortcode that the plugin uses is on a page on the main (site 0) subsite of the multisite test system.
- links on all comments go to the editing url of the comment
- any comments on the site 0 subsite (where the page is that displays the list of comments of all sites) bring you to the comment edit screen, and then "update" will return you to the page defined by the filter (as intended).
- any comment links from site-1 or other non-site-0 sites bring you to the comment edit screee, and then "update" will reload the calling page (the comment list page (not as intended)
- with the wp_die() inserted into the filter function (the function that sets up the desired return page, overriding the $location setting in comments.php), the site-0 editing/update process shows the 'wp_die' message. The site-1 or site-2 editing/update process does not show the 'wp_die' message.
From this, I conclude that for some reason, the add-filter is not called by any link to a comment on site-1 or site-2, but works if called from links to a comment on site-0. Again, the page that displays the comments is on site-0.
So, why doesn't the add-filter work on any link that goes to the comment editing screen for site-1 or site-2, when it works properly on site-0?
POST
-target link does not have the filter that you found in core?