Make WordPress Themes

Changeset 220756


Ignore:
Timestamp:
03/13/2024 12:01:18 PM (21 months ago)
Author:
themedropbox
Message:

New version of BlockStrap - 0.1.5

Location:
blockstrap/0.1.5
Files:
1 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • blockstrap/0.1.5/classes/class-blockstrap-admin.php

    r215341 r220756  
    1616
    1717    /**
     18     * Variable declaration for the option slug.
     19     *
     20     * @var string $option_slug The slug used for the options.
     21     */
     22    public $option_key = 'blockstrap_options';
     23
     24    /**
    1825     * Constructor.
    1926     *
     
    3542
    3643        // Page install on activation
    37         add_action('admin_init', array( $this, 'maybe_add_pages' ) );
    38 
     44        add_action( 'admin_init', array( $this, 'maybe_add_pages' ) );
     45
     46        // GeoDirectory filters
     47        if ( defined( 'GEODIRECTORY_VERSION' ) ) {
     48            add_filter( 'geodir_default_dummy_data_type', array( $this, 'gd_set_default_dummy_data_type' ), 10, 2 );
     49            add_filter( 'geodir_recommend_wp_plugins', array( $this, 'gd_recommend_wp_plugins' ) );
     50        }
     51
     52        // maybe update option to single key
     53        $this->maybe_convert_options();
     54
     55    }
     56
     57    /**
     58     * This can be set in child themes to set the GD dummy data default type.
     59     *
     60     * @param $type
     61     * @param $post_type
     62     *
     63     * @return mixed
     64     */
     65    public function gd_set_default_dummy_data_type( $type, $post_type ) {
     66
     67        return $type;
     68    }
     69
     70
     71    /**
     72     * Removes the "ninjs-forms" plugin from the list of recommended WordPress plugins.
     73     *
     74     * @param array $plugins The array of recommended WordPress plugins.
     75     *
     76     * @return array The updated array of recommended WordPress plugins with "ninjs-forms" plugin removed.
     77     */
     78    public function gd_recommend_wp_plugins( $plugins ) {
     79
     80        // remove ninja forms as we have our own built-in contact form.
     81        unset( $plugins['ninja-forms'] );
     82
     83        $plugins['blockstrap-page-builder-blocks'] = array(
     84            'url'      => 'https://wordpress.org/plugins/blockstrap-page-builder-blocks/',
     85            'slug'     => 'blockstrap-page-builder-blocks',
     86            'name'     => 'Blockstrap Page Builder',
     87            'file'     => 'blockstrap-page-builder-blocks/blockstrap-page-builder-blocks.php',
     88            'desc'     => __( 'Required to display page template blocks, the theme will be blank without this.', 'blockstrap' ),
     89            'required' => true,
     90        );
     91
     92        return $plugins;
    3993    }
    4094
     
    4498     * @return void
    4599     */
    46     public function maybe_add_pages(){
     100    public function maybe_add_pages() {
    47101        $pages = $this->get_demo_pages();
    48102
    49103        if ( ! empty( $pages ) ) {
    50104            $theme_slug = sanitize_title_with_dashes( $this->get_theme_title() );
    51             if ( ! get_option( 'blockstrap_demo_pages_installed_' . $theme_slug ) ) {
     105            if ( ! blockstrap_get_option( 'blockstrap_demo_pages_installed_' . $theme_slug ) ) {
    52106                foreach ( $pages as $page ) {
    53                     if(!$this->demo_page_exists( $page['slug'] )){
     107                    if ( ! $this->demo_page_exists( $page['slug'] ) ) {
    54108                        $page_id = $this->add_demo_page( $page );
    55109                    }
    56110                }
    57                 update_option( 'blockstrap_demo_pages_installed_' . $theme_slug, true );
    58             }
    59 
     111                blockstrap_update_option( 'blockstrap_demo_pages_installed_' . $theme_slug, true );
     112            }
    60113        }
    61114    }
    62115
    63116    /**
     117     * Get the array of demo pages.
     118     *
     119     * @return array[]
     120     */
     121    public function get_demo_pages() {
     122        return array();
     123    }
     124
     125    /**
     126     * Get the theme title.
     127     *
     128     * @return string|null
     129     */
     130    public function get_theme_title() {
     131        return __( 'BlockStrap', 'blockstrap' );
     132    }
     133
     134    /**
     135     * Check if demo page exists and return the ID if so.
     136     *
     137     * @param $page_slug
     138     *
     139     * @return int|string
     140     */
     141    public function demo_page_exists( $page_slug ) {
     142        $theme_slug  = get_template();
     143        $option_key  = 'blockstrap_demo_pages';
     144        $page_status = blockstrap_get_option( $option_key );
     145
     146        return isset( $page_status[ $theme_slug ][ $page_slug ] ) ? absint( $page_status[ $theme_slug ][ $page_slug ] ) : '';
     147    }
     148
     149    /**
     150     * Add a demo page from arguments.
     151     *
     152     * @param $page
     153     *
     154     * @return false|int|WP_Error
     155     */
     156    public function add_demo_page( $page ) {
     157
     158        $theme_slug  = get_template();
     159        $option_key  = 'blockstrap_demo_pages';
     160        $page_status = blockstrap_get_option( $option_key );
     161        $page_status = empty( $page_status ) ? array() : $page_status;
     162        $page_slug   = esc_attr( $page['slug'] );
     163
     164        $page_id = wp_insert_post(
     165            array(
     166                'post_title'   => $page['title'],
     167                'post_name'    => $page['slug'],
     168                'post_content' => $page['desc'],
     169                'post_status'  => 'publish',
     170                'post_type'    => 'page',
     171            )
     172        );
     173
     174        if ( is_wp_error( $page_id ) ) {
     175            return false;
     176        } else {
     177            $page_status[ $theme_slug ][ $page_slug ] = $page_id;
     178            blockstrap_update_option( $option_key, $page_status );
     179
     180            if ( ! empty( $page['is_blog'] ) ) {
     181                update_option( 'page_for_posts', $page_id );
     182                update_option( 'show_on_front', 'page' );
     183
     184                if ( ! get_option( 'page_on_front' ) ) {
     185                    update_option( 'page_on_front', 2 ); // if page on front not set then it will show blog page on front.
     186                }
     187            } elseif ( ! empty( $page['is_front'] ) ) {
     188                update_option( 'page_on_front', $page_id ); // this is probably not needed as the theme can set the front page anyway.
     189                update_option( 'show_on_front', 'page' );
     190            }
     191        }
     192
     193        return $page_id;
     194
     195    }
     196
     197    /**
    64198     * Load AUI on our settings page.
    65199     *
     
    76210
    77211    /**
     212     * Returns the count of required plugins that are not activated.
     213     *
     214     * @return int The count of required plugins that are not activated.
     215     */
     216    public function required_plugins_count() {
     217        $count            = 0;
     218        $required_plugins = $this->get_required_plugins();
     219
     220        foreach ( $required_plugins as $slug => $name ) {
     221            $active = is_plugin_active( $slug . '/' . $slug . '.php' );
     222            if ( ! $active ) {
     223                $count++;
     224            }
     225        }
     226
     227        return $count;
     228    }
     229
     230    /**
    78231     * Register the menu item.
    79232     * @return void
    80233     */
    81234    public function register_menu_page() {
     235        $notifications_count = self::required_plugins_count();
     236
    82237        add_submenu_page(
    83238            'themes.php',
    84239            __( 'BlockStrap Settings', 'blockstrap' ),
    85             __( 'Theme Setup', 'blockstrap' ),
     240            ! empty( $notifications_count ) ? __( 'Theme Setup', 'blockstrap' ) . ' <span class="awaiting-mod">' . absint( $notifications_count ) . '</span>' : __( 'Theme Setup', 'blockstrap' ),
    86241            'manage_options',
    87242            'blockstrap',
     
    102257                <div class="d-flex align-items-center">
    103258                    <h1 class="text-dark "><?php echo esc_html( $this->get_theme_title() ); ?></h1>
    104                     <span class="badge bg-faded-info fs-sm mb-2 ms-2">v<?php echo esc_html( $this->get_version() ); ?></span>
     259                    <span
     260                        class="badge bg-faded-info fs-sm mb-2 ms-2">v<?php echo esc_html( $this->get_version() ); ?></span>
    105261                </div>
    106262
     
    128284
    129285    /**
    130      * Get the theme title.
    131      *
    132      * @return string|null
    133      */
    134     public function get_theme_title() {
    135         return __( 'BlockStrap', 'blockstrap' );
    136     }
    137 
    138     /**
    139286     * Get the required pages HTML output.
    140287     *
     
    145292        ?>
    146293        <div class="col">
    147         <div class="card h-100 mw-100">
    148         <h3 class="h4 text-dark"><?php _e( 'Optional Pages', 'blockstrap' ); ?></h3>
    149             <ul class="list-group  list-group-flush">
    150 
    151                 <?php
    152 
    153                 if ( empty( $pages ) ) {
    154                     echo aui()->alert(
    155                         array(
    156                             'type'    => 'info',
    157                             'content' => __( 'No demo pages for this theme', 'blockstrap' ),
    158                             'class'   => 'mb-3 text-left text-start',
    159                         )
    160                     );
    161                 } else {
    162                     foreach ( $pages as $slug => $page ) {
    163                         $active = $this->demo_page_exists( $slug );
    164 
    165                         $exists = false;// !$active ? get_page_by_path($slug) : false;
    166                         ?>
    167                         <li class="list-group-item d-flex justify-content-between align-items-center">
    168                             <span class="mr-auto me-auto"><?php echo esc_html( $page['title'] ); ?></span>
     294            <div class="card h-100 mw-100">
     295                <h3 class="h4 text-dark"><?php _e( 'Optional Pages', 'blockstrap' ); ?></h3>
     296                <ul class="list-group  list-group-flush">
     297
     298                    <?php
     299
     300                    if ( empty( $pages ) ) {
     301                        echo aui()->alert(
     302                            array(
     303                                'type'    => 'info',
     304                                'content' => __( 'No demo pages for this theme', 'blockstrap' ),
     305                                'class'   => 'mb-3 text-left text-start',
     306                            )
     307                        );
     308                    } else {
     309                        foreach ( $pages as $slug => $page ) {
     310                            $active = $this->demo_page_exists( $slug );
     311
     312                            $exists = false;// !$active ? get_page_by_path($slug) : false;
     313                            ?>
     314                            <li class="list-group-item d-flex justify-content-between align-items-center">
     315                                <span class="mr-auto me-auto"><?php echo esc_html( $page['title'] ); ?></span>
     316                                <?php
     317                                if ( $exists ) {
     318                                    echo '<i class="fas fa-exclamation-triangle mr-2 me-2 text-warning fa-lg c-pointer" data-bs-toggle="tooltip" data-bs-title="' . __( 'Page with same slug exists', 'blockstrap' ) . '"></i>';
     319                                }
     320
     321                                if ( $active && false ) {
     322                                    $link = get_permalink( $active );
     323                                    echo '<a class="bs-demo-link" href="' . esc_url( $link ) . '" target="_blank" ><i class="fas fa-external-link-alt mr-2 me-2 text-muted fa-lg c-pointer" data-bs-toggle="tooltip" data-bs-title="' . __( 'Page with same slug exists', 'blockstrap' ) . '"></i></a>';
     324                                }
     325                                ?>
     326                                <div class="spinner-border spinner-border-sm mr-2 me-2 d-none text-muted" role="status">
     327                                    <span class="visually-hidden">Loading...</span>
     328                                </div>
     329                                <div class="form-check form-switch mb-0">
     330                                    <input class="form-check-input" type="checkbox" role="switch"
     331                                           id="blockstrap-req-plugin-<?php echo esc_attr( $slug ); ?>"
     332                                        <?php
     333                                        if ( $active ) {
     334                                            echo 'checked';
     335                                        }
     336
     337                                        if ( $exists ) {
     338                                            echo ' disabled ';
     339                                        }
     340                                        ?>
     341                                           onclick="blockstrap_admin_toggle_demo_page(this,'<?php echo esc_attr( $slug ); ?>',!jQuery(this).is(':checked'));">
     342                                </div>
     343                            </li>
    169344                            <?php
    170                             if ( $exists ) {
    171                                 echo '<i class="fas fa-exclamation-triangle mr-2 me-2 text-warning fa-lg c-pointer" data-bs-toggle="tooltip" data-bs-title="' . __( 'Page with same slug exists', 'blockstrap' ) . '"></i>';
    172                             }
    173 
    174                             if ( $active && false ) {
    175                                 $link = get_permalink( $active );
    176                                 echo '<a class="bs-demo-link" href="' . esc_url( $link ) . '" target="_blank" ><i class="fas fa-external-link-alt mr-2 me-2 text-muted fa-lg c-pointer" data-bs-toggle="tooltip" data-bs-title="' . __( 'Page with same slug exists', 'blockstrap' ) . '"></i></a>';
    177                             }
    178                             ?>
    179                             <div class="spinner-border spinner-border-sm mr-2 me-2 d-none text-muted" role="status">
    180                                 <span class="visually-hidden">Loading...</span>
    181                             </div>
    182                             <div class="form-check form-switch mb-0">
    183                                 <input class="form-check-input" type="checkbox" role="switch" id="blockstrap-req-plugin-<?php echo esc_attr( $slug ); ?>"
    184                                     <?php
    185                                     if ( $active ) {
    186                                         echo 'checked';
    187                                     }
    188 
    189                                     if ( $exists ) {
    190                                         echo ' disabled ';
    191                                     }
    192                                     ?>
    193                                        onclick="blockstrap_admin_toggle_demo_page(this,'<?php echo esc_attr( $slug ); ?>',!jQuery(this).is(':checked'));">
    194                             </div>
    195                         </li>
    196                         <?php
     345                        }
    197346                    }
    198                 }
    199 
    200                 ?>
    201             </ul>
    202         </div>
     347
     348                    ?>
     349                </ul>
     350            </div>
    203351        </div>
    204352        <?php
     
    212360    public function get_required_plugins_html() {
    213361        $required_plugins = $this->get_required_plugins();
     362        $border_class     = self::required_plugins_count() ? 'border-danger' : '';
    214363        ?>
    215364        <div class="col">
    216             <div class="card h-100 mw-100">
    217                 <h3 class="h4 text-dark"><?php _e( 'Required Plugins', 'blockstrap' ); ?></h3>
     365            <div class="card h-100 mw-100 p-0 bs-required-plugin-card <?php echo $border_class; ?>">
     366                <h5 class="card-header h4 text-dark"><?php _e( 'Required Plugins', 'blockstrap' ); ?></h5>
     367                <div class="card-body">
    218368                <ul class="list-group list-group-flush">
    219369
     
    228378                            </div>
    229379                            <div class="form-check form-switch mb-0">
    230                                 <input class="form-check-input" type="checkbox" role="switch" id="blockstrap-req-plugin-<?php echo esc_attr( $slug ); ?>"
    231                                                                                                                                    <?php
    232                                                                                                                                     if ( $active ) {
    233                                                                                                                                         echo 'checked';}
    234                                                                                                                                     ?>
    235                                  onclick="blockstrap_admin_toggle_plugin_activation(this,'<?php echo esc_attr( $slug ); ?>',!jQuery(this).is(':checked'));">
     380                                <input class="form-check-input" type="checkbox" role="switch"
     381                                       id="blockstrap-req-plugin-<?php echo esc_attr( $slug ); ?>"
     382                                    <?php
     383                                    if ( $active ) {
     384                                        echo 'checked';
     385                                    }
     386                                    ?>
     387                                       onclick="blockstrap_admin_toggle_plugin_activation(this,'<?php echo esc_attr( $slug ); ?>',!jQuery(this).is(':checked'));">
    236388                            </div>
    237389                        </li>
     
    240392                    ?>
    241393                </ul>
    242             </div>
    243         </div>
    244         <?php
    245 
    246         $this->get_setting_js();
    247     }
    248 
    249     /**
    250      * Get the required plugins HTML output.
    251      *
    252      * @return void
    253      */
    254     public function get_recaptcha_html() {
    255         $keys = get_option('blockstrap_recaptcha_keys');
    256         $site_key = isset($keys['site_key']) ? esc_attr($keys['site_key']) : '';
    257         $site_secret = isset($keys['site_secret']) ? esc_attr($keys['site_secret']) : '';
    258         ?>
    259         <div class="col mt-5">
    260             <div class="card h-100 mw-100 p-0">
    261                 <h5 class="card-header h4 text-dark"><?php _e( 'Recaptcha Keys', 'blockstrap' ); ?></h5>
    262                  <div class="card-body">
    263                         <div class="alert alert-info" role="alert">
    264                             <?php _e( 'Please enter your Google recaptcha <b>v2 Tickbox</b> keys. (this helps protect the contact form block)', 'blockstrap' ); ?>
    265                             <a href="https://www.google.com/recaptcha/admin" target="_blank"> <?php _e( 'Get Keys', 'blockstrap' ); ?> <i class="fas fa-external-link-alt"></i></a>
    266                         </div>
    267                         <form class="w-100" onsubmit="blockstrap_admin_save_recaptcha_keys(this);return false;">
    268                             <div class="mb-3">
    269                                 <label for="gc-site-key" class="form-label"><?php _e( 'Site Key', 'blockstrap' ); ?></label>
    270                                 <input type="text" class="form-control" name="site_key" id="gc-site-key" value="<?php echo esc_attr($site_key); ?>">
    271                             </div>
    272                             <div class="mb-3">
    273                                 <label for="gc-secret-key" class="form-label"><?php _e( 'Secret Key', 'blockstrap' ); ?></label>
    274                                 <input type="password" class="form-control" name="site_secret" id="gc-secret-key" value="<?php echo esc_attr($site_secret); ?>">
    275                             </div>
    276                             <button type="submit" class="btn btn-primary">  <span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
    277                                 <?php _e( 'Save', 'blockstrap' ); ?></button>
    278                         </form>
    279394                </div>
    280395            </div>
    281396        </div>
    282397        <?php
     398
     399        $this->get_setting_js();
     400    }
     401
     402    /**
     403     * Get the required plugins details array.
     404     *
     405     * @return array
     406     */
     407    public function get_required_plugins() {
     408        return array(
     409            'blockstrap-page-builder-blocks' => __( 'BlockStrap Builder', 'blockstrap' ),
     410        );
    283411    }
    284412
     
    300428             * @param $deactivate
    301429             */
    302             function blockstrap_admin_save_recaptcha_keys($this){
     430            function blockstrap_admin_save_recaptcha_keys($this) {
    303431
    304432                var data = {
     
    313441                    data: data,
    314442                    // dataType: 'html'
    315                     beforeSend: function() {
     443                    beforeSend: function () {
    316444                        jQuery($this).find('.btn-primary').prop('disabled', true).find('.spinner-border').removeClass('d-none');
    317445                    },
    318                     success: function(data) {
     446                    success: function (data) {
    319447                        if (data.success) {
    320448                            jQuery($this).find('.btn-primary').prop('disabled', false).find('.spinner-border').addClass('d-none');
    321                             aui_toast('blockstrap_recaptcha_keys_success','success', data.data);
     449                            aui_toast('blockstrap_recaptcha_keys_success', 'success', data.data);
    322450
    323451                        } else {
     
    327455                        }
    328456                    },
    329                     error: function(xhr) { // if error occured
     457                    error: function (xhr) { // if error occured
    330458                        alert("Error occured.please try again");
    331459                    },
    332                     complete: function() {
     460                    complete: function () {
    333461                        jQuery($this).find('.btn-primary').prop('disabled', false).find('.spinner-border').addClass('d-none');
    334462
     
    344472             * @param $deactivate
    345473             */
    346             function blockstrap_admin_toggle_plugin_activation($this,$plugin,$deactivate){
     474            function blockstrap_admin_toggle_plugin_activation($this, $plugin, $deactivate) {
    347475
    348476                var data = {
     
    358486                    data: data,
    359487                    // dataType: 'html'
    360                     beforeSend: function() {
     488                    beforeSend: function () {
    361489                        jQuery($this).prop('disabled', true).parent().parent().find('.spinner-border').removeClass('d-none');
    362490                    },
    363                     success: function(data) {
     491                    success: function (data) {
    364492                        if (data.success) {
    365493                            jQuery($this).prop('disabled', false).parent().parent().find('.spinner-border').addClass('d-none');
    366494                            if ($deactivate) {
    367                                 aui_toast('blockstrap_plugin_deactivation_success','success', data.data);
    368                             }else{
    369                                 aui_toast('blockstrap_plugin_activation_success','success', data.data);
     495                                aui_toast('blockstrap_plugin_deactivation_success', 'success', data.data);
     496                            } else {
     497                                aui_toast('blockstrap_plugin_activation_success', 'success', data.data);
    370498                            }
    371499                        } else {
    372500                            let $checked = !!data.deactivate;
    373501                            jQuery($this).prop('disabled', false).prop('checked', $checked).parent().parent().find('.spinner-border').addClass('d-none');
    374                             aui_toast('blockstrap_plugin_management_error_'+$plugin,'error', data.data);
     502                            aui_toast('blockstrap_plugin_management_error_' + $plugin, 'error', data.data);
    375503                        }
    376504                    },
    377                     error: function(xhr) { // if error occured
     505                    error: function (xhr) { // if error occured
    378506                        alert("Error occured.please try again");
    379507                    },
    380                     complete: function() {
     508                    complete: function () {
    381509                        jQuery($this).prop('disabled', false).parent().parent().find('.spinner-border').addClass('d-none');
     510                        blockstrap_admin_toggle_required_plugins_border();
    382511                    },
    383512                });
     513            }
     514
     515            /**
     516             * Toggles the required plugins border class.
     517             *
     518             * @return {void}
     519             */
     520            function blockstrap_admin_toggle_required_plugins_border() {
     521                // Total number of checkboxes
     522                var totalCheckboxes = jQuery('.bs-required-plugin-card .form-check-input').length;
     523                // Number of checkboxes that are checked
     524                var checkedCheckboxes = jQuery('.bs-required-plugin-card .form-check-input:checked').length;
     525
     526                // Check if all checkboxes are checked
     527                if(totalCheckboxes === checkedCheckboxes) {
     528                    jQuery('.bs-required-plugin-card').removeClass('border-danger');
     529                } else {
     530                    jQuery('.bs-required-plugin-card').addClass('border-danger');
     531                }
    384532            }
    385533
     
    391539             * @param $delete
    392540             */
    393             function blockstrap_admin_toggle_demo_page($this,$page_slug,$delete){
     541            function blockstrap_admin_toggle_demo_page($this, $page_slug, $delete) {
    394542
    395543                var data = {
     
    405553                    data: data,
    406554                    // dataType: 'html'
    407                     beforeSend: function() {
     555                    beforeSend: function () {
    408556                        jQuery($this).prop('disabled', true).parent().parent().find('.spinner-border').removeClass('d-none');
    409557                    },
    410                     success: function(data) {
     558                    success: function (data) {
    411559                        if (data.success) {
    412560                            jQuery($this).prop('disabled', false).parent().parent().find('.spinner-border').addClass('d-none');
    413561                            if ($delete) {
    414                                 aui_toast('blockstrap_page_deactivation_success','success', data.data);
    415                             }else{
    416                                 aui_toast('blockstrap_page_activation_success','success', data.data);
     562                                aui_toast('blockstrap_page_deactivation_success', 'success', data.data);
     563                            } else {
     564                                aui_toast('blockstrap_page_activation_success', 'success', data.data);
    417565                            }
    418566                        } else {
    419567                            let $checked = !!data.delete;
    420568                            jQuery($this).prop('disabled', false).prop('checked', $checked).parent().parent().find('.spinner-border').addClass('d-none');
    421                             aui_toast('blockstrap_page_management_error','error', data.data);
     569                            aui_toast('blockstrap_page_management_error', 'error', data.data);
    422570                        }
    423571                    },
    424                     error: function(xhr) { // if error occured
     572                    error: function (xhr) { // if error occured
    425573                        let $checked = !!data.delete;
    426574                        jQuery($this).prop('disabled', false).prop('checked', $checked).parent().parent().find('.spinner-border').addClass('d-none');
    427575                        alert("Error occured.please try again");
    428576                    },
    429                     complete: function() {
     577                    complete: function () {
    430578                        jQuery($this).prop('disabled', false).parent().parent().find('.spinner-border').addClass('d-none');
    431579                    },
     
    438586
    439587    /**
    440      * Get the required plugins details array.
    441      *
    442      * @return array
    443      */
    444     public function get_required_plugins() {
    445         return array(
    446             'blockstrap-page-builder-blocks' => __( 'BlockStrap Builder', 'blockstrap' ),
    447         );
    448     }
    449 
    450     /**
    451      * Get the array of demo pages.
    452      *
    453      * @return array[]
    454      */
    455     public function get_demo_pages() {
    456         return array();
     588     * Get the required plugins HTML output.
     589     *
     590     * @return void
     591     */
     592    public function get_recaptcha_html() {
     593        $keys        = blockstrap_get_option( 'blockstrap_recaptcha_keys' );
     594        $site_key    = isset( $keys['site_key'] ) ? esc_attr( $keys['site_key'] ) : '';
     595        $site_secret = isset( $keys['site_secret'] ) ? esc_attr( $keys['site_secret'] ) : '';
     596        ?>
     597        <div class="col mt-5">
     598            <div class="card h-100 mw-100 p-0">
     599                <h5 class="card-header h4 text-dark"><?php _e( 'Recaptcha Keys', 'blockstrap' ); ?></h5>
     600                <div class="card-body">
     601                    <div class="alert alert-info" role="alert">
     602                        <?php _e( 'Please enter your Google recaptcha <b>v2 Tickbox</b> keys. (this helps protect the contact form block)', 'blockstrap' ); ?>
     603                        <a href="https://www.google.com/recaptcha/admin"
     604                           target="_blank"> <?php _e( 'Get Keys', 'blockstrap' ); ?> <i
     605                                class="fas fa-external-link-alt"></i></a>
     606                    </div>
     607                    <form class="w-100" onsubmit="blockstrap_admin_save_recaptcha_keys(this);return false;">
     608                        <div class="mb-3">
     609                            <label for="gc-site-key" class="form-label"><?php _e( 'Site Key', 'blockstrap' ); ?></label>
     610                            <input type="text" class="form-control" name="site_key" id="gc-site-key"
     611                                   value="<?php echo esc_attr( $site_key ); ?>">
     612                        </div>
     613                        <div class="mb-3">
     614                            <label for="gc-secret-key"
     615                                   class="form-label"><?php _e( 'Secret Key', 'blockstrap' ); ?></label>
     616                            <input type="password" class="form-control" name="site_secret" id="gc-secret-key"
     617                                   value="<?php echo esc_attr( $site_secret ); ?>">
     618                        </div>
     619                        <button type="submit" class="btn btn-primary"><span
     620                                class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
     621                            <?php _e( 'Save', 'blockstrap' ); ?></button>
     622                    </form>
     623                </div>
     624            </div>
     625        </div>
     626        <?php
    457627    }
    458628
     
    467637        ob_start();
    468638        include $path;
     639
    469640        return ob_get_clean();
    470641    }
     
    540711
    541712    /**
    542      * Check if demo page exists and return the ID if so.
    543      *
    544      * @param $page_slug
    545      *
    546      * @return int|string
    547      */
    548     public function demo_page_exists( $page_slug ) {
    549         $theme_slug  = get_template();
    550         $option_key  = 'blockstrap_demo_pages';
    551         $page_status = get_option( $option_key );
    552         return isset( $page_status[ $theme_slug ][ $page_slug ] ) ? absint( $page_status[ $theme_slug ][ $page_slug ] ) : '';
    553     }
    554 
    555     /**
    556713     * The AJAX function that will add or remove the demo pages.
    557714     *
     
    579736            $theme_slug  = get_template();
    580737            $option_key  = 'blockstrap_demo_pages';
    581             $page_status = get_option( $option_key );
     738            $page_status = blockstrap_get_option( $option_key );
    582739            $page_id     = $this->demo_page_exists( $page_slug );
    583740
     
    587744                    wp_trash_post( $page_id );
    588745                    unset( $page_status[ $theme_slug ][ $page_slug ] );
    589                     update_option( $option_key, $page_status );
     746                    blockstrap_update_option( $option_key, $page_status );
    590747                }
    591748
     
    595752            } else {
    596753                if ( ! $page_id ) {
    597                     $page_id = $this-> add_demo_page( $page );
     754                    $page_id = $this->add_demo_page( $page );
    598755
    599756                    if ( is_wp_error( $page_id ) ) {
     
    617774
    618775    /**
    619      * Add a demo page from arguments.
    620      *
    621      * @param $page
    622      *
    623      * @return false|int|WP_Error
    624      */
    625     public function add_demo_page( $page ) {
    626 
    627         $theme_slug  = get_template();
    628         $option_key  = 'blockstrap_demo_pages';
    629         $page_status = get_option( $option_key );
    630         $page_slug   = esc_attr( $page['slug'] );
    631 
    632         $page_id = wp_insert_post(
    633             array(
    634                 'post_title'   => $page['title'],
    635                 'post_name'    => $page['slug'],
    636                 'post_content' => $page['desc'],
    637                 'post_status'  => 'publish',
    638                 'post_type'    => 'page',
    639             )
    640         );
    641 
    642         if ( is_wp_error( $page_id ) ) {
    643             return false;
    644         }else{
    645             $page_status[ $theme_slug ][ $page_slug ] = $page_id;
    646             update_option( $option_key, $page_status );
    647 
    648             if ( ! empty( $page['is_blog'] ) ) {
    649                 update_option( 'page_for_posts', $page_id );
    650                 update_option('show_on_front', 'page');
    651 
    652                 if ( ! get_option( 'page_on_front' ) ) {
    653                     update_option( 'page_on_front', 2 ); // if page on front not set then it will show blog page on front.
    654                 }
    655             } elseif ( ! empty( $page['is_front'] ) ) {
    656                 update_option( 'page_on_front', $page_id ); // this is probably not needed as the theme can set the front page anyway.
    657                 update_option('show_on_front', 'page');
    658             }
    659         }
    660 
    661         return $page_id;
    662 
    663 
    664     }
    665 
    666     /**
    667776     * The AJAX function that will save the recaptcha keys.
    668777     *
     
    677786            }
    678787
    679 
    680788            parse_str( $_POST['form_data'], $data );
    681 //          print_r($data );
    682 
    683             if(isset($data['site_key']) && isset($data['site_secret'])) {
    684                 update_option('blockstrap_recaptcha_keys',array(
    685                     'site_key' => sanitize_html_class($data['site_key']),
    686                     'site_secret' => sanitize_html_class($data['site_secret']),
    687                 ));
     789
     790            if ( isset( $data['site_key'] ) && isset( $data['site_secret'] ) ) {
     791                blockstrap_update_option(
     792                    'blockstrap_recaptcha_keys',
     793                    array(
     794                        'site_key'    => sanitize_html_class( $data['site_key'] ),
     795                        'site_secret' => sanitize_html_class( $data['site_secret'] ),
     796                    )
     797                );
    688798                wp_send_json_success( __( 'Keys Saved', 'blockstrap' ) );
    689             }else{
     799            } else {
    690800                wp_send_json_error( 'Something went wrong' );
    691801            }
    692 
    693802        } else {
    694803            wp_send_json_error( 'You do not have permission for this.' );
     
    698807    }
    699808
     809
     810    /**
     811     * Maybe update single options to our new one array of options.
     812     *
     813     * @return void
     814     */
     815    public function maybe_convert_options() {
     816            $options = blockstrap_get_options();
     817
     818        if ( empty( $options ) ) {
     819            $theme_slug = sanitize_title_with_dashes( $this->get_theme_title() );
     820
     821            $keys = array(
     822                'blockstrap_recaptcha_keys',
     823                'blockstrap_demo_pages_installed_' . $theme_slug,
     824                'directory_geodirectory_dismiss',
     825                'directory_theme_v3',
     826                'school_theme_v2',
     827            );
     828
     829            foreach ( $keys as $key ) {
     830                blockstrap_update_option( $key, get_option( $key ) );
     831            }
     832        }
     833    }
     834
    700835}
    701836
  • blockstrap/0.1.5/classes/class-blockstrap-theme-support.php

    r215341 r220756  
    2828
    2929        // load only if theme is not blockstrap
    30         if ( ! defined('BLOCKSTRAP_BLOCKS_VERSION' ) ) {
     30        if ( ! defined( 'BLOCKSTRAP_BLOCKS_VERSION' ) ) {
    3131            add_action( 'admin_notices', array( __CLASS__, 'plugin_notice' ) );
    3232        }
     
    4040    public static function plugin_notice() {
    4141
     42        // bail if the user should not be here
     43        if ( ! current_user_can( 'edit_theme_options' ) ) {
     44            return;
     45        }
     46
     47        // nonce check for dismiss action
     48        if ( isset( $_REQUEST['blockstrap_plugin_notice_dismiss'] ) ) {
     49            check_admin_referer( 'blockstrap_plugin_notice_dismiss' );
     50            blockstrap_update_option( 'blockstrap_plugin_notice_dismiss', time() );
     51        }
     52
     53        // bail if already dismissed
     54        if ( blockstrap_get_option( 'blockstrap_plugin_notice_dismiss' ) ) {
     55            return;
     56        }
     57
    4258        $pathpluginurl = WP_PLUGIN_DIR . '/blockstrap-page-builder-blocks/blockstrap-page-builder-blocks.php';
    4359
    4460        $installed = file_exists( $pathpluginurl );
    4561
     62        $dismiss_url = wp_nonce_url(
     63            add_query_arg(
     64                array(
     65                    'blockstrap_plugin_notice_dismiss' => 'true',
     66                )
     67            ),
     68            'blockstrap_plugin_notice_dismiss'
     69        );
     70
    4671        if ( $installed ) {
    4772
    48             $activate_url     = wp_nonce_url(
     73            $activate_url = wp_nonce_url(
    4974                add_query_arg(
    5075                    array(
    5176                        'action' => 'activate',
    52                         'plugin'  => 'blockstrap-page-builder-blocks/blockstrap-page-builder-blocks.php',
     77                        'plugin' => 'blockstrap-page-builder-blocks/blockstrap-page-builder-blocks.php',
    5378                    ),
    5479                    admin_url( 'plugins.php' )
     
    6287
    6388            printf(
    64                 '<div class="%1$s"><h3>%2$s</h3><p>%3$s</p><p><a href="%4$s" class="button button-primary">%5$s</a> </p></div>',
     89                '<div class="%1$s"><h3>%2$s</h3><p>%3$s</p><p><a href="%4$s" class="button button-primary">%5$s</a>  <a href="%6$s" class="">%7$s</a> </p></div>',
    6590                esc_attr( $class ),
    6691                esc_html( $name ),
    6792                esc_html( $install_message ),
    68                 esc_url_raw( $activate_url ),
    69                 esc_html__( 'Activate BlockStrap Blocks Plugin', 'blockstrap' )
    70             );
    71         }else{
    72             $install_url     = wp_nonce_url(
     93                esc_url( $activate_url ),
     94                esc_html__( 'Activate BlockStrap Blocks Plugin', 'blockstrap' ),
     95                esc_url( $dismiss_url ),
     96                esc_html__( 'Dismiss', 'blockstrap' )
     97            );
     98        } else {
     99            $install_url = wp_nonce_url(
    73100                add_query_arg(
    74101                    array(
    75102                        'action' => 'install-plugin',
    76                         'plugin'  => 'blockstrap-page-builder-blocks',
     103                        'plugin' => 'blockstrap-page-builder-blocks',
    77104                    ),
    78105                    admin_url( 'update.php' )
     
    94121            );
    95122        }
    96 
    97123
    98124    }
     
    189215
    190216        // Menus
    191 //      add_theme_support( 'menus' );
     217        //      add_theme_support( 'menus' );
    192218
    193219        // remove wp-container-X inline CSS helpers
  • blockstrap/0.1.5/functions.php

    r215341 r220756  
    2929
    3030function blockstrap_load_admin() {
     31    global $blockstrap_admin;
    3132    if ( is_admin() ) {
    3233        if ( class_exists( 'BlockStrap_Admin_Child' ) ) {
    33             new BlockStrap_Admin_Child();
    34         } else if ( class_exists( 'BlockStrap_Admin' ) ) {
    35             new BlockStrap_Admin();
     34            $blockstrap_admin = new BlockStrap_Admin_Child();
     35        } elseif ( class_exists( 'BlockStrap_Admin' ) ) {
     36            $blockstrap_admin = new BlockStrap_Admin();
    3637        }
    3738    }
    3839}
    3940add_action( 'after_setup_theme', 'blockstrap_load_admin' );
     41
     42// Helper functions
     43require_once 'inc/helper-functions.php';
    4044
    4145// Theme support.
  • blockstrap/0.1.5/inc/plugin-functions.php

    r189286 r220756  
    11<?php
    22
    3 // load only if theme is not blockstrap
    4 if ( defined( 'BLOCKSTRAP_BLOCKS_VERSION' ) && ! defined( 'GEODIRECTORY_VERSION' ) ) {
    5     add_action( 'admin_notices', 'blockstrap_theme_plugin_suggestions' );
    6 }
     3// add admin notice if required plugins not active/installed
     4add_action( 'admin_notices', 'blockstrap_theme_plugin_suggestions' );
    75
    86if ( ! function_exists( 'blockstrap_theme_plugin_suggestions' ) ) {
     
    1311     */
    1412    function blockstrap_theme_plugin_suggestions() {
     13        global $blockstrap_admin;
    1514
    16         if ( isset( $_REQUEST['blockstrap_geodirectory_dismiss'] ) && check_admin_referer( 'blockstrap_geodirectory_nonce' ) ) {
    17             update_option( 'blockstrap_geodirectory_dismiss', time() );
    18         }
    19 
    20         $no_gd = get_option( 'blockstrap_geodirectory_dismiss' );
    21 
    22         // if accepted v3 then bail
    23         if ( $no_gd ) {
     15        // Bail if not loaded
     16        if ( empty( $blockstrap_admin ) ) {
    2417            return;
    2518        }
    2619
    27         $install_url = wp_nonce_url(
    28             add_query_arg(
     20        $required_plugins_count = $blockstrap_admin->required_plugins_count();
     21
     22        if ( $required_plugins_count && (!isset($_REQUEST['page']) || ( isset($_REQUEST['page'])) && $_REQUEST['page'] !== 'blockstrap' ) ) {
     23            $setup_url = add_query_arg(
    2924                array(
    30                     'action' => 'install-plugin',
    31                     'plugin' => 'geodirectory',
     25                    'page' => 'blockstrap',
    3226                ),
    33                 admin_url( 'update.php' )
    34             ),
    35             'install-plugin_geodirectory'
    36         );
     27                admin_url( 'themes.php' )
     28            );
    3729
    38         $dismiss_url = wp_nonce_url(
    39             add_query_arg(
    40                 array(
    41                     'blockstrap_geodirectory_dismiss' => 1,
    42                 )
    43             ),
    44             'blockstrap_geodirectory_nonce'
    45         );
     30            printf(
     31                '<div class="%1$s"><h3 class="h5 font-bold mt-2">%2$s</h3><p>%3$s</p><p><a href="%4$s" class="button button-primary">%5$s</a></p></div>',
     32                'notice notice-warning is-dismissible',
     33                esc_attr( __( 'Required Plugins', 'blockstrap' ) ),
     34                /* translators: The theme active theme name */
     35                esc_html( sprintf( __( '%s theme requires some plugins for complete functionality', 'blockstrap' ), $blockstrap_admin->get_theme_title() ) ),
     36                esc_url_raw( $setup_url ),
     37                esc_html__( 'Setup Theme', 'blockstrap' )
     38            );
     39        }
    4640
    47         $class           = 'notice notice-info is-dismissible';
    48         $name            = __( 'GeoDirectory', 'blockstrap' );
    49         $install_message = __( 'BlockStrap works great with GeoDirectory to create a fast and modern listing directory.', 'blockstrap' );
    50 
    51         printf(
    52             '<div class="%1$s"><h3>%2$s</h3><p>%3$s</p><p><a href="%4$s" class="button button-primary">%5$s</a> <a href="%6$s" class="button button-secondary">%7$s</a> </p></div>',
    53             esc_attr( $class ),
    54             esc_html( $name ),
    55             esc_html( $install_message ),
    56             esc_url_raw( $install_url ),
    57             esc_html__( 'Install GeoDirectory', 'blockstrap' ),
    58             esc_url_raw( $dismiss_url ),
    59             esc_html__( 'No thanks', 'blockstrap' )
    60         );
    6141    }
    6242}
  • blockstrap/0.1.5/readme.txt

    r215341 r220756  
    44Requires at least: 6.0
    55Requires PHP: 7.2
    6 Version: 0.1.4
     6Version: 0.1.5
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414
    1515== Changelog ==
     16
     17= 0.1.5 =
     18* Required plugins flow changed slightly for better UX - CHANGED
     19* Helper functions introduced for getting and updating theme setting options - ADDED
    1620
    1721= 0.1.4 =
  • blockstrap/0.1.5/style.css

    r215341 r220756  
    44Author URI: https://ayecode.io
    55Theme URI: https://wpblockstrap.com
    6 Version: 0.1.4
     6Version: 0.1.5
    77Description: Introducing BlockStrap, a revolutionary WordPress theme that marries the streamlined agility of Bootstrap with the cutting-edge functionality of WordPress Full Site Editing (FSE). Crafted for performance, BlockStrap is all about simplicity, speed, and elegance. With Bootstrap's responsive design and WordPress FSE's real-time customization, you can effortlessly create a stunning look across all devices. Its lightweight build ensures rapid loading times, while a plethora of customization options allows for a unique expression of your brand's identity. Whether you're an individual, business, or creative agency, BlockStrap's blend of design and functionality offers a modern and efficient solution for your online presence. Explore the endless possibilities with BlockStrap today!
    88Tags: full-site-editing, blog, food-and-drink, two-columns, editor-style, block-styles
Note: See TracChangeset for help on using the changeset viewer.