getLogRowPlainTextOutput() public method

Defaults to log message with context interpolated. Keep format as plain and simple as possible. Links are ok, for example to link to users or posts. Tags will be stripped when text is used for CSV-exports and so on. Keep it on a single line. No

or
and so on. Example output: Edited post "About the company" Message should sound like it's coming from the user. Image that the name of the user is added in front of the text: Jessie James: Edited post "About the company"

public getLogRowPlainTextOutput ( $row )
Exemplo n.º 1
0
 /**
  * Modify plain output to inlcude link to post
  */
 public function getLogRowPlainTextOutput($row)
 {
     $message = $row->message;
     $context = $row->context;
     $message_key = $context["_message_key"];
     $attachment_id = $context["attachment_id"];
     $attachment_post = get_post($attachment_id);
     $attachment_is_available = is_a($attachment_post, "WP_Post");
     // Only link to attachment if it is still available
     if ($attachment_is_available) {
         if ("attachment_updated" == $message_key) {
             $message = __('Edited {post_type} <a href="{edit_link}">"{attachment_title}"</a>', "simple-history");
         } else {
             if ("attachment_created" == $message_key) {
                 $message = __('Uploaded {post_type} <a href="{edit_link}">"{attachment_title}"</a>', "simple-history");
             }
         }
         $context["post_type"] = esc_html($context["post_type"]);
         $context["attachment_filename"] = esc_html($context["attachment_filename"]);
         $context["edit_link"] = get_edit_post_link($attachment_id);
         $message = $this->interpolate($message, $context, $row);
     } else {
         // Attachment post is not available, attachment has probably been deleted
         $message = parent::getLogRowPlainTextOutput($row);
     }
     return $message;
 }
Exemplo n.º 2
0
 /**
  * Add widget name and sidebar name to output
  */
 function getLogRowPlainTextOutput($row)
 {
     $context = $row->context;
     $message_key = $context["_message_key"];
     $message = $row->message;
     $output = "";
     // Widget changed or added or removed
     // Simple replace widget_id_base and sidebar_id with widget name and sidebar name
     if (in_array($message_key, array("widget_added", "widget_edited", "widget_removed"))) {
         $widget = $this->getWidgetByIdBase($context["widget_id_base"]);
         $sidebar = $this->getSidebarById($context["sidebar_id"]);
         if ($widget && $sidebar) {
             // Translate message first
             $message = $this->messages[$message_key]["translated_text"];
             $message = $this->interpolate($message, array("widget_id_base" => $widget->name, "sidebar_id" => $sidebar["name"]), $row);
             $output .= $message;
         }
     }
     // Fallback to default/parent output if nothing was added to output
     if (!$output) {
         $output .= parent::getLogRowPlainTextOutput($row);
     }
     return $output;
 }
 /**
  * Modify row output
  */
 public function getLogRowPlainTextOutput($row)
 {
     $context = $row->context;
     $output = parent::getLogRowPlainTextOutput($row);
     $current_user_id = get_current_user_id();
     if ("user_updated_profile" == $context["_message_key"]) {
         $wp_user = get_user_by("id", $context["edited_user_id"]);
         // If edited_user_id and _user_id is the same then a user edited their own profile
         // Note: it's not the same thing as the currently logged in user (but.. it can be!)
         if (!empty($context["_user_id"]) && $context["edited_user_id"] === $context["_user_id"]) {
             if ($wp_user) {
                 $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
                 // User still exist, so link to their profile
                 if ($current_user_id === $context["_user_id"]) {
                     // User that is viewing the log is the same as the edited user
                     $msg = __('Edited <a href="{edit_profile_link}">your profile</a>', "simple-history");
                 } else {
                     $msg = __('Edited <a href="{edit_profile_link}">their profile</a>', "simple-history");
                 }
                 $output = $this->interpolate($msg, $context, $row);
             } else {
                 // User does not exist any longer
                 $output = __("Edited your profile", "simple-history");
             }
         } else {
             // User edited another users profile
             if ($wp_user) {
                 // Edited user still exist, so link to their profile
                 $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
                 $msg = __('Edited the profile for user <a href="{edit_profile_link}">{edited_user_login} ({edited_user_email})</a>', "simple-history");
                 $output = $this->interpolate($msg, $context, $row);
             } else {
                 // Edited user does not exist any longer
             }
         }
     }
     // if user_updated_profile
     return $output;
 }
 /**
  * Modify plain text row output
  * - adds link to user profil
  * - change to "your profile" if you're looking at your own edit
  */
 public function getLogRowPlainTextOutput($row)
 {
     $context = $row->context;
     $output = parent::getLogRowPlainTextOutput($row);
     $current_user_id = get_current_user_id();
     if ("user_updated_profile" == $context["_message_key"]) {
         $wp_user = get_user_by("id", $context["edited_user_id"]);
         // If edited_user_id and _user_id is the same then a user edited their own profile
         // Note: it's not the same thing as the currently logged in user (but.. it can be!)
         if (!empty($context["_user_id"]) && $context["edited_user_id"] === $context["_user_id"]) {
             if ($wp_user) {
                 $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
                 $use_you = apply_filters("simple_history/user_logger/plain_text_output_use_you", true);
                 //error_log( serialize( $current_user_id) ); // int 1
                 //error_log( serialize( $context["_user_id"]) ); // string 1
                 // User still exist, so link to their profile
                 if ((int) $current_user_id === (int) $context["_user_id"] && $use_you) {
                     // User that is viewing the log is the same as the edited user
                     $msg = __('Edited <a href="{edit_profile_link}">your profile</a>', "simple-history");
                 } else {
                     $msg = __('Edited <a href="{edit_profile_link}">their profile</a>', "simple-history");
                 }
                 $output = $this->interpolate($msg, $context, $row);
             } else {
                 // User does not exist any longer
                 $output = __("Edited your profile", "simple-history");
             }
         } else {
             // User edited another users profile
             if ($wp_user) {
                 // Edited user still exist, so link to their profile
                 $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
                 $msg = __('Edited the profile for user <a href="{edit_profile_link}">{edited_user_login} ({edited_user_email})</a>', "simple-history");
                 $output = $this->interpolate($msg, $context, $row);
             } else {
                 // Edited user does not exist any longer
             }
         }
         // if user_updated_profile
     } else {
         if ("user_created" == $context["_message_key"]) {
             // A user was created. Create link of username that goes to user profile.
             $wp_user = get_user_by("id", $context["created_user_id"]);
             // If edited_user_id and _user_id is the same then a user edited their own profile
             // Note: it's not the same thing as the currently logged in user (but.. it can be!)
             if ($wp_user) {
                 $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
                 // User that is viewing the log is the same as the edited user
                 $msg = __('Created user <a href="{edit_profile_link}">{created_user_login} ({created_user_email})</a> with role {created_user_role}', "simple-history");
                 $output = $this->interpolate($msg, $context, $row);
             } else {
                 // User does not exist any longer, keep original message
             }
         }
     }
     return $output;
 }
 /**
  * Give some options better plain text output
  *
  * Not doing anything at the moment, because it was really difficaly to give them meaningful text values
  */
 public function getLogRowPlainTextOutput($row)
 {
     $message = $row->message;
     $context = $row->context;
     $message_key = $context["_message_key"];
     $return_message = "";
     // Only link to attachment if it is still available
     if ("option_updated" == $message_key) {
         /*
         $option = isset( $context["option"] ) ? $context["option"] : null;
         $option_page = isset( $context["option_page"] ) ? $context["option_page"] : null;
         $new_value = isset( $context["new_value"] ) ? $context["new_value"] : null;
         $old_value = isset( $context["old_value"] ) ? $context["old_value"] : null;
         
         # $return_message = "";
         $arr_options_to_translate = array(
         	"$option_page/blog_public" => array(
         		"text" => "Updated setting Search Engine Visibility"
         	),
         	"$option_page/rss_use_excerpt" => array(
         		"text" => "Updated setting For each article in a feed, show"
         	),
         	"$option_page/posts_per_rss" => array(
         		"text" => "Updated setting for Syndication feeds show the most recent"
         	),
         	"$option_page/posts_per_page" => array(
         		"text" => "Updated setting for Blog pages show at most"
         	)
         );
         
         if ( isset( $arr_options_to_translate[ "{$option_page}/{$option}" ] ) ) {
         	$return_message = $arr_options_to_translate[ "{$option_page}/{$option}" ]["text"];
         }
         */
     }
     if (empty($return_message)) {
         // No specific text to output, fallback to default
         $return_message = parent::getLogRowPlainTextOutput($row);
     }
     return $return_message;
 }