monsterinsights_get_addon_card

Outputs the addon "box" on the addons page.

Description

monsterinsights_get_addon_card( (object) $addon, (int) $counter = 0, (constant) $is_licensed = false, (bool) $installed_plugins = false ); 

Parameters (4)

0. $addon (object)
Addon data from the API / transient call
1. $counter — Optional. (int)
Index of this Addon in the collection
2. $is_licensed — Optional. (constant) => false
Whether the Addon is licensed for use
3. $installed_plugins — Optional. (bool) => false
Installed WordPress Plugins

Usage

  1. if ( !function_exists( 'monsterinsights_get_addon_card' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/pages/addons.php'; 
  3.  
  4. // Addon data from the API / transient call 
  5. $addon = null; 
  6.  
  7. // Index of this Addon in the collection 
  8. $counter = -1; 
  9.  
  10. // Whether the Addon is licensed for use 
  11. $is_licensed = false; 
  12.  
  13. // Installed WordPress Plugins 
  14. $installed_plugins = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = monsterinsights_get_addon_card($addon, $counter, $is_licensed, $installed_plugins); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/pages/addons.php  
  1. function monsterinsights_get_addon_card( $addon, $counter = 0, $is_licensed = false, $installed_plugins = false ) { 
  2.  
  3. // Setup some vars 
  4. $slug = str_replace( 'monsterinsights-', '', $addon->slug ); 
  5. $slug = 'monsterinsights-' . $addon->slug; 
  6. if ( $slug === 'monsterinsights-ecommerce' ) { 
  7. $slug = 'ga-ecommerce'; 
  8. }  
  9.  
  10. $plugin_basename = monsterinsights_get_plugin_basename_from_slug( $slug ); 
  11. $categories = implode( ', ', $addon->categories ); 
  12. if ( ! $installed_plugins ) { 
  13. $installed_plugins = get_plugins(); 
  14.  
  15. // If the Addon doesn't supply an upgrade_url key, it's because the user hasn't provided a license 
  16. // get_upgrade_link() will return the Lite or Pro link as necessary for us. 
  17. if ( ! isset( $addon->upgrade_url ) ) { 
  18. $addon->upgrade_url = monsterinsights_get_upgrade_link(); 
  19.  
  20. // Link user to doc to install MI pro to install addons 
  21. if ( ! monsterinsights_is_pro_version() && $is_licensed && ! isset( $installed_plugins[ $plugin_basename ] ) ) { 
  22. $addon->url = 'https://www.monsterinsights.com/docs/install-monsterinsights-pro-to-use-addons'; 
  23.  
  24. // Output the card 
  25. ?> 
  26. <div class="monsterinsights-addon"> 
  27. <h3 class="monsterinsights-addon-title"><?php echo esc_html( $addon->title ); ?></h3> 
  28. <?php 
  29. if ( ! empty( $addon->image ) ) { 
  30. ?> 
  31. <img class="monsterinsights-addon-thumb" src="<?php echo esc_attr( esc_url( $addon->image ) ); ?>" alt="<?php echo esc_attr( $addon->title ); ?>" /> 
  32. <?php 
  33. ?> 
  34.  
  35. <p class="monsterinsights-addon-excerpt"><?php echo esc_html( $addon->excerpt ); ?></p> 
  36.  
  37. <?php 
  38. // If the Addon is unlicensed, show the upgrade button  
  39. if ( ! $is_licensed ) { 
  40. ?> 
  41. <div class="monsterinsights-addon-active monsterinsights-addon-message"> 
  42. <div class="interior"> 
  43. <div class="monsterinsights-addon-upgrade"> 
  44. <a href="<?php echo esc_attr( esc_url( $addon->upgrade_url ) ); ?>" target="_blank" rel="noopener noreferrer" referrer="no-referrer" class="button button-primary monsterinsights-addon-upgrade-button" rel="<?php echo esc_attr( $plugin_basename ); ?>"> 
  45. <?php esc_html_e( 'Upgrade Now', 'google-analytics-for-wordpress' ); ?> 
  46. </a> 
  47. <span class="spinner monsterinsights-spinner"></span> 
  48. </div> 
  49. </div> 
  50. </div> 
  51. <?php 
  52. } else { 
  53. // Addon is licensed 
  54.  
  55. // If the plugin is not installed, display an install message and button. 
  56. if ( ! isset( $installed_plugins[ $plugin_basename ] ) ) { 
  57. if ( empty( $addon->url ) ) { 
  58. $addon->url = ''; 
  59. ?> 
  60. <div class="monsterinsights-addon-not-installed monsterinsights-addon-message"> 
  61. <div class="interior"> 
  62. <?php if ( monsterinsights_is_pro_version() ) { ?> 
  63. <span class="addon-status"><?php echo sprintf( esc_html__( 'Status: %1$sNot Installed%2$s', 'google-analytics-for-wordpress' ), '<span>', '</span>' ); ?></span> 
  64. <?php } ?> 
  65. <div class="monsterinsights-addon-action"> 
  66. <?php if ( monsterinsights_is_pro_version() ) { ?> 
  67. <a class="button button-primary monsterinsights-addon-action-button monsterinsights-install-addon" href="#" rel="<?php echo esc_attr( esc_url( $addon->url ) ); ?>"> 
  68. <i class="monsterinsights-cloud-download"></i> 
  69. <?php esc_html_e( 'Install', 'google-analytics-for-wordpress' ); ?>  
  70. </a> 
  71. <?php } else { ?> 
  72. <a class="button button-primary monsterinsights-addon-action-button" href="<?php echo esc_url( $addon->url ); ?>" rel="noopener noreferrer" referrer="no-referrer" target="_blank"> 
  73. <i class="monsterinsights-cloud-download"></i> 
  74. <?php esc_html_e( "Why can't I install addons?", 'google-analytics-for-wordpress' ); ?>  
  75. </a> 
  76. <?php } ?> 
  77. <span class="spinner monsterinsights-spinner"></span> 
  78. </div> 
  79. </div> 
  80. </div> 
  81. <?php 
  82. } else { 
  83. // Plugin is installed. 
  84.  
  85. $active = false; 
  86. $ms_active = is_plugin_active_for_network( $plugin_basename ); 
  87. $ss_active = is_plugin_active( $plugin_basename ); 
  88.  
  89. if ( is_multisite() && is_network_admin() ) { 
  90. $active = is_plugin_active_for_network( $plugin_basename ); 
  91. } else { 
  92. $active = is_plugin_active( $plugin_basename ); 
  93.  
  94. if ( $active ) { 
  95. // Plugin is active. Display the active message and deactivate button. 
  96. ?> 
  97. <div class="monsterinsights-addon-active monsterinsights-addon-message"> 
  98. <div class="interior"> 
  99. <?php if ( $ms_active ) { ?> 
  100. <span class="addon-status"><?php echo sprintf( esc_html__( 'Status: %1$sNetwork Active%2$s', 'google-analytics-for-wordpress'), '<span>', '</span>' ); ?></span> 
  101. <?php } else { ?> 
  102. <span class="addon-status"><?php echo sprintf( esc_html__( 'Status: %1$sActive%2$s', 'google-analytics-for-wordpress'), '<span>', '</span>' ); ?></span> 
  103. <?php } ?>  
  104. <?php if ( ( is_multisite() && is_network_admin() && $ms_active ) || ! is_multisite() || ( is_multisite() && !is_network_admin() && !$ms_active && $ss_active ) ) { ?> 
  105. <div class="monsterinsights-addon-action"> 
  106. <a class="button button-primary monsterinsights-addon-action-button monsterinsights-deactivate-addon" href="#" rel="<?php echo esc_attr( $plugin_basename ); ?>"> 
  107. <i class="monsterinsights-toggle-on"></i> 
  108. <?php if ( is_multisite() && is_network_admin() && $ms_active ) { ?> 
  109. <?php esc_html_e( 'Network deactivate', 'google-analytics-for-wordpress' ); ?>  
  110. <?php } else if ( is_multisite() && !is_network_admin() && !$ms_active && $ss_active ) { ?> 
  111. <?php esc_html_e( 'Deactivate', 'google-analytics-for-wordpress' ); ?>  
  112. <?php } else { ?> 
  113. <?php esc_html_e( 'Deactivate', 'google-analytics-for-wordpress' ); ?>  
  114. <?php } ?>  
  115. </a> 
  116. <span class="spinner google-analytics-for-wordpress-spinner"></span> 
  117. </div> 
  118. <?php } ?> 
  119. </div> 
  120. </div> 
  121. <?php 
  122. } else { 
  123. // Plugin is inactivate. Display the inactivate mesage and activate button. 
  124. ?> 
  125. <div class="monsterinsights-addon-inactive monsterinsights-addon-message"> 
  126. <div class="interior"> 
  127. <?php if ( $ms_active ) { ?> 
  128. <span class="addon-status"><?php echo sprintf( esc_html__( 'Status: %1$sNetwork Inactive%2$s', 'google-analytics-for-wordpress'), '<span>', '</span>' ); ?></span> 
  129. <?php } else { ?> 
  130. <span class="addon-status"><?php echo sprintf( esc_html__( 'Status: %1$sInactive%2$s', 'google-analytics-for-wordpress'), '<span>', '</span>' ); ?></span> 
  131. <?php } ?>  
  132. <div class="monsterinsights-addon-action"> 
  133. <a class="button button-primary monsterinsights-addon-action-button monsterinsights-activate-addon" href="#" rel="<?php echo esc_attr( $plugin_basename ); ?>"> 
  134. <i class="monsterinsights-toggle-on"></i> 
  135. <?php if ( is_multisite() && is_network_admin() && ! $ms_active ) { ?> 
  136. <?php esc_html_e( 'Network activate', 'google-analytics-for-wordpress' ); ?>  
  137. <?php } else { ?> 
  138. <?php esc_html_e( 'Activate', 'google-analytics-for-wordpress' ); ?>  
  139. <?php } ?> 
  140. </a> 
  141. <span class="spinner monsterinsights-spinner"></span> 
  142. </div> 
  143.  
  144. </div> 
  145. </div> 
  146. <?php 
  147. ?> 
  148. </div> 
  149. <?php