| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Core; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Utils\Base; |
| 6 |
use WPDeveloper\BetterDocs\Utils\Helper; |
| 7 |
use WPDeveloper\BetterDocs\SetupWizard\SetupWizard as SetupWizardHelper; |
| 8 |
|
| 9 |
class SetupWizard extends Base { |
| 10 |
private $settings; |
| 11 |
public function __construct( Settings $settings ) { |
| 12 |
$this->settings = $settings; |
| 13 |
|
| 14 |
add_action( 'admin_enqueue_scripts', [$this, 'enqueue'] ); |
| 15 |
add_action( 'admin_init', [$this, 'load'] ); |
| 16 |
} |
| 17 |
|
| 18 |
public function load() { |
| 19 |
SetupWizardHelper::load( $this->settings ); |
| 20 |
} |
| 21 |
|
| 22 |
public function enqueue( $hook ) { |
| 23 |
if ( $hook !== 'betterdocs_page_betterdocs-setup' ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
betterdocs()->assets->enqueue( 'betterdocs-sweetalert', 'vendor/js/sweetalert.min.js', [] ); |
| 28 |
betterdocs()->assets->enqueue( 'betterdocs-setup-wizard', 'admin/css/setup-wizard.css' ); |
| 29 |
betterdocs()->assets->enqueue( 'betterdocs-setup-wizard', 'admin/js/setup-wizard.js', ['jquery', 'betterdocs-sweetalert'] ); |
| 30 |
|
| 31 |
// Localize the script with new data |
| 32 |
betterdocs()->assets->localize( 'betterdocs-setup-wizard', 'bdquicksetup', [ |
| 33 |
'finish_txt' => __( 'Finish', 'betterdocs' ), |
| 34 |
'next_txt' => __( 'Next', 'betterdocs' ), |
| 35 |
'customizerurl' => $this->customizer_settings_url(), |
| 36 |
'docspageurl' => $this->docs_page_url(), |
| 37 |
'currentslug' => $this->settings->get( 'docs_slug' ) |
| 38 |
] ); |
| 39 |
} |
| 40 |
|
| 41 |
public function init() { |
| 42 |
SetupWizardHelper::setSection( [ |
| 43 |
'id' => 'betterdocs_getting_started_settings', |
| 44 |
'title' => __( 'Getting Started', 'betterdocs' ), |
| 45 |
'fields' => [ |
| 46 |
[ |
| 47 |
'id' => 'getting_started', |
| 48 |
'title' => __( 'Getting Started', 'betterdocs' ), |
| 49 |
'sub_title' => __( 'Easily get started with this easy setup wizard and complete setting up your Knowledge Base.', 'betterdocs' ), |
| 50 |
'type' => 'welcome', |
| 51 |
'video_url' => 'https://www.youtube.com/embed/57BioKfROlo' |
| 52 |
] |
| 53 |
] |
| 54 |
] ); |
| 55 |
|
| 56 |
$existing_plugins = $this->knowledge_base_plugins(); |
| 57 |
if ( $existing_plugins ) { |
| 58 |
SetupWizardHelper::setSection( [ |
| 59 |
'id' => 'betterdocs_migration_settings', |
| 60 |
'title' => __( 'Migration', 'betterdocs' ), |
| 61 |
'fields' => [ |
| 62 |
[ |
| 63 |
'id' => 'migration_step', |
| 64 |
'sub_title' => __( 'We detected another Knowledge Base Plugin installed in this site. For BetterDocs to work efficiently, we will migrate the data from the plugin listed below, and deactivate the plgugin, to avoid conflict.', 'betterdocs' ), |
| 65 |
'type' => 'migration', |
| 66 |
'options' => [ |
| 67 |
[ |
| 68 |
'id' => $existing_plugins[0][0], |
| 69 |
'title' => 'Migrate ' . $existing_plugins[0][1], |
| 70 |
'type' => 'checkbox', |
| 71 |
'default' => 1 |
| 72 |
] |
| 73 |
] |
| 74 |
] |
| 75 |
] |
| 76 |
] ); |
| 77 |
} |
| 78 |
|
| 79 |
// Setup Pages |
| 80 |
SetupWizardHelper::setSection( [ |
| 81 |
'id' => 'betterdocs_setup_page_settings', |
| 82 |
'title' => __( 'Setup Pages', 'betterdocs' ), |
| 83 |
'fields' => [ |
| 84 |
[ |
| 85 |
'id' => 'builtin_doc_page', |
| 86 |
'title' => __( 'Enable Built-in Documentation Page', 'betterdocs' ), |
| 87 |
'type' => 'checkbox' |
| 88 |
], |
| 89 |
[ |
| 90 |
'id' => 'docs_slug', |
| 91 |
'title' => __( 'Page Slug', 'betterdocs' ), |
| 92 |
'type' => 'text', |
| 93 |
'placeholder' => 'Page Slug', |
| 94 |
'default' => 'docs' |
| 95 |
], |
| 96 |
[ |
| 97 |
'id' => 'enable_disable', |
| 98 |
'title' => __( 'Enable Instant Answer', 'betterdocs' ), |
| 99 |
'type' => 'checkbox_pro_feature' |
| 100 |
] |
| 101 |
] |
| 102 |
] ); |
| 103 |
|
| 104 |
// Create Content |
| 105 |
SetupWizardHelper::setSection( [ |
| 106 |
'id' => 'betterdocs_create_content_settings', |
| 107 |
'title' => __( 'Create Content', 'betterdocs' ), |
| 108 |
'fields' => [ |
| 109 |
[ |
| 110 |
'id' => 'content_step', |
| 111 |
'title' => __( 'Create Documentation Content', 'betterdocs' ), |
| 112 |
'sub_title' => __( 'Let\'s create some categories and articles. And then assign the articles to proper categories.', 'betterdocs' ), |
| 113 |
'type' => 'link', |
| 114 |
'image_url' => betterdocs()->assets->icon( 'setup-wizard/setup-articles.png', true ), |
| 115 |
'options' => [ |
| 116 |
[ |
| 117 |
'title' => __( 'Create Categories', 'betterdocs' ), |
| 118 |
'url' => admin_url( 'edit-tags.php?taxonomy=doc_category&post_type=docs' ), |
| 119 |
'feature_title' => __( 'Create Categories', 'betterdocs' ), |
| 120 |
'feature_content' => sprintf( '%s %s > <strong>%s</strong>', __( 'You can create Categories from', 'betterdocs' ), '<strong>BetterDocs</strong>', __( 'Categories', 'betterdocs' ) ) |
| 121 |
], |
| 122 |
[ |
| 123 |
'title' => __( 'Create Docs', 'betterdocs' ), |
| 124 |
'url' => admin_url( 'post-new.php?post_type=docs' ), |
| 125 |
'feature_title' => __( 'Create Docs', 'betterdocs' ), |
| 126 |
'feature_content' => sprintf( '%1$s %2$s %3$s', __( 'You can create Docs from ', 'betterdocs' ), '<strong>BetterDocs ></strong>', __( 'Add New', 'betterdocs' ) ) |
| 127 |
] |
| 128 |
] |
| 129 |
] |
| 130 |
] |
| 131 |
] ); |
| 132 |
|
| 133 |
// Customize |
| 134 |
SetupWizardHelper::setSection( [ |
| 135 |
'id' => 'betterdocs_customize_settings', |
| 136 |
'title' => __( 'Customize', 'betterdocs' ), |
| 137 |
'fields' => [ |
| 138 |
[ |
| 139 |
'id' => 'customize_step', |
| 140 |
'title' => __( 'Customize Everything', 'betterdocs' ), |
| 141 |
'sub_title' => __( 'Take control of your settings and customize your documentation page, articles and archive pages live, with the power of Customizer', 'betterdocs' ), |
| 142 |
'type' => 'link', |
| 143 |
'image_url' => betterdocs()->assets->icon( 'customizer/setup-customizer.png', true ), |
| 144 |
'options' => [ |
| 145 |
[ |
| 146 |
'id' => 'bdgotocustomize', |
| 147 |
'title' => __( 'Go To Customizer', 'betterdocs' ), |
| 148 |
'url' => $this->customizer_settings_url(), |
| 149 |
'feature_title' => __( 'Easy To Customize', 'betterdocs' ), |
| 150 |
'feature_content' => __( 'Customize Docs page, Docs, Archive page Live', 'betterdocs' ) |
| 151 |
], |
| 152 |
[ |
| 153 |
'title' => __( 'Go To Settings', 'betterdocs' ), |
| 154 |
'url' => $this->settings->url(), |
| 155 |
'feature_title' => __( 'Extensive Options Panel', 'betterdocs' ), |
| 156 |
'feature_content' => __( 'Take control of your pages with extensive settings options', 'betterdocs' ) |
| 157 |
] |
| 158 |
] |
| 159 |
] |
| 160 |
] |
| 161 |
] ); |
| 162 |
|
| 163 |
// Finalize |
| 164 |
SetupWizardHelper::setSection( [ |
| 165 |
'id' => 'betterdocs_finalize_settings', |
| 166 |
'title' => __( 'Finalize', 'betterdocs' ), |
| 167 |
'fields' => [ |
| 168 |
[ |
| 169 |
'id' => 'finnilize_step', |
| 170 |
'title' => __( 'Great Job!', 'betterdocs' ), |
| 171 |
'sub_title' => __( 'Your documentation page is ready! Make sure to add more articles and assign them to proper categories and you are good to go.', 'betterdocs' ), |
| 172 |
'type' => 'final_step', |
| 173 |
'image_url' => betterdocs()->assets->icon( 'setup-wizard/setup-finalize.svg', true ), |
| 174 |
'options' => [ |
| 175 |
[ |
| 176 |
'id' => 'bdgotodocspage', |
| 177 |
'title' => __( 'Visit Your Documentation Page', 'betterdocs' ), |
| 178 |
'url' => $this->docs_page_url() |
| 179 |
] |
| 180 |
] |
| 181 |
] |
| 182 |
] |
| 183 |
] ); |
| 184 |
} |
| 185 |
|
| 186 |
public function views() { |
| 187 |
betterdocs()->views->get( 'admin/setup-wizard' ); |
| 188 |
} |
| 189 |
|
| 190 |
public function customizer_settings_url() { |
| 191 |
$query = [ |
| 192 |
'autofocus[panel]' => 'betterdocs_customize_options', |
| 193 |
'return' => admin_url( 'edit.php?post_type=docs' ) |
| 194 |
]; |
| 195 |
|
| 196 |
$docs_slug = $this->settings->get( 'docs_slug', 'docs' ); |
| 197 |
if ( $docs_slug ) { |
| 198 |
$query['url'] = site_url( '/' . $docs_slug ); |
| 199 |
} |
| 200 |
$customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) ); |
| 201 |
|
| 202 |
return esc_url( $customizer_link ); |
| 203 |
} |
| 204 |
|
| 205 |
public function docs_page_url() { |
| 206 |
return esc_url( site_url( '/' . $this->settings->get( 'docs_slug', 'docs' ) ) ); |
| 207 |
} |
| 208 |
|
| 209 |
public function knowledge_base_plugins() { |
| 210 |
$plugins = []; |
| 211 |
|
| 212 |
if ( Helper::is_plugin_active( 'wedocs/wedocs.php' ) ) { |
| 213 |
$plugins[] = ['wedocs', 'weDocs']; |
| 214 |
} |
| 215 |
if ( Helper::is_plugin_active( 'bsf-docs/bsf-docs.php' ) ) { |
| 216 |
$plugins[] = ['bsf-docs', 'BSF docs']; |
| 217 |
} |
| 218 |
if ( Helper::is_plugin_active( 'documentor-lite/documentor-lite.php' ) ) { |
| 219 |
$plugins[] = ['documentor-lite', 'Documentor']; |
| 220 |
} |
| 221 |
if ( Helper::is_plugin_active( 'echo-knowledge-base/echo-knowledge-base.php' ) ) { |
| 222 |
$plugins[] = ['echo-knowledge-base', 'Echo Knowledge Base']; |
| 223 |
} |
| 224 |
if ( Helper::is_plugin_active( 'pressapps-knowledge-base/pressapps-knowledge-base.php' ) ) { |
| 225 |
$plugins[] = ['pressapps-knowledge-base', 'PressApps Knowledge Base']; |
| 226 |
} |
| 227 |
|
| 228 |
return $plugins; |
| 229 |
} |
| 230 |
} |
| 231 |
|