|
1 | | -<?php |
2 | | - |
3 | | -namespace WeDevs\WeDocs\Admin; |
4 | | - |
5 | | -/** |
6 | | - * Modifier functions in docs list table. |
7 | | - */ |
8 | | -class Docs_List_Table { |
9 | | - |
10 | | - /** |
11 | | - * Constructor |
12 | | - */ |
13 | | - public function __construct() { |
14 | | - add_filter( 'manage_docs_posts_columns', [ $this, 'docs_list_columns' ] ); |
15 | | - add_action( 'manage_docs_posts_custom_column', [ $this, 'docs_list_columns_row' ], 10, 2 ); |
16 | | - add_filter( 'manage_edit-docs_sortable_columns', [ $this, 'docs_sortable_columns' ] ); |
17 | | - |
18 | | - add_action( 'load-edit.php', [ $this, 'edit_docs_load' ] ); |
19 | | - add_action( 'load-post.php', [ $this, 'add_meta_box' ] ); |
20 | | - |
21 | | - // load css |
22 | | - add_action( 'admin_print_styles-post.php', [ $this, 'helpfulness_css' ] ); |
23 | | - add_action( 'admin_print_styles-edit.php', [ $this, 'helpfulness_css' ] ); |
24 | | - } |
25 | | - |
26 | | - public function add_meta_box() { |
27 | | - add_meta_box( 'op-menu-meta-box-id', __( 'Helpfulness', 'wedocs' ), [ $this, 'helpfulness_metabox' ], 'docs', 'side', 'core' ); |
28 | | - } |
29 | | - |
30 | | - public function helpfulness_css() { |
31 | | - if ( 'docs' != get_current_screen()->post_type ) { |
32 | | - return; |
33 | | - } ?> |
34 | | - <style type="text/css"> |
35 | | - .wedocs-positive { color: green; } |
36 | | - .wedocs-negative { color: red; text-align: right; } |
37 | | - </style> |
38 | | - <?php |
39 | | - } |
40 | | - |
41 | | - public function helpfulness_metabox() { |
42 | | - global $post; ?> |
43 | | - <table style="width: 100%;"> |
44 | | - <tr> |
45 | | - <td class="wedocs-positive"> |
46 | | - <span class="dashicons dashicons-thumbs-up"></span> |
47 | | - <?php printf( '%d', get_post_meta( $post->ID, 'positive', true ) ); ?> |
48 | | - </td> |
49 | | - |
50 | | - <td class="wedocs-negative"> |
51 | | - <span class="dashicons dashicons-thumbs-down"></span> |
52 | | - <?php printf( '%d', get_post_meta( $post->ID, 'negative', true ) ); ?> |
53 | | - </td> |
54 | | - </tr> |
55 | | - </table> |
56 | | - <?php |
57 | | - } |
58 | | - |
59 | | - /** |
60 | | - * Vote column in the class UI. |
61 | | - * |
62 | | - * @param array $column |
63 | | - * |
64 | | - * @return array |
65 | | - */ |
66 | | - public function docs_list_columns( $columns ) { |
67 | | - $vote = [ 'votes' => __( 'Votes', 'wedocs' ) ]; |
68 | | - |
69 | | - // insert before last element, date |
70 | | - $first_items = array_splice( $columns, 0, 3 ); // remove first 3 items and store to $first_items, date remains to $columns |
71 | | - $new_columns = array_merge( $first_items, $vote, $columns ); // merge all those |
72 | | - |
73 | | - return $new_columns; |
74 | | - } |
75 | | - |
76 | | - public function docs_sortable_columns( $columns ) { |
77 | | - $columns['votes'] = [ 'votes', true ]; |
78 | | - |
79 | | - return $columns; |
80 | | - } |
81 | | - |
82 | | - public function docs_list_columns_row( $column_name, $post_id ) { |
83 | | - if ( 'votes' == $column_name ) { |
84 | | - $positive = get_post_meta( $post_id, 'positive', true ); |
85 | | - $negative = get_post_meta( $post_id, 'negative', true ); |
86 | | - |
87 | | - printf( '<span class="wedocs-positive">%d</span>/<span class="wedocs-negative">%d</span>', $positive, $negative ); |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - public function edit_docs_load() { |
92 | | - add_filter( 'request', [ $this, 'sort_docs' ] ); |
93 | | - } |
94 | | - |
95 | | - // Sorts the movies. |
96 | | - public function sort_docs( $vars ) { |
97 | | - // Check if we're viewing the 'movie' post type. |
98 | | - if ( isset( $vars['post_type'] ) && 'docs' == $vars['post_type'] ) { |
99 | | - // Check if 'orderby' is set to 'duration'. |
100 | | - if ( isset( $vars['orderby'] ) && 'votes' == $vars['orderby'] ) { |
101 | | - $vars = array_merge( |
102 | | - $vars, |
103 | | - [ |
104 | | - 'meta_key' => 'positive', |
105 | | - 'orderby' => 'meta_value_num', |
106 | | - ] |
107 | | - ); |
108 | | - } |
109 | | - } |
110 | | - |
111 | | - return $vars; |
112 | | - } |
113 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace WeDevs\WeDocs\Admin; |
| 4 | + |
| 5 | +/** |
| 6 | + * Modifier functions in docs list table. |
| 7 | + */ |
| 8 | +class Docs_List_Table { |
| 9 | + |
| 10 | + /** |
| 11 | + * Constructor |
| 12 | + */ |
| 13 | + public function __construct() { |
| 14 | + add_filter( 'manage_docs_posts_columns', [ $this, 'docs_list_columns' ] ); |
| 15 | + add_action( 'manage_docs_posts_custom_column', [ $this, 'docs_list_columns_row' ], 10, 2 ); |
| 16 | + add_filter( 'manage_edit-docs_sortable_columns', [ $this, 'docs_sortable_columns' ] ); |
| 17 | + |
| 18 | + add_action( 'load-edit.php', [ $this, 'edit_docs_load' ] ); |
| 19 | + add_action( 'load-post.php', [ $this, 'add_meta_box' ] ); |
| 20 | + |
| 21 | + // load css |
| 22 | + add_action( 'admin_print_styles-post.php', [ $this, 'helpfulness_css' ] ); |
| 23 | + add_action( 'admin_print_styles-edit.php', [ $this, 'helpfulness_css' ] ); |
| 24 | + } |
| 25 | + |
| 26 | + public function add_meta_box() { |
| 27 | + add_meta_box( 'op-menu-meta-box-id', __( 'Helpfulness', 'wedocs' ), [ $this, 'helpfulness_metabox' ], 'docs', 'side', 'core' ); |
| 28 | + } |
| 29 | + |
| 30 | + public function helpfulness_css() { |
| 31 | + if ( 'docs' != get_current_screen()->post_type ) { |
| 32 | + return; |
| 33 | + } ?> |
| 34 | + <style type="text/css"> |
| 35 | + .wedocs-positive { color: green; } |
| 36 | + .wedocs-negative { color: red; text-align: right; } |
| 37 | + </style> |
| 38 | + <?php |
| 39 | + } |
| 40 | + |
| 41 | + public function helpfulness_metabox() { |
| 42 | + global $post; ?> |
| 43 | + <table style="width: 100%;"> |
| 44 | + <tr> |
| 45 | + <td class="wedocs-positive"> |
| 46 | + <span class="dashicons dashicons-thumbs-up"></span> |
| 47 | + <?php printf( '%d', get_post_meta( $post->ID, 'positive', true ) ); ?> |
| 48 | + </td> |
| 49 | + |
| 50 | + <td class="wedocs-negative"> |
| 51 | + <span class="dashicons dashicons-thumbs-down"></span> |
| 52 | + <?php printf( '%d', get_post_meta( $post->ID, 'negative', true ) ); ?> |
| 53 | + </td> |
| 54 | + </tr> |
| 55 | + </table> |
| 56 | + <?php |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Vote column in the class UI. |
| 61 | + * |
| 62 | + * @param array $column |
| 63 | + * |
| 64 | + * @return array |
| 65 | + */ |
| 66 | + public function docs_list_columns( $columns ) { |
| 67 | + $vote = [ 'votes' => __( 'Votes', 'wedocs' ) ]; |
| 68 | + |
| 69 | + // insert before last element, date |
| 70 | + $first_items = array_splice( $columns, 0, 3 ); // remove first 3 items and store to $first_items, date remains to $columns |
| 71 | + $new_columns = array_merge( $first_items, $vote, $columns ); // merge all those |
| 72 | + |
| 73 | + return $new_columns; |
| 74 | + } |
| 75 | + |
| 76 | + public function docs_sortable_columns( $columns ) { |
| 77 | + $columns['votes'] = [ 'votes', true ]; |
| 78 | + |
| 79 | + return $columns; |
| 80 | + } |
| 81 | + |
| 82 | + public function docs_list_columns_row( $column_name, $post_id ) { |
| 83 | + if ( 'votes' == $column_name ) { |
| 84 | + $positive = get_post_meta( $post_id, 'positive', true ); |
| 85 | + $negative = get_post_meta( $post_id, 'negative', true ); |
| 86 | + |
| 87 | + printf( '<span class="wedocs-positive">%d</span>/<span class="wedocs-negative">%d</span>', $positive, $negative ); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public function edit_docs_load() { |
| 92 | + add_filter( 'request', [ $this, 'sort_docs' ] ); |
| 93 | + } |
| 94 | + |
| 95 | + // Sorts the movies. |
| 96 | + public function sort_docs( $vars ) { |
| 97 | + // Check if we're viewing the 'movie' post type. |
| 98 | + if ( isset( $vars['post_type'] ) && 'docs' == $vars['post_type'] ) { |
| 99 | + // Check if 'orderby' is set to 'duration'. |
| 100 | + if ( isset( $vars['orderby'] ) && 'votes' == $vars['orderby'] ) { |
| 101 | + $vars = array_merge( |
| 102 | + $vars, |
| 103 | + [ |
| 104 | + 'meta_key' => 'positive', |
| 105 | + 'orderby' => 'meta_value_num', |
| 106 | + ] |
| 107 | + ); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + return $vars; |
| 112 | + } |
| 113 | +} |
0 commit comments