| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! class_exists( 'Qi_Blocks_Admin_General_Page' ) ) { |
| 4 |
class Qi_Blocks_Admin_General_Page { |
| 5 |
private static $instance; |
| 6 |
private $wizard_status; |
| 7 |
private $menu_slug; |
| 8 |
private $title; |
| 9 |
private $sub_pages; |
| 10 |
private $transient; |
| 11 |
|
| 12 |
function __construct() { |
| 13 |
$this->set_wizard_status( get_option( 'qi_blocks_setup_wizard', 'init' ) ); |
| 14 |
|
| 15 |
$main_page = 'completed' === $this->get_wizard_status() ? 'qi_blocks_welcome' : 'qi_blocks_setup_wizard'; |
| 16 |
|
| 17 |
$this->set_menu_slug( $main_page ); |
| 18 |
$this->set_title( esc_html__( 'Qi Blocks', 'qi-blocks' ) ); |
| 19 |
$this->set_transient( 'qi_blocks_set_redirect' ); |
| 20 |
|
| 21 |
add_filter( 'plugin_row_meta', array( $this, 'extend_plugin_info' ), 10, 2 ); |
| 22 |
add_filter( 'plugin_action_links_' . QI_BLOCKS_PLUGIN_BASE_FILE, array( $this, 'plugin_action_links' ) ); |
| 23 |
|
| 24 |
add_action( 'init', array( $this, 'register_sub_pages' ) ); |
| 25 |
add_action( 'admin_menu', array( $this, 'dashboard_add_page' ) ); |
| 26 |
|
| 27 |
add_action( 'admin_init', array( $this, 'redirect' ) ); |
| 28 |
add_action( 'admin_init', array( $this, 'external_redirect' ) ); |
| 29 |
|
| 30 |
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 20 ); |
| 31 |
|
| 32 |
add_filter( 'admin_body_class', array( $this, 'add_admin_body_classes' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @return Qi_Blocks_Admin_General_Page |
| 37 |
*/ |
| 38 |
public static function get_instance() { |
| 39 |
|
| 40 |
if ( is_null( self::$instance ) ) { |
| 41 |
self::$instance = new self(); |
| 42 |
} |
| 43 |
|
| 44 |
return self::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_wizard_status() { |
| 48 |
return $this->wizard_status; |
| 49 |
} |
| 50 |
|
| 51 |
public function set_wizard_status( $wizard_status ) { |
| 52 |
$this->wizard_status = $wizard_status; |
| 53 |
} |
| 54 |
|
| 55 |
public function get_menu_slug() { |
| 56 |
return $this->menu_slug; |
| 57 |
} |
| 58 |
|
| 59 |
public function set_menu_slug( $menu_slug ) { |
| 60 |
$this->menu_slug = $menu_slug; |
| 61 |
} |
| 62 |
|
| 63 |
public function get_title() { |
| 64 |
return $this->title; |
| 65 |
} |
| 66 |
|
| 67 |
public function set_title( $title ) { |
| 68 |
$this->title = $title; |
| 69 |
} |
| 70 |
|
| 71 |
public function set_sub_pages( Qi_Blocks_Admin_Sub_Pages $sub_page ) { |
| 72 |
$this->sub_pages[ $sub_page->get_position() ] = $sub_page; |
| 73 |
} |
| 74 |
|
| 75 |
public function get_sub_pages() { |
| 76 |
return $this->sub_pages; |
| 77 |
} |
| 78 |
|
| 79 |
public function get_transient() { |
| 80 |
return $this->transient; |
| 81 |
} |
| 82 |
|
| 83 |
public function set_transient( string $transient ) { |
| 84 |
$this->transient = $transient; |
| 85 |
} |
| 86 |
|
| 87 |
function extend_plugin_info( $plugin_meta, $plugin_file ) { |
| 88 |
|
| 89 |
if ( QI_BLOCKS_PLUGIN_BASE_FILE === $plugin_file ) { |
| 90 |
$plugin_meta['qi-support'] = '<a href="https://helpcenter.qodeinteractive.com/" target="_blank">' . esc_html__( 'Help Center', 'qi-blocks' ) . '</a>'; |
| 91 |
$plugin_meta['qi-video'] = '<a href="https://www.youtube.com/watch?v=m9beJAnVCnI&list=PLNypD600o6nIILMn287UeeRWsfc8lyiPa" target="_blank">' . esc_html__( 'Video Tutorials', 'qi-blocks' ) . '</a>'; |
| 92 |
$plugin_meta['qi-templates'] = '<a href="https://qodeinteractive.com/qi-templates?utm_source=dash&utm_medium=qiblocks&utm_campaign=gopremium" target="_blank">' . esc_html__( 'Qi Templates', 'qi-blocks' ) . '</a>'; |
| 93 |
} |
| 94 |
|
| 95 |
return $plugin_meta; |
| 96 |
} |
| 97 |
|
| 98 |
function plugin_action_links( $links ) { |
| 99 |
$links['premium'] = sprintf( '<a href="%1$s" target="_blank" class="qi-blocks-premium-link" style="color:#ee2852;font-weight:700">%2$s</a>', 'https://qodeinteractive.com/pricing-gutenberg?utm_source=dash&utm_medium=qiblocks&utm_campaign=gopremium', esc_html__( 'Upgrade', 'qi-blocks' ) ); |
| 100 |
|
| 101 |
return $links; |
| 102 |
} |
| 103 |
|
| 104 |
function dashboard_add_page() { |
| 105 |
$page = add_menu_page( |
| 106 |
$this->get_title(), |
| 107 |
$this->get_title(), |
| 108 |
'edit_theme_options', |
| 109 |
$this->get_menu_slug(), |
| 110 |
null, |
| 111 |
QI_BLOCKS_ADMIN_URL_PATH . '/admin-pages/assets/img/logo-qi.png', |
| 112 |
998 |
| 113 |
); |
| 114 |
|
| 115 |
add_action( 'load-' . $page, array( $this, 'load_admin_css' ) ); |
| 116 |
|
| 117 |
$subpages_array = $this->get_sub_pages(); |
| 118 |
|
| 119 |
ksort( $subpages_array ); |
| 120 |
|
| 121 |
foreach ( $subpages_array as $key => $sub_page ) { |
| 122 |
$sub_page_instance = add_submenu_page( |
| 123 |
$this->get_menu_slug(), |
| 124 |
$sub_page->get_title(), |
| 125 |
$sub_page->get_title(), |
| 126 |
'edit_theme_options', |
| 127 |
$sub_page->get_menu_slug(), |
| 128 |
array( $sub_page, 'render' ), |
| 129 |
$sub_page->get_position() |
| 130 |
); |
| 131 |
|
| 132 |
add_action( 'load-' . $sub_page_instance, array( $this, 'load_admin_css' ) ); |
| 133 |
} |
| 134 |
|
| 135 |
if ( ! empty( $subpages_array ) && count( $subpages_array ) > 1 ) { |
| 136 |
add_submenu_page( |
| 137 |
$this->get_menu_slug(), |
| 138 |
'', |
| 139 |
esc_html__( 'Qi Blocks Premium', 'qi-blocks' ), |
| 140 |
'edit_theme_options', |
| 141 |
'qi_blocks_pro', |
| 142 |
array( $this, 'external_redirect' ) |
| 143 |
); |
| 144 |
|
| 145 |
add_submenu_page( |
| 146 |
$this->get_menu_slug(), |
| 147 |
'', |
| 148 |
esc_html__( 'Qi Templates', 'qi-blocks' ), |
| 149 |
'edit_theme_options', |
| 150 |
'qi_templates', |
| 151 |
array( $this, 'external_redirect' ) |
| 152 |
); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
function get_header( $object = null ) { |
| 157 |
$object = ! empty( $object ) ? $object : $this; |
| 158 |
|
| 159 |
$args = array( |
| 160 |
'menu_slug' => $object->get_menu_slug(), |
| 161 |
'menu_title' => $object->get_title(), |
| 162 |
'menu_url' => admin_url( 'admin.php?page=' . $this->get_menu_slug() ), |
| 163 |
); |
| 164 |
|
| 165 |
qi_blocks_template_part( 'admin/admin-pages', 'templates/header', '', $args ); |
| 166 |
} |
| 167 |
|
| 168 |
function get_footer() { |
| 169 |
qi_blocks_template_part( 'admin/admin-pages', 'templates/footer' ); |
| 170 |
} |
| 171 |
|
| 172 |
function get_sidebar() { |
| 173 |
qi_blocks_template_part( 'admin/admin-pages', 'templates/sidebar' ); |
| 174 |
} |
| 175 |
|
| 176 |
function get_content() { |
| 177 |
qi_blocks_template_part( 'admin/admin-pages', 'templates/general' ); |
| 178 |
} |
| 179 |
|
| 180 |
function render_holder() { |
| 181 |
$args = array( |
| 182 |
'this_object' => $this, |
| 183 |
); |
| 184 |
|
| 185 |
qi_blocks_template_part( 'admin/admin-pages', 'templates/holder', '', $args ); |
| 186 |
} |
| 187 |
|
| 188 |
public function register_sub_pages() { |
| 189 |
$sub_pages = apply_filters( 'qi_blocks_filter_add_sub_page', array() ); |
| 190 |
|
| 191 |
if ( ! empty( $sub_pages ) ) { |
| 192 |
foreach ( $sub_pages as $sub_page ) { |
| 193 |
|
| 194 |
if ( class_exists( $sub_page ) ) { |
| 195 |
$add_flag = false; |
| 196 |
|
| 197 |
if ( 'completed' === $this->get_wizard_status() && strpos( $sub_page, 'Setup_Wizard' ) === false ) { |
| 198 |
$add_flag = true; |
| 199 |
} else if ( 'completed' !== $this->get_wizard_status() && strpos( $sub_page, 'Setup_Wizard' ) !== false ) { |
| 200 |
$add_flag = true; |
| 201 |
} |
| 202 |
|
| 203 |
if ( $add_flag ) { |
| 204 |
$sub_object = new $sub_page(); |
| 205 |
$this->set_sub_pages( $sub_object ); |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
function load_admin_css() { |
| 213 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
| 214 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 215 |
} |
| 216 |
|
| 217 |
function enqueue_styles() { |
| 218 |
wp_enqueue_style( 'qi-blocks-dashboard-style', QI_BLOCKS_ASSETS_URL_PATH . '/dist/dashboard.css' ); |
| 219 |
} |
| 220 |
|
| 221 |
function enqueue_scripts() { |
| 222 |
wp_enqueue_script( 'qi-blocks-framework-script', QI_BLOCKS_ASSETS_URL_PATH . '/dist/dashboard.js', array( 'jquery' ), false, true ); |
| 223 |
|
| 224 |
do_action( 'qi_blocks_action_additional_scripts' ); |
| 225 |
} |
| 226 |
|
| 227 |
function add_admin_body_classes( $classes ) { |
| 228 |
$pages = $this->get_all_dashboard_slugs(); |
| 229 |
|
| 230 |
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $pages, true ) ) { |
| 231 |
$classes = $classes . ' qi-blocks-dashboard'; |
| 232 |
} |
| 233 |
|
| 234 |
return $classes; |
| 235 |
} |
| 236 |
|
| 237 |
function admin_footer_text( $text ) { |
| 238 |
$pages = $this->get_all_dashboard_slugs(); |
| 239 |
|
| 240 |
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $pages, true ) ) { |
| 241 |
return qi_blocks_get_template_part( 'admin/admin-pages', 'templates/parts/footer-text' ); |
| 242 |
} |
| 243 |
|
| 244 |
return $text; |
| 245 |
} |
| 246 |
|
| 247 |
function get_all_dashboard_slugs() { |
| 248 |
$pages = array( |
| 249 |
$this->get_menu_slug(), |
| 250 |
); |
| 251 |
|
| 252 |
foreach ( $this->get_sub_pages() as $sub_page ) { |
| 253 |
$pages[] = $sub_page->get_menu_slug(); |
| 254 |
} |
| 255 |
|
| 256 |
return $pages; |
| 257 |
} |
| 258 |
|
| 259 |
function redirect() { |
| 260 |
|
| 261 |
if ( wp_doing_ajax() ) { |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
| 266 |
return; |
| 267 |
} |
| 268 |
|
| 269 |
if ( ! empty( get_transient( QI_BLOCKS_ACTIVATED_TRANSIENT ) ) && empty( get_transient( $this->get_transient() ) ) ) { |
| 270 |
set_transient( $this->get_transient(), 1 ); |
| 271 |
|
| 272 |
$redirect_page = 'completed' === $this->get_wizard_status() ? $this->get_menu_slug() : 'qi_blocks_setup_wizard'; |
| 273 |
|
| 274 |
wp_safe_redirect( |
| 275 |
esc_url( admin_url( 'admin.php?page=' . esc_attr( $redirect_page ) ) ) |
| 276 |
); |
| 277 |
|
| 278 |
exit; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
function external_redirect() { |
| 283 |
|
| 284 |
if ( empty( $_GET['page'] ) ) { |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
if ( 'qi_blocks_pro' === $_GET['page'] ) { |
| 289 |
wp_redirect( 'https://qodeinteractive.com/pricing-gutenberg?utm_source=dash&utm_medium=qiblocks&utm_campaign=gopremium' ); |
| 290 |
die; |
| 291 |
} |
| 292 |
|
| 293 |
if ( 'qi_templates' === $_GET['page'] ) { |
| 294 |
wp_redirect( 'https://qodeinteractive.com/qi-templates?utm_source=dash&utm_medium=qiblocks&utm_campaign=gopremium' ); |
| 295 |
die; |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
Qi_Blocks_Admin_General_Page::get_instance(); |
| 301 |
} |
| 302 |
|