item-reports.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Author: ExactMetrics team
  4. * Author URI: https://exactmetrics.com
  5. * Copyright 2018 ExactMetrics team
  6. * License: GPLv2 or later
  7. * License URI: http://www.gnu.org/licenses/gpl-2.0.html
  8. */
  9. // Exit if accessed directly
  10. if ( ! defined( 'ABSPATH' ) )
  11. exit();
  12. if ( ! class_exists( 'GADWP_Backend_Item_Reports' ) ) {
  13. final class GADWP_Backend_Item_Reports {
  14. private $gadwp;
  15. public function __construct() {
  16. $this->gadwp = GADWP();
  17. if ( GADWP_Tools::check_roles( $this->gadwp->config->options['access_back'] ) && 1 == $this->gadwp->config->options['backend_item_reports'] ) {
  18. // Add custom column in Posts List
  19. add_filter( 'manage_posts_columns', array( $this, 'add_columns' ) );
  20. // Populate custom column in Posts List
  21. add_action( 'manage_posts_custom_column', array( $this, 'add_icons' ), 10, 2 );
  22. // Add custom column in Pages List
  23. add_filter( 'manage_pages_columns', array( $this, 'add_columns' ) );
  24. // Populate custom column in Pages List
  25. add_action( 'manage_pages_custom_column', array( $this, 'add_icons' ), 10, 2 );
  26. }
  27. }
  28. public function add_icons( $column, $id ) {
  29. global $wp_version;
  30. if ( 'gadwp_stats' != $column ) {
  31. return;
  32. }
  33. if ( version_compare( $wp_version, '3.8.0', '>=' ) ) {
  34. echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area">&nbsp;</a>';
  35. } else {
  36. echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadwp-icon.png"</a>';
  37. }
  38. }
  39. public function add_columns( $columns ) {
  40. return array_merge( $columns, array( 'gadwp_stats' => __( 'Analytics', 'google-analytics-dashboard-for-wp' ) ) );
  41. }
  42. }
  43. }