示例#1
0
 /**
  * Initialize the install strings.
  *
  * @since 1.0.0
  */
 public function install_strings()
 {
     parent::install_strings();
     $this->strings['downloading_package'] = __('Downloading the Envato Market install package…', 'envato-market');
 }
示例#2
0
 function install_bsf_product($install_id)
 {
     global $bsf_product_validate_url, $bsf_support_url;
     if (!current_user_can('install_plugins')) {
         wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'bsf'));
     }
     $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array();
     $install_product_data = array();
     if (!empty($brainstrom_bundled_products)) {
         foreach ($brainstrom_bundled_products as $keys => $products) {
             if (strlen($keys) > 1) {
                 foreach ($products as $key => $product) {
                     if ($product->id === $install_id) {
                         $install_product_data = $product;
                         break;
                     }
                 }
             } else {
                 if ($products->id === $install_id) {
                     $install_product_data = $products;
                     break;
                 }
             }
         }
     }
     if (empty($install_product_data)) {
         return false;
     }
     if ($install_product_data->type !== 'plugin') {
         return false;
     }
     /* temp */
     /*$install_product_data->in_house = 'wp';
     		$install_product_data->download_url = 'https://downloads.wordpress.org/plugin/redux-framework.3.5.9.zip';*/
     $is_wp = isset($install_product_data->in_house) && $install_product_data->in_house === 'wp' ? true : false;
     if ($is_wp) {
         $download_path = $install_product_data->download_url;
     } else {
         $path = $bsf_product_validate_url;
         $timezone = date_default_timezone_get();
         $call = 'file=' . $install_product_data->download_url . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone;
         $hash = $call;
         //$parse = parse_url($path);
         //$download = $parse['scheme'].'://'.$parse['host'];
         $get_path = 'http://downloads.brainstormforce.com/';
         $download_path = rtrim($get_path, '/') . '/download.php?' . $hash . '&base=ignore';
     }
     require_once ABSPATH . '/wp-admin/includes/file.php';
     WP_Filesystem();
     global $wp_filesystem;
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $WP_Upgrader = new WP_Upgrader();
     $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR));
     if (!$res) {
         wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf')));
     }
     $Plugin_Upgrader = new Plugin_Upgrader();
     $defaults = array('clear_update_cache' => true);
     $args = array();
     $parsed_args = wp_parse_args($args, $defaults);
     $Plugin_Upgrader->init();
     $Plugin_Upgrader->install_strings();
     $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
     $Plugin_Upgrader->strings['remove_old'] = __('Removing old plugin, if exists', 'bsf');
     add_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package'));
     $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install')));
     remove_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package'));
     if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) {
         return $Plugin_Upgrader->result;
     }
     // Force refresh of plugin update information
     wp_clean_plugins_cache($parsed_args['clear_update_cache']);
     //return true;
     $response = array('status' => true, 'type' => 'plugin', 'name' => $install_product_data->name, 'init' => $install_product_data->init);
     $plugin_abs_path = WP_PLUGIN_DIR . '/' . $install_product_data->init;
     if (is_file($plugin_abs_path)) {
         if (!isset($_GET['action']) && !isset($_GET['id'])) {
             echo '|bsf-plugin-installed|';
         }
         $is_plugin_installed = true;
         if (!is_plugin_active($install_product_data->init)) {
             activate_plugin($install_product_data->init);
             if (is_plugin_active($install_product_data->init)) {
                 if (!isset($_GET['action']) && !isset($_GET['id'])) {
                     echo '|bsf-plugin-activated|';
                 }
             }
         } else {
             if (!isset($_GET['action']) && !isset($_GET['id'])) {
                 echo '|bsf-plugin-activated|';
             }
         }
     }
     return $response;
 }