-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac-column-custom_author.php
executable file
·110 lines (83 loc) · 3.49 KB
/
ac-column-custom_author.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
class AC_Column_custom_author extends AC_Column {
public function __construct() {
// Identifier, pick an unique name. Single word, no spaces. Underscores allowed.
$this->set_type( 'column-custom_author' );
// Default column label.
$this->set_label( __( 'Custom Author', 'ac-custom_author' ) );
}
/**
* Returns the display value for the column.
*
* @param int $id ID
* @return string Value
*/
public function get_value( $post_id ) {
// get raw value
$value = $this->get_raw_value( $post_id );
// optionally you can change the display of the value. In this example we added a post link.
$value = '<a href="' . esc_url( get_permalink( $post_id ) ) . '">' . $value . '</a>';
return $value;
}
/**
* Get the raw, underlying value for the column
* Not suitable for direct display, use get_value() for that
* This value will be used by 'inline-edit' and get_value().
*
* @param int $id ID
* @return mixed Value
*/
public function get_raw_value( $post_id ) {
// put all the column logic here to retrieve the value you need
// For example: $value = get_post_meta( $post_id, '_my_custom_field_example', true );
$value = 'something';
return $value;
}
/**
* (Optional) Create extra settings for you column. These are visible when editing a column. You can remove this function is you do not use it!
*
* Write your own settings or use any of the standard available settings.
*/
protected function register_settings() {
// NOTE! When you use any of these settings, you should remove the get_value() method from this column, because the value will be rendered by the AC_Settings_Column_{$type} classes.
// Display an image preview size settings screen
// $this->add_setting( new AC_Settings_Column_Image( $this ) );
// Display an excerpt length input field in words
// $this->add_setting( new AC_Settings_Column_WordLimit( $this ) );
// Display an excerpt length input field in characters
// $this->add_setting( new AC_Settings_Column_CharacterLimit( $this ) );
// Display a date format settings input field
// $this->add_setting( new AC_Settings_Column_Date( $this ) );
// Display before and after input fields
// $this->add_setting( new AC_Settings_Column_BeforeAfter( $this ) );
// Displays a dropdown menu with user display formats
// $this->add_setting( new AC_Settings_Column_User( $this ) );
// Displays a dropdown menu with post display formats
// $this->add_setting( new AC_Settings_Column_Post( $this ) );
}
/**
* (Optional) Is valid. You can remove this function is you do not use it!
*
* This determines whether the column should be available. If you want to disable this column
* for a particular post type you can set this to false.
*
* @return bool True/False Default should be 'true'.
*/
public function is_valid() {
// Example: if the post type does not support thumbnails then return false
// if ( ! post_type_supports( $this->get_post_type(), 'thumbnail' ) ) {
// return false;
// }
return true;
}
/*
* (Optional) Enqueue CSS + JavaScript on the admin listings screen. You can remove this function is you do not use it!
*
* This action is called in the admin_head action on the listings screen where your column values are displayed.
* Use this action to add CSS + JavaScript
*/
public function scripts() {
// wp_enqueue_script( 'ac-custom_author', plugin_dir_url( __FILE__ ) . "js/column.js" );
// wp_enqueue_style( 'ac-custom_author', plugin_dir_url( __FILE__ ) . "css/column.css" );
}
}