get_theme_title() ); ?>

vget_version() ); ?>
get( 'Version' ) ); } /** * Get the theme title. * * @return string|null */ public function get_theme_title() { return __( 'BlockStrap', 'blockstrap' ); } /** * Get the required pages HTML output. * * @return void */ public function get_required_pages_html() { $pages = $this->get_demo_pages(); ?>

get_required_plugins(); ?>

get_setting_js(); } /** * Get the required plugins HTML output. * * @return void */ public function get_recaptcha_html() { $keys = get_option('blockstrap_recaptcha_keys'); $site_key = isset($keys['site_key']) ? esc_attr($keys['site_key']) : ''; $site_secret = isset($keys['site_secret']) ? esc_attr($keys['site_secret']) : ''; ?>
__( 'BlockStrap Builder', 'blockstrap' ), ); } /** * Get the array of demo pages. * * @return array[] */ public function get_demo_pages() { return array(); return array( 'about' => array( 'title' => __( 'About', 'blockstrap' ), 'slug' => 'about', 'desc' => __( 'About content', 'blockstrap' ), ), ); } /** * Get the content of the template file. * * @param $path string Relative to theme root. * * @return false|string */ public function get_template_content( $path ) { ob_start(); include $path; return ob_get_clean(); } /** * The AJAX function that will activate or deactivate require plugins. * * @return void */ public function plugin_management_handler() { if ( current_user_can( 'activate_plugins' ) ) { if ( ! check_ajax_referer( 'blockstrap_plugin_management', 'security', false ) ) { wp_send_json_error( 'Invalid nonce' ); wp_die(); } $plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( $_POST['plugin_slug'] ) : ''; $deactivate = isset( $_POST['deactivate'] ) ? filter_var( $_POST['deactivate'], FILTER_VALIDATE_BOOLEAN ) : false; require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Check if the plugin is installed. $plugin_info = plugins_api( 'plugin_information', array( 'slug' => $plugin_slug ) ); if ( is_wp_error( $plugin_info ) ) { wp_send_json_error( 'Plugin not found' ); wp_die(); } $plugin_file = $plugin_slug . '/' . $plugin_info->slug . '.php'; $plugin_installed = is_plugin_active( $plugin_file ); if ( ! $plugin_installed ) { $installed_plugins = get_plugins(); $plugin_installed = array_key_exists( $plugin_file, $installed_plugins ) || in_array( $plugin_file, $installed_plugins, true ); } if ( $deactivate ) { if ( $plugin_installed ) { deactivate_plugins( $plugin_file ); wp_send_json_success( 'Plugin deactivated successfully' ); } else { wp_send_json_error( 'Plugin not active' ); } } else { if ( ! $plugin_installed ) { // Install and activate the plugin. $upgrader = new Plugin_Upgrader(); $install_result = $upgrader->install( $plugin_info->download_link ); if ( is_wp_error( $install_result ) ) { wp_send_json_error( 'Plugin installation failed: ' . $install_result->get_error_message() ); wp_die(); } } // Activate the plugin. $activate_result = activate_plugin( $plugin_file ); if ( is_wp_error( $activate_result ) ) { wp_send_json_error( 'Plugin activation failed: ' . $activate_result->get_error_message() ); wp_die(); } else { wp_send_json_success( 'Plugin activated successfully' ); } } } else { wp_send_json_error( 'You do not have permission to activate/deactivate plugins' ); } wp_die(); } /** * Check if demo page exists and return the ID if so. * * @param $page_slug * * @return int|string */ public function demo_page_exists( $page_slug ) { $theme_slug = get_template(); $option_key = 'blockstrap_demo_pages'; $page_status = get_option( $option_key ); return isset( $page_status[ $theme_slug ][ $page_slug ] ) ? absint( $page_status[ $theme_slug ][ $page_slug ] ) : ''; } /** * The AJAX function that will add or remove the demo pages. * * @return void */ public function page_management_handler() { if ( current_user_can( 'activate_plugins' ) ) { if ( ! check_ajax_referer( 'blockstrap_page_management', 'security', false ) ) { wp_send_json_error( 'Invalid nonce' ); wp_die(); } $demo_pages = $this->get_demo_pages(); $page_slug = isset( $_POST['page_slug'] ) ? sanitize_text_field( $_POST['page_slug'] ) : ''; $delete = isset( $_POST['delete'] ) && $_POST['delete'] === 'true'; if ( ! isset( $demo_pages[ $page_slug ] ) ) { wp_send_json_error( __( 'Page is not set', 'blockstrap' ) ); wp_die(); } else { $page = $demo_pages[ $page_slug ]; } $theme_slug = get_template(); $option_key = 'blockstrap_demo_pages'; $page_status = get_option( $option_key ); $page_id = $this->demo_page_exists( $page_slug ); if ( $delete ) { if ( $page_id ) { wp_trash_post( $page_id ); unset( $page_status[ $theme_slug ][ $page_slug ] ); update_option( $option_key, $page_status ); } wp_send_json_success( __( 'Page moved to trash', 'blockstrap' ) ); wp_die(); } else { if ( ! $page_id ) { $page_id = wp_insert_post( array( 'post_title' => $page['title'], 'post_name' => $page['slug'], 'post_content' => $page['desc'], 'post_status' => 'publish', 'post_type' => 'page', ) ); if ( is_wp_error( $page_id ) ) { wp_send_json_error( __( 'Page failed to create', 'blockstrap' ) ); wp_die(); } $page_status[ $theme_slug ][ $page_slug ] = $page_id; update_option( $option_key, $page_status ); if ( ! empty( $page['is_blog'] ) ) { update_option( 'page_for_posts', $page_id ); } elseif ( ! empty( $page['is_fron'] ) ) { update_option( 'page_on_front', $page_id ); // this is probably not needed as the theme can set the front page anyway. } wp_send_json_success( __( 'Page Added', 'blockstrap' ) ); wp_die(); } else { wp_send_json_error( __( 'Page already exists', 'blockstrap' ) ); wp_die(); } } } else { wp_send_json_error( 'You do not have permission to add/remove pages.' ); } wp_die(); } /** * The AJAX function that will save the recaptcha keys. * * @return void */ public function recaptcha_management_handler() { if ( current_user_can( 'activate_plugins' ) ) { if ( ! check_ajax_referer( 'blockstrap_save_recaptcha_keys', 'security', false ) ) { wp_send_json_error( 'Invalid nonce' ); wp_die(); } parse_str( $_POST['form_data'], $data ); // print_r($data ); if(isset($data['site_key']) && isset($data['site_secret'])) { update_option('blockstrap_recaptcha_keys',array( 'site_key' => sanitize_html_class($data['site_key']), 'site_secret' => sanitize_html_class($data['site_secret']), )); wp_send_json_success( __( 'Keys Saved', 'blockstrap' ) ); }else{ wp_send_json_error( 'Something went wrong' ); } } else { wp_send_json_error( 'You do not have permission for this.' ); } wp_die(); } }