| 1 |
<?php |
| 2 |
|
| 3 |
abstract class Logtivity_Abstract_Logger |
| 4 |
{ |
| 5 |
protected $logger; |
| 6 |
|
| 7 |
protected $ignoredPostTypes = ['revision', 'customize_changeset']; |
| 8 |
|
| 9 |
protected $ignoredPostTitles = ['Auto Draft']; |
| 10 |
|
| 11 |
protected $ignoredPostStatuses = ['trash']; |
| 12 |
|
| 13 |
public function __construct() |
| 14 |
{ |
| 15 |
$this->registerHooks(); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Check against certain rules on whether we should ignore the logging of a certain post |
| 20 |
* |
| 21 |
* @param WP_Post $post |
| 22 |
* @return bool |
| 23 |
*/ |
| 24 |
protected function shouldIgnore($post) |
| 25 |
{ |
| 26 |
if ($this->ignoringPostType($post->post_type)) { |
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
if ($this->ignoringPostTitle($post->post_title)) { |
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
if ($this->ignoringPostStatus($post->post_status)) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Ignoring certain post statuses. Example: trash. |
| 43 |
* We already have a postWasTrashed hook so |
| 44 |
* don't need to log twice. |
| 45 |
* |
| 46 |
* @param string $post_status |
| 47 |
* @return bool |
| 48 |
*/ |
| 49 |
protected function ignoringPostStatus($post_status) |
| 50 |
{ |
| 51 |
return in_array($post_status, $this->ignoredPostStatuses); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Ignoring certain post types. Particularly system generated |
| 56 |
* that are not directly triggered by the user. |
| 57 |
* |
| 58 |
* @param string $post_type |
| 59 |
* @return bool |
| 60 |
*/ |
| 61 |
protected function ignoringPostType($post_type) |
| 62 |
{ |
| 63 |
return in_array($post_type, $this->ignoredPostTypes); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Ignore certain system generated post titles |
| 68 |
* |
| 69 |
* @param string $title |
| 70 |
* @return bool |
| 71 |
*/ |
| 72 |
protected function ignoringPostTitle($title) |
| 73 |
{ |
| 74 |
return in_array($title, $this->ignoredPostTitles); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Generate a label version of the given post ids post type |
| 79 |
* |
| 80 |
* @param integer $post_id |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
protected function getPostTypeLabel($post_id) |
| 84 |
{ |
| 85 |
return ucwords( str_replace(['_', '-'], ' ', get_post_type($post_id)) ); |
| 86 |
} |
| 87 |
} |