Plugin Directory

Changeset 3424554


Ignore:
Timestamp:
12/21/2025 10:23:47 AM (3 months ago)
Author:
blockskitdev
Message:
  • Theme recomendation in demo import updated.
Location:
blockskit
Files:
29 added
5 edited

Legend:

Unmodified
Added
Removed
  • blockskit/trunk/blockskit.php

    r3402294 r3424554  
    77 * Author: blockskitdev
    88 * Author URI: https://blockskit.com/
    9  * Version: 1.2.1
     9 * Version: 1.2.2
    1010 * Text Domain: blockskit
    1111 * Domain Path: https://blockskit.com/free
    12  * Tested up to: 6.8
     12 * Tested up to: 6.9
    1313 *
    1414 * Blockskit is free software: you can redistribute it and/or modify
     
    3232
    3333define( 'BLOCKSKIT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    34 define( 'BLOCKSKIT_PLUGIN_VERSION', '1.2.1');
     34define( 'BLOCKSKIT_PLUGIN_VERSION', '1.2.2');
    3535
    3636function create_block_bk_block_init() {
     
    4646// Blockskit Pro Admin Notice
    4747require plugin_dir_path( __FILE__ ) . 'includes/class-blockskit-pro-upgrade-notice.php';
     48
     49// Advanced Import Override
     50require plugin_dir_path(__FILE__) . 'includes/class-bk-advanced-import-override.php';
     51new Bk_Advanced_Import_Override();
  • blockskit/trunk/import/base-install/assets/base-install.js

    r3143728 r3424554  
    1 jQuery( document ).ready( function ( $ ) {
    2     $(".ai-demo-import").click(function(){
    3        
    4         var base_html = direct_install.base_html;
    5         $('body').append( base_html );
     1jQuery(document).ready(function ($) {
     2    $(".ai-demo-import").click(function (e) {
    63
    7     } );
    8     $(document.body).on('click', '.close-base-notice' ,function(){
     4        var $item = $(this).closest('.ai-item');
     5        var slug = $item.data('slug').replace('-pro', '');
     6        var name = $item.attr('aria-label') || slug; // Fallback to slug if no label
     7
     8        name = name.replace(/Pro/g, '').trim();
     9
     10        if (name.indexOf('BlocksKit') === -1) {
     11            name = 'BlocksKit ' + name;
     12        }
     13
     14
     15
     16        // Check if theme is not active
     17        if (direct_install.active_theme_slug !== slug) {
     18            var is_installed = direct_install.installed_themes && direct_install.installed_themes.indexOf(slug) !== -1;
     19
     20            if (is_installed || (!is_installed && direct_install.installed_themes)) {
     21                e.preventDefault();
     22
     23                var template = direct_install.popup_template;
     24                var btn_text = is_installed ? 'Activate ' + name : 'Install and Activate ' + name;
     25
     26                // Replace name, slug and button text
     27                var html = template.replace(/{{name}}/g, name)
     28                    .replace(/{{slug}}/g, slug)
     29                    .replace(/Install and Activate {{name}}/g, btn_text);
     30
     31                html = template.replace(/{{name}}/g, name).replace(/{{slug}}/g, slug);
     32
     33                if (is_installed) {
     34                    html = html.replace(/Install and Activate/g, 'Activate');
     35                }
     36
     37                $('body').append(html);
     38            }
     39        }
     40
     41    });
     42    $(document.body).on('click', '.close-base-notice', function () {
    943        $(".base-install-notice-outer").remove();
    1044    });
    1145    //install base theme
    12     $(document.body).on('click', '.install-base-theme' ,function(){
    13         $( this ).addClass( 'updating-message' );
    14         $.ajax({
     46    $(document.body).on('click', '.install-base-theme', function () {
     47        $(this).addClass('updating-message');
     48        var slug = $(this).data('slug').replace('-pro', '');
     49
     50        $.ajax({
    1551            type: "POST",
    1652            url: direct_install.ajax_url,
    1753            data: {
    18                 action     : 'install_base_theme',
    19                 security   : direct_install.nonce
    20             },
    21             success:function() {
    22                 $( this ).removeClass( 'updating-message' );
    23                 $( '.base-install-prompt' ).remove(); 
    24                 $( '.base-install-success' ).show(); 
     54                action: 'install_base_theme',
     55                security: direct_install.nonce,
     56                slug: slug
    2557            },
    26             error: function( xhr, ajaxOptions, thrownError ){
     58            success: function () {
     59                $(this).removeClass('updating-message');
     60                $('.base-install-prompt').remove();
     61                $('.base-install-success').show();
     62
     63                // Add the new slug to installed list locally so subsequent clicks don't trigger popup
     64                if (direct_install.installed_themes) {
     65                    direct_install.installed_themes.push(slug);
     66                }
     67            },
     68            error: function (xhr, ajaxOptions, thrownError) {
    2769                console.log(thrownError);
    2870            }
    2971        });
    3072    });
    31 } );
     73});
  • blockskit/trunk/import/base-install/base-install.php

    r3338758 r3424554  
    11<?php
    22// Exit if accessed directly
    3 if ( !defined( 'ABSPATH' ) ) exit;
     3if (!defined('ABSPATH'))
     4    exit;
    45/**
    56 * The Blockskit Import hooks callback functionality of the plugin.
    67 *
    78 */
    8 class Bk_Base_Install_Hooks {
     9class Bk_Base_Install_Hooks
     10{
    911
    1012    /**
     
    1214     *
    1315     */
    14     public function __construct() {
    15         add_action( 'wp_ajax_install_base_theme', array( $this, 'install_base_theme' ));
    16         add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ), 10, 1 );
    17         add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 1 );
     16    public function __construct()
     17    {
     18        add_action('wp_ajax_install_base_theme', array($this, 'install_base_theme'));
     19        add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'), 10, 1);
     20        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 10, 1);
    1821    }
    1922
     
    2225     *
    2326     */
    24     public function enqueue_styles() {
    25    
    26         wp_enqueue_style( 'bk-base-install', plugin_dir_url( __FILE__ ) . 'assets/base-install.css',array( 'wp-admin' ), '1.0.0', 'all' );
     27    public function enqueue_styles()
     28    {
     29
     30        wp_enqueue_style('bk-base-install', plugin_dir_url(__FILE__) . 'assets/base-install.css', array('wp-admin'), '1.0.0', 'all');
    2731    }
    2832
     
    3135     *
    3236     */
    33     public function enqueue_scripts() {
     37    public function enqueue_scripts()
     38    {
    3439
    35         wp_enqueue_script( 'bk-base-install', plugin_dir_url( __FILE__ ) . 'assets/base-install.js', array( 'jquery' ), '1.0.0', true );
     40        wp_enqueue_script('bk-base-install', plugin_dir_url(__FILE__) . 'assets/base-install.js', array('jquery'), '1.0.0', true);
    3641
    37         $base_theme = bk_import_get_base_theme();
    38         $action = __( 'Install and Activate', 'blockskit' );
    39         if( bk_import_base_theme_installed() ){
    40             $action = __( 'Activate', 'blockskit' );
    41         }
     42        // Get all installed theme slugs
     43        $all_themes = wp_get_themes();
     44        $installed_themes_slugs = array_keys($all_themes);
     45
    4246        wp_localize_script(
    4347            'bk-base-install',
    4448            'direct_install',
    4549            array(
    46                 'ajax_url'  => admin_url( 'admin-ajax.php' ),
    47                 'nonce'     => wp_create_nonce( 'direct_theme_install' ),
    48                 'base_html' => sprintf(
     50                'ajax_url' => admin_url('admin-ajax.php'),
     51                'nonce' => wp_create_nonce('direct_theme_install'),
     52                'installed_themes' => $installed_themes_slugs,
     53                'active_theme_slug' => wp_get_theme()->get_stylesheet(),
     54                'popup_template' =>
    4955                    '<div class="base-install-notice-outer">
    5056                        <div class="base-install-notice-inner">
    5157                            <div class="base-install-prompt">
    52                                 <div class="base-install-content"><h2 class="base-install-title">%1$s</h2><p>We recommend to %2$s %1$s theme as all our demo works perfectly with this theme. You can still try our demo on any block theme but it might not look as you see on our demo.</p></div>
     58                                <div class="base-install-content"><h2 class="base-install-title">{{name}}</h2><p>We recommend to Install and Activate {{name}} theme as all our demo works perfectly with this theme. You can still try our demo on any block theme but it might not look as you see on our demo.</p></div>
    5359                                <div class="base-install-btn">
    54                                     <a class= "install-base-theme button button-primary">%2$s %1$s</a>
     60                                    <a class="install-base-theme button button-primary" data-slug="{{slug}}">Install and Activate {{name}}</a>
    5561                                    <br>
    56                                     <a class= "close-base-notice close-base-button">Skip</a>
     62                                    <a class="close-base-notice close-base-button">Skip</a>
    5763                                </div>
    5864                            </div>
    5965                            <div class="base-install-success">
    60                                 <div class="base-install-content"><h3>Thank you for installing %1$s. Click on Next to proceed to demo importer.</h3></div>
     66                                <div class="base-install-content"><h3>Thank you for installing {{name}}. Click on Next to proceed to demo importer.</h3></div>
    6167                                <div class="base-install-btn">
    62                                     <a class= "close-base-notice button button-primary">Next</a>
     68                                    <a class="close-base-notice button button-primary">Next</a>
    6369                                </div>
    6470                            </div>
     
    7278                        </div>
    7379                    </div>',
    74                     $base_theme['name'],
    75                     $action
    76                 ),
    7780            )
    7881        );
     
    8285     * Install base theme.
    8386     */
    84     public function install_base_theme(){
    85         check_ajax_referer( 'direct_theme_install', 'security' );
     87    public function install_base_theme()
     88    {
     89        check_ajax_referer('direct_theme_install', 'security');
    8690
    87         if( !current_user_can('manage_options') ) {
    88             $error = __( 'Sorry, you are not allowed to install themes on this site.', 'blockskit' );
    89             wp_send_json_error( $error );
     91        if (!current_user_can('manage_options')) {
     92            $error = __('Sorry, you are not allowed to install themes on this site.', 'blockskit');
     93            wp_send_json_error($error);
    9094        }
    91         $base_theme = bk_import_get_base_theme();
    92         if ( bk_import_base_theme_installed() ) {
    93             switch_theme( $base_theme['slug'] );
     95
     96        $slug = isset($_POST['slug']) ? sanitize_text_field($_POST['slug']) : '';
     97        if (empty($slug)) {
     98            $base_theme = bk_import_get_base_theme();
     99            $slug = $base_theme['slug']; // Fallback
     100        }
     101
     102        // Check if already installed
     103        $theme = wp_get_theme($slug);
     104        if ($theme->exists()) {
     105            switch_theme($slug);
    94106            wp_send_json_success();
    95107        }
     
    97109        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    98110        include_once ABSPATH . 'wp-admin/includes/theme.php';
    99        
     111
    100112        $api = themes_api(
    101113            'theme_information',
    102114            array(
    103                 'slug'   => $base_theme['slug'],
    104                 'fields' => array( 'sections' => false ),
     115                'slug' => $slug,
     116                'fields' => array('sections' => false),
    105117            )
    106118        );
    107      
    108         if ( is_wp_error( $api ) ) {
     119
     120        if (is_wp_error($api)) {
    109121            $status['errorMessage'] = $api->get_error_message();
    110             wp_send_json_error( $status['errorMessage'] );
     122            wp_send_json_error($status['errorMessage']);
    111123        }
    112124
    113         $skin     = new WP_Ajax_Upgrader_Skin();
    114         $upgrader = new Theme_Upgrader( $skin );
    115         $result   = $upgrader->install( $api->download_link );
     125        $skin = new WP_Ajax_Upgrader_Skin();
     126        $upgrader = new Theme_Upgrader($skin);
     127        $result = $upgrader->install($api->download_link);
    116128
    117129        if (is_wp_error($result)) {
    118            wp_send_json_error( $result->errors );
     130            wp_send_json_error($result->errors);
    119131        }
    120132
    121         switch_theme( $base_theme['slug'] );
     133        switch_theme($slug);
    122134        wp_send_json_success();
    123135        die();
     
    129141 * Checks if base theme installed.
    130142 */
    131 function bk_import_base_theme_installed(){
     143function bk_import_base_theme_installed()
     144{
    132145    $base_theme = bk_import_get_base_theme();
    133146    $all_themes = wp_get_themes();
    134147    $installed_themes = array();
    135     foreach( $all_themes as $theme ){
    136         $theme_text_domain = esc_attr ( $theme->get('TextDomain') );
     148    foreach ($all_themes as $theme) {
     149        $theme_text_domain = esc_attr($theme->get('TextDomain'));
    137150        $installed_themes[] = $theme_text_domain;
    138151    }
    139     if( in_array( $base_theme['slug'], $installed_themes, true ) ){
     152    if (in_array($base_theme['slug'], $installed_themes, true)) {
    140153        return true;
    141154    }
    142155    return false;
    143    
     156
    144157}
    145158
     
    147160 * Returns base theme.
    148161 */
    149 function bk_import_get_base_theme(){
     162function bk_import_get_base_theme()
     163{
    150164    $theme = bk_import_get_theme_slug();
    151165    $base_theme = array(
     
    153167        'slug' => '',
    154168    );
    155     if( strpos( $theme, 'blockskit' ) !== false ){
     169    if (strpos($theme, 'blockskit') !== false) {
    156170        $base_theme['name'] = 'Blockskit Base';
    157171        $base_theme['slug'] = 'blockskit-base';
    158172    }
    159173    return $base_theme;
    160    
     174
    161175}
    162176
  • blockskit/trunk/import/demo-import.php

    r3402294 r3424554  
    11<?php
    22// Exit if accessed directly
    3 if ( !defined( 'ABSPATH' ) ) exit;
     3if (!defined('ABSPATH'))
     4    exit;
    45
    5 define( 'BK_TEMPLATE_URL', plugin_dir_url( __FILE__ ) );
    6 define( 'BK_PATH', plugin_dir_path( __FILE__ ) );
     6define('BK_TEMPLATE_URL', plugin_dir_url(__FILE__));
     7define('BK_PATH', plugin_dir_path(__FILE__));
    78
    89/**
     
    1011 *
    1112 */
    12 function bk_import_get_theme_slug(){
     13function bk_import_get_theme_slug()
     14{
    1315    $demo_theme = wp_get_theme();
    14     return $demo_theme->get( 'TextDomain' );
     16    return $demo_theme->get('TextDomain');
    1517}
    1618
     
    1921 *
    2022 */
    21 function bk_import_get_theme_screenshot(){
    22     $demo_theme = wp_get_theme();
     23function bk_import_get_theme_screenshot()
     24{
     25    $demo_theme = wp_get_theme();
    2326    return $demo_theme->get_screenshot();
    2427}
     
    3235 * @return bool
    3336 */
    34 function bk_import_theme_check( $needle ){
    35     if( strpos( bk_import_get_theme_slug(), $needle ) !== false  ){
     37function bk_import_theme_check($needle)
     38{
     39    if (strpos(bk_import_get_theme_slug(), $needle) !== false) {
    3640        return true;
    37     }else{
     41    } else {
    3842        return false;
    3943    }
     
    4448 * and public-facing site hooks..
    4549 *
    46  */   
     50 */
    4751require BK_PATH . 'demo/functions.php';
    4852
    4953// Base theme installation
    50 // if( get_stylesheet() !== 'blockskit-education' && get_stylesheet() !== 'blockskit-agency' && get_stylesheet() !== 'blockskit-base' ){
    51 //     require BK_PATH . 'base-install/base-install.php'; 
     54// if (get_stylesheet() !== 'blockskit-education' && get_stylesheet() !== 'blockskit-agency' && get_stylesheet() !== 'blockskit-base') {
     55require BK_PATH . 'base-install/base-install.php';
    5256// }
    5357
     
    5862 */
    5963$plugin_admin = bk_import_hooks();
    60 add_filter( 'advanced_import_demo_lists', array( $plugin_admin,'bk_import_demo_import_lists'), 20, 1 );
    61 add_filter( 'admin_menu', array( $plugin_admin, 'import_menu' ), 10, 1 );
    62 add_filter( 'wp_ajax_bk_import_getting_started', array( $plugin_admin, 'install_advanced_import' ), 10, 1 );
    63 add_filter( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_styles' ), 10, 1 );
    64 add_filter( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_scripts' ), 10, 1 );
    65 add_filter( 'advanced_export_include_options', array( $plugin_admin, 'bk_import_include_options' ), 10, 1 );
    66 add_action( 'advanced_import_replace_post_ids', array( $plugin_admin, 'bk_import_replace_attachment_ids' ), 30 );
     64add_filter('advanced_import_demo_lists', array($plugin_admin, 'bk_import_demo_import_lists'), 20, 1);
     65add_filter('admin_menu', array($plugin_admin, 'import_menu'), 10, 1);
     66add_filter('wp_ajax_bk_import_getting_started', array($plugin_admin, 'install_advanced_import'), 10, 1);
     67add_filter('admin_enqueue_scripts', array($plugin_admin, 'enqueue_styles'), 10, 1);
     68add_filter('admin_enqueue_scripts', array($plugin_admin, 'enqueue_scripts'), 10, 1);
     69add_filter('advanced_export_include_options', array($plugin_admin, 'bk_import_include_options'), 10, 1);
     70add_action('advanced_import_replace_post_ids', array($plugin_admin, 'bk_import_replace_attachment_ids'), 30);
  • blockskit/trunk/readme.txt

    r3402294 r3424554  
    55Tested up to: 6.8
    66Requires PHP: 7.4.9
    7 Stable tag: 1.2.1
     7Stable tag: 1.2.2
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    4343
    4444== Changelog ==
     45
     46= 1.2.2 =
     47* Theme recomendation in demo import updated.
    4548
    4649= 1.2.1 =
Note: See TracChangeset for help on using the changeset viewer.