class-admin-feed-columns.php
10 months ago
class-admin-menu.php
2 years ago
class-admin-notice.php
1 year ago
class-admin-page.php
3 years ago
class-admin-rateus-ajax.php
1 year ago
class-admin-rev.php
1 year ago
class-admin-tophead.php
1 year ago
class-admin-feed-columns.php
100 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 | 'rating' => 'Rating' |
| 16 | ); |
| 17 | |
| 18 | public function __construct($feed_deserializer) { |
| 19 | $this->feed_deserializer = $feed_deserializer; |
| 20 | } |
| 21 | |
| 22 | public function register() { |
| 23 | add_filter('get_edit_post_link', array($this, 'change_edit_post_link'), 10, 3); |
| 24 | add_filter('manage_edit-' . Post_Types::FEED_POST_TYPE . '_columns', array($this, 'get_columns')); |
| 25 | add_action('manage_' . Post_Types::FEED_POST_TYPE . '_posts_custom_column', array($this, 'render'), 10, 2); |
| 26 | add_filter('post_row_actions', array($this, 'change_post_row_actions'), 10, 2); |
| 27 | add_filter('get_the_excerpt', array($this, 'hide_grw_feed_excerpt'), 10, 2); |
| 28 | } |
| 29 | |
| 30 | public function change_edit_post_link($link, $id, $context) { |
| 31 | if (function_exists('get_current_screen')) { |
| 32 | $screen = get_current_screen(); |
| 33 | if (empty($screen) || $screen->post_type !== Post_Types::FEED_POST_TYPE) { |
| 34 | return $link; |
| 35 | } |
| 36 | return admin_url('admin.php?page=grw-builder&' . Post_Types::FEED_POST_TYPE . '_id=' . $id); |
| 37 | } else { |
| 38 | return; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public function get_columns($columns) { |
| 43 | $columns = $columns; |
| 44 | $columns = array( |
| 45 | 'cb' => '<input type="checkbox">', |
| 46 | 'title' => __('Title', 'widget-google-reviews'), |
| 47 | 'ID' => __('ID', 'widget-google-reviews'), |
| 48 | 'grw_theme' => __('Theme', 'widget-google-reviews'), |
| 49 | 'grw_shortcode' => __('Shortcode', 'widget-google-reviews'), |
| 50 | 'date' => __('Date', 'widget-google-reviews'), |
| 51 | ); |
| 52 | return $columns; |
| 53 | } |
| 54 | |
| 55 | public function render($column_name, $post_id) { |
| 56 | $args = array(); |
| 57 | |
| 58 | if (isset($_GET['post_status'])) { |
| 59 | $post_status = sanitize_text_field(wp_unslash($_GET['post_status'])); |
| 60 | |
| 61 | if ($post_status === 'trash') { |
| 62 | $args['post_status'] = array('trash'); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $feed = $this->feed_deserializer->get_feed($post_id, $args); |
| 67 | if (!$feed) { |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | $connection = json_decode($feed->post_content); |
| 72 | |
| 73 | switch ($column_name) { |
| 74 | case 'ID': |
| 75 | echo $feed->ID; |
| 76 | break; |
| 77 | case 'grw_theme': |
| 78 | echo isset($connection->options->view_mode) ? self::$plugin_themes[$connection->options->view_mode] : 'List'; |
| 79 | break; |
| 80 | case 'grw_shortcode': |
| 81 | echo '<input type="text" value="[grw id=' . $feed->ID . ']" onclick="this.select(); document.execCommand(\'copy\');var sm=this.nextSibling;sm.className=\'\';setTimeout(function() {sm.className=\'grw_hide\';},10);" readonly=""><small>shortcode copied</small>'; |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | public function change_post_row_actions($actions, $post) { |
| 87 | if (isset($actions) && $post->post_type === Post_Types::FEED_POST_TYPE) { |
| 88 | $changed_actions = array( |
| 89 | 'post-id' => '<span class="grw-admin-column-action">ID: ' . $post->ID . '</span>', |
| 90 | ); |
| 91 | $actions = $changed_actions + $actions; |
| 92 | } |
| 93 | return $actions; |
| 94 | } |
| 95 | |
| 96 | public function hide_grw_feed_excerpt($excerpt, $post = null) { |
| 97 | return $post->post_type !== Post_Types::FEED_POST_TYPE ? $excerpt : ''; |
| 98 | } |
| 99 | } |
| 100 |