Giter Site home page Giter Site logo

samuelaguilera / sar-update-gravity-forms-license-networkwide Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 10 KB

Update the license key in all sites of a WordPress multisite network with only one click.

License: GNU Lesser General Public License v3.0

PHP 100.00%

sar-update-gravity-forms-license-networkwide's Introduction

Description

The purpose of this tool is to allow you to update the license key in all sites of a WordPress multisite network with only one click. It will save the key, remove the UNLICENSED COPY message (if the key used is valid), and validate the key in the Gravity Forms settings page of each site with it activated. To do it read the instructions below.

It is recommended to enable Logging in Forms -> Settings for Gravity Forms core before using this tool.

If you have a lot of sites in your network it could take a while, be patient and DO NOT close the browser before time, also DO NOT click the button more than once, BE PATIENT!, a notice indicating the process was successful will be shown at the top of the page, just wait for it.

Installation

  1. Download the plugin zip file.
  2. Go to Network Admin -> Plugins page and click the Add New button.
  3. Click the Upload Plugin button to upload and then enable it.

Usage

  1. Make sure you have GF_LICENSE_KEY set in your wp-config.php file.
  2. Gravity Forms and this add-on must be enabled network-wide.
  3. Go to Network Admin -> Dashboard.
  4. Click on the Update GF License submenu.
  5. Follow instructions displayed in the page.

sar-update-gravity-forms-license-networkwide's People

Contributors

samuelaguilera avatar

Stargazers

 avatar Joshua Vandercar avatar Fede Isas avatar

Watchers

James Cloos avatar  avatar

Forkers

almostdaniel

sar-update-gravity-forms-license-networkwide's Issues

Enhancement: wp-cli script

Thanks for this add-on. I made a little wp-cli script based on your code, and it solve my issue. In case it can help anyone else, here's what I did.

<?php
/**
 * fix.php
 */

// Get all the sites.
$sites = get_sites( array( 'fields' => 'ids', 'number' => 0 ) );
foreach ( $sites as $site_id ) {
    switch_to_blog( $site_id );
    $msg = get_option( 'rg_gforms_message', '' );
    // Only if we detect the string "unlicensed" in the message will we run the code.
    if ( false !== stripos( $msg, 'unlicensed' ) ) {
        echo 'Fixing ' . get_bloginfo( 'url' ) . '...';
        RGFormsModel::save_key( GF_LICENSE_KEY ); // Save the key.
        GFCommon::cache_remote_message(); // Remove the UNLICENSED COPY message once we have the valid key saved.
        GFCommon::get_version_info( false ); // Update key validaton in Forms -> Settings page.
        echo "done.\n";
    }
    restore_current_blog();
}

Usage: wp eval-file fix.php

only updates the license for 100 sites

Not all my sites were being updated.

I did some hunting and discovered that the get_sites() function defaults to returning 100 sites. The number of sites returned is controlled by the 'number' argument. Setting this argument to '0' will retrieve all sites in a network.

Here's the line of code in question:

$blog_ids = get_sites( array( 'fields' => 'ids' ) ); // Return only blog_id for each site of the network

I modified my code to the following and I was able to update all 300+ sites in my network:

$blog_ids = get_sites( array( 'fields' => 'ids', 'number' => '0' ) ); // Return only blog_id for each site of the network

I'll try to put together a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.