PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
2.5.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 All 30 releases
← All changes | includes/admin/notices/bbPress-required.php +125 -16 1.4.0 → 2.5.0 View file →
@@ -1,30 +1,37 @@
1 1 <?php
2 2 /**
3 - * Notice
4 - * Activate the bbPress
5 - * @return void
3 + * Forumax Installer - No Class Version
6 4 */
7 5
8 -include_once BBPC_DIR . '/includes/admin/notices/core_installer.php';
9 -new BBPCore_Install_Core('');
6 +if ( ! function_exists( 'bbpcore_admin_notice' ) ) :
10 7
11 -add_action( 'admin_notices', function(){
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 + }
12 15
13 - $has_installed = get_plugins();
14 - $button_text = isset( $has_installed['bbpress/bbpress.php'] ) ? esc_html__( 'Activate Now!', 'bbp-core' ) : esc_html__( 'Install Now!', 'bbp-core' );
16 + if ( ! function_exists( 'get_plugins' ) ) {
17 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
18 + }
15 19
16 - if ( ! class_exists( 'bbPress' ) ) :
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' );
17 24 ?>
18 - <div class="error notice is-dismissible bottom-10">
25 + <div class="notice notice-error is-dismissible">
19 26 <p>
20 27 <?php
21 28 printf(
22 29 '<strong>%1$s</strong> %2$s <strong>%3$s</strong> %4$s',
23 - esc_html__( 'BBP Core', 'bbp-core' ),
24 - esc_html__( 'requires', 'bbp-core' ),
25 - esc_html__( 'bbPress', 'bbp-core' ),
26 - esc_html__( 'plugin to be installed. Please get the plugin now!', 'bbp-core' )
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' )
27 34 );
28 35 ?>
29 36 </p>
30 37 <p>
@@ -32,8 +39,110 @@
32 39 <?php echo esc_html( $button_text ); ?>
33 40 </button>
34 41 </p>
35 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>
36 80 <?php
37 - endif;
81 + }
82 + add_action( 'admin_notices', 'bbpcore_admin_notice' );
38 83
39 -});
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;