PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
← All changes | includes/admin/notices/bbPress-required.php +148 -31 1.3.3 → 2.2.0 View file →
@@ -1,31 +1,148 @@
1 -<?php
2 -/**
3 - * Notice
4 - * Activate the bbPress
5 - * @return void
6 - */
7 -
8 -include_once BBPC_DIR . '/includes/admin/notices/core_installer.php';
9 -new BBPCore_Install_Core('');
10 -
11 -add_action( 'admin_notices', function(){
12 -
13 - $has_installed = get_plugins();
14 - $button_text = isset( $has_installed['bbpress/bbpress.php'] ) ? __( 'Activate Now!', 'bbp-core' ) : __( 'Install Now!', 'bbp-core' );
15 -
16 - if( ! class_exists( 'bbPress' ) ) :
17 - ?>
18 - <div class="error notice is-dismissible bottom-10">
19 - <p>
20 - <?php echo sprintf( '<strong>%1$s</strong> %2$s <strong>%3$s</strong> %4$s', __( 'BBP Core', 'bbp-core' ), __( 'requires', 'bbp-core' ), __( 'bbPress', 'bbp-core' ), __( ' plugin to be installed. Please get the plugin now!', 'bbp-core' ) ) ?>
21 - </p>
22 - <p>
23 - <button id="bbp-core-install-core" class="button button-primary">
24 - <?php echo esc_html($button_text); ?>
25 - </button>
26 - </p>
27 - </div>
28 - <?php
29 - endif;
30 -
31 -});
1 +<?php
2 +/**
3 + * Forumax Installer - No Class Version
4 + */
5 +
6 +if ( ! function_exists( 'bbpcore_admin_notice' ) ) :
7 +
8 + /**
9 + * Show admin notice for bbPress requirement
10 + */
11 + function bbpcore_admin_notice() {
12 + if ( class_exists( 'bbPress' ) ) {
13 + return; // bbPress is active, no notice needed
14 + }
15 +
16 + if ( ! function_exists( 'get_plugins' ) ) {
17 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
18 + }
19 +
20 + $has_installed = get_plugins();
21 + $button_text = isset( $has_installed['bbpress/bbpress.php'] )
22 + ? esc_html__( 'Activate Now!', 'forumax' )
23 + : esc_html__( 'Install Now!', 'forumax' );
24 + ?>
25 + <div class="notice notice-error is-dismissible">
26 + <p>
27 + <?php
28 + printf(
29 + '<strong>%1$s</strong> %2$s <strong>%3$s</strong> %4$s',
30 + esc_html__( 'Forumax', 'forumax' ),
31 + esc_html__( 'requires', 'forumax' ),
32 + esc_html__( 'bbPress', 'forumax' ),
33 + esc_html__( 'plugin to be installed and active. Please install or activate it now!', 'forumax' )
34 + );
35 + ?>
36 + </p>
37 + <p>
38 + <button id="bbp-core-install-core" class="button button-primary">
39 + <?php echo esc_html( $button_text ); ?>
40 + </button>
41 + </p>
42 + </div>
43 +
44 + <script>
45 + jQuery(document).ready(function ($) {
46 + $('#bbp-core-install-core').on('click', function (e) {
47 + e.preventDefault();
48 + var self = $(this);
49 + self.addClass('install-now updating-message');
50 + self.text('<?php echo esc_js( __( 'Installing...', 'forumax' ) ); ?>');
51 +
52 + $.ajax({
53 + url: ajaxurl,
54 + type: 'POST',
55 + data: {
56 + action: 'bbpcore_install_core',
57 + _wpnonce: '<?php echo esc_js( wp_create_nonce( 'bbpcore_install_core' ) ); ?>',
58 + },
59 + success: function (response) {
60 + if (response.success) {
61 + self.text('<?php echo esc_js( __( 'Installed', 'forumax' ) ); ?>');
62 + window.location.reload();
63 + } else {
64 + alert(response.data || '<?php echo esc_js( __( 'Something went wrong.', 'forumax' ) ); ?>');
65 + self.text('<?php echo esc_js( __( 'Failed', 'forumax' ) ); ?>');
66 + }
67 + },
68 + error: function (xhr) {
69 + alert('AJAX Error: ' + xhr.responseText);
70 + self.removeClass('install-now updating-message');
71 + },
72 + complete: function () {
73 + self.attr('disabled', 'disabled');
74 + self.removeClass('install-now updating-message');
75 + }
76 + });
77 + });
78 + });
79 + </script>
80 + <?php
81 + }
82 + add_action( 'admin_notices', 'bbpcore_admin_notice' );
83 +
84 +endif;
85 +
86 +if ( ! function_exists( 'bbpcore_install_core' ) ) :
87 +
88 + /**
89 + * Handle AJAX install/activation of bbPress
90 + */
91 + function bbpcore_install_core() {
92 + check_ajax_referer( 'bbpcore_install_core' );
93 +
94 + if ( ! current_user_can( 'manage_options' ) ) {
95 + wp_send_json_error( __( 'You don\'t have permission to install plugins.', 'forumax' ) );
96 + }
97 +
98 + $result = bbpcore_install_plugin( 'bbpress', 'bbpress.php' );
99 +
100 + if ( is_wp_error( $result ) ) {
101 + wp_send_json_error( $result->get_error_message() );
102 + }
103 +
104 + wp_send_json_success();
105 + }
106 + add_action( 'wp_ajax_bbpcore_install_core', 'bbpcore_install_core' );
107 +
108 +endif;
109 +
110 +if ( ! function_exists( 'bbpcore_install_plugin' ) ) :
111 +
112 + /**
113 + * Install and activate a plugin
114 + */
115 + function bbpcore_install_plugin( $slug, $file ) {
116 + include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
117 + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
118 + include_once ABSPATH . 'wp-admin/includes/plugin.php';
119 +
120 + $plugin_basename = $slug . '/' . $file;
121 +
122 + // Already installed? Just activate
123 + if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_basename ) ) {
124 + return activate_plugin( $plugin_basename );
125 + }
126 +
127 + // Download from WP.org
128 + $api = plugins_api( 'plugin_information', array(
129 + 'slug' => $slug,
130 + 'fields' => array( 'sections' => false ),
131 + ) );
132 +
133 + if ( is_wp_error( $api ) ) {
134 + return $api;
135 + }
136 +
137 + $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
138 + $result = $upgrader->install( $api->download_link );
139 +
140 + if ( is_wp_error( $result ) ) {
141 + return $result;
142 + }
143 +
144 + // Activate after install
145 + return activate_plugin( $plugin_basename );
146 + }
147 +
148 +endif;