Install plugin with current logged WP user info.

@author Vova Feldman (@svovaf)
@since  1.0.7
542627
function _install_with_current_user() {
            $this->_logger->entrance();

            if ( $this->is_registered() ) {
                return;
            }

            if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
//				check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );

                /**
                 * @author Vova Feldman (@svovaf)
                 * @since  1.1.9 Add license key if given.
                 */
                $license_key = fs_request_get( 'license_secret_key' );

                $this->install_with_current_user( $license_key );
            }
        }
1057969
function(data) {
            if (data.active) {
                bs.pluginManager.enablePlugin(data.name);
            } else {
                bs.pluginManager.disablePlugin(data.name);
            }
            bs.setOption("userPlugins", bs.getUserPlugins());
        }
84441
private function addPluginInDB()
    {
        $configContent = Plugin::config($this->pluginNamespace);

        $plugin = new Plugin();
        $plugin->title = $configContent->title;
        $plugin->namespace = $configContent->namespace;
        $plugin->organization = $configContent->organization;
        $plugin->version = $configContent->version;
        $plugin->isActive = 1;
        return $plugin->save();
    }
540336
public function action_init() {
		load_plugin_textdomain( 'user-switching', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

		if ( ! isset( $_REQUEST['action'] ) ) {
			return;
		}

		$current_user = ( is_user_logged_in() ) ? wp_get_current_user() : null;

		switch ( $_REQUEST['action'] ) {

			// We're attempting to switch to another user:
			case 'switch_to_user':
				if ( isset( $_REQUEST['user_id'] ) ) {
					$user_id = absint( $_REQUEST['user_id'] );
				} else {
					$user_id = 0;
				}

				// Check authentication:
				if ( ! current_user_can( 'switch_to_user', $user_id ) ) {
					wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
				}

				// Check intent:
				check_admin_referer( "switch_to_user_{$user_id}" );

				// Switch user:
				$user = switch_to_user( $user_id, self::remember() );
				if ( $user ) {
					$redirect_to = self::get_redirect( $user, $current_user );

					// Redirect to the dashboard or the home URL depending on capabilities:
					$args = array(
						'user_switched' => 'true',
					);

					if ( $redirect_to ) {
						wp_safe_redirect( add_query_arg( $args, $redirect_to ), 302, self::$application );
					} elseif ( ! current_user_can( 'read' ) ) {
						wp_safe_redirect( add_query_arg( $args, home_url() ), 302, self::$application );
					} else {
						wp_safe_redirect( add_query_arg( $args, admin_url() ), 302, self::$application );
					}
					exit;
				} else {
					wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
				}
				break;

			// We're attempting to switch back to the originating user:
			case 'switch_to_olduser':
				// Fetch the originating user data:
				$old_user = self::get_old_user();
				if ( ! $old_user ) {
					wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
				}

				// Check authentication:
				if ( ! self::authenticate_old_user( $old_user ) ) {
					wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
				}

				// Check intent:
				check_admin_referer( "switch_to_olduser_{$old_user->ID}" );

				// Switch user:
				if ( switch_to_user( $old_user->ID, self::remember(), false ) ) {

					if ( ! empty( $_REQUEST['interim-login'] ) ) {
						$GLOBALS['interim_login'] = 'success'; // @codingStandardsIgnoreLine
						login_header( '', '' );
						exit;
					}

					$redirect_to = self::get_redirect( $old_user, $current_user );
					$args        = array(
						'user_switched' => 'true',
						'switched_back' => 'true',
					);

					if ( $redirect_to ) {
						wp_safe_redirect( add_query_arg( $args, $redirect_to ), 302, self::$application );
					} else {
						wp_safe_redirect( add_query_arg( $args, admin_url( 'users.php' ) ), 302, self::$application );
					}
					exit;
				} else {
					wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
				}
				break;

			// We're attempting to switch off the current user:
			case 'switch_off':
				// Check authentication:
				if ( ! current_user_can( 'switch_off' ) ) {
					/* Translators: "switch off" means to temporarily log out */
					wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
				}

				// Check intent:
				check_admin_referer( "switch_off_{$current_user->ID}" );

				// Switch off:
				if ( switch_off_user() ) {
					$redirect_to = self::get_redirect( null, $current_user );
					$args        = array(
						'switched_off' => 'true',
					);

					if ( $redirect_to ) {
						wp_safe_redirect( add_query_arg( $args, $redirect_to ), 302, self::$application );
					} else {
						wp_safe_redirect( add_query_arg( $args, home_url() ), 302, self::$application );
					}
					exit;
				} else {
					/* Translators: "switch off" means to temporarily log out */
					wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
				}
				break;

		}
	}
584184
function get_install_by_blog_id( $blog_id = null ) {
            $installs = self::get_all_sites( $this->_module_type, $blog_id );
            $install  = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;

            if ( is_object( $install ) &&
                 is_numeric( $install->id ) &&
                 is_numeric( $install->user_id ) &&
                 FS_Plugin_Plan::is_valid_id( $install->plan_id )
            ) {
                // Load site.
                $install = clone $install;
            }

            return $install;
        }
406247
function _activate_plugin_event_hook() {
            $this->_logger->entrance( 'slug = ' . $this->_slug );

            if ( ! $this->is_user_admin() ) {
                return;
            }

            $this->unregister_uninstall_hook();

            // Clear API cache on activation.
            FS_Api::clear_cache();

            $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );

            $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );

            // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
            // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
            $other_version_basename = $is_premium_version_activation ?
                $this->_free_plugin_basename :
                $this->premium_plugin_basename();

            if ( ! $this->_is_network_active ) {
                /**
                 * During the activation, the plugin isn't yet active, therefore,
                 * _is_network_active will be set to false even if it's a network level
                 * activation. So we need to fix that by looking at the is_network_admin() value.
                 *
                 * @author Vova Feldman
                 */
                $this->_is_network_active = (
                    $this->_is_multisite_integrated &&
                    // Themes are always network activated, but the ACTUAL activation is per site.
                    $this->is_plugin() &&
                    fs_is_network_admin()
                );
            }

            /**
             * If the other module version is activate, deactivate it.
             *
             * is_plugin_active() checks if the plugin active on the site or the network level
             * and deactivate_plugins() deactivates the plugin whether its activated on the site
             * or network level.
             *
             * @author Leo Fajardo (@leorw)
             * @since  1.2.2
             */
            if ( is_plugin_active( $other_version_basename ) ) {
                deactivate_plugins( $other_version_basename );
            }

            if ( $this->is_registered() ) {
                if ( $is_premium_version_activation ) {
                    $this->reconnect_locally();
                }


                // Schedule re-activation event and sync.
//				$this->sync_install( array(), true );
                $this->schedule_install_sync();

                // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
                if ( $is_premium_version_activation ) {
                    $this->_admin_notices->add(
                        sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
                        $this->get_text_x_inline( 'W00t',
                            'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
                    );
                }
            } else if ( $this->is_anonymous() ) {
                if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
                    $plugin_version = $this->_storage->is_anonymous_ms['version'];
                    $network        = true;
                } else {
                    $plugin_version = $this->_storage->is_anonymous['version'];
                    $network        = false;
                }

                /**
                 * Reset "skipped" click cache on the following:
                 *  1. Freemius DEV mode.
                 *  2. WordPress DEBUG mode.
                 *  3. If a plugin and the user skipped the exact same version before.
                 *
                 * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
                 *
                 * @todo  4. If explicitly asked to retry after every activation.
                 */
                if ( WP_FS__DEV_MODE ||
                     (
                         ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
                         $this->get_plugin_version() == $plugin_version
                     )
                ) {
                    $this->reset_anonymous_mode( $network );
                }
            }

            if (
                $is_premium_version_activation &&
                (
                    ( ! $this->is_registered() && $this->is_anonymous() ) ||
                    (
                        $this->is_registered() &&
                        ! $this->is_trial() &&
                        ! $this->has_features_enabled_license()
                    )
                )
            ) {
                $this->_storage->require_license_activation = true;
            }

            if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
                /**
                 * If no previous version of plugin's version exist, it means that it's either
                 * the first time that the plugin installed on the site, or the plugin was installed
                 * before but didn't have Freemius integrated.
                 *
                 * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
                 * on manual activation via the dashboard, is_plugin_activation() is TRUE
                 * only after immediate activation.
                 *
                 * @since 1.1.4
                 * @link  https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
                 */
                $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
            }

            if ( ! $this->_anonymous_mode &&
                 $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
                 ! $this->_isAutoInstall
            ) {
                // Store hint that the plugin was just activated to enable auto-redirection to settings.
                set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
            }

            /**
             * Activation hook is executed after the plugin's main file is loaded, therefore,
             * after the plugin was loaded. The logic is located at activate_plugin()
             * ./wp-admin/includes/plugin.php.
             *
             * @author Vova Feldman (@svovaf)
             * @since  1.1.9
             */
            $this->_storage->was_plugin_loaded = true;
        }
305776
protected function loadPluginInfo()
    {
        $this->pluginInfo = array();
        foreach ($this->files as $fileInfo) {
            if ($fileInfo instanceof \SplFileInfo) {
                if ($fileInfo->isFile() && $fileInfo->getExtension() == 'php') {
                    $this->addPluginFromFile($fileInfo);
                }
            }
        }
    }
711623
final function finalOnPluginsLoaded()
  {
    // setup easy to access git revision number
    if (file_exists($revFilePath = ABSPATH.'../../.rev')) {
      $rev = array_map('trim', explode(' ', file_get_contents($revFilePath)));
      $this->config->set('.rev', $rev[0]);
    } else {
      $this->config->set('.rev', 'dev');
    }

    // if we don't have the get_plugin_data() function, load it
    if (!function_exists('get_plugin_data')) {
      require_once ABSPATH.'wp-admin/includes/plugin.php';
    }

    $this->pluginData = get_plugin_data($this->mainFile);

    foreach($this->pluginData as $key => $value) {
      $propertyName = Str::camel($key);
      $this->bind($propertyName, function() use ($value) {
        return $value;
      });
    }

    $this->loadTextDomain();

    // TODO: check to see if routes.php file is empty or not, and
    // then only do this extra initialization if it has routes in it
    $this->make('router');
  }
586294
function Plugin () {
  var seneca = this

  seneca.add('role:admin,cmd:home', (msg, done) => {
    done(null, {ok: true, message: 'please log in...'})
  })

  seneca.add('role:admin,cmd:logout', (msg, done) => {
    msg.request$.logout()

    done(null, {ok: true})
  })

  seneca.add('role:admin,cmd:profile', (msg, done) => {
    done(null, {ok: true, user: msg.args.user})
  })
}
268995
static function plugins()
    {
        if (! self::isEnabledPlugins() )
            throw new \Exception('Using Plugins depends on Poirot/Ioc; that not exists currently.');


        if (! self::$pluginManager )
            self::$pluginManager = new PluginsHttpHeader;

        return self::$pluginManager;
    }
1044769
function _account_page_load() {
            $this->_logger->entrance();

            $this->_logger->info( var_export( $_REQUEST, true ) );

            fs_enqueue_local_style( 'fs_account', '/admin/account.css' );

            if ( $this->has_addons() ) {
                wp_enqueue_script( 'plugin-install' );
                add_thickbox();

                function fs_addons_body_class( $classes ) {
                    $classes .= ' plugins-php';

                    return $classes;
                }

                add_filter( 'admin_body_class', 'fs_addons_body_class' );
            }

            if ( $this->has_paid_plan() &&
                 ! $this->has_any_license() &&
                 ! $this->is_sync_executed() &&
                 $this->is_tracking_allowed()
            ) {
                /**
                 * If no licenses found and no sync job was executed during the last 24 hours,
                 * just execute the sync job right away (blocking execution).
                 *
                 * @since 1.1.7.3
                 */
                $this->run_manual_sync();
            }

            $this->_handle_account_edits();

            $this->do_action( 'account_page_load_before_departure' );
        }
1170412
public function setupTinymcePlugin()
    {
        if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
            return;
        }

        // Check if the logged in WordPress User has the Visual Editor enabled
        // If not, don't register our TinyMCE plugin
        if (get_user_option('rich_editing') !== 'true') {
            return;
        }

        $this->init();

        if (!$this->pluginSlug || !$this->pluginSlug) {
            return;
        }

        //Change button row placement if buttonRow is defined
        if (isset($this->buttonRow) && is_numeric($this->buttonRow) && $this->buttonRow > 1) {
            $this->buttonFilter .= '_' . $this->buttonRow;
        }

        //LocalizeData (if any)
        if (is_array($this->data) && !empty($this->data)) {
            add_action('admin_head', array($this, 'localizeScript'));
        }

        add_filter('mce_external_plugins', array($this, 'addTinyMcePlugin'));
        add_filter($this->buttonFilter, array($this, 'addTinymceToolbarButton' ));
    }
536694
protected function loadPluginInfo()
    {
        if ($this->pluginInfo !== null) {
            return;
        }
        $this->pluginInfo = array();
        foreach ($this->composerPackages as $package) {
            $this->addPluginsFromPackage($package);
        }
    }
470879
public function init()
    {
        // Works only on frontend site
        if (OL_ZEUS_ISADMIN) {
            return;
        }

        // Check filepath
        if (empty($this->filepath)) {
            return;
        }

        // Get configurations
        $configs = include $this->filepath;

        // Check
        if (empty($configs) || in_array($GLOBALS['pagenow'], ['wp-login.php'])) {
            return;
        }

        // Enqueue scripts and styles
        add_action('wp_enqueue_scripts', function () use ($configs) {
            // Iterate on configs
            foreach ($configs as $key => $props) {
                $props = !is_array($props) && !is_bool($props) ? [$props] : $props;

                if ('scripts' === $key) {
                    // Enqueue scripts
                    $this->enqueueScripts($props);
                } else if ('styles' === $key) {
                    // Enqueue styles
                    $this->enqueueStyles($props);
                }
            }
        });
    }
543751
public function action_plugins_loaded() {
		// User Switching's auth_cookie
		if ( ! defined( 'USER_SWITCHING_COOKIE' ) ) {
			define( 'USER_SWITCHING_COOKIE', 'wordpress_user_sw_' . COOKIEHASH );
		}

		// User Switching's secure_auth_cookie
		if ( ! defined( 'USER_SWITCHING_SECURE_COOKIE' ) ) {
			define( 'USER_SWITCHING_SECURE_COOKIE', 'wordpress_user_sw_secure_' . COOKIEHASH );
		}

		// User Switching's logged_in_cookie
		if ( ! defined( 'USER_SWITCHING_OLDUSER_COOKIE' ) ) {
			define( 'USER_SWITCHING_OLDUSER_COOKIE', 'wordpress_user_sw_olduser_' . COOKIEHASH );
		}
	}
1003489
public function activate()
    {
        $muPluginDir = WP_CONTENT_DIR . '/mu-plugins';

        if (!is_dir($muPluginDir)) {
            wp_mkdir_p($muPluginDir);
        }

        if (!is_dir($this->destination)) {
            wp_mkdir_p($this->destination);
        }

        $data = "<?php\n"
              . "/*\n"
              . "Plugin Name: StaticWP MU\n"
              . "Description: Converts your blog into a static site. This part of StaticWP"
                          . " allows StaticWP to bypass as much Wordpress as possible.\n"
              . "Author: Shane Logsdon\n"
              . 'Version: ' . STATICWP_VERSION . "\n"
              . "Author URI: http://www.slogsdon.com/\n"
              . "License: MIT\n"
              . "*/\n"
              . "\n"
              . "require_once '" . plugin_dir_path($this->file) . $this->plugin . ".php';\n";
        file_put_contents($muPluginDir . '/' . $this->plugin . '-mu.php', $data);

        // Can't use View::page :(
        $notice = 'Thanks for installing StaticWP! Might we suggest <a href="'
                . self::url('preload')
                . '">preloading your site</a>?';
        $this->addNotice($notice);
    }
1071758
private function get_gdpr_admin_notice_string( $user_plugins ) {
            $this->_logger->entrance();

            $addons = self::get_all_addons();

            foreach ( $user_plugins as $user_plugin ) {
                $has_addons = isset( $addons[ $user_plugin->id ] );

                if ( WP_FS__MODULE_TYPE_PLUGIN === $user_plugin->type && ! $has_addons ) {
                    if ( $this->_module_id == $user_plugin->id ) {
                        $addons     = $this->get_addons();
                        $has_addons = ( ! empty( $addons ) );
                    } else {
                        $plugin_api = FS_Api::instance(
                            $user_plugin->id,
                            'plugin',
                            $user_plugin->id,
                            $user_plugin->public_key,
                            ! $user_plugin->is_live
                        );

                        $addons_result = $plugin_api->get( '/addons.json?enriched=true', true );

                        if ( $this->is_api_result_object( $addons_result, 'plugins' ) &&
                             is_array( $addons_result->plugins ) &&
                             ! empty( $addons_result->plugins )
                        ) {
                            $has_addons = true;
                        }
                    }
                }

                $user_plugin->has_addons = $has_addons;
            }

            $is_single_parent_product = ( 1 === count( $user_plugins ) );

            $multiple_products_text = '';

            if ( $is_single_parent_product ) {
                $single_parent_product = reset( $user_plugins );

                $thank_you = sprintf(
                    "<span data-plugin-id='%d'>%s</span>",
                    $single_parent_product->id,
                    sprintf(
                        $single_parent_product->has_addons ?
                            $this->get_text_inline( 'Thank you so much for using %s and its add-ons!', 'thank-you-for-using-product-and-its-addons' ) :
                            $this->get_text_inline( 'Thank you so much for using %s!', 'thank-you-for-using-product' ),
                        sprintf('<b><i>%s</i></b>', $single_parent_product->title)
                    )
                );

                $already_opted_in = sprintf(
                    $this->get_text_inline( "You've already opted-in to our usage-tracking, which helps us keep improving the %s.", 'already-opted-in-to-product-usage-tracking' ),
                    ( WP_FS__MODULE_TYPE_THEME === $single_parent_product->type ) ? WP_FS__MODULE_TYPE_THEME : WP_FS__MODULE_TYPE_PLUGIN
                );
            } else {
                $thank_you        = $this->get_text_inline( 'Thank you so much for using our products!', 'thank-you-for-using-products' );
                $already_opted_in = $this->get_text_inline( "You've already opted-in to our usage-tracking, which helps us keep improving them.", 'already-opted-in-to-products-usage-tracking' );

                $products_and_add_ons = '';
                foreach ( $user_plugins as $user_plugin ) {
                    if ( ! empty( $products_and_add_ons ) ) {
                        $products_and_add_ons .= ', ';
                    }

                    if ( ! $user_plugin->has_addons ) {
                        $products_and_add_ons .= sprintf(
                            "<span data-plugin-id='%d'>%s</span>",
                            $user_plugin->id,
                            $user_plugin->title
                        );
                    } else {
                        $products_and_add_ons .= sprintf(
                            "<span data-plugin-id='%d'>%s</span>",
                            $user_plugin->id,
                            sprintf(
                                $this->get_text_inline( '%s and its add-ons', 'product-and-its-addons' ),
                                $user_plugin->title
                            )
                        );
                    }
                }

                $multiple_products_text = sprintf(
                    "<small class='products'><strong>%s:</strong> %s</small>",
                    $this->get_text_inline( 'Products', 'products' ),
                    $products_and_add_ons
                );
            }

            $actions = sprintf(
                '<ul><li>%s<span class="action-description"> - %s</span></li><li>%s<span class="action-description"> - %s</span></li></ul>',
                sprintf('<button class="button button-primary allow-marketing">%s</button>', $this->get_text_inline( 'Yes', 'yes' ) ),
                $this->get_text_inline( 'send me security & feature updates, educational content and offers.', 'send-updates' ),
                sprintf('<button class="button button-secondary">%s</button>', $this->get_text_inline( 'No', 'no' ) ),
                sprintf(
                    $this->get_text_inline( 'do %sNOT%s send me security & feature updates, educational content and offers.', 'do-not-send-updates' ),
                    '<span class="underlined">',
                    '</span>'
                )
            );

            return sprintf(
                '%s %s %s',
                $thank_you,
                $already_opted_in,
                sprintf($this->get_text_inline( 'Due to the new %sEU General Data Protection Regulation (GDPR)%s compliance requirements it is required that you provide your explicit consent, again, confirming that you are onboard 🙂', 'due-to-gdpr-compliance-requirements' ), '<a href="https://eugdpr.org/" target="_blank" rel="noopener noreferrer">', '</a>') .
                '<br><br>' .
                '<b>' . $this->get_text_inline( "Please let us know if you'd like us to contact you for security & feature updates, educational content, and occasional offers:", 'contact-for-updates' ) . '</b>' .
                $actions .
                ( $is_single_parent_product ? '' : $multiple_products_text )
            );
        }