common.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <?php
  2. /**
  3. * Common admin class.
  4. *
  5. * @since 6.0.0
  6. *
  7. * @package MonsterInsights
  8. * @subpackage Common
  9. * @author Chris Christoff
  10. */
  11. // Exit if accessed directly
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit;
  14. }
  15. /**
  16. * Loads styles for all MonsterInsights-based Administration Screens.
  17. *
  18. * @since 6.0.0
  19. * @access public
  20. *
  21. * @return null Return early if not on the proper screen.
  22. */
  23. function monsterinsights_admin_styles() {
  24. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
  25. // Load Common admin styles.
  26. wp_register_style( 'monsterinsights-admin-common-style', plugins_url( 'assets/css/admin-common' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  27. wp_enqueue_style( 'monsterinsights-admin-common-style' );
  28. // Get current screen.
  29. $screen = get_current_screen();
  30. // Bail if we're not on a MonsterInsights screen.
  31. if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
  32. return;
  33. }
  34. // Bootstrap
  35. // Primary
  36. wp_register_style( 'monsterinsights-bootstrap', plugins_url( 'assets/css/bootstrap-prefixed' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  37. wp_enqueue_style( 'monsterinsights-bootstrap' );
  38. // Secondary
  39. //wp_register_style( 'monsterinsights-bootstrap-base', plugins_url( 'assets/css/bootstrap' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  40. //wp_enqueue_style( 'monsterinsights-bootstrap-base' );
  41. //wp_register_style( 'monsterinsights-bootstrap-theme', plugins_url( 'assets/css/bootstrap-theme' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'monsterinsights-bootstrap-base' ), monsterinsights_get_asset_version() );
  42. //wp_enqueue_style( 'monsterinsights-bootstrap-theme' );
  43. // Select300
  44. wp_register_style( 'monsterinsights-select300-style', plugins_url( 'assets/css/select300/select300.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  45. wp_enqueue_style( 'monsterinsights-select300-style' );
  46. // Vendors
  47. wp_register_style( 'monsterinsights-vendors-style', plugins_url( 'assets/css/vendors' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  48. wp_enqueue_style( 'monsterinsights-vendors-style' );
  49. // Tooltips
  50. wp_enqueue_script( 'jquery-ui-tooltip' );
  51. // Load necessary admin styles.
  52. wp_register_style( 'monsterinsights-admin-style', plugins_url( 'assets/css/admin' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  53. wp_enqueue_style( 'monsterinsights-admin-style' );
  54. // Load LTR stylesheet where needed.
  55. if ( is_rtl() ) {
  56. wp_enqueue_style( 'monsterinsights-admin-style-rtl', plugins_url( 'assets/css/admin-rtl' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
  57. }
  58. }
  59. add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_styles' );
  60. /**
  61. * Loads scripts for all MonsterInsights-based Administration Screens.
  62. *
  63. * @since 6.0.0
  64. * @access public
  65. *
  66. * @return null Return early if not on the proper screen.
  67. */
  68. function monsterinsights_admin_scripts() {
  69. // Our Common Admin JS
  70. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
  71. wp_register_script( 'monsterinsights-admin-common-script', plugins_url( 'assets/js/admin-common' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() );
  72. wp_enqueue_script( 'monsterinsights-admin-common-script' );
  73. wp_localize_script(
  74. 'monsterinsights-admin-common-script',
  75. 'monsterinsights_admin_common',
  76. array(
  77. 'ajax' => admin_url( 'admin-ajax.php' ),
  78. 'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ),
  79. )
  80. );
  81. // Get current screen.
  82. $screen = get_current_screen();
  83. // Bail if we're not on a MonsterInsights screen.
  84. if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
  85. return;
  86. }
  87. // Tooltips
  88. wp_enqueue_script( 'jquery-ui-tooltip' );
  89. // Select300
  90. wp_register_script( 'monsterinsights-select300-script', plugins_url( 'assets/js/select300/select300.full.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() );
  91. wp_enqueue_script( 'monsterinsights-select300-script' );
  92. // Vendors
  93. wp_register_script( 'monsterinsights-vendors-script', plugins_url( 'assets/js/vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() );
  94. wp_enqueue_script( 'monsterinsights-vendors-script' );
  95. // Our Admin JS
  96. $deps = array(
  97. 'jquery',
  98. 'jquery-ui-tooltip',
  99. 'monsterinsights-select300-script',
  100. 'monsterinsights-vendors-script'
  101. );
  102. wp_register_script( 'monsterinsights-admin-script', plugins_url( 'assets/js/admin.js', MONSTERINSIGHTS_PLUGIN_FILE ), $deps, monsterinsights_get_asset_version() );
  103. wp_enqueue_script( 'monsterinsights-admin-script' );
  104. wp_localize_script(
  105. 'monsterinsights-admin-script',
  106. 'monsterinsights_admin',
  107. array(
  108. 'ajax' => admin_url( 'admin-ajax.php' ),
  109. 'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ),
  110. 'loadingtext' => esc_html__( 'Loading...', 'google-analytics-for-wordpress' ),
  111. 'settings_changed_confirm' => esc_html__( 'Warning: You have unsaved setting changes. If you leave the settings page without saving your changes will be lost. Did you still want to leave the page?', 'google-analytics-for-wordpress' ),
  112. 'activate_nonce' => wp_create_nonce( 'monsterinsights-activate' ),
  113. 'active' => esc_html__( 'Status: Active', 'google-analytics-for-wordpress' ),
  114. 'activate' => esc_html__( 'Activate', 'google-analytics-for-wordpress' ),
  115. 'networkactive' => esc_html__( 'Status: Network Activated', 'google-analytics-for-wordpress' ),
  116. 'networkactivate' => esc_html__( 'Network activate', 'google-analytics-for-wordpress' ),
  117. 'get_addons_nonce' => wp_create_nonce( 'monsterinsights-get-addons' ),
  118. 'activating' => esc_html__( 'Activating...', 'google-analytics-for-wordpress' ),
  119. 'deactivate' => esc_html__( 'Deactivate', 'google-analytics-for-wordpress' ),
  120. 'networkdeactivate' => esc_html__( 'Network deactivate', 'google-analytics-for-wordpress' ),
  121. 'deactivate_nonce' => wp_create_nonce( 'monsterinsights-deactivate' ),
  122. 'deactivating' => esc_html__( 'Deactivating...', 'google-analytics-for-wordpress' ),
  123. 'inactive' => esc_html__( 'Status: Inactive', 'google-analytics-for-wordpress' ),
  124. 'networkinactive' => esc_html__( 'Status: Network inactive', 'google-analytics-for-wordpress' ),
  125. 'install' => esc_html__( 'Install', 'google-analytics-for-wordpress' ),
  126. 'install_nonce' => wp_create_nonce( 'monsterinsights-install' ),
  127. 'installing' => esc_html__( 'Installing...', 'google-analytics-for-wordpress' ),
  128. 'proceed' => esc_html__( 'Proceed', 'google-analytics-for-wordpress' ),
  129. 'isnetwork' => is_network_admin(),
  130. 'copied' => esc_html__( 'Copied!', 'google-analytics-for-wordpress' ),
  131. 'copytoclip' => esc_html__( 'Copy to Clipboard', 'google-analytics-for-wordpress' ),
  132. 'failed' => esc_html__( 'Failed!', 'google-analytics-for-wordpress' ),
  133. 'admin_nonce' => wp_create_nonce( 'mi-admin-nonce' ),
  134. 'shorten' => esc_html__( 'Shorten URL' ,'google-analytics-for-wordpress'),
  135. 'shortened' => esc_html__( 'Shortened!' ,'google-analytics-for-wordpress'),
  136. 'working' => esc_html__( 'Working...' ,'google-analytics-for-wordpress'),
  137. 'importtext' => esc_html__( 'Import' ,'google-analytics-for-wordpress'),
  138. 'imported' => esc_html__( 'Imported!' ,'google-analytics-for-wordpress'),
  139. 'redirect_loading_title_text' => esc_html__( 'Preparing to redirect:' ,'google-analytics-for-wordpress'),
  140. 'redirect_loading_text_text' => esc_html__( "You'll be redirected momentarily to complete authentication. This may take a couple seconds." ,'google-analytics-for-wordpress'),
  141. 'redirect_loading_error_title' => esc_html__( "Authentication Error:" ,'google-analytics-for-wordpress'),
  142. 'deauth_loading_title_text' => esc_html__( 'Deauthenticating....' ,'google-analytics-for-wordpress'),
  143. 'deauth_loading_text_text' => esc_html__( "We're deactivating your site. This may take a couple seconds." ,'google-analytics-for-wordpress'),
  144. 'deauth_loading_error_title' => esc_html__( "Deactivation Error:" ,'google-analytics-for-wordpress'),
  145. 'deauth_success_title_text' => esc_html__( 'Deactivated Successfully!' ,'google-analytics-for-wordpress'),
  146. 'deauth_success_text_text' => esc_html__( "You've disconnected your site from MonsterInsights. Your site is no longer being tracked by Google Analytics and you won't see reports anymore." ,'google-analytics-for-wordpress'),
  147. 'verify_loading_title_text' => esc_html__( 'Verifying....' ,'google-analytics-for-wordpress'),
  148. 'verify_loading_text_text' => esc_html__( "We're verifying your site. This may take a couple seconds." ,'google-analytics-for-wordpress'),
  149. 'verify_loading_error_title' => esc_html__( "Verification Error:" ,'google-analytics-for-wordpress'),
  150. 'verify_success_title_text' => esc_html__( 'Verified Successfully!' ,'google-analytics-for-wordpress'),
  151. 'verify_success_text_text' => esc_html__( "Your site is connected to MonsterInsights!" ,'google-analytics-for-wordpress'),
  152. 'ok_text' => esc_html__( "OK" ,'google-analytics-for-wordpress'),
  153. 'force_deauth_button_text' => esc_html__( "Force Deauthenticate" ,'google-analytics-for-wordpress'),
  154. 'refresh_report_title' => esc_html__( 'Refreshing Report', 'google-analytics-for-wordpress' ),
  155. 'refresh_report_text' => esc_html__( 'Loading new report data...', 'google-analytics-for-wordpress' ),
  156. 'refresh_report_success_text' => esc_html__( 'Success', 'google-analytics-for-wordpress' ),
  157. 'refresh_report_success_text' => esc_html__( 'Retrieved the new report data successfully', 'google-analytics-for-wordpress' ),
  158. 'refresh_report_failure_title' => esc_html__( 'Error', 'google-analytics-for-wordpress' ),
  159. 'timezone' => date('e'),
  160. )
  161. );
  162. // ublock notice
  163. add_action( 'admin_print_footer_scripts', 'monsterinsights_settings_ublock_error_js', 9999999 );
  164. }
  165. add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_scripts' );
  166. /**
  167. * Remove Assets that conflict with ours from our screens.
  168. *
  169. * @since 6.0.4
  170. * @access public
  171. *
  172. * @return null Return early if not on the proper screen.
  173. */
  174. function monsterinsights_remove_conflicting_asset_files() {
  175. // Get current screen.
  176. $screen = get_current_screen();
  177. // Bail if we're not on a MonsterInsights screen.
  178. if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
  179. return;
  180. }
  181. $styles = array(
  182. 'kt_admin_css', // Pinnacle theme
  183. 'select2-css', // Schema theme
  184. 'tweetshare_style', // TweetShare - Click To Tweet
  185. 'tweetshare_custom_style', // TweetShare - Click To Tweet
  186. 'tweeetshare_custome_style', // TweetShare - Click To Tweet
  187. 'tweeetshare_notice_style', // TweetShare - Click To Tweet
  188. 'tweeetshare_theme_style', // TweetShare - Click To Tweet
  189. 'tweeetshare_tweet_box_style', // TweetShare - Click To Tweet
  190. 'soultype2-admin', // SoulType Plugin
  191. 'thesis-options-stylesheet', // Thesis Options Stylesheet
  192. 'imagify-sweetalert-core', // Imagify
  193. 'imagify-sweetalert', // Imagify
  194. 'smls-backend-style', // Smart Logo Showcase Lite
  195. 'wp-reactjs-starter', // wp-real-media-library
  196. 'control-panel-modal-plugin', // Ken Theme
  197. 'theme-admin-css', // Vitrine Theme
  198. 'qi-framework-styles', // Artisan Nayma Theme
  199. 'artisan-pages-style', // Artisan Pages Plugin
  200. 'control-panel-modal-plugin', // Ken Theme
  201. 'sweetalert', // Church Suite Theme by Webnus
  202. 'woo_stock_alerts_admin_css', // WooCommerce bolder product alerts
  203. 'custom_wp_admin_css', // Fix for Add Social Share
  204. 'fo_css', // Fix for Add Social Share
  205. 'font_css', // Fix for Add Social Share
  206. 'font2_css', // Fix for Add Social Share
  207. 'font3_css', // Fix for Add Social Share
  208. 'hover_css', // Fix for Add Social Share
  209. 'fontend_styling' // Fix for Add Social Share
  210. );
  211. $scripts = array(
  212. 'kad_admin_js', // Pinnacle theme
  213. 'dt-chart', // DesignThemes core features plugin
  214. 'tweeetshare_font_script', // TweetShare - Click To Tweet
  215. 'tweeetshare_jquery_script', // TweetShare - Click To Tweet
  216. 'tweeetshare_jqueryui_script', // TweetShare - Click To Tweet
  217. 'tweeetshare_custom_script', // TweetShare - Click To Tweet
  218. 'imagify-promise-polyfill', // Imagify
  219. 'imagify-sweetalert', // Imagify
  220. 'imagify-chart', // Imagify
  221. 'chartjs', // Comet Cache Pro
  222. 'wp-reactjs-starter', // wp-real-media-library
  223. 'jquery-tooltipster', // WP Real Media Library
  224. 'jquery-nested-sortable', // WP Real Media Library
  225. 'jquery-aio-tree', // WP Real Media Library
  226. 'wp-media-picker', // WP Real Media Library
  227. 'rml-general', // WP Real Media Library
  228. 'rml-library', // WP Real Media Library
  229. 'rml-grid', // WP Real Media Library
  230. 'rml-list', // WP Real Media Library
  231. 'rml-modal', // WP Real Media Library
  232. 'rml-order', // WP Real Media Library
  233. 'rml-meta', // WP Real Media Library
  234. 'rml-uploader', // WP Real Media Library
  235. 'rml-options', // WP Real Media Library
  236. 'rml-usersettings', // WP Real Media Library
  237. 'rml-main', // WP Real Media Library
  238. 'control-panel-sweet-alert', // Ken Theme
  239. 'sweet-alert-js', // Vitrine Theme
  240. 'theme-admin-script', // Vitrine Theme
  241. 'sweetalert', // Church Suite Theme by Webnus
  242. 'be_alerts_charts', // WooCommerce bolder product alerts
  243. 'magayo-lottery-results', // Magayo Lottery Results
  244. 'control-panel-sweet-alert', // Ken Theme
  245. 'cpm_chart', // WP Project Manager
  246. 'adminscripts', // Artisan Nayma Theme
  247. 'artisan-pages-script', // Artisan Pages Plugin
  248. 'tooltipster', // Grand News Theme
  249. 'fancybox', // Grand News Theme
  250. 'grandnews-admin-cript', // Grand News Theme
  251. 'colorpicker', // Grand News Theme
  252. 'eye', // Grand News Theme
  253. 'utils', // Grand News Theme
  254. 'icheck', // Grand News Theme
  255. 'learn-press-chart', // LearnPress
  256. 'theme-script-main', // My Listing Theme by 27collective
  257. 'selz', // Selz eCommerce
  258. 'tie-admin-scripts', // Tie Theme
  259. 'blossomthemes-toolkit', // BlossomThemes Toolkit
  260. 'illdy-widget-upload-image', // Illdy Companion By Colorlib
  261. 'moment.js', // WooCommerce Table Rate Shipping
  262. 'default', // Bridge Theme
  263. 'qode-tax-js', // Bridge Theme
  264. 'wc_smartship_moment_js', // WooCommerce Posti SmartShip by markup.fi
  265. 'ecwid-admin-js', // Fixes Conflict for Ecwid Shopping Cart
  266. 'td-wp-admin-js', // Newspaper by tagDiv
  267. 'moment', // Screets Live Chat
  268. 'wpmf-base', // WP Media Folder Fix
  269. 'wpmf-media-filters', // WP Media Folder Fix
  270. 'wpmf-folder-tree', // WP Media Folder Fix
  271. 'wpmf-assign-tree', // WP Media Folder Fix
  272. 'js_files_for_wp_admin', // TagDiv Composer Fix
  273. 'tdb_js_files_for_wp_admin_last', // TagDiv Composer Fix
  274. 'tdb_js_files_for_wp_admin', // TagDiv Composer Fix
  275. 'wd-functions', // affiliate boxes
  276. 'ellk-aliExpansion', // Ali Dropship Plugin
  277. 'ftmetajs', // Houzez Theme
  278. 'qode_admin_default', // Fix For Stockholm Theme
  279. 'qodef-tax-js', // Fix for Prowess Theme
  280. 'qodef-user-js', // Fix for Prowess Theme
  281. 'qodef-ui-admin', // Fix for Prowess Theme
  282. 'ssi_script', // Fix for Add Social Share
  283. 'live_templates', // Fix for Add Social Share
  284. 'default', // Fix for Add Social Share
  285. 'handsontable', // Fix WP Tables
  286. 'moment-js', // Magee Shortcodes
  287. 'postbox', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
  288. 'link', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
  289. 'wpvr_scripts', // WP Video Robot
  290. 'wpvr_scripts_loaded', // WP Video Robot
  291. 'wpvr_scripts_assets' // WP Video Robot
  292. );
  293. if ( ! empty( $styles ) ) {
  294. foreach ( $styles as $style ) {
  295. wp_dequeue_style( $style ); // Remove CSS file from MI screen
  296. wp_deregister_style( $style );
  297. }
  298. }
  299. if ( ! empty( $scripts ) ) {
  300. foreach ( $scripts as $script ) {
  301. wp_dequeue_script( $script ); // Remove JS file from MI screen
  302. wp_deregister_script( $script );
  303. }
  304. }
  305. $third_party = array(
  306. 'select300',
  307. 'sweetalert',
  308. 'clipboard',
  309. 'matchHeight',
  310. 'inputmask',
  311. 'jquery-confirm',
  312. 'list',
  313. 'toastr',
  314. 'tooltipster',
  315. 'flag-icon',
  316. 'bootstrap',
  317. );
  318. global $wp_styles;
  319. foreach ( $wp_styles->queue as $handle ) {
  320. if ( strpos( $wp_styles->registered[$handle]->src, 'wp-content') === false ) {
  321. return;
  322. }
  323. if ( strpos( $wp_styles->registered[$handle]->handle, 'monsterinsights') !== false ) {
  324. return;
  325. }
  326. foreach( $third_party as $partial ) {
  327. if ( strpos( $wp_styles->registered[$handle]->handle, $partial ) !== false ) {
  328. wp_dequeue_style( $handle ); // Remove css file from MI screen
  329. wp_deregister_style( $handle );
  330. break;
  331. } else if ( strpos( $wp_styles->registered[$handle]->src, $partial ) !== false ) {
  332. wp_dequeue_style( $handle ); // Remove css file from MI screen
  333. wp_deregister_style( $handle );
  334. break;
  335. }
  336. }
  337. }
  338. global $wp_scripts;
  339. foreach ( $wp_scripts->queue as $handle ) {
  340. if ( strpos( $wp_scripts->registered[$handle]->src, 'wp-content') === false ) {
  341. return;
  342. }
  343. if ( strpos( $wp_scripts->registered[$handle]->handle, 'monsterinsights') !== false ) {
  344. return;
  345. }
  346. foreach( $third_party as $partial ) {
  347. if ( strpos( $wp_scripts->registered[$handle]->handle, $partial ) !== false ) {
  348. wp_dequeue_script( $handle ); // Remove JS file from MI screen
  349. wp_deregister_script( $handle );
  350. break;
  351. } else if ( strpos( $wp_scripts->registered[$handle]->src, $partial ) !== false ) {
  352. wp_dequeue_script( $handle ); // Remove JS file from MI screen
  353. wp_deregister_script( $handle );
  354. break;
  355. }
  356. }
  357. }
  358. // Remove actions from themes that are not following best practices and break the admin doing so
  359. // Theme: Newspaper by tagDiv
  360. remove_action('admin_enqueue_scripts', 'load_wp_admin_js');
  361. remove_action('admin_enqueue_scripts', 'load_wp_admin_css');
  362. remove_action('admin_print_scripts-widgets.php', 'td_on_admin_print_scripts_farbtastic');
  363. remove_action('admin_print_styles-widgets.php', 'td_on_admin_print_styles_farbtastic');
  364. remove_action('admin_print_footer_scripts', 'check_if_media_uploads_is_loaded', 9999);
  365. remove_action('print_media_templates', 'td_custom_gallery_settings_hook');
  366. remove_action('print_media_templates', 'td_change_backbone_js_hook');
  367. remove_action('admin_head', 'tdc_on_admin_head'); // TagDiv Composer Fix
  368. remove_action('print_media_templates', 'us_media_templates'); // Impreza Theme Fix
  369. remove_action('admin_footer', 'gt3pg_add_gallery_template'); // GT3 Photo & Video Gallery By GT3 Themes Plugin Fix
  370. // Plugin WP Booklist:
  371. remove_action('admin_footer', 'wpbooklist_jre_dismiss_prem_notice_forever_action_javascript');
  372. remove_action('admin_footer', 'wpbooklist_dashboard_add_book_action_javascript');
  373. remove_action('admin_footer', 'wpbooklist_edit_book_show_form_action_javascript');
  374. remove_action('admin_footer', 'wpbooklist_show_book_in_colorbox_action_javascript');
  375. remove_action('admin_footer', 'wpbooklist_new_lib_shortcode_action_javascript');
  376. remove_action('admin_footer', 'wpbooklist_dashboard_save_library_display_options_action_javascript');
  377. remove_action('admin_footer', 'wpbooklist_dashboard_save_post_display_options_action_javascript');
  378. remove_action('admin_footer', 'wpbooklist_dashboard_save_page_display_options_action_javascript');
  379. remove_action('admin_footer', 'wpbooklist_update_display_options_action_javascript');
  380. remove_action('admin_footer', 'wpbooklist_edit_book_pagination_action_javascript');
  381. remove_action('admin_footer', 'wpbooklist_edit_book_switch_lib_action_javascript');
  382. remove_action('admin_footer', 'wpbooklist_edit_book_search_action_javascript');
  383. remove_action('admin_footer', 'wpbooklist_edit_book_actual_action_javascript');
  384. remove_action('admin_footer', 'wpbooklist_delete_book_action_javascript');
  385. remove_action('admin_footer', 'wpbooklist_user_apis_action_javascript');
  386. remove_action('admin_footer', 'wpbooklist_upload_new_stylepak_action_javascript');
  387. remove_action('admin_footer', 'wpbooklist_upload_new_post_template_action_javascript');
  388. remove_action('admin_footer', 'wpbooklist_upload_new_page_template_action_javascript');
  389. remove_action('admin_footer', 'wpbooklist_create_db_library_backup_action_javascript');
  390. remove_action('admin_footer', 'wpbooklist_restore_db_library_backup_action_javascript');
  391. remove_action('admin_footer', 'wpbooklist_create_csv_action_javascript');
  392. remove_action('admin_footer', 'wpbooklist_amazon_localization_action_javascript');
  393. remove_action('admin_footer', 'wpbooklist_delete_book_bulk_action_javascript');
  394. remove_action('admin_footer', 'wpbooklist_reorder_action_javascript');
  395. remove_action('admin_footer', 'wpbooklist_exit_results_action_javascript');
  396. remove_action('admin_footer', 'wpbooklist_storytime_select_category_action_javascript');
  397. remove_action('admin_footer', 'wpbooklist_storytime_get_story_action_javascript');
  398. remove_action('admin_footer', 'wpbooklist_storytime_expand_browse_action_javascript');
  399. remove_action('admin_footer', 'wpbooklist_storytime_save_settings_action_javascript');
  400. remove_action('admin_footer', 'wpbooklist_delete_story_action_javascript');
  401. }
  402. add_action( 'admin_enqueue_scripts', 'monsterinsights_remove_conflicting_asset_files', 9999 );
  403. /**
  404. * Remove non-MI notices from MI page.
  405. *
  406. * @since 6.0.0
  407. * @access public
  408. *
  409. * @return null Return early if not on the proper screen.
  410. */
  411. function hide_non_monsterinsights_warnings () {
  412. // Bail if we're not on a MonsterInsights screen.
  413. if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'monsterinsights' ) === false ) {
  414. return;
  415. }
  416. global $wp_filter;
  417. if ( !empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
  418. foreach( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
  419. foreach ( $hooks as $name => $arr ) {
  420. if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
  421. unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
  422. continue;
  423. }
  424. if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
  425. continue;
  426. }
  427. if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
  428. unset( $wp_filter['user_admin_notices']->callbacks[$priority][$name] );
  429. }
  430. }
  431. }
  432. }
  433. if ( !empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
  434. foreach( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
  435. foreach ( $hooks as $name => $arr ) {
  436. if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
  437. unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
  438. continue;
  439. }
  440. if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
  441. continue;
  442. }
  443. if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
  444. unset( $wp_filter['admin_notices']->callbacks[$priority][$name] );
  445. }
  446. }
  447. }
  448. }
  449. if ( !empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
  450. foreach( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
  451. foreach ( $hooks as $name => $arr ) {
  452. if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
  453. unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
  454. continue;
  455. }
  456. if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
  457. continue;
  458. }
  459. if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
  460. unset( $wp_filter['all_admin_notices']->callbacks[$priority][$name] );
  461. }
  462. }
  463. }
  464. }
  465. }
  466. add_action('admin_print_scripts', 'hide_non_monsterinsights_warnings');
  467. add_action('admin_head', 'hide_non_monsterinsights_warnings', PHP_INT_MAX );
  468. /**
  469. * Called whenever an upgrade button / link is displayed in Lite, this function will
  470. * check if there's a shareasale ID specified.
  471. *
  472. * There are three ways to specify an ID, ordered by highest to lowest priority
  473. * - add_filter( 'monsterinsights_shareasale_id', function() { return 1234; } );
  474. * - define( 'MONSTERINSIGHTS_SHAREASALE_ID', 1234 );
  475. * - get_option( 'monsterinsights_shareasale_id' ); (with the option being in the wp_options table)
  476. *
  477. * If an ID is present, returns the ShareASale link with the affiliate ID, and tells
  478. * ShareASale to then redirect to monsterinsights.com/lite
  479. *
  480. * If no ID is present, just returns the monsterinsights.com/lite URL with UTM tracking.
  481. *
  482. * @since 6.0.0
  483. * @access public
  484. *
  485. * @return string Upgrade link.
  486. */
  487. function monsterinsights_get_upgrade_link( $medium = '', $campaign = '', $url = '' ) {
  488. $url = monsterinsights_get_url( $medium, $campaign, $url, false );
  489. if ( monsterinsights_is_pro_version() ) {
  490. return esc_url( $url );
  491. }
  492. // Get the ShareASale ID
  493. $shareasale_id = monsterinsights_get_shareasale_id();
  494. // If we have a shareasale ID return the shareasale url
  495. if ( ! empty( $shareasale_id ) ) {
  496. $shareasale_id = absint( $shareasale_id );
  497. return esc_url( monsterinsights_get_shareasale_url( $shareasale_id, $url ) );
  498. } else {
  499. return esc_url( $url );
  500. }
  501. }
  502. function monsterinsights_get_url( $medium = '', $campaign = '', $url = '', $escape = true ) {
  503. // Setup Campaign variables
  504. $source = monsterinsights_is_pro_version() ? 'proplugin' : 'liteplugin';
  505. $medium = ! empty( $medium ) ? $medium : 'defaultmedium';
  506. $campaign = ! empty( $campaign ) ? $campaign : 'defaultcampaign';
  507. $content = MONSTERINSIGHTS_VERSION;
  508. $default_url = monsterinsights_is_pro_version() ? '' : 'lite/';
  509. $url = ! empty( $url ) ? $url : 'https://www.monsterinsights.com/' . $default_url;
  510. // Put together redirect URL
  511. $url = add_query_arg(
  512. array(
  513. 'utm_source' => $source, // Pro/Lite Plugin
  514. 'utm_medium' => sanitize_key( $medium ), // Area of MonsterInsights (example Reports)
  515. 'utm_campaign' => sanitize_key( $campaign ), // Which link (example eCommerce Report)
  516. 'utm_content' => $content, // Version number of MI
  517. ),
  518. trailingslashit( $url )
  519. );
  520. if ( $escape ) {
  521. return esc_url( $url );
  522. } else {
  523. return $url;
  524. }
  525. }
  526. function monsterinsights_get_shareasale_id() {
  527. // Check if there's a constant.
  528. $shareasale_id = '';
  529. if ( defined( 'MONSTERINSIGHTS_SHAREASALE_ID' ) ) {
  530. $shareasale_id = MONSTERINSIGHTS_SHAREASALE_ID;
  531. }
  532. // If there's no constant, check if there's an option.
  533. if ( empty( $shareasale_id ) ) {
  534. $shareasale_id = get_option( 'monsterinsights_shareasale_id', '' );
  535. }
  536. // Whether we have an ID or not, filter the ID.
  537. $shareasale_id = apply_filters( 'monsterinsights_shareasale_id', $shareasale_id );
  538. // Ensure it's a number
  539. $shareasale_id = absint( $shareasale_id );
  540. return $shareasale_id;
  541. }
  542. // Passed in with mandatory default redirect and shareasaleid from monsterinsights_get_upgrade_link
  543. function monsterinsights_get_shareasale_url( $shareasale_id, $shareasale_redirect ) {
  544. // Check if there's a constant.
  545. $custom = false;
  546. if ( defined( 'MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL' ) ) {
  547. $shareasale_redirect = MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL;
  548. $custom = true;
  549. }
  550. // If there's no constant, check if there's an option.
  551. if ( empty( $custom ) ) {
  552. $shareasale_redirect = get_option( 'monsterinsights_shareasale_redirect_url', '' );
  553. $custom = true;
  554. }
  555. // Whether we have an ID or not, filter the ID.
  556. $shareasale_redirect = apply_filters( 'monsterinsights_shareasale_redirect_url', $shareasale_redirect, $custom );
  557. $shareasale_url = sprintf( 'http://www.shareasale.com/r.cfm?B=971799&U=%s&M=69975&urllink=%s', $shareasale_id, $shareasale_redirect );
  558. return $shareasale_url;
  559. }
  560. function monsterinsights_settings_ublock_error_js(){
  561. echo "<script type='text/javascript'>\n";
  562. echo "jQuery( document ).ready( function( $ ) {
  563. if ( window.uorigindetected == null){
  564. $('#monsterinsights-ublock-origin-error').show();
  565. $('.monsterinsights-nav-tabs').hide();
  566. $('.monsterinsights-nav-container').hide();
  567. $('#monsterinsights-addon-heading').hide();
  568. $('#monsterinsights-addons').hide();
  569. $('#monsterinsights-reports').hide();
  570. }
  571. });";
  572. echo "\n</script>";
  573. }
  574. function monsterinsights_ublock_notice() {
  575. ob_start();?>
  576. <div id="monsterinsights-ublock-origin-error" class="error inline" style="display:none;">
  577. <?php echo sprintf( esc_html__( 'MonsterInsights has detected that it\'s files are being blocked. This is usually caused by a adblock browser plugin (particularly uBlock Origin), or a conflicting WordPress theme or plugin. This issue only affects the admin side of MonsterInsights. To solve this, ensure MonsterInsights is whitelisted for your website URL in any adblock browser plugin you use. For step by step directions on how to do this, %1$sclick here%2$s. If this doesn\'t solve the issue (rare), send us a ticket %3$shere%2$s and we\'ll be happy to help diagnose the issue.', 'google-analytics-for-wordpress'), '<a href="https://monsterinsights.com/docs/monsterinsights-asset-files-blocked/" target="_blank" rel="noopener noreferrer" referrer="no-referrer">', '</a>', '<a href="https://monsterinsights.com/contact/" target="_blank" rel="noopener noreferrer" referrer="no-referrer">');
  578. ?>
  579. </div>
  580. <?php
  581. return ob_get_clean();
  582. }
  583. /**
  584. * Some themes/plugins don't add proper checks and load JS code in all admin pages causing conflicts.
  585. */
  586. function monsterinsights_remove_unnecessary_footer_hooks() {
  587. $screen = get_current_screen();
  588. // Bail if we're not on a MonsterInsights screen.
  589. if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
  590. return;
  591. }
  592. // Remove js code added by Newspaper theme - version 8.8.0.
  593. remove_action( 'print_media_templates', 'td_custom_gallery_settings_hook' );
  594. remove_action( 'print_media_templates', 'td_change_backbone_js_hook' );
  595. // Remove js code added by the Brooklyn theme - version 4.5.3.1.
  596. remove_action( 'print_media_templates', 'ut_create_gallery_options' );
  597. // Remove js code added by WordPress Book List Plugin - version 5.8.1.
  598. remove_action( 'admin_footer', 'wpbooklist_jre_dismiss_prem_notice_forever_action_javascript' );
  599. remove_action( 'admin_footer', 'wpbooklist_dashboard_add_book_action_javascript' );
  600. remove_action( 'admin_footer', 'wpbooklist_edit_book_show_form_action_javascript' );
  601. remove_action( 'admin_footer', 'wpbooklist_show_book_in_colorbox_action_javascript' );
  602. remove_action( 'admin_footer', 'wpbooklist_new_lib_shortcode_action_javascript' );
  603. remove_action( 'admin_footer', 'wpbooklist_dashboard_save_library_display_options_action_javascript' );
  604. remove_action( 'admin_footer', 'wpbooklist_dashboard_save_post_display_options_action_javascript' );
  605. remove_action( 'admin_footer', 'wpbooklist_dashboard_save_page_display_options_action_javascript' );
  606. remove_action( 'admin_footer', 'wpbooklist_update_display_options_action_javascript' );
  607. remove_action( 'admin_footer', 'wpbooklist_edit_book_pagination_action_javascript' );
  608. remove_action( 'admin_footer', 'wpbooklist_edit_book_switch_lib_action_javascript' );
  609. remove_action( 'admin_footer', 'wpbooklist_edit_book_search_action_javascript' );
  610. remove_action( 'admin_footer', 'wpbooklist_edit_book_actual_action_javascript' );
  611. remove_action( 'admin_footer', 'wpbooklist_delete_book_action_javascript' );
  612. remove_action( 'admin_footer', 'wpbooklist_user_apis_action_javascript' );
  613. remove_action( 'admin_footer', 'wpbooklist_upload_new_stylepak_action_javascript' );
  614. remove_action( 'admin_footer', 'wpbooklist_upload_new_post_template_action_javascript' );
  615. remove_action( 'admin_footer', 'wpbooklist_upload_new_page_template_action_javascript' );
  616. remove_action( 'admin_footer', 'wpbooklist_create_db_library_backup_action_javascript' );
  617. remove_action( 'admin_footer', 'wpbooklist_restore_db_library_backup_action_javascript' );
  618. remove_action( 'admin_footer', 'wpbooklist_create_csv_action_javascript' );
  619. remove_action( 'admin_footer', 'wpbooklist_amazon_localization_action_javascript' );
  620. remove_action( 'admin_footer', 'wpbooklist_delete_book_bulk_action_javascript' );
  621. remove_action( 'admin_footer', 'wpbooklist_reorder_action_javascript' );
  622. remove_action( 'admin_footer', 'wpbooklist_exit_results_action_javascript' );
  623. remove_action( 'admin_footer', 'wpbooklist_storytime_select_category_action_javascript' );
  624. remove_action( 'admin_footer', 'wpbooklist_storytime_get_story_action_javascript' );
  625. remove_action( 'admin_footer', 'wpbooklist_storytime_expand_browse_action_javascript' );
  626. remove_action( 'admin_footer', 'wpbooklist_storytime_save_settings_action_javascript' );
  627. remove_action( 'admin_footer', 'wpbooklist_delete_story_action_javascript' );
  628. }
  629. add_action( 'admin_head', 'monsterinsights_remove_unnecessary_footer_hooks', 15 );