Giter Site home page Giter Site logo

dtbaker / envato-wp-theme-setup-wizard Goto Github PK

View Code? Open in Web Editor NEW
203.0 22.0 67.0 391 KB

A step by step setup wizard that runs after a ThemeForest theme has been activated.

License: GNU General Public License v2.0

PHP 75.45% CSS 5.97% JavaScript 18.57% Hack 0.01%

envato-wp-theme-setup-wizard's Introduction

Envato WordPress Theme Setup Wizard

A step by step setup wizard that runs after a ThemeForest theme has been activated.

Video Demo:

Best to watch this video demo to see exactly what this plugin does: ScreenShot

Setup Instructions

  • Copy the api folder onto your web server ( e.g. yoursite.com/envato/api/ ) - it's best if this is hosted on SSL
  • This API folder will handle oAuth login for automatic theme updates in the (new) Envato Market plugin.
  • Register a new App at http://build.envato.com ( tick the "Download the users purchased items", and "View the users purchases of the app creators items" permissions). Put in the full URL to server-script.php as the confirmation URL.
  • At the top of api/server-script.php fill in the values from your Envato app and the full URL to server-script.php :
define('_ENVATO_APP_ID','put-your-envato-app-id-here');
define('_ENVATO_APP_SECRET','put-your-envato-app-secret-here');
define('_ENVATO_APP_URL','http://yoursite.com/envato/api/server-script.php');
  • Copy the envato_setup folder into your private $envato_usernameheme folder.
  • In your theme's functions.php set your Envato username and the full url to your server-script.php file via filters:,
// Please don't forgot to change filters tag.
// It must start from your theme's name.
add_filter('twentyfifteen_theme_setup_wizard_username', 'twentyfifteen_set_theme_setup_wizard_username', 10);
if( ! function_exists('twentyfifteen_set_theme_setup_wizard_username') ){
    function twentyfifteen_set_theme_setup_wizard_username($username){
        return 'dtbaker';
    }
}

add_filter('twentyfifteen_theme_setup_wizard_oauth_script', 'twentyfifteen_set_theme_setup_wizard_oauth_script', 10);
if( ! function_exists('twentyfifteen_set_theme_setup_wizard_oauth_script') ){
    function twentyfifteen_set_theme_setup_wizard_oauth_script($oauth_url){
        return 'http://yoursite.com/envato/api/server-script.php';
    }
}
  • Make sure TGMPA is enabled, configured and working correctly in your theme ( see http://tgmpluginactivation.com/ ). This wizard integrates with the latest version of TGM to find which plugins needs to be installed.
  • Make sure the Envato Market plugin is added to the required plugin list in TGM, it can be added like this:
        array(
            'name' => 'Envato Market',
            'slug' => 'envato-market',
            'source' => 'https://envato.github.io/wp-envato-market/dist/envato-market.zip',
            'required' => true,
            'recommended' => true,
            'force_activation' => true,
        ),
  • envato_setup/js/envato-setup.js is the script which handles the "Loading Button" animation (pretty simple and cool hey?) along with processing the ajax requests for each default installation action.
  • The ajax requests happen in two queries. The first ajax query from javascript will get the "Loading" text to display (e.g. "Installing Pages") along with the URL and data to perform the actual ajax task. Javascript then executes the second ajax task to actually perform the action. And then a third ajax request to confirm it worked.
  • envato_setup/content/ contains the default content that will be loaded during the wizard. e.g. envato_setup/content/default.json contains all posts and custom post types.
  • If you add &export=true to the URL of the first page setup wizard it will output the required json data into the envato_setup/content/ folder, it will also put media files into a local images/stock/ folder.
  • If you're looking to change what meta fields get exported have a look here: https://github.com/dtbaker/envato-wp-theme-setup-wizard/blob/master/envato_setup/envato-setup-export.php#L54
  • If you need to replace post ids, urls or shortcode content that is stored in a post meta field, look at the _elementor_id_import function here: https://github.com/dtbaker/envato-wp-theme-setup-wizard/blob/master/envato_setup/envato_setup.php#L1890
  • The _parse_gallery_shortcode_content function is what replaces URL's, gallery shortcode id's and contact-form-7 id's. This function is run on some meta fields as well (e.g. Elementor can store shortcodes and section content in meta fields, need to replace content in here)

Site Styles

ScreenShot

You can setup multiple styles for your site. This lets you export different content/images/options/posts/etc.. and the user can pick which one they want during the setup wizard.

The installer reads the dtbwp_site_style theme mod value like this:

get_theme_mod( 'dtbwp_site_style', $this->get_default_theme_style() );

Change the available styles in envato_setup.php here:

$this->site_styles = array(
    'style1' => 'Style 1',
    'style2' => 'Style 2',
);

If you only have 1 style you can set this to an empty array.

Place the logo/thumbnail for each style into the envato_setup/images/styleX/ folders.

Envato Market Plugin

The Envato Market plugin is very new. Details here: https://github.com/envato/wp-envato-market By default the Envato Market plugin requires users generate a personal token for the API. This can be time consuming and confusing for first time buyers. This envato-setup.php script combined with the code in /api/ adds a few hooks to the Envato Market plugin to enable single click oAuth login for updates. It's by far from perfect but the only way to get oAuth login working with updates.

Feel free to pull my oAuth code apart. You'll see this is a method of getting a purchase code back into the WordPress theme. So if you just need a purchase code for some other purpose then you can use this oAuth bounce to get one easily.

Warning

This script integrates heavily into my current theme (beautiful watercolor) by pulling in configuration variables and running some other hooks/functions that are defined in my theme. This wizard will not work completely straight out of the box. But hopefully it gives you some ideas :)

More Details.

Feel free to do a pull request with improvements.

Feel free to ask questions on the forum ( https://forums.envato.com/t/fully-automatic-plugin-install-default-content-oauth-theme-updates-in-a-wizard/20504 ) or create issues here on github.

envato-wp-theme-setup-wizard's People

Contributors

cyberwani avatar dtbaker avatar vburlak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

envato-wp-theme-setup-wizard's Issues

How to export content just like yours

Hi @dtbaker,
there are some options to export demo content from existing demo site but I wonder how you separately exported for all types like below.

|---
|--- all.xml
|--- menu.json
|--- options.json
|--- products.xml
|--- variations.xml
|--- widget_options.json
|--- widget_positions.json

Theme Configuratiions

I love this script, but would love to see how you integrated it in your theme. Can you share the theme with me? me @ (myusername).com ? Or let me know when it is available to be downloaded/bought.

How to test ?

The single biggest issue which really haunts me before migrating to a new update system. How do I test if it works or not ?

Could not load installer

Thanks for this great installer.

I wish I can use it but no chance. I have upload api folder to my server. ( of course I have changed id, secret and url).

Then uploaded envato_setup folder
mytheme / plugins / envato_setup

I have added to function.php

include (get_template_directory() . 'plugins/envato_setup/envato_setup.php');

add_filter('my_theme_theme_setup_wizard_username', 'my_theme_set_theme_setup_wizard_username', 10);
if( ! function_exists('my_theme_set_theme_setup_wizard_username') ){
    function my_theme_set_theme_setup_wizard_username($username){
        return 'myUser';
    }
}

add_filter('my_theme_theme_setup_wizard_oauth_script', 'my_theme_set_theme_setup_wizard_oauth_script', 10);
if( ! function_exists('my_theme_set_theme_setup_wizard_oauth_script') ){
    function my_theme_set_theme_setup_wizard_oauth_script($oauth_url){
        return 'http://mysite.com/envato/api/server-script.php';
    }
}

There is not any screen for setup theme. I have checked Appearence and other menus on wordpress. Tried deactivate and reactivate theme. Tried to include other files too envato_setup_init.php ....
I have tried to include files to mytheme/plugins/myUsername/envato_setup... Tried all combination, checked everything but could not open setup screen.

I am going to lose my mind :D What's your suggestion :)

License

Hi!

It is possible to use your codes inamcommercial themes fot themeforest market?

Good work!!

Issue with import Pages

Hello

We try to import a pages with your installer but get an error "Error"

We also noticed that in the class Envato_Theme_Setup_Wizard there is no import function for pages

_content_install_pages

Also, there is no function to import from xml as you have written in the Readme

return $this->_import_wordpress_xml_file(DIR ."/content/all.xml");

[Discussion] Split server side and theme/client side into 2 different repos?

Hi @dtbaker
What about transfer api folder into another repository, for eg: envato-wp-theme-setup-wizard-server.
And also move envato_setup folder contents into repo's root folder.

It will increase better file structure. And theme developers can require different repo's via composer without the need to download unnecessary files on server, or in theme's folder.

Cheers!

Plugin selection

Hi @dtbaker.

This is a really nice work.

Is there an option to give user to choose from plugins just as like you did on importing demo content section.

And another issue is: can we use regular wordpress header and footer for this wizard. Do you know a way to achieve this.

Thank you

PHP 7.4 problem

Hi,

if anybody's here still ;) I'm still using this awesome piece of code and I still believe it's the only and best way to import demo contant, however it doesn't work on PHP 7.4. Every import ends up with a bunch of "Unable to find replacement." in ajax response, and it doesn't import anything except Media files.

Better handling of data

Hello,

I bumped into an issue where the default.json file was returning NULL. As far my understanding it was due to some kind of permission issue. So what I did to solve this is to make proper use of WP_Filesystem.

Here is my code. I think it can further be improved.

private function _get_json( $file ) {
    WP_Filesystem();
    $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, array());
    if ( ! WP_Filesystem($creds) ) {
        return false;
    }   
    global $wp_filesystem;
    // change path with path to your content dir
    $dir = $wp_filesystem->find_folder(WP_CONTENT_DIR . "/themes/offshore/envato_setup/content");
    $file = trailingslashit($dir) . $file;
    if ( $wp_filesystem->exists( $file ) ) {
        return json_decode( $wp_filesystem->get_contents( $file ), true );
    } else {
        return array();
    }
}

Same approach can be used for _get_sql function. Thoughts?

menus do not connect.

Thanks for this amazing setup wizard. I am having some trouble in the menu linking. The menus are imported but the set_theme_mod does not assign the correct navigation menus which is causing issues. I am also not able to debug the "settings" part as the logs and errors do not appear in the ajax request return.
Any help would be appreciated.

Handling of Custom fields

Hi,

I am trying to use this theme on my next theme and so far everything is good. I found one issue though. The custom fields for the post/pages were not exported/imported. Do you have any idea about this ?
PS: I am using default.json method, not xml.

Unable to save session values

Hello,

I have an issue! The session values are empty. I see the session files being generated but the values are empty. I just end up with 'Failed to find WordPress return URL. Please report this error to the item author.'

Can you please add license?

Hi there,
Amazing job!

Can you please add license to this project?
Without it we can't legally use/copy/change/improve it in any way.

Thank you.

all.xml not working , function missing

Hi , please provide me the complete function for make working all.xml

i include the

private function _content_install_pages(){
    return $this->_import_wordpress_xml_file(__DIR__ ."/content/all.xml");
}

in envato_setup.php giving ajax error ,

and one more thing i want to ask about , m i have to include the

both

include(get_template_directory().'/lib/envato_setup/envato_setup_init.php'); // Functions

include(get_template_directory().'/lib/envato_setup/envato_setup.php');

and i have to include the wodpres-importer.php too...
in funtion.php

please help

'upgrader_post_install' prompts setup wizard again?

I've never actually been able to test the theme update process as a customer, since Themeforest doesn't add your own theme to your account.

I noticed this code here and it made me wonder, when a client updates the theme through the Envato Market plugin, will they be prompted to run the setup wizard again?

/**
 * After a theme update we clear the setup_complete option. This prompts the user to visit the update page again.
 *
 * @since 1.1.8
 * @access public
 */
public function upgrader_post_install( $return, $theme ) {
	if ( is_wp_error( $return ) ) {
		return $return;
	}
	if ( $theme != get_stylesheet() ) {
		return $return;
	}
	update_option( 'envato_setup_complete', false );
	return $return;
}

Envato Authentication

I am receiving an error when the authentication via our server is completed, the API connection doesn't seem to be connected even after pressing save changes.

Unexpected token s in JSON at position 0

Making it work with a plugin

I have managed to do most of the stuff and it seems to be working with my plugin. But after I 'Approve' the request for updates I get this error - 'Failed to find WordPress return URL. Please report this error to the item author.'.

What I missed?

bbPress conflict

Hi @dtbaker,
When I preinstalled bbpress I am having the error below.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'filter_permalink' not found or invalid function name in C:\wamp\www\themeforest\wordpress\statix\wp-includes\plugin.php on line 235

Have you ever tried using this wizard in theme while woocommerce and bbpress installed?

Thanks

Importing Theme Images

Hi dtbaker,

Amazing script you have created. I am just trying to import the standard theme images using the "default.json" file.

I have been playing around with the function private function _fetch_remote_file( $url, $post ) { to try and revert it back to the normal WordPress image importer however am having no luck.

Whenever I try and change this function on the wizard under the "Media" section is just hangs and keeps stating "Installing"

Wondering if you have any default code I could use to revert the image import back to the normal WordPress importer.

The script works great apart from being able to import my images.

capture

Thanks

Elementor background images

HI David, thanks so much for sharing this import script. I'm noticing a small issue, wondering if you've come across this as well.

As I'm testing, I'm noticing that background images stored in Elementor widgets are broken during import. I think this is because Elementor is storing them in the _elementor_data post meta field as css, and I didn't see anywhere in the envato_setup.php that replaces the path from the originating site.

It looks like you've provided space to do the find / replace on line 1780 of envato_setup.php but no find / replace logic.

Just wondering if you updated the script recently.

Thanks again. Cheers.

[Need help] Get TGMPA parent_slug and menu from it's own config

Hi @dtbaker

I've recently changed my tgmpa function config to:

$config = array(
    'parent_slug'            => 'my_theme_dashboard',
    'menu'                      => 'my_theme_install_plugins',
);
tgmpa( $plugins, $config );

In this case my TGMPA link should looks like: http://example.com/wp-admin/admin.php?page=my_theme_install_plugins.
If we try to use setup wizard within custom TGMPA parent slug / menu it will cause ajax error when activating / installing plugins.

Found that you statically defined default TGMPA menu slug as a tgmpa-install-plugins and parent slug as themes.php.
I think it will be better to get them directly from TGM_Plugin_Activation class properties via __get() magic method.

I've tried to implement it, but i can't figure out how to get TGMPA Instance with configured properties.
It's returns only defaults properties values instead of the values specified above in the tgmpa() function config.
Any ideas, how to properly get TGM_Plugin_Activation 'menu' and parent_slug properties?

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.