/**
  * Activate add-on.
  *
  * @access public
  * @return void
  */
 public function activate_addon()
 {
     //make sure we activated an add-on
     if (empty($_POST['gmw_action']) || $_POST['gmw_action'] != 'activate_addon') {
         return;
     }
     $active_addon = $_POST['gmw_addon_activated'];
     $plugin_basename = $_POST['gmw_addon_basename'];
     //look for nonce
     if (empty($_POST[$active_addon . '_activate_addon_nonce'])) {
         return;
     }
     //varify nonce
     if (!wp_verify_nonce($_POST[$active_addon . '_activate_addon_nonce'], $active_addon . '_activate_addon_nonce')) {
         return;
     }
     unset($this->addons[$active_addon]);
     $this->addons[$active_addon] = 'active';
     update_option('gmw_addons', $this->addons);
     $plugins = get_plugins();
     //activate the addon
     if (array_key_exists($plugin_basename, $plugins) && is_plugin_inactive($plugin_basename)) {
         activate_plugins($plugin_basename);
     }
     //reload the page to prevent resubmission
     wp_safe_redirect(admin_url('admin.php?page=gmw-add-ons&gmw_notice=addon_activated&gmw_notice_status=updated'));
     exit;
 }
Exemple #2
0
 /**
  * If Vimeography was just updated, make sure all the Vimeography plugins are activated.
  *
  * @return void
  */
 public function vimeography_check_if_just_updated()
 {
     $plugins = get_option('vimeography_reactivate_plugins');
     if ($plugins) {
         activate_plugins($plugins);
         delete_option('vimeography_reactivate_plugins');
     }
 }
Exemple #3
0
 public function testActivationAndDeactivation()
 {
     global $wp_rewrite;
     include_once $this->getWpRoot() . '/wp-admin/includes/plugin.php';
     if (!is_plugin_active('wprsrv/wprsrv.php')) {
         activate_plugins('wprsrv/wprsrv.php');
     }
     deactivate_plugins('wprsrv/wprsrv.php');
     activate_plugins('wprsrv/wprsrv.php');
     $this->assertTrue(is_plugin_active('wprsrv/wprsrv.php'));
 }
 public static function setUpBeforeClass()
 {
     wp_set_current_user(1, 'Alexander Gruzov');
     if (!is_plugin_active('social-community-popup/social-community-popup.php') || !isset($GLOBALS['social-community-popup'])) {
         die("Plugin deactivated. Activate the plugin first before run this test.\n");
     }
     self::$plugin = $GLOBALS['social-community-popup'];
     self::$plugin->set_scp_version('0.7.1');
     self::cleanUp();
     // Очищаем всю информацию о плагине во время тестирования
     deactivate_plugins('social-community-popup/social-community-popup.php');
     activate_plugins('social-community-popup/social-community-popup.php');
     self::$plugin->set_scp_version('0.1');
 }
	public static function execute( $params ) {

		// Set shutdown handler
		@register_shutdown_function( 'Ai1wm_Import_Done::shutdown' );

		// Check multisite.json file
		if ( true === is_file( ai1wm_multisite_path( $params ) ) ) {

			// Read multisite.json file
			$handle = fopen( ai1wm_multisite_path( $params ), 'r' );
			if ( $handle === false ) {
				throw new Ai1wm_Import_Exception( __( 'Unable to read multisite.json file', AI1WM_PLUGIN_NAME ) );
			}

			// Parse multisite.json file
			$multisite = fread( $handle, filesize( ai1wm_multisite_path( $params ) ) );
			$multisite = json_decode( $multisite );

			// Close handle
			fclose( $handle );

			// Activate plugins
			if ( isset( $multisite->Plugins ) && ( $active_sitewide_plugins = $multisite->Plugins ) ) {
				activate_plugins( $active_sitewide_plugins, null, is_multisite() );
			}
		}

		// Set the new MS files rewriting
		if ( get_site_option( AI1WM_MS_FILES_REWRITING ) ) {
			update_site_option( AI1WM_MS_FILES_REWRITING, 0 );
		}

		// Open the archive file for reading
		$archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );

		// Unpack must-use plugins
		$archive->extract_by_files_array( WP_CONTENT_DIR, array( AI1WM_MUPLUGINS_NAME ) );

		// Close the archive file
		$archive->close();

		// Load must-use plugins
		foreach ( wp_get_mu_plugins() as $mu_plugin ) {
			include_once( $mu_plugin );
		}

		return $params;
	}
 /**
  * Install options
  *
  * @param  string $stylesheet
  *
  * @return bool
  */
 private function options($stylesheet)
 {
     $response = wp_remote_get(Admin::demo_site_url(['theme' => urlencode($stylesheet), 'action' => 'get_options']));
     if (is_wp_error($response)) {
         return false;
     }
     $json = wp_remote_retrieve_body($response);
     $options = json_decode($json, true);
     if (!$options) {
         return false;
     }
     if (isset($options['home'])) {
         $this->strings[$options['home']] = get_option('home');
     }
     if (isset($options['admin_email'])) {
         $this->strings[$options['admin_email']] = get_option('admin_email');
     }
     if ($this->strings) {
         // Chicken/egg situation means we must replace strings and decode the JSON again
         $json = str_replace(array_keys($this->strings), array_values($this->strings), $json);
         $options = json_decode($json, true);
     }
     foreach ($options as $option => $value) {
         switch ($option) {
             case 'active_plugins':
                 activate_plugins($value);
                 update_option('wpem_plugins', $value);
                 break;
             case 'stylesheet':
                 switch_theme($value);
                 update_option('wpem_theme', $value);
                 break;
             case 'template':
                 if ($value !== $options['stylesheet']) {
                     update_option('wpem_parent_theme', $value);
                 }
                 break;
             default:
                 update_option($option, $value);
         }
     }
     return true;
 }
 public static function execute($params)
 {
     // Check multisite.json file
     if (true === is_file(ai1wm_multisite_path($params))) {
         // Read multisite.json file
         $handle = fopen(ai1wm_multisite_path($params), 'r');
         if ($handle === false) {
             throw new Ai1wm_Import_Exception(__('Unable to read multisite.json file', AI1WM_PLUGIN_NAME));
         }
         // Parse multisite.json file
         $multisite = fread($handle, filesize(ai1wm_multisite_path($params)));
         $multisite = json_decode($multisite, true);
         // Close handle
         fclose($handle);
         // Activate plugins
         if (isset($multisite['Plugins']) && ($active_sitewide_plugins = $multisite['Plugins'])) {
             activate_plugins($active_sitewide_plugins, null, is_multisite(), true);
         }
     }
     // Set progress
     Ai1wm_Status::done(sprintf(__('You need to perform two more steps:<br />' . '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s" target="_blank">Permalinks Settings</a></strong> <small>(opens a new window)</small><br />' . '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Optionally, review the plugin</a>.</strong> <small>(opens a new window)</small>', AI1WM_PLUGIN_NAME), admin_url('options-permalink.php#submit')), __('Your data has been imported successfuly!', AI1WM_PLUGIN_NAME));
     return $params;
 }
Exemple #8
0
 function new_blog($blog_id)
 {
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     global $psts;
     $psts_plugins = (array) $psts->get_setting('pp_plugins');
     $auto_activate = array();
     switch_to_blog($blog_id);
     //look for valid plugins with anyone access
     foreach ($psts_plugins as $plugin_file => $data) {
         if ($data['auto'] && is_numeric($data['level']) && (is_pro_site($blog_id, $data['level']) || $data['level'] == 0) && !is_plugin_active($plugin_file)) {
             $auto_activate[] = $plugin_file;
         }
     }
     //if any activate them
     if (count($auto_activate)) {
         activate_plugins($auto_activate, '', false);
         //silently activate any plugins
     }
     restore_current_blog();
 }
 public static function execute($params)
 {
     global $wpdb;
     // Skip database import
     if (!is_file(ai1wm_database_path($params))) {
         return $params;
     }
     // Read blogs.json file
     $handle = fopen(ai1wm_blogs_path($params), 'r');
     if ($handle === false) {
         throw new Ai1wm_Import_Exception('Unable to read blogs.json file');
     }
     // Parse blogs.json file
     $blogs = fread($handle, filesize(ai1wm_blogs_path($params)));
     $blogs = json_decode($blogs);
     // Close handle
     fclose($handle);
     // Read package.json file
     $handle = fopen(ai1wm_package_path($params), 'r');
     if ($handle === false) {
         throw new Ai1wm_Import_Exception('Unable to read package.json file');
     }
     // Parse package.json file
     $config = fread($handle, filesize(ai1wm_package_path($params)));
     $config = json_decode($config);
     // Close handle
     fclose($handle);
     // Set progress
     Ai1wm_Status::info(__('Restoring database...', AI1WM_PLUGIN_NAME));
     $old_values = array();
     $new_values = array();
     // Get Blog URLs
     foreach ($blogs as $blog) {
         // Get blogs dir Upload Path
         if (!in_array(sprintf("'%s'", trim(ai1wm_blogsdir_path($blog->Old->Id), '/')), $old_values)) {
             $old_values[] = sprintf("'%s'", trim(ai1wm_blogsdir_path($blog->Old->Id), '/'));
             $new_values[] = sprintf("'%s'", get_option('upload_path'));
         }
         // Get sites Upload Path
         if (!in_array(sprintf("'%s'", trim(ai1wm_uploads_path($blog->Old->Id), '/')), $old_values)) {
             $old_values[] = sprintf("'%s'", trim(ai1wm_uploads_path($blog->Old->Id), '/'));
             $new_values[] = sprintf("'%s'", get_option('upload_path'));
         }
         // Handle old and new sites dir style
         if (defined('UPLOADBLOGSDIR')) {
             // Get Upload Path
             if (!in_array(ai1wm_blogsdir_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_blogsdir_path($blog->Old->Id);
                 $new_values[] = ai1wm_blogsdir_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->New->Id), '\\/'));
             }
             // Get Upload Path
             if (!in_array(ai1wm_uploads_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_uploads_path($blog->Old->Id);
                 $new_values[] = ai1wm_blogsdir_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->New->Id), '\\/'));
             }
         } else {
             // Get Upload Path
             if (!in_array(ai1wm_blogsdir_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_blogsdir_path($blog->Old->Id);
                 $new_values[] = ai1wm_uploads_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_blogsdir_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->New->Id), '\\/'));
             }
             // Get Upload Path
             if (!in_array(ai1wm_uploads_path($blog->Old->Id), $old_values)) {
                 $old_values[] = ai1wm_uploads_path($blog->Old->Id);
                 $new_values[] = ai1wm_uploads_path($blog->New->Id);
             }
             // Get escaped Upload Path
             if (!in_array(addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/')), $old_values)) {
                 $old_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->Old->Id), '\\/'));
                 $new_values[] = addslashes(addcslashes(ai1wm_uploads_path($blog->New->Id), '\\/'));
             }
         }
         // Get Site URL
         if (isset($blog->Old->SiteURL) && $blog->Old->SiteURL !== $blog->New->SiteURL) {
             // Get domain
             $old_domain = parse_url($blog->Old->SiteURL, PHP_URL_HOST);
             $new_domain = parse_url($blog->New->SiteURL, PHP_URL_HOST);
             // Get scheme
             $new_scheme = parse_url($blog->New->SiteURL, PHP_URL_SCHEME);
             // Replace Site URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Site URL
                 if (!in_array(set_url_scheme($blog->Old->SiteURL, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($blog->Old->SiteURL, $old_scheme);
                     $new_values[] = set_url_scheme($blog->New->SiteURL, $new_scheme);
                 }
                 // Add encoded Site URL
                 if (!in_array(urlencode(set_url_scheme($blog->Old->SiteURL, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($blog->Old->SiteURL, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme($blog->New->SiteURL, $new_scheme));
                 }
                 // Add escaped Site URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($blog->Old->SiteURL, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($blog->Old->SiteURL, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme($blog->New->SiteURL, $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
         // Get Home URL
         if (isset($blog->Old->HomeURL) && $blog->Old->HomeURL !== $blog->New->HomeURL) {
             // Get domain
             $old_domain = parse_url($blog->Old->HomeURL, PHP_URL_HOST);
             $new_domain = parse_url($blog->New->HomeURL, PHP_URL_HOST);
             // Get scheme
             $new_scheme = parse_url($blog->New->HomeURL, PHP_URL_SCHEME);
             // Replace Home URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Home URL
                 if (!in_array(set_url_scheme($blog->Old->HomeURL, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($blog->Old->HomeURL, $old_scheme);
                     $new_values[] = set_url_scheme($blog->New->HomeURL, $new_scheme);
                 }
                 // Add encoded Home URL
                 if (!in_array(urlencode(set_url_scheme($blog->Old->HomeURL, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($blog->Old->HomeURL, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme($blog->New->HomeURL, $new_scheme));
                 }
                 // Add escaped Home URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($blog->Old->HomeURL, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($blog->Old->HomeURL, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme($blog->New->HomeURL, $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get Site URL
     if (isset($config->SiteURL) && $config->SiteURL !== site_url()) {
         // Get www URL
         if (stripos($config->SiteURL, '//www.') !== false) {
             $www = str_ireplace('//www.', '//', $config->SiteURL);
         } else {
             $www = str_ireplace('//', '//www.', $config->SiteURL);
         }
         // Replace Site URL
         foreach (array($config->SiteURL, $www) as $url) {
             // Get domain
             $old_domain = parse_url($url, PHP_URL_HOST);
             $new_domain = parse_url(site_url(), PHP_URL_HOST);
             // Get path
             $old_path = parse_url($url, PHP_URL_PATH);
             $new_path = parse_url(site_url(), PHP_URL_PATH);
             // Get scheme
             $new_scheme = parse_url(site_url(), PHP_URL_SCHEME);
             // Add domain and path
             if (!in_array(sprintf("%s','%s", $old_domain, trailingslashit($old_path)), $old_values)) {
                 $old_values[] = sprintf("%s','%s", $old_domain, trailingslashit($old_path));
                 $new_values[] = sprintf("%s','%s", $new_domain, trailingslashit($new_path));
             }
             // Replace Site URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Site URL
                 if (!in_array(set_url_scheme($url, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($url, $old_scheme);
                     $new_values[] = set_url_scheme(site_url(), $new_scheme);
                 }
                 // Add encoded Site URL
                 if (!in_array(urlencode(set_url_scheme($url, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($url, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme(site_url(), $new_scheme));
                 }
                 // Add escaped Site URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme(site_url(), $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get Home URL
     if (isset($config->HomeURL) && $config->HomeURL !== home_url()) {
         // Get www URL
         if (stripos($config->HomeURL, '//www.') !== false) {
             $www = str_ireplace('//www.', '//', $config->HomeURL);
         } else {
             $www = str_ireplace('//', '//www.', $config->HomeURL);
         }
         // Replace Home URL
         foreach (array($config->HomeURL, $www) as $url) {
             // Get domain
             $old_domain = parse_url($url, PHP_URL_HOST);
             $new_domain = parse_url(home_url(), PHP_URL_HOST);
             // Get path
             $old_path = parse_url($url, PHP_URL_PATH);
             $new_path = parse_url(home_url(), PHP_URL_PATH);
             // Get scheme
             $new_scheme = parse_url(home_url(), PHP_URL_SCHEME);
             // Add domain and path
             if (!in_array(sprintf("%s','%s", $old_domain, trailingslashit($old_path)), $old_values)) {
                 $old_values[] = sprintf("%s','%s", $old_domain, trailingslashit($old_path));
                 $new_values[] = sprintf("%s','%s", $new_domain, trailingslashit($new_path));
             }
             // Replace Home URL scheme
             foreach (array('http', 'https') as $old_scheme) {
                 // Add plain Home URL
                 if (!in_array(set_url_scheme($url, $old_scheme), $old_values)) {
                     $old_values[] = set_url_scheme($url, $old_scheme);
                     $new_values[] = set_url_scheme(home_url(), $new_scheme);
                 }
                 // Add encoded Home URL
                 if (!in_array(urlencode(set_url_scheme($url, $old_scheme)), $old_values)) {
                     $old_values[] = urlencode(set_url_scheme($url, $old_scheme));
                     $new_values[] = urlencode(set_url_scheme(home_url(), $new_scheme));
                 }
                 // Add escaped Home URL
                 if (!in_array(addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/')), $old_values)) {
                     $old_values[] = addslashes(addcslashes(set_url_scheme($url, $old_scheme), '/'));
                     $new_values[] = addslashes(addcslashes(set_url_scheme(home_url(), $new_scheme), '/'));
                 }
             }
             // Add email
             if (!isset($config->NoEmailReplace)) {
                 if (!in_array(sprintf("@%s", $old_domain), $old_values)) {
                     $old_values[] = sprintf("@%s", $old_domain);
                     $new_values[] = sprintf("@%s", $new_domain);
                 }
             }
         }
     }
     // Get WordPress Content
     if (isset($config->WordPress->Content) && $config->WordPress->Content !== WP_CONTENT_DIR) {
         // Add plain WordPress Content
         if (!in_array($config->WordPress->Content, $old_values)) {
             $old_values[] = $config->WordPress->Content;
             $new_values[] = WP_CONTENT_DIR;
         }
         // Add encoded WordPress Content
         if (!in_array(urlencode($config->WordPress->Content), $old_values)) {
             $old_values[] = urlencode($config->WordPress->Content);
             $new_values[] = urlencode(WP_CONTENT_DIR);
         }
         // Add escaped WordPress Content
         if (!in_array(addslashes(addcslashes($config->WordPress->Content, '\\/')), $old_values)) {
             $old_values[] = addslashes(addcslashes($config->WordPress->Content, '\\/'));
             $new_values[] = addslashes(addcslashes(WP_CONTENT_DIR, '\\/'));
         }
     }
     // Get URL IP
     $url_ip = get_option(AI1WM_URL_IP);
     // Get URL adapter
     $url_adapter = get_option(AI1WM_URL_ADAPTER);
     // Get secret key
     $secret_key = get_option(AI1WM_SECRET_KEY);
     // Get HTTP user
     $auth_user = get_option(AI1WM_AUTH_USER);
     // Get HTTP password
     $auth_password = get_option(AI1WM_AUTH_PASSWORD);
     // Get active ServMask plugins
     $active_servmask_plugins = ai1wm_active_servmask_plugins();
     $old_prefixes = array();
     $new_prefixes = array();
     // Set main table prefixes
     $old_prefixes[] = ai1wm_servmask_prefix('mainsite');
     $new_prefixes[] = ai1wm_table_prefix();
     // Set site table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === false) {
             $old_prefixes[] = ai1wm_servmask_prefix($blog->Old->Id);
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set base table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === true) {
             $old_prefixes[] = ai1wm_servmask_prefix('basesite');
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set site table prefixes
     foreach ($blogs as $blog) {
         if (ai1wm_main_site($blog->Old->Id) === true) {
             $old_prefixes[] = ai1wm_servmask_prefix($blog->Old->Id);
             $new_prefixes[] = ai1wm_table_prefix($blog->New->Id);
         }
     }
     // Set table prefixes
     $old_prefixes[] = ai1wm_servmask_prefix();
     $new_prefixes[] = ai1wm_table_prefix();
     // Get database client
     if (empty($wpdb->use_mysqli)) {
         $client = new Ai1wm_Database_Mysql($wpdb);
     } else {
         $client = new Ai1wm_Database_Mysqli($wpdb);
     }
     // Set database options
     $client->set_old_table_prefixes($old_prefixes)->set_new_table_prefixes($new_prefixes)->set_old_replace_values($old_values)->set_new_replace_values($new_values);
     // Flush database
     if ($version = $config->Plugin->Version) {
         if ($version !== 'develop' && version_compare($version, '4.10', '<')) {
             $client->set_include_table_prefixes(array(ai1wm_table_prefix()));
             $client->flush();
         }
     }
     // Import database
     $client->import(ai1wm_database_path($params));
     // Flush WP cache
     ai1wm_cache_flush();
     // Activate plugins
     activate_plugins($active_servmask_plugins, null, is_multisite());
     // Set the new URL IP
     update_option(AI1WM_URL_IP, $url_ip);
     // Set the new URL adapter
     update_option(AI1WM_URL_ADAPTER, $url_adapter);
     // Set the new secret key value
     update_option(AI1WM_SECRET_KEY, $secret_key);
     // Set the new HTTP user
     update_option(AI1WM_AUTH_USER, $auth_user);
     // Set the new HTTP password
     update_option(AI1WM_AUTH_PASSWORD, $auth_password);
     return $params;
 }
 function new_blog($blog_id)
 {
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     $auto_activate = (array) get_site_option('pm_auto_activate_list');
     if (count($auto_activate)) {
         switch_to_blog($blog_id);
         activate_plugins($auto_activate, '', false);
         //silently activate any plugins
         restore_current_blog();
     }
 }
Exemple #11
0
 function activate($args)
 {
     $this->_escape($args);
     $username = $args[0];
     $password = $args[1];
     $plugin_files = $args[2];
     if ($password != get_option('wpr_cron')) {
         if (!($user = $this->login($username, $password))) {
             return $this->error;
         }
         if (!current_user_can('activate_plugins')) {
             return new IXR_Error(401, 'Sorry, you cannot manage plugins on the remote blog.');
         }
     }
     $this->refresh_transient();
     $success = activate_plugins($plugin_files, '', FALSE);
     if (is_wp_error($success)) {
         return false;
     }
     chdir(WP_PLUGIN_DIR);
     if (is_array($plugin_files)) {
         return true;
     }
     // get the plugin again
     return $this->_get_plugin_data($plugin_files);
 }
     $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
     if (is_wp_error($result)) {
         wp_die($result);
     }
     $recent = (array) get_option('recently_activated');
     if (isset($recent[$plugin])) {
         unset($recent[$plugin]);
         update_option('recently_activated', $recent);
     }
     wp_redirect('plugins.php?activate=true');
     // overrides the ?error=true one above
     exit;
     break;
 case 'activate-selected':
     check_admin_referer('bulk-manage-plugins');
     activate_plugins($_POST['checked'], 'plugins.php?error=true');
     $recent = (array) get_option('recently_activated');
     foreach ((array) $_POST['checked'] as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     if ($recent != get_option('recently_activated')) {
         //If array changed, update it.
         update_option('recently_activated', $recent);
     }
     wp_redirect('plugins.php?activate-multi=true');
     exit;
     break;
 case 'error_scrape':
     check_admin_referer('plugin-activation-error_' . $plugin);
$plugin = $plugin_slug . "/" . 'yop_poll' . ".php";
$upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(array('title' => 'Yop Poll 2.0 Plugin', 'plugin' => $plugin_slug . '/yop_poll.php')));
$options = get_option('yop_poll_options');
$options['vote_permisions_facebook'] = "no";
$options['vote_permisions_google'] = "no";
$options['vote_permisions_facebook_label'] = __yop_poll('Vote as Facebook User');
$options['vote_permisions_google_label'] = __yop_poll('Vote as G+ User');
$options['facebook_share_description'] = __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name');
$options['show_google_share_button'] = "no";
$options['facebook_share_after_vote'] = "no";
$options['google_integration'] = "no";
$options['facebook_integration'] = "no";
$options['user_interface_type'] = "beginner";
$options['is_default_other_answer'] = "no";
$options['facebook_show_comments_widget'] = "no";
update_option('yop_poll_options', $options);
$upgrader->init();
if (is_plugin_active($plugin)) {
    deactivate_plugins($plugin);
}
$result = @$upgrader->run(array('package' => $download_link, 'destination' => WP_PLUGIN_DIR . "/" . $plugin_slug . "/", 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array()));
if (!is_wp_error($result)) {
    if (!is_plugin_active($plugin)) {
        $pro_options = get_option("yop_poll_pro");
        unset($pro_options['rand_number']);
        update_option("yop_poll_pro", $pro_options);
        activate_plugins($plugin);
    }
}
Yop_Poll_DbSchema::add_defaults_to_database();
wp_die();
Exemple #14
0
function shareaholic_activate_primary_plugin()
{
    deactivate_plugins('sexybookmarks/shareaholic.php');
    activate_plugins('shareaholic/shareaholic.php');
    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ShareaholicUtilities::admin_plugin_action_links', -10);
}
Exemple #15
0
 function upgrade_pp_package($plugin)
 {
     $is_active = is_plugin_active($plugin);
     $this->init();
     $this->upgrade_strings();
     $current = get_site_transient('ppc_update_info');
     if (!isset($current->response[$plugin])) {
         $this->skin->set_result(false);
         $this->skin->error('up_to_date');
         $this->skin->after();
         return false;
     }
     // Get the URL to the zip file
     $r = $current->response[$plugin];
     add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2);
     add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
     $this->run(array('package' => $r->package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update')));
     // Cleanup our hooks, incase something else does a upgrade on this connection.
     remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'));
     remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
     if (!$this->result || is_wp_error($this->result)) {
         delete_site_transient('update_plugins');
         // force reload of plugin status in case this is due to a key expiration
         pp_get_version_info(true, false, true);
         return $this->result;
     }
     if (!is_multisite() && $is_active) {
         activate_plugins($plugin);
     }
     // Force refresh of plugin update information
     set_site_transient('ppc_update_info', false);
     // Force refresh of plugin update information
     delete_site_transient('update_plugins');
     wp_cache_delete('plugins', 'plugins');
 }
 /**
  * activate plugins
  * @param $plugins_to_activate
  * @example $plugins_to_activate = [['plugin/path','repo','plugin name'],[]]
  */
 public function hw_activate_plugins($plugins_to_activate)
 {
     // Return early if there are no plugins to activate.
     if (empty($plugins_to_activate)) {
         return;
     }
     $plugins = array();
     $plugin_names = array();
     foreach ($plugins_to_activate as $plugin_string) {
         $plugins[] = $plugin_string[0];
         $plugin_names[] = $plugin_string[2];
     }
     $count = count($plugin_names);
     // Count so we can use _n function.
     $last_plugin = array_pop($plugin_names);
     // Pop off last name to prep for readability.
     $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.');
     // Now we are good to go - let's start activating plugins.
     $activate = activate_plugins($plugins);
     if (is_wp_error($activate)) {
         echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
     } else {
         printf('<div id="message" class="updated"><p>%1$s %2$s.</p></div>', _n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa'), $imploded);
     }
     // Update recently activated plugins option.
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     update_option('recently_activated', $recent);
     unset($_POST);
     // Reset the $_POST variable in case user wants to perform one action after another.
 }
Exemple #17
0
// **********************************************************
// Install the plugin into the WordPress plugin directory
if ($action == __('Install', 'amazon-link') || $Action == __('Upgrade', 'amazon-link')) {
    $result = copy($extras_dir . $plugin_ID, WP_PLUGIN_DIR . '/' . $plugin_ID);
    if ($result) {
        $update = __('Plugin ' . $avail_plugins[$plugin_ID]['Name'] . ' - has been Installed', 'amazon-link');
        $installed_plugins[$plugin_ID] = $avail_plugins[$plugin_ID];
        $action = __('Activate', 'amazon-link');
    } else {
        $error = __('Plugin ' . $avail_plugins[$plugin_ID]['Name'] . ' - failed to Install', 'amazon-link');
    }
}
// **********************************************************
// Activate the selected plugin
if ($action == __('Activate', 'amazon-link')) {
    $result = activate_plugins($plugin_ID);
    if (!is_wp_error($result)) {
        if ($update !== False) {
            $update .= __(' and Activated', 'amazon-link');
        } else {
            $update = __('Plugin ' . $installed_plugins[$plugin_ID]['Name'] . ' - has been Activated', 'amazon-link');
        }
        $installed_plugins[$plugin_ID]['Activated'] = True;
    } else {
        $error = $result->get_error_message();
    }
    // **********************************************************
    // Uninstall the selected plugin
} else {
    if ($action == __('Uninstall', 'amazon-link')) {
        $result = delete_plugins((array) $plugin_ID);
Exemple #18
0
    function my_admin_notice()
    {
        ?>
        <div class="error">
            <p><?php 
        _e('YOP POLL!', 'my-text-domain');
        ?>
</p>
       	<p> 
       		<?php 
        _e("Your server is running php lower than 5.3. Please update your Php version and try again!");
        ?>
       	</p>
        </div>
        <?php 
        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        include_once ABSPATH . 'wp-admin/includes/plugin.php';
        $plugin_slug = basename(dirname(__FILE__));
        $plugin = $plugin_slug . "/" . 'yop_poll' . ".php";
        $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(array('title' => 'Yop Poll Downgrade', 'plugin' => $plugin_slug . '/yop_poll.php')));
        $upgrader->init();
        if (is_plugin_active($plugin)) {
            deactivate_plugins($plugin);
        }
        $result = @$upgrader->run(array('package' => "https://downloads.wordpress.org/plugin/yop-poll.4.9.3.zip", 'destination' => WP_PLUGIN_DIR . "/" . $plugin_slug . "/", 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array()));
        if (!is_wp_error($result)) {
            if (!is_plugin_active($plugin)) {
                activate_plugins($plugin);
            }
        }
        wp_die();
    }
Exemple #19
0
     // overrides the ?error=true one above
     exit;
     break;
 case 'activate-selected':
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to activate plugins for this blog.'));
     }
     check_admin_referer('bulk-manage-plugins');
     $plugins = (array) $_POST['checked'];
     $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);'));
     //Only activate plugins which are not already active.
     if (empty($plugins)) {
         wp_redirect("plugins.php?plugin_status={$status}&paged={$page}");
         exit;
     }
     activate_plugins($plugins, 'plugins.php?error=true');
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     update_option('recently_activated', $recent);
     wp_redirect("plugins.php?activate-multi=true&plugin_status={$status}&paged={$page}");
     exit;
     break;
 case 'error_scrape':
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to activate plugins for this blog.'));
     }
     check_admin_referer('plugin-activation-error_' . $plugin);
Exemple #20
0
         wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
     }
     check_admin_referer('bulk-plugins');
     $plugins = isset($_POST['checked']) ? (array) $_POST['checked'] : array();
     // Only activate plugins which are not already active.
     $check = $network_wide ? 'is_plugin_active_for_network' : 'is_plugin_active';
     foreach ($plugins as $i => $plugin) {
         if ($check($plugin)) {
             unset($plugins[$i]);
         }
     }
     if (empty($plugins)) {
         wp_redirect(self_admin_url("plugins.php?plugin_status={$status}&paged={$page}&s={$s}"));
         exit;
     }
     activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide);
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     update_option('recently_activated', $recent);
     wp_redirect(self_admin_url("plugins.php?activate-multi=true&plugin_status={$status}&paged={$page}&s={$s}"));
     exit;
     break;
 case 'update-selected':
     check_admin_referer('bulk-plugins');
     if (isset($_GET['plugins'])) {
         $plugins = explode(',', $_GET['plugins']);
     } elseif (isset($_POST['checked'])) {
 public static function bulkActivate()
 {
     $plugins = $_POST['plugins'];
     if (is_array($plugins) && count($plugins) > 0) {
         if (current_user_can('activate_plugins')) {
             activate_plugins($plugins);
             die('SUCCESS');
         }
     }
     die('FAILED');
 }
Exemple #22
0
     exit;
     break;
 case 'activate-selected':
 case 'network-activate-selected':
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
     }
     check_admin_referer('bulk-plugins');
     $plugins = isset($_POST['checked']) ? (array) $_POST['checked'] : array();
     $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);'));
     // Only activate plugins which are not already active.
     if (empty($plugins)) {
         wp_redirect("plugins.php?plugin_status={$status}&paged={$page}");
         exit;
     }
     activate_plugins($plugins, 'plugins.php?error=true', $network_wide);
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     update_option('recently_activated', $recent);
     wp_redirect("plugins.php?activate-multi=true&plugin_status={$status}&paged={$page}");
     exit;
     break;
 case 'update-selected':
     check_admin_referer('bulk-plugins');
     if (isset($_GET['plugins'])) {
         $plugins = explode(',', $_GET['plugins']);
     } elseif (isset($_POST['checked'])) {
                        window.location = "admin.php?page=td_theme_plugins";
                    </script>
                    <?php 
                    break;
                }
            }
        }
    }
    // Activate a plugin
    if (isset($_GET['td_activate_plugin_slug'])) {
        $td_activate_plugin_slug = $_GET['td_activate_plugin_slug'];
        if (!empty($td_activate_plugin_slug)) {
            $plugins = TGM_Plugin_Activation::$instance->plugins;
            foreach ($plugins as $plugin) {
                if ($plugin['slug'] == $td_activate_plugin_slug) {
                    activate_plugins($plugin['file_path']);
                    ?>
                    <script type="text/javascript">
                        window.location = "admin.php?page=td_theme_plugins";
                    </script>
                    <?php 
                    break;
                }
            }
        }
    }
}
require_once "td_view_header.php";
//print_r(get_plugins());
$theme_plugins = TGM_Plugin_Activation::$instance->plugins;
?>
Exemple #24
0
<?php

load_global_ui("top");
validate_plugins(activate_plugins());
load_global_ui("bottom");
function activate_plugins()
{
    if (!file_exists("config.json")) {
        die("Unable to open configuration file! Is it there ?");
    } else {
        $configuration_file = fopen("config.json", "r");
        $list_of_activated_plugins = json_decode(fread($configuration_file, filesize("config.json")), true);
        fclose($configuration_file);
    }
    return $list_of_activated_plugins;
}
function validate_plugins($configuration)
{
    // For each plugin listed in the config.json, we get it's name, and validate then load the shit outta him.
    foreach ($configuration as $key => $value) {
        $plugin_name = $key;
        if ($value == 1) {
            error_log("[ ✔️ ] The plugin : " . $plugin_name . " is activated !", 0);
            $valid_plugin_config = 0;
            if (!file_exists("plugins/" . $plugin_name . "/" . $plugin_name . ".json")) {
                error_log("[ ❌ ] Unable to find the config file for : " . $plugin_name . " ! Is it there ?");
                error_log("[ ❌ ] The plugin : " . $plugin_name . " has not been loaded because of a missing " . $plugin_name . ".json file.");
                continue;
            } else {
                // Read it's plugin_name.json settings file
                $plugin_config_file = fopen("plugins/" . $plugin_name . "/" . $plugin_name . ".json", "r");
 /**
  * Processes bulk installation and activation actions.
  *
  * The bulk installation process looks for the $_POST information and passes that
  * through if a user has to use WP_Filesystem to enter their credentials.
  *
  * @since 2.2.0
  */
 public function process_bulk_actions()
 {
     // Bulk installation process.
     if ('tgmpa-bulk-install' === $this->current_action() || 'tgmpa-bulk-update' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         $install_type = 'install';
         if ('tgmpa-bulk-update' === $this->current_action()) {
             $install_type = 'update';
         }
         $plugins_to_install = array();
         // Did user actually select any plugins to install/update ?
         if (empty($_POST['plugin'])) {
             if ('install' === $install_type) {
                 $message = __('No plugins were selected to be installed. No action taken.', 'tgmpa');
             } else {
                 $message = __('No plugins were selected to be updated. No action taken.', 'tgmpa');
             }
             echo '<div id="message" class="error"><p>', esc_html($message), '</p></div>';
             return false;
         }
         if (is_array($_POST['plugin'])) {
             $plugins_to_install = (array) $_POST['plugin'];
         } elseif (is_string($_POST['plugin'])) {
             // Received via Filesystem page - un-flatten array (WP bug #19643).
             $plugins_to_install = explode(',', $_POST['plugin']);
         }
         // Sanitize the received input.
         $plugins_to_install = array_map('urldecode', $plugins_to_install);
         $plugins_to_install = array_map(array($this->tgmpa, 'sanitize_key'), $plugins_to_install);
         // Validate the received input.
         foreach ($plugins_to_install as $key => $slug) {
             // Check if the plugin was registered with TGMPA and remove if not.
             if (!isset($this->tgmpa->plugins[$slug])) {
                 unset($plugins_to_install[$key]);
                 continue;
             }
             // For updates: make sure this is a plugin we *can* update (update available and WP version ok).
             if ('update' === $install_type && ($this->tgmpa->is_plugin_installed($slug) && (false === $this->tgmpa->does_plugin_have_update($slug) || !$this->tgmpa->can_plugin_update($slug)))) {
                 unset($plugins_to_install[$key]);
             }
         }
         // No need to proceed further if we have no plugins to handle.
         if (empty($plugins_to_install)) {
             if ('install' === $install_type) {
                 $message = __('No plugins are available to be installed at this time.', 'tgmpa');
             } else {
                 $message = __('No plugins are available to be updated at this time.', 'tgmpa');
             }
             echo '<div id="message" class="error"><p>', esc_html($message), '</p></div>';
             return false;
         }
         // Pass all necessary information if WP_Filesystem is needed.
         $url = wp_nonce_url($this->tgmpa->get_tgmpa_url(), 'bulk-' . $this->_args['plural']);
         // Give validated data back to $_POST which is the only place the filesystem looks for extra fields.
         $_POST['plugin'] = implode(',', $plugins_to_install);
         // Work around for WP bug #19643.
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary.
         $fields = array_keys($_POST);
         // Extra fields to pass to WP_Filesystem.
         if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, $fields))) {
             return true;
             // Stop the normal page form from displaying, credential request form will be shown.
         }
         // Now we have some credentials, setup WP_Filesystem.
         if (!WP_Filesystem($creds)) {
             // Our credentials were no good, ask the user for them again.
             request_filesystem_credentials(esc_url_raw($url), $method, true, false, $fields);
             return true;
         }
         /* If we arrive here, we have the filesystem */
         // Store all information in arrays since we are processing a bulk installation.
         $names = array();
         $sources = array();
         // Needed for installs.
         $file_paths = array();
         // Needed for upgrades.
         $to_inject = array();
         // Information to inject into the update_plugins transient.
         // Prepare the data for validated plugins for the install/upgrade.
         foreach ($plugins_to_install as $slug) {
             $name = $this->tgmpa->plugins[$slug]['name'];
             $source = $this->tgmpa->get_download_url($slug);
             if (!empty($name) && !empty($source)) {
                 $names[] = $name;
                 switch ($install_type) {
                     case 'install':
                         $sources[] = $source;
                         break;
                     case 'update':
                         $file_paths[] = $this->tgmpa->plugins[$slug]['file_path'];
                         $to_inject[$slug] = $this->tgmpa->plugins[$slug];
                         $to_inject[$slug]['source'] = $source;
                         break;
                 }
             }
         }
         unset($slug, $name, $source);
         // Create a new instance of TGMPA_Bulk_Installer.
         $installer = new TGMPA_Bulk_Installer(new TGMPA_Bulk_Installer_Skin(array('url' => esc_url_raw($this->tgmpa->get_tgmpa_url()), 'nonce' => 'bulk-' . $this->_args['plural'], 'names' => $names, 'install_type' => $install_type)));
         // Wrap the install process with the appropriate HTML.
         echo '<div class="tgmpa wrap">', '<h2>', esc_html(get_admin_page_title()), '</h2>';
         // Process the bulk installation submissions.
         add_filter('upgrader_source_selection', array($this->tgmpa, 'maybe_adjust_source_dir'), 1, 3);
         if ('tgmpa-bulk-update' === $this->current_action()) {
             // Inject our info into the update transient.
             $this->tgmpa->inject_update_info($to_inject);
             $installer->bulk_upgrade($file_paths);
         } else {
             $installer->bulk_install($sources);
         }
         remove_filter('upgrader_source_selection', array($this->tgmpa, 'maybe_adjust_source_dir'), 1, 3);
         echo '</div>';
         return true;
     }
     // Bulk activation process.
     if ('tgmpa-bulk-activate' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         // Did user actually select any plugins to activate ?
         if (empty($_POST['plugin'])) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins were selected to be activated. No action taken.', 'tgmpa'), '</p></div>';
             return false;
         }
         // Grab plugin data from $_POST.
         $plugins = array();
         if (isset($_POST['plugin'])) {
             $plugins = array_map('urldecode', (array) $_POST['plugin']);
             $plugins = array_map(array($this->tgmpa, 'sanitize_key'), $plugins);
         }
         $plugins_to_activate = array();
         $plugin_names = array();
         // Grab the file paths for the selected & inactive plugins from the registration array.
         foreach ($plugins as $slug) {
             if ($this->tgmpa->can_plugin_activate($slug)) {
                 $plugins_to_activate[] = $this->tgmpa->plugins[$slug]['file_path'];
                 $plugin_names[] = $this->tgmpa->plugins[$slug]['name'];
             }
         }
         unset($slug);
         // Return early if there are no plugins to activate.
         if (empty($plugins_to_activate)) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins are available to be activated at this time.', 'tgmpa'), '</p></div>';
             return false;
         }
         // Now we are good to go - let's start activating plugins.
         $activate = activate_plugins($plugins_to_activate);
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>';
         } else {
             $count = count($plugin_names);
             // Count so we can use _n function.
             $plugin_names = array_map(array('TGMPA_Utils', 'wrap_in_strong'), $plugin_names);
             $last_plugin = array_pop($plugin_names);
             // Pop off last name to prep for readability.
             $imploded = empty($plugin_names) ? $last_plugin : implode(', ', $plugin_names) . ' ' . esc_html_x('and', 'plugin A *and* plugin B', 'tgmpa') . ' ' . $last_plugin;
             printf('<div id="message" class="updated"><p>%1$s %2$s.</p></div>', esc_html(_n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa')), $imploded);
             // Update recently activated plugins option.
             $recent = (array) get_option('recently_activated');
             foreach ($plugins_to_activate as $plugin => $time) {
                 if (isset($recent[$plugin])) {
                     unset($recent[$plugin]);
                 }
             }
             update_option('recently_activated', $recent);
         }
         unset($_POST);
         // Reset the $_POST variable in case user wants to perform one action after another.
         return true;
     }
     return false;
 }
 /**
  * @covers ::activate_plugins
  */
 public function test_activate_plugins_single_array()
 {
     $name = 'hello.php';
     activate_plugins(array($name));
     $this->assertTrue(is_plugin_active($name));
     deactivate_plugins($name);
 }
 /**
  * Processes bulk installation and activation actions.
  *
  * The bulk installation process looks either for the $_POST
  * information or for the plugin info within the $_GET variable if
  * a user has to use WP_Filesystem to enter their credentials.
  *
  * @since 2.2.0
  */
 public function process_bulk_actions()
 {
     // Bulk installation process.
     if ('tgmpa-bulk-install' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         // Prep variables to be populated.
         $plugins_to_install = array();
         $plugin_installs = array();
         $plugin_path = array();
         $plugin_name = array();
         // Look first to see if information has been passed via WP_Filesystem.
         if (isset($_GET['plugins'])) {
             $plugins = explode(',', stripslashes($_GET['plugins']));
         } elseif (isset($_POST['plugin'])) {
             $plugins = (array) $_POST['plugin'];
             // @todo needs sanitizing, figure out how
         } else {
             $plugins = array();
         }
         // Grab information from $_POST if available.
         if (isset($_POST['plugin'])) {
             foreach ($plugins as $plugin_data) {
                 $plugins_to_install[] = explode(',', $plugin_data);
             }
             foreach ($plugins_to_install as $plugin_data) {
                 $plugin_installs[] = $plugin_data[0];
                 $plugin_path[] = $plugin_data[1];
                 $plugin_name[] = $plugin_data[2];
             }
         } else {
             foreach ($plugins as $key => $value) {
                 // Grab plugin slug for each plugin.
                 if (0 === $key % 3 || 0 === $key) {
                     $plugins_to_install[] = $value;
                     $plugin_installs[] = $value;
                 }
             }
         }
         // Look first to see if information has been passed via WP_Filesystem.
         if (isset($_GET['plugin_paths'])) {
             $plugin_paths = explode(',', stripslashes($_GET['plugin_paths']));
         } elseif (isset($_POST['plugin'])) {
             $plugin_paths = (array) $plugin_path;
         } else {
             $plugin_paths = array();
         }
         // Look first to see if information has been passed via WP_Filesystem.
         if (isset($_GET['plugin_names'])) {
             $plugin_names = explode(',', stripslashes($_GET['plugin_names']));
         } elseif (isset($_POST['plugin'])) {
             $plugin_names = (array) $plugin_name;
         } else {
             $plugin_names = array();
         }
         // Loop through plugin slugs and remove already installed plugins from the list.
         $i = 0;
         foreach ($plugin_installs as $key => $plugin) {
             if (preg_match('|.php$|', $plugin)) {
                 unset($plugin_installs[$key]);
                 // If the plugin path isn't in the $_GET variable, we can unset the corresponding path.
                 if (!isset($_GET['plugin_paths'])) {
                     unset($plugin_paths[$i]);
                 }
                 // If the plugin name isn't in the $_GET variable, we can unset the corresponding name.
                 if (!isset($_GET['plugin_names'])) {
                     unset($plugin_names[$i]);
                 }
             }
             $i++;
         }
         // No need to proceed further if we have no plugins to install.
         if (empty($plugin_installs)) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins are available to be installed at this time.', 'tgmpa'), '</p></div>';
             return false;
         }
         // Reset array indexes in case we removed already installed plugins.
         $plugin_installs = array_values($plugin_installs);
         $plugin_paths = array_values($plugin_paths);
         $plugin_names = array_values($plugin_names);
         // If we grabbed our plugin info from $_GET, we need to decode it for use.
         $plugin_installs = array_map('urldecode', $plugin_installs);
         $plugin_paths = array_map('urldecode', $plugin_paths);
         $plugin_names = array_map('urldecode', $plugin_names);
         // Pass all necessary information via URL if WP_Filesystem is needed.
         $url = wp_nonce_url(add_query_arg(array('page' => $this->tgmpa->menu, 'tgmpa-action' => 'install-selected', 'plugins' => urlencode(implode(',', $plugins)), 'plugin_paths' => urlencode(implode(',', $plugin_paths)), 'plugin_names' => urlencode(implode(',', $plugin_names))), self_admin_url($this->admin_page_base)), 'bulk-plugins');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary.
         $fields = array('action', '_wp_http_referer', '_wpnonce');
         // Extra fields to pass to WP_Filesystem.
         if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, $fields))) {
             return true;
         }
         if (!WP_Filesystem($creds)) {
             request_filesystem_credentials(esc_url_raw($url), $method, true, false, $fields);
             // Setup WP_Filesystem.
             return true;
         }
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         // Need for plugins_api
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         // Need for upgrade classes
         // Store all information in arrays since we are processing a bulk installation.
         $api = array();
         $sources = array();
         $install_path = array();
         // Loop through each plugin to install and try to grab information from WordPress API, if not create 'tgmpa-empty' scalar.
         $i = 0;
         foreach ($plugin_installs as $plugin) {
             $temp = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false)));
             $api[$i] = (object) 'tgmpa-empty';
             if (!is_wp_error($temp)) {
                 $api[$i] = $temp;
             }
             $i++;
         }
         unset($plugin, $temp);
         if (is_wp_error($api)) {
             if (WP_DEBUG === true) {
                 wp_die(esc_html($this->tgmpa->strings['oops']) . var_dump($api));
                 // wpcs: xss ok
             } else {
                 wp_die(esc_html($this->tgmpa->strings['oops']));
             }
         }
         // Capture download links from $api or set install link to pre-packaged/private repo.
         $i = 0;
         foreach ($api as $object) {
             $sources[$i] = isset($object->download_link) && 'repo' === $plugin_paths[$i] ? $object->download_link : $plugin_paths[$i];
             $i++;
         }
         // Finally, all the data is prepared to be sent to the installer.
         $url = esc_url_raw(add_query_arg(array('page' => $this->tgmpa->menu), self_admin_url($this->admin_page_base)));
         $nonce = 'bulk-plugins';
         $names = $plugin_names;
         // Create a new instance of TGM_Bulk_Installer.
         $installer = new TGM_Bulk_Installer($skin = new TGM_Bulk_Installer_Skin(compact('url', 'nonce', 'names')));
         // Wrap the install process with the appropriate HTML.
         echo '<div class="tgmpa wrap">', '<h2>', esc_html(get_admin_page_title()), '</h2>';
         // Process the bulk installation submissions.
         $installer->bulk_install($sources);
         echo '</div>';
         return true;
     }
     // Bulk activation process.
     if ('tgmpa-bulk-activate' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         // Grab plugin data from $_POST.
         $plugins = isset($_POST['plugin']) ? (array) $_POST['plugin'] : array();
         // @todo needs sanitizing, figure out how
         $plugins_to_activate = array();
         // Split plugin value into array with plugin file path, plugin source and plugin name.
         foreach ($plugins as $i => $plugin) {
             $plugins_to_activate[] = explode(',', $plugin);
         }
         foreach ($plugins_to_activate as $i => $array) {
             if (!preg_match('|.php$|', $array[0])) {
                 unset($plugins_to_activate[$i]);
             }
         }
         // Return early if there are no plugins to activate.
         if (empty($plugins_to_activate)) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins are available to be activated at this time.', 'tgmpa'), '</p></div>';
             return false;
         }
         $plugins = array();
         $plugin_names = array();
         foreach ($plugins_to_activate as $plugin_string) {
             $plugins[] = $plugin_string[0];
             $plugin_names[] = $plugin_string[2];
         }
         $count = count($plugin_names);
         // Count so we can use _n function.
         $last_plugin = array_pop($plugin_names);
         // Pop off last name to prep for readability.
         $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.');
         // Now we are good to go - let's start activating plugins.
         $activate = activate_plugins($plugins);
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>';
         } else {
             printf('<div id="message" class="updated"><p>%1$s %2$s.</p></div>', esc_html(_n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa')), wp_kses_post($imploded));
         }
         // Update recently activated plugins option.
         $recent = (array) get_option('recently_activated');
         foreach ($plugins as $plugin => $time) {
             if (isset($recent[$plugin])) {
                 unset($recent[$plugin]);
             }
         }
         update_option('recently_activated', $recent);
         unset($_POST);
         // Reset the $_POST variable in case user wants to perform one action after another.
         return true;
     }
 }
Exemple #28
0
                 unset($plugins[$i]);
             }
         }
     } else {
         foreach ($plugins as $i => $plugin) {
             // Only activate plugins which are not already active and are not network-only when on Multisite.
             if (is_plugin_active($plugin) || is_multisite() && is_network_only_plugin($plugin)) {
                 unset($plugins[$i]);
             }
         }
     }
     if (empty($plugins)) {
         wp_redirect(self_admin_url("plugins.php?plugin_status={$status}&paged={$page}&s={$s}"));
         exit;
     }
     activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin());
     if (!is_network_admin()) {
         $recent = (array) get_option('recently_activated');
         foreach ($plugins as $plugin) {
             unset($recent[$plugin]);
         }
         update_option('recently_activated', $recent);
     }
     wp_redirect(self_admin_url("plugins.php?activate-multi=true&plugin_status={$status}&paged={$page}&s={$s}"));
     exit;
 case 'update-selected':
     check_admin_referer('bulk-plugins');
     if (isset($_GET['plugins'])) {
         $plugins = explode(',', $_GET['plugins']);
     } elseif (isset($_POST['checked'])) {
         $plugins = (array) $_POST['checked'];
 /**
  * Processes bulk installation and activation actions.
  *
  * The bulk installation process looks either for the $_POST
  * information or for the plugin info within the $_GET variable if
  * a user has to use WP_Filesystem to enter their credentials.
  *
  * @since 2.2.0
  */
 public function process_bulk_actions()
 {
     /** Bulk installation process */
     if ('tgmpa-bulk-install' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         /** Prep variables to be populated */
         $plugins_to_install = array();
         $plugin_installs = array();
         $plugin_path = array();
         $plugin_name = array();
         /** Look first to see if information has been passed via WP_Filesystem */
         if (isset($_GET[sanitize_key('plugins')])) {
             $plugins = explode(',', stripslashes($_GET[sanitize_key('plugins')]));
         } elseif (isset($_POST[sanitize_key('plugin')])) {
             $plugins = (array) $_POST[sanitize_key('plugin')];
         } else {
             $plugins = array();
         }
         $a = 0;
         // Incremental variable
         /** Grab information from $_POST if available */
         if (isset($_POST[sanitize_key('plugin')])) {
             foreach ($plugins as $plugin_data) {
                 $plugins_to_install[] = explode(',', $plugin_data);
             }
             foreach ($plugins_to_install as $plugin_data) {
                 $plugin_installs[] = $plugin_data[0];
                 $plugin_path[] = $plugin_data[1];
                 $plugin_name[] = $plugin_data[2];
             }
         } else {
             foreach ($plugins as $key => $value) {
                 /** Grab plugin slug for each plugin */
                 if (0 == $key % 3 || 0 == $key) {
                     $plugins_to_install[] = $value;
                     $plugin_installs[] = $value;
                 }
                 $a++;
             }
         }
         /** Look first to see if information has been passed via WP_Filesystem */
         if (isset($_GET[sanitize_key('plugin_paths')])) {
             $plugin_paths = explode(',', stripslashes($_GET[sanitize_key('plugin_paths')]));
         } elseif (isset($_POST[sanitize_key('plugin')])) {
             $plugin_paths = (array) $plugin_path;
         } else {
             $plugin_paths = array();
         }
         /** Look first to see if information has been passed via WP_Filesystem */
         if (isset($_GET[sanitize_key('plugin_names')])) {
             $plugin_names = explode(',', stripslashes($_GET[sanitize_key('plugin_names')]));
         } elseif (isset($_POST[sanitize_key('plugin')])) {
             $plugin_names = (array) $plugin_name;
         } else {
             $plugin_names = array();
         }
         $b = 0;
         // Incremental variable
         /** Loop through plugin slugs and remove already installed plugins from the list */
         foreach ($plugin_installs as $key => $plugin) {
             if (preg_match('|.php$|', $plugin)) {
                 unset($plugin_installs[$key]);
                 /** If the plugin path isn't in the $_GET variable, we can unset the corresponding path */
                 if (!isset($_GET[sanitize_key('plugin_paths')])) {
                     unset($plugin_paths[$b]);
                 }
                 /** If the plugin name isn't in the $_GET variable, we can unset the corresponding name */
                 if (!isset($_GET[sanitize_key('plugin_names')])) {
                     unset($plugin_names[$b]);
                 }
             }
             $b++;
         }
         /** No need to proceed further if we have no plugins to install */
         if (empty($plugin_installs)) {
             return false;
         }
         /** Reset array indexes in case we removed already installed plugins */
         $plugin_installs = array_values($plugin_installs);
         $plugin_paths = array_values($plugin_paths);
         $plugin_names = array_values($plugin_names);
         /** If we grabbed our plugin info from $_GET, we need to decode it for use */
         $plugin_installs = array_map('urldecode', $plugin_installs);
         $plugin_paths = array_map('urldecode', $plugin_paths);
         $plugin_names = array_map('urldecode', $plugin_names);
         /** Pass all necessary information via URL if WP_Filesystem is needed */
         $url = wp_nonce_url(add_query_arg(array('page' => TGM_Plugin_Activation::$instance->menu, 'tgmpa-action' => 'install-selected', 'plugins' => urlencode(implode(',', $plugins)), 'plugin_paths' => urlencode(implode(',', $plugin_paths)), 'plugin_names' => urlencode(implode(',', $plugin_names))), admin_url(TGM_Plugin_Activation::$instance->parent_url_slug)), 'bulk-plugins');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary
         $fields = array(sanitize_key('action'), sanitize_key('_wp_http_referer'), sanitize_key('_wpnonce'));
         // Extra fields to pass to WP_Filesystem
         if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
             return true;
         }
         if (!WP_Filesystem($creds)) {
             request_filesystem_credentials($url, $method, true, false, $fields);
             // Setup WP_Filesystem
             return true;
         }
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         // Need for plugins_api
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         // Need for upgrade classes
         /** Store all information in arrays since we are processing a bulk installation */
         $api = array();
         $sources = array();
         $install_path = array();
         $c = 0;
         // Incremental variable
         /** Loop through each plugin to install and try to grab information from WordPress API, if not create 'tgmpa-empty' scalar */
         foreach ($plugin_installs as $plugin) {
             $api[$c] = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) ? plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) : (object) ($api[$c] = 'tgmpa-empty');
             $c++;
         }
         if (is_wp_error($api)) {
             wp_die(TGM_Plugin_Activation::$instance->strings['oops'] . var_dump($api));
         }
         $d = 0;
         // Incremental variable
         /** Capture download links from $api or set install link to pre-packaged/private repo */
         foreach ($api as $object) {
             $sources[$d] = isset($object->download_link) && 'repo' == $plugin_paths[$d] ? $object->download_link : $plugin_paths[$d];
             $d++;
         }
         /** Finally, all the data is prepared to be sent to the installer */
         $url = add_query_arg(array('page' => TGM_Plugin_Activation::$instance->menu), admin_url(TGM_Plugin_Activation::$instance->parent_url_slug));
         $nonce = 'bulk-plugins';
         $names = $plugin_names;
         /** Create a new instance of TGM_Bulk_Installer */
         $installer = new TGM_Bulk_Installer($skin = new TGM_Bulk_Installer_Skin(compact('url', 'nonce', 'names')));
         /** Wrap the install process with the appropriate HTML */
         echo '<div class="tgmpa wrap">';
         screen_icon(apply_filters('tgmpa_default_screen_icon', 'themes'));
         echo '<h2>' . esc_html(get_admin_page_title()) . '</h2>';
         /** Process the bulk installation submissions */
         $installer->bulk_install($sources);
         echo '</div>';
         return true;
     }
     /** Bulk activation process */
     if ('tgmpa-bulk-activate' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         /** Grab plugin data from $_POST */
         $plugins = isset($_POST[sanitize_key('plugin')]) ? (array) $_POST[sanitize_key('plugin')] : array();
         $plugins_to_activate = array();
         /** Split plugin value into array with plugin file path, plugin source and plugin name */
         foreach ($plugins as $i => $plugin) {
             $plugins_to_activate[] = explode(',', $plugin);
         }
         foreach ($plugins_to_activate as $i => $array) {
             if (!preg_match('|.php$|', $array[0])) {
                 // Plugins that haven't been installed yet won't have the correct file path
                 unset($plugins_to_activate[$i]);
             }
         }
         /** Return early if there are no plugins to activate */
         if (empty($plugins_to_activate)) {
             return;
         }
         $plugins = array();
         $plugin_names = array();
         foreach ($plugins_to_activate as $plugin_string) {
             $plugins[] = $plugin_string[0];
             $plugin_names[] = $plugin_string[2];
         }
         $count = count($plugin_names);
         // Count so we can use _n function
         $last_plugin = array_pop($plugin_names);
         // Pop off last name to prep for readability
         $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.');
         /** Now we are good to go - let's start activating plugins */
         $activate = activate_plugins($plugins);
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
         } else {
             printf('<div id="message" class="updated"><p>%1$s %2$s</p></div>', _n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, TGM_Plugin_Activation::$instance->domain), $imploded);
         }
         /** Update recently activated plugins option */
         $recent = (array) get_option('recently_activated');
         foreach ($plugins as $plugin => $time) {
             if (isset($recent[$plugin])) {
                 unset($recent[$plugin]);
             }
         }
         update_option('recently_activated', $recent);
         unset($_POST);
         // Reset the $_POST variable in case user wants to perform one action after another
     }
 }
Exemple #30
-3
function update_primary_shareaholic_plugin_file()
{
    if (is_plugin_active('shareaholic/sexy-bookmarks.php')) {
        deactivate_plugins('shareaholic/sexy-bookmarks.php');
        activate_plugins('shareaholic/shareaholic.php');
    }
}