Giter Site home page Giter Site logo

obiplabon / tws-admin-onboarding Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thewebsolver/tws-admin-onboarding

1.0 1.0 0.0 464 KB

WordPress Admin Onboarding Wizard helps plugins to start onboarding wizard after activation. Check file tws-admin-onboarding.php and start your plugin's onboarding.

License: GNU General Public License v3.0

CSS 12.14% JavaScript 6.68% PHP 81.18%

tws-admin-onboarding's Introduction

GPL License

Donate Link: https://paypal.me/gg1008

WordPress Admin Onboarding Wizard

CREATE WORDPRESS ADMIN ONBOARDING WIZARD -|- INSTALL DEPENDENCY/RECOMMENDED PLUGINS

This plugin is a framework meant for creating onboarding wizard for any plugins.
(For testing purpose, this can be installed as a plugin itself)

Installation (via Composer)

To install this plugin, edit your composer.json file:

"require": {
	"thewebsolver/tws-admin-onboarding": "dev-master"
}

Then from terminal, run:

$ composer install

Example Code

File tws-admin-onboarding.php contains all the codes to start onboarding on plugin activation. Mainly check My_Plugin\My_Feature\Onboarding::activate method on how to redirect to onboarding after plugin activation.

Below is the extract of this file. You must use below codes in your own plugin file and delete the tws-admin-onboarding.php file.

In brief, you must:

  • set your own plugin's prefix,
  • declare your own plugin's namespace in files Config.php and Wizard.php,
  • set your own step contents in Wizard.php, and
  • check @todo tags across all files and make appropriate changes.

NOTE: Before plugin activation

Must make changes to namespace and prefix. If no changes are made to namespace and prefix, WordPress dies with appropriate message.


<?php // file tws-admin-onboarding.php

/**
 * Onboarding namespace.
 *
 * @todo MUST REPLACE AND USE OWN NAMESPACE.
 */
namespace My_Plugin\My_Feature;

/**
 * Boilerplate plugin for The Web Solver WordPress Admin Onboarding Wizard.
 */
final class Onboarding {
	/**
	 * Onboarding wizard prefix.
	 *
	 * @var string
	 * @todo Prefix for onboarding wizard. DO NOT CHANGE IT ONCE SET.\
	 *       It will be used for WordPress Hooks, Options, Transients, etc.\
	 *       MUST BE A UNIQUE PREFIX FOR YOUR PLUGIN.
	 */
	public $prefix = 'thewebsolver';

	/**
	 * Onboarding Wizard Config.
	 *
	 * @var Config
	 */
	public $config;

	/**
	 * Starts Onboarding.
	 *
	 * @return Onboarding
	 */
	public static function start() {
		static $onboarding;
		if ( ! is_a( $onboarding, get_class() ) ) {
			$onboarding = new self();
		}
		return $onboarding;
	}

	/**
	 * Private constructor to prevent direct instantiation.
	 */
	private function __construct() {
		$this->config();
		register_activation_hook( __FILE__, array( $this, 'activate' ) );
		register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );

		/**
		 * If all onboarding steps are not completed, show admin notice.
		 *
		 * At last step of onboarding, $status => 'complete'.
		 *
		 * @var string
		 *
		 * @todo Need to perform additional checks before showing notice
		 *       Such as show notice on plugins, themes and dashboard pages only.
		 */
		$status = get_option( $this->prefix . '_onboarding_steps_status' );
		if ( 'pending' === $status ) {
			add_action( 'admin_notices', array( $this, 'onboarding_notice' ) );
		}
	}

	/**
	 * Instantiates onboarding config.
	 */
	private function config() {
		// Onboarding config file path.
		include_once __DIR__ . '/Config.php';
		$config = array( '\\' . __NAMESPACE__ . '\\Config', 'get' );

		// Only call config if it is on the same namespace.
		if ( is_callable( $config ) ) {
			$this->config = call_user_func( $config, $this->prefix );
		}
	}

	/**
	 * Sets onboarding notice if not completed.
	 */
	public function onboarding_notice() {
		$msg = sprintf(
			'<p><b>%1$s</b> - %2$s.</p><p><a href="%3$s" class="button-primary">%4$s</a></p>',
			__( 'Namaste! from The Web Solver Onboarding Wizard', 'tws-onboarding' ),
			__( 'Let us help you quickly setup the plugin with our onboarding wizard', 'tws-onboarding' ),
			admin_url( 'admin.php?page=' . $this->config->get_page() ),
			__( 'Run the Wizard Now', 'tws-onboarding' )
		);

		echo '<div class="notice notice-info">' . wp_kses_post( $msg ) . '</div>';
	}

	/**
	 * Performs task on plugin activation.
	 *
	 * @todo Configured with example codes. Make changes as needed.
	 */
	public function activate() {
		// Check if plugin is already installed.
		$old_install = get_option( $this->prefix . '_install_version', false );

		if ( ! $old_install ) {
			// if new install => enable onboarding.
			$check[] = 'true';

			// Set the plugin install version to "1.0".
			update_option( $this->prefix . '_install_version', '1.0' );
		} else {
			// There is now installed version "1.0" => disable onboarding.
			$check[] = 'false';
		}

		// If PHP version less than or equal to "7.0" => disable onboarding.
		if ( version_compare( phpversion(), '7.0', '<=' ) ) {
			$check[] = 'false';
		}

		// Now onboarding will run on the basis of check parameter passed.
		// If this is first activation or PHP > 7.0 => redirect to onboarding page.
		// Lets also verify if config has been instantiated.
		if ( is_object( $this->config ) ) {
			$this->config->enable_onboarding( $check );
		}
	}

	/**
	 * Performs task on plugin deactivation.
	 *
	 * @todo Configured to delete onboarding options on plugin deactivation.\
	 *       Cane be safely deleted for production.
	 */
	public function deactivate() {
		// Onboarding options.
		delete_option( $this->prefix . '_onboarding_steps_status' );
		delete_option( $this->prefix . '_onboarding_dependency_status' );
		delete_option( $this->prefix . '_onboarding_dependency_name' );
		delete_option( $this->prefix . '_install_version' );

		// Onboarding transitents.
		delete_transient( $this->prefix . '_onboarding_redirect' );
	}
}

Onboarding::start();

Screenshots

Introduction, Recommended and Ready steps are default steps and are created from onboarding abstract class file.

Other steps added from the wizard file.

Introduction

Intro Step

Introduction (after install)

Intro post install

Text/Checkbox Fields

Text/Checkbox Step

Radio/Select Fields

Radio/Select Step

Recommended

Recommended Step

Ready

Ready Step

Contact

----------------------------------
DEVELOPED-MAINTAINED-SUPPPORTED BY
----------------------------------
███║     ███╗   ████████████████
███║     ███║   ═════════██████╗
███║     ███║        ╔══█████═╝
 ████████████║      ╚═█████
███║═════███║      █████╗
███║     ███║    █████═╝
███║     ███║   ████████████████╗
╚═╝      ╚═╝    ═══════════════╝

Shesh Ghimire - @hsehszroc

tws-admin-onboarding's People

Stargazers

Mahmudul Hasan Mukul avatar

Watchers

 avatar

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.