PluginProbe
OPcache Manager / 3.3.0
OPcache Manager v3.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.14.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.5.0 2.6.0 All 36 releases
opcache-manager / includes / system / class-post.php

class-post.php in OPcache Manager 3.3.0, at includes/system/class-post.php

67 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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