class-admin-feed-columns.php
2 years ago
class-admin-menu.php
3 years ago
class-admin-notice.php
3 years ago
class-admin-page.php
3 years ago
class-admin-rateus-ajax.php
3 years ago
class-admin-rev.php
3 years ago
class-admin-tophead.php
3 years ago
class-admin-feed-columns.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes\Admin; |
| 4 | |
| 5 | use WP_Rplg_Google_Reviews\Includes\Post_Types; |
| 6 | |
| 7 | class Admin_Feed_Columns { |
| 8 | |
| 9 | private $feed_deserializer; |
| 10 | |
| 11 | private static $plugin_themes = array( |
| 12 | 'list' => 'List', |
| 13 | 'slider' => 'Slider', |
| 14 | 'grid' => 'Grid', |
| 15 | ); |
| 16 | |
| 17 | public function __construct($feed_deserializer) { |
| 18 | $this->feed_deserializer = $feed_deserializer; |
| 19 | } |
| 20 | |
| 21 | public function register() { |
| 22 | add_filter('get_edit_post_link', array($this, 'change_edit_post_link'), 10, 3); |
| 23 | add_filter('manage_edit-' . Post_Types::FEED_POST_TYPE . '_columns', array($this, 'get_columns')); |
| 24 | add_action('manage_' . Post_Types::FEED_POST_TYPE . '_posts_custom_column', array($this, 'render'), 10, 2); |
| 25 | add_filter('post_row_actions', array($this, 'change_post_row_actions'), 10, 2); |
| 26 | add_filter('get_the_excerpt', array($this, 'hide_grw_feed_excerpt'), 10, 2); |
| 27 | } |
| 28 | |
| 29 | public function change_edit_post_link($link, $id, $context) { |
| 30 | if (function_exists('get_current_screen')) { |
| 31 | $screen = get_current_screen(); |
| 32 | if (empty($screen) || $screen->post_type !== Post_Types::FEED_POST_TYPE) { |
| 33 | return $link; |
| 34 | } |
| 35 | return admin_url('admin.php?page=grw-builder&' . Post_Types::FEED_POST_TYPE . '_id=' . $id); |
| 36 | } else { |
| 37 | return; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public function get_columns($columns) { |
| 42 | $columns = $columns; |
| 43 | $columns = array( |
| 44 | 'cb' => '<input type="checkbox">', |
| 45 | 'title' => __('Title', 'widget-google-reviews'), |
| 46 | 'ID' => __('ID', 'widget-google-reviews'), |
| 47 | 'grw_theme' => __('Theme', 'widget-google-reviews'), |
| 48 | 'date' => __('Date', 'widget-google-reviews'), |
| 49 | ); |
| 50 | return $columns; |
| 51 | } |
| 52 | |
| 53 | public function render($column_name, $post_id) { |
| 54 | $args = array(); |
| 55 | |
| 56 | if (isset($_GET['post_status'])) { |
| 57 | $post_status = sanitize_text_field(wp_unslash($_GET['post_status'])); |
| 58 | |
| 59 | if ($post_status === 'trash') { |
| 60 | $args['post_status'] = array('trash'); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | $feed = $this->feed_deserializer->get_feed($post_id, $args); |
| 65 | if (!$feed) { |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | $connection = json_decode($feed->post_content); |
| 70 | |
| 71 | switch ($column_name) { |
| 72 | case 'ID': |
| 73 | echo $feed->ID; |
| 74 | break; |
| 75 | case 'grw_theme': |
| 76 | echo isset($connection->options->view_mode) ? self::$plugin_themes[$connection->options->view_mode] : 'List'; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public function change_post_row_actions($actions, $post) { |
| 82 | if (isset($actions) && $post->post_type === Post_Types::FEED_POST_TYPE) { |
| 83 | $changed_actions = array( |
| 84 | 'post-id' => '<span class="grw-admin-column-action">ID: ' . $post->ID . '</span>', |
| 85 | ); |
| 86 | $actions = $changed_actions + $actions; |
| 87 | } |
| 88 | return $actions; |
| 89 | } |
| 90 | |
| 91 | public function hide_grw_feed_excerpt($excerpt, $post = null) { |
| 92 | return $post->post_type !== Post_Types::FEED_POST_TYPE ? $excerpt : ''; |
| 93 | } |
| 94 | } |
| 95 |