| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post Views |
| 4 |
* |
| 5 |
* @package Powerkit |
| 6 |
* @subpackage Modules |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Init module |
| 11 |
*/ |
| 12 |
class Powerkit_Post_Views extends Powerkit_Module { |
| 13 |
|
| 14 |
/** |
| 15 |
* Register module |
| 16 |
*/ |
| 17 |
public function register() { |
| 18 |
$this->name = esc_html__( 'Post Views', 'powerkit' ); |
| 19 |
$this->desc = esc_html__( 'This module links to your Google Analytics account to retrieve the pageviews for your posts.', 'powerkit' ); |
| 20 |
$this->slug = 'post_views'; |
| 21 |
$this->type = 'default'; |
| 22 |
$this->category = 'tools'; |
| 23 |
$this->priority = 140; |
| 24 |
$this->public = true; |
| 25 |
$this->enabled = true; |
| 26 |
|
| 27 |
$this->initialize_database(); |
| 28 |
|
| 29 |
// Check Post Views Counter. |
| 30 |
if ( $this->post_views_counter() ) { |
| 31 |
|
| 32 |
// Making the module inactive. |
| 33 |
add_filter( 'powerkit_module_enabled', function( $status, $slug ) { |
| 34 |
|
| 35 |
if ( 'post_views' === $slug ) { |
| 36 |
$status = false; |
| 37 |
} |
| 38 |
|
| 39 |
return $status; |
| 40 |
}, 10, 2 ); |
| 41 |
|
| 42 |
// Set message. |
| 43 |
ob_start(); |
| 44 |
?> |
| 45 |
<div class="update-message notice inline notice-warning notice-alt"> |
| 46 |
<?php esc_html_e( 'Please deactivate the Post Views Counter plugin.', 'powerkit' ); ?> |
| 47 |
</div> |
| 48 |
<?php |
| 49 |
$this->desc .= ob_get_clean(); |
| 50 |
} else { |
| 51 |
|
| 52 |
$this->links = array( |
| 53 |
array( |
| 54 |
'name' => esc_html__( 'Go to settings', 'powerkit' ), |
| 55 |
'url' => powerkit_get_page_url( $this->slug ), |
| 56 |
), |
| 57 |
array( |
| 58 |
'name' => esc_html__( 'View documentation', 'powerkit' ), |
| 59 |
'url' => powerkit_get_setting( 'documentation' ) . '/post-views/', |
| 60 |
'target' => '_blank', |
| 61 |
), |
| 62 |
); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
/** |
| 68 |
* Check post views plugin. |
| 69 |
*/ |
| 70 |
public function post_views_counter() { |
| 71 |
return class_exists( 'Post_Views_Counter' ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Initialize database |
| 76 |
*/ |
| 77 |
public function initialize_database() { |
| 78 |
require_once dirname( __FILE__ ) . '/helpers/db-powerkit-post-views.php'; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Initialize module |
| 83 |
*/ |
| 84 |
public function initialize() { |
| 85 |
if ( $this->post_views_counter() ) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
/* Load the required dependencies for this module */ |
| 90 |
|
| 91 |
// Helpers Functions for the module. |
| 92 |
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-post-views.php'; |
| 93 |
require_once dirname( __FILE__ ) . '/helpers/query-powerkit-post-views.php'; |
| 94 |
|
| 95 |
// Admin and public area. |
| 96 |
require_once dirname( __FILE__ ) . '/admin/class-powerkit-post-views-admin.php'; |
| 97 |
|
| 98 |
new Powerkit_Post_Views_Admin( $this->slug ); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
new Powerkit_Post_Views(); |
| 103 |
|