| 1 |
<?php |
| 2 |
/** |
| 3 |
* Posts handling |
| 4 |
* |
| 5 |
* Handles all post operations and detection. |
| 6 |
* |
| 7 |
* @package System |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace OPcacheManager\System; |
| 13 |
|
| 14 |
|
| 15 |
/** |
| 16 |
* Define the post functionality. |
| 17 |
* |
| 18 |
* Handles all post operations and detection. |
| 19 |
* |
| 20 |
* @package System |
| 21 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Post { |
| 25 |
|
| 26 |
/** |
| 27 |
* Initializes the class and set its properties. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get a user nice name. |
| 36 |
* |
| 37 |
* @param integer $id Optional. The post id. |
| 38 |
* @param string $default Optional. Default value to return if post has no title. |
| 39 |
* @return string The user nice name if detected, $default otherwise. |
| 40 |
* @since 1.0.0 |
| 41 |
*/ |
| 42 |
public static function get_post_title( $id = 0, $default = 'untitled' ) { |
| 43 |
$title = get_the_title( $id ); |
| 44 |
if ( '' !== $id ) { |
| 45 |
return $title; |
| 46 |
|
| 47 |
} else { |
| 48 |
return $default; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Get a user string representation. |
| 54 |
* |
| 55 |
* @param integer $id Optional. The user id. |
| 56 |
* @return string The post string representation, ready to be inserted in a log. |
| 57 |
* @since 1.0.0 |
| 58 |
*/ |
| 59 |
public static function get_post_string( $id = 0 ) { |
| 60 |
$post = get_post( $id ); |
| 61 |
$id = isset( $post->ID ) ? $post->ID : 0; |
| 62 |
$title = self::get_post_title( $id ); |
| 63 |
return sprintf( '"%s" (post ID %s)', $title, $id ); |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|