Advertisement
geminilabs

[site-reviews] add assigned_to permalink to summary text

Apr 1st, 2019
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. /**
  2.  * Adds a link of the assigned page to the Site Reviews summary text
  3.  * Paste this in your active theme's functions.php file.
  4.  * @param array $fields
  5.  * @return array
  6.  */
  7. add_filter( 'site-reviews/rendered/template/reviews-summary', function( $template, $data ) {
  8.     if( !empty( $data['context']['assigned_to'] )) {
  9.         $permalink = get_the_permalink( $data['context']['assigned_to'] );
  10.         $title = get_the_title( $data['context']['assigned_to'] );
  11.         if( $permalink && $title ) {
  12.             $assignedToPermalink = sprintf( ' of <a href="%s">%s</a>', $permalink, $title );
  13.             $template = preg_replace( '/(\(based on \d+ reviews?)(\))/', '$1'.$assignedToPermalink.'$2', $template );
  14.         }
  15.     }
  16.     return $template;
  17. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement