feature-feedback
1 year ago
licensing
1 year ago
notifications
6 months ago
pages
1 month ago
reports
1 month ago
site-notes
1 month ago
admin-assets.php
1 month ago
admin.php
1 month ago
ajax.php
1 month ago
api-auth.php
1 month ago
class-monsterinsights-am-deactivation-survey.php
8 months ago
class-monsterinsights-charitable-notice.php
7 months ago
class-monsterinsights-onboarding.php
1 month ago
class-monsterinsights-usage-tracking.php
1 month ago
common.php
1 month ago
eea-compliance.php
1 month ago
exclude-page-metabox.php
1 month ago
index.php
3 years ago
notice.php
1 year ago
notification-event-runner.php
1 year ago
notification-event.php
1 year ago
notifications.php
1 month ago
product-feed-cronjob.php
6 months ago
reporting.php
3 years ago
review.php
1 year ago
routes.php
1 month ago
setup-checklist.php
1 month ago
sharedcount.php
1 year ago
tracking.php
7 months ago
translations.php
1 year ago
uninstall.php
4 years ago
wp-site-health.php
3 years ago
exclude-page-metabox.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Metabox class. |
| 5 | */ |
| 6 | |
| 7 | // Exit if accessed directly |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | if ( ! class_exists( 'MonsterInsights_MetaBox_ExcludePage' ) ) { |
| 12 | class MonsterInsights_MetaBox_ExcludePage { |
| 13 | |
| 14 | public function __construct() { |
| 15 | add_action( 'init', [ $this, 'register_meta' ] ); |
| 16 | |
| 17 | if ( ! is_admin() ) { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | add_action( 'load-post.php', [ $this, 'meta_box_init' ] ); |
| 22 | add_action( 'load-post-new.php', [ $this, 'meta_box_init' ] ); |
| 23 | } |
| 24 | |
| 25 | private function is_gutenberg_editor() { |
| 26 | if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | $current_screen = get_current_screen(); |
| 31 | if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) { |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | private function get_current_post_type() { |
| 39 | global $post; |
| 40 | |
| 41 | if ( $post && $post->post_type ) { |
| 42 | return $post->post_type; |
| 43 | } |
| 44 | |
| 45 | global $typenow; |
| 46 | |
| 47 | if ( $typenow ) { |
| 48 | return $typenow; |
| 49 | } |
| 50 | |
| 51 | global $current_screen; |
| 52 | |
| 53 | if ( $current_screen && $current_screen->post_type ) { |
| 54 | return $current_screen->post_type; |
| 55 | } |
| 56 | |
| 57 | if ( isset( $_REQUEST['post_type'] ) ) { |
| 58 | return sanitize_key( $_REQUEST['post_type'] ); |
| 59 | } |
| 60 | |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | public function meta_box_init() { |
| 65 | $post_type = $this->get_current_post_type(); |
| 66 | if ( ! is_post_type_viewable( $post_type ) ) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | add_action( 'admin_enqueue_scripts', array( $this, 'load_metabox_styles' ) ); |
| 71 | if ( $this->is_gutenberg_editor() ) { |
| 72 | return; |
| 73 | } |
| 74 | if ( 'attachment' !== $post_type ) { |
| 75 | add_action( 'add_meta_boxes', [ $this, 'create_meta_box' ] ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public function register_meta() { |
| 80 | if ( ! function_exists( 'register_post_meta' ) ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | register_post_meta( |
| 85 | '', |
| 86 | '_monsterinsights_skip_tracking', |
| 87 | [ |
| 88 | 'auth_callback' => '__return_true', |
| 89 | 'default' => false, |
| 90 | 'show_in_rest' => true, |
| 91 | 'single' => true, |
| 92 | 'type' => 'boolean', |
| 93 | ] |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | public function create_meta_box() { |
| 98 | add_meta_box( |
| 99 | 'monsterinsights-metabox', |
| 100 | 'MonsterInsights', |
| 101 | [ $this, 'print_metabox_html' ], |
| 102 | null, |
| 103 | 'side', |
| 104 | 'high' |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | public function print_metabox_html( $post ) { |
| 109 | $skipped = (bool) get_post_meta( $post->ID, '_monsterinsights_skip_tracking', true ); |
| 110 | wp_nonce_field( 'monsterinsights_metabox', 'monsterinsights_metabox_nonce' ); |
| 111 | ?> |
| 112 | <div class="monsterinsights-metabox" id="monsterinsights-metabox-skip-tracking"> |
| 113 | <div class="monsterinsights-metabox-input-checkbox"> |
| 114 | <label class=""> |
| 115 | <input type="checkbox" name="_monsterinsights_skip_tracking" |
| 116 | value="1" <?php checked( $skipped ); ?> <?php disabled( ! monsterinsights_is_pro_version() ); ?>> |
| 117 | <span |
| 118 | class="monsterinsights-metabox-input-checkbox-label"><?php _e( 'Exclude page from Google Analytics Tracking', 'google-analytics-for-wordpress' ); ?></span> |
| 119 | </label> |
| 120 | </div> |
| 121 | <div class="monsterinsights-metabox-helper"> |
| 122 | <?php _e( 'Toggle to prevent Google Analytics from tracking this page.', 'google-analytics-for-wordpress' ); ?> |
| 123 | </div> |
| 124 | </div> |
| 125 | |
| 126 | <?php do_action( 'monsterinsights_after_exclude_metabox', $skipped, $post ); ?> |
| 127 | |
| 128 | <?php if ( ! monsterinsights_is_pro_version() ) { ?> |
| 129 | <div class="monsterinsights-metabox-pro-badge"> |
| 130 | <span> |
| 131 | <svg width="15" height="14" viewBox="0 0 15 14" fill="none" |
| 132 | xmlns="http://www.w3.org/2000/svg"> |
| 133 | <path |
| 134 | d="M6.57617 1.08203L4.92578 4.45898L1.19336 4.99219C0.533203 5.09375 0.279297 5.90625 0.761719 6.38867L3.42773 9.00391L2.79297 12.6855C2.69141 13.3457 3.40234 13.8535 3.98633 13.5488L7.3125 11.7969L10.6133 13.5488C11.1973 13.8535 11.9082 13.3457 11.8066 12.6855L11.1719 9.00391L13.8379 6.38867C14.3203 5.90625 14.0664 5.09375 13.4062 4.99219L9.69922 4.45898L8.02344 1.08203C7.74414 0.498047 6.88086 0.472656 6.57617 1.08203Z" |
| 135 | fill="#31862D"/> |
| 136 | </svg> |
| 137 | <?php _e( 'This is a PRO feature.', 'google-analytics-for-wordpress' ); ?> |
| 138 | </span> |
| 139 | <div class="monsterinsights-metabox-pro-badge-upgrade"> |
| 140 | <a href="<?php echo monsterinsights_get_upgrade_link( 'exclude-page-tracking', 'lite-metabox', "https://www.monsterinsights.com/lite/" ); // phpcs:ignore ?>" |
| 141 | target="_blank" rel="noopener"> |
| 142 | <?php _e( 'Upgrade', 'google-analytics-for-wordpress' ); ?> |
| 143 | </a> |
| 144 | </div> |
| 145 | </div> |
| 146 | <?php } ?> |
| 147 | |
| 148 | <?php |
| 149 | } |
| 150 | |
| 151 | public function load_metabox_styles() { |
| 152 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 153 | |
| 154 | wp_register_style( 'monsterinsights-admin-metabox-style', plugins_url( 'assets/css/admin-metabox' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
| 155 | wp_enqueue_style( 'monsterinsights-admin-metabox-style' ); |
| 156 | |
| 157 | if ( monsterinsights_is_pro_version() ) { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | wp_register_script( 'monsterinsights-admin-metabox-script', plugins_url( 'assets/js/admin-metabox' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() ); |
| 162 | wp_enqueue_script( 'monsterinsights-admin-metabox-script' ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | new MonsterInsights_MetaBox_ExcludePage(); |
| 167 | } |
| 168 |