Skip to content

Commit 9fbe737

Browse files
committed
Implemented Freemius
1 parent 9ad3bf6 commit 9fbe737

File tree

204 files changed

+65651
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+65651
-3
lines changed
7.55 KB
Loading

includes/class-main.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ private function init() {
179179

180180
$this->hooks();
181181

182-
// Conditionally load Pro if available.
183-
if ( class_exists( 'WebberZone\\Knowledge_Base\\Pro\\Pro' ) ) {
184-
$this->pro = new Pro\Pro();
182+
// Initialize pro features.
183+
if ( wzkb_freemius()->is__premium_only() ) {
184+
if ( wzkb_freemius()->can_use_premium_code() ) {
185+
$this->pro = new Pro\Pro();
186+
}
185187
}
186188

187189
if ( is_admin() ) {

knowledgebase.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,75 @@
7373
define( 'WZKB_PLUGIN_FILE', __FILE__ );
7474
}
7575

76+
77+
if ( ! function_exists( __NAMESPACE__ . '\wzkb_deactivate_other_instances' ) ) {
78+
/**
79+
* Deactivate other instances of WZKB when this plugin is activated.
80+
*
81+
* @param string $plugin The plugin being activated.
82+
* @param bool $network_wide Whether the plugin is being activated network-wide.
83+
*/
84+
function wzkb_deactivate_other_instances( $plugin, $network_wide = false ) {
85+
$free_plugin = 'knowledgebase/knowledgebase.php';
86+
$pro_plugin = 'knowledgebase-pro/knowledgebase.php';
87+
88+
// Only proceed if one of our plugins is being activated.
89+
if ( ! in_array( $plugin, array( $free_plugin, $pro_plugin ), true ) ) {
90+
return;
91+
}
92+
93+
$plugins_to_deactivate = array();
94+
$deactivated_plugin = '';
95+
96+
// If pro is being activated, deactivate free.
97+
if ( $pro_plugin === $plugin ) {
98+
if ( is_plugin_active( $free_plugin ) || ( $network_wide && is_plugin_active_for_network( $free_plugin ) ) ) {
99+
$plugins_to_deactivate[] = $free_plugin;
100+
$deactivated_plugin = 'WebberZone Knowledge Base';
101+
}
102+
}
103+
104+
// If free is being activated, deactivate pro.
105+
if ( $free_plugin === $plugin ) {
106+
if ( is_plugin_active( $pro_plugin ) || ( $network_wide && is_plugin_active_for_network( $pro_plugin ) ) ) {
107+
$plugins_to_deactivate[] = $pro_plugin;
108+
$deactivated_plugin = 'WebberZone Knowledge Base Pro';
109+
}
110+
}
111+
112+
if ( ! empty( $plugins_to_deactivate ) ) {
113+
deactivate_plugins( $plugins_to_deactivate, false, $network_wide );
114+
set_transient( 'wzkb_deactivated_notice', $deactivated_plugin, 1 * HOUR_IN_SECONDS );
115+
}
116+
}
117+
add_action( 'activated_plugin', __NAMESPACE__ . '\wzkb_deactivate_other_instances', 10, 2 );
118+
}
119+
120+
// Show admin notice about automatic deactivation.
121+
if ( ! has_action( 'admin_notices', __NAMESPACE__ . '\wzkb_show_deactivation_notice' ) ) {
122+
add_action(
123+
'admin_notices',
124+
function () {
125+
$deactivated_plugin = get_transient( 'wzkb_deactivated_notice' );
126+
if ( $deactivated_plugin ) {
127+
/* translators: %s: Name of the deactivated plugin */
128+
$message = sprintf( __( "WebberZone Knowledge Base and WebberZone Knowledge Base Pro should not be active at the same time. We've automatically deactivated %s.", 'knowledgebase' ), $deactivated_plugin );
129+
?>
130+
<div class="updated" style="border-left: 4px solid #ffba00;">
131+
<p><?php echo esc_html( $message ); ?></p>
132+
</div>
133+
<?php
134+
delete_transient( 'wzkb_deactivated_notice' );
135+
}
136+
}
137+
);
138+
}
139+
140+
if ( ! function_exists( __NAMESPACE__ . '\wzkb_freemius' ) ) {
141+
// Finally load Freemius integration.
142+
require_once plugin_dir_path( __FILE__ ) . 'load-freemius.php';
143+
}
144+
76145
// Load the autoloader.
77146
require_once WZKB_PLUGIN_DIR . 'includes/autoloader.php';
78147

load-freemius.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Initializes Freemius SDK for WebberZone Knowledge Base Pro.
4+
*
5+
* @package WebberZone\Knowledge_Base
6+
*/
7+
8+
namespace WebberZone\Knowledge_Base;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
14+
if ( ! function_exists( __NAMESPACE__ . '\wzkb_freemius' ) ) {
15+
/**
16+
* Initialize Freemius SDK.
17+
*/
18+
function wzkb_freemius() {
19+
global $wzkb_freemius;
20+
if ( ! isset( $wzkb_freemius ) ) {
21+
// Activate multisite network integration.
22+
if ( ! defined( 'WP_FS__PRODUCT_21392_MULTISITE' ) ) {
23+
define( 'WP_FS__PRODUCT_21392_MULTISITE', true );
24+
}
25+
// Include Freemius SDK.
26+
require_once __DIR__ . '/vendor/freemius/start.php';
27+
$wzkb_freemius = \fs_dynamic_init(
28+
array(
29+
'id' => '21392',
30+
'slug' => 'knowledgebase',
31+
'premium_slug' => 'knowledgebase-pro',
32+
'type' => 'plugin',
33+
'public_key' => 'pk_1f07ee1df929932e63005f9866901',
34+
'is_premium' => true,
35+
'premium_suffix' => 'Pro',
36+
'has_premium_version' => true,
37+
'has_addons' => false,
38+
'has_paid_plans' => true,
39+
'wp_org_gatekeeper' => 'OA7#BoRiBNqdf52FvzEf!!074aRLPs8fspif$7K1#4u4Csys1fQlCecVcUTOs2mcpeVHi#C2j9d09fOTvbC0HloPT7fFee5WdS3G',
40+
'trial' => array(
41+
'days' => 14,
42+
'is_require_payment' => true,
43+
),
44+
'menu' => array(
45+
'slug' => 'edit.php?post_type=wz_knowledgebase',
46+
'first-path' => 'edit.php?post_type=wz_knowledgebase&page=wzkb-setup',
47+
'contact' => false,
48+
'support' => false,
49+
),
50+
)
51+
);
52+
}
53+
$wzkb_freemius->add_filter( 'plugin_icon', __NAMESPACE__ . '\\wzkb_freemius_get_plugin_icon' );
54+
$wzkb_freemius->add_filter( 'after_uninstall', __NAMESPACE__ . '\\wzkb_freemius_uninstall' );
55+
return $wzkb_freemius;
56+
}
57+
58+
/**
59+
* Get the plugin icon.
60+
*
61+
* @return string
62+
*/
63+
function wzkb_freemius_get_plugin_icon() {
64+
return __DIR__ . '/includes/admin/images/wzkb-icon.jpg';
65+
}
66+
67+
/**
68+
* Uninstall the plugin.
69+
*/
70+
function wzkb_freemius_uninstall() {
71+
require_once __DIR__ . '/uninstaller.php';
72+
}
73+
74+
// Init Freemius.
75+
wzkb_freemius();
76+
// Signal that SDK was initiated.
77+
do_action( 'wzkb_freemius_loaded' );
78+
}

0 commit comments

Comments
 (0)