PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0
Admin Columns v3.0
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Helper / Post.php
codepress-admin-columns / classes / Helper Last commit date
Array.php 9 years ago Date.php 9 years ago File.php 9 years ago Html.php 9 years ago Icon.php 9 years ago Image.php 9 years ago Network.php 9 years ago Post.php 9 years ago String.php 9 years ago Taxonomy.php 9 years ago User.php 9 years ago
Post.php
119 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Helper_Post {
8
9 /**
10 * @param int $id
11 *
12 * @return bool
13 */
14 public function exists( $id ) {
15 return $this->get_raw_field( 'ID', $id ) ? true : false;
16 }
17
18 /**
19 * @param int $id Post ID
20 *
21 * @return false|string Post Title
22 */
23 public function get_raw_post_title( $id ) {
24 return ac_helper()->post->get_raw_field( 'post_title', $id );
25 }
26
27 /**
28 * @since 1.0
29 *
30 * @param int $post_id Post ID
31 *
32 * @return string Post Excerpt.
33 */
34 public function excerpt( $post_id, $words = 400 ) {
35 global $post;
36
37 $save_post = $post;
38 $post = get_post( $post_id );
39
40 setup_postdata( $post );
41
42 $excerpt = get_the_excerpt();
43 $post = $save_post;
44
45 if ( $post ) {
46 setup_postdata( $post );
47 }
48
49 return ac_helper()->string->trim_words( $excerpt, $words );
50 }
51
52 /**
53 * @param string $post_type
54 * @param bool $plural
55 *
56 * @return bool
57 */
58 public function get_post_type_label( $post_type, $plural = false ) {
59 $post_type = get_post_type_object( $post_type );
60
61 if ( ! $post_type ) {
62 return false;
63 }
64
65 if ( $plural ) {
66 return $post_type->labels->name;
67 }
68
69 return $post_type->labels->singular_name;
70 }
71
72 /**
73 * @param string $field Field
74 * @param int $id Post ID
75 *
76 * @return string|false
77 */
78 public function get_raw_field( $field, $id ) {
79 global $wpdb;
80
81 if ( ! $id || ! is_numeric( $id ) ) {
82 return false;
83 }
84
85 $sql = "
86 SELECT " . $wpdb->_real_escape( $field ) . "
87 FROM $wpdb->posts
88 WHERE ID = %d
89 LIMIT 1
90 ";
91
92 return $wpdb->get_var( $wpdb->prepare( $sql, $id ) );
93 }
94
95 /**
96 * Get Post Title or Media Filename
97 *
98 * @param int|WP_Post $post
99 *
100 * @return bool|string
101 */
102 public function get_title( $post ) {
103 $post = get_post( $post );
104
105 if ( ! $post ) {
106 return false;
107 }
108
109 $title = $post->post_title;
110
111 if ( 'attachment' == $post->post_type ) {
112 $title = ac_helper()->image->get_file_name( $post->ID );
113 }
114
115 return $title;
116 }
117
118 }
119