Skip to content

Commit

Permalink
Merge pull request #138 from philbuchanan/#137
Browse files Browse the repository at this point in the history
Properly set default globally load scripts setting (#137)
  • Loading branch information
philbuchanan authored May 27, 2021
2 parents 8b4307e + 2efb868 commit 4a2f9e8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 55 deletions.
57 changes: 39 additions & 18 deletions accordion-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Accordion Blocks
* Plugin URI: https://github.com/philbuchanan/Accordion-Blocks
* Description: Gutenberg blocks for creating responsive accordion drop-downs.
* Version: 1.3.4
* Version: 1.3.5
* Requires at least: 5.5
* Author: Phil Buchanan
* Author URI: https://philbuchanan.com
Expand Down Expand Up @@ -112,9 +112,9 @@ public function enqueue_editor_assets() {
* Enqueue the block's assets for the frontend
*/
public function enqueue_frontend_assets() {
$load_scripts_globablly = get_option('accordion_blocks_load_scripts_globablly');
$load_scripts_globally = $this->should_load_scripts_globally();

if ($load_scripts_globablly || has_block('pb/accordion-item', get_the_ID())) {
if ($load_scripts_globally || has_block('pb/accordion-item', get_the_ID())) {
$min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';

wp_enqueue_script(
Expand Down Expand Up @@ -188,10 +188,10 @@ public function register_settings() {

register_setting(
'accordion_blocks_settings',
'accordion_blocks_load_scripts_globablly',
'accordion_blocks_load_scripts_globally',
array(
'type' => 'boolean',
'default' => true,
'default' => 'on',
)
);
}
Expand Down Expand Up @@ -283,6 +283,27 @@ public function add_documentation_link($links) {



/**
* Get the load_scripts_globally option and return true or false.
*/
private function should_load_scripts_globally() {
/**
* This removes the old option (the option name had a typo), but ensures
* the new option gets updated with the same setting.
*/
if (get_option('accordion_blocks_load_scripts_globablly') == 'on') {
update_option('accordion_blocks_load_scripts_globally', 'on');
}

delete_option('accordion_blocks_load_scripts_globablly');

$load_scripts_globally = get_option('accordion_blocks_load_scripts_globally', 'on');

return !!$load_scripts_globally;
}



/**
* Add the admin menu settings page
*/
Expand Down Expand Up @@ -332,13 +353,13 @@ public function settings_api_init() {
);

add_settings_field(
'accordion_blocks_load_scripts_globablly',
'accordion_blocks_load_scripts_globally',
__('Scripts and Styles', 'accordion-blocks'),
array($this, 'load_scripts_globablly_setting_callback'),
array($this, 'load_scripts_globally_setting_callback'),
'accordion_blocks_settings',
'accordion_blocks_global_settings_section',
array(
'label_for' => 'accordion_blocks_load_scripts_globablly',
'label_for' => 'accordion_blocks_load_scripts_globally',
)
);
}
Expand All @@ -356,28 +377,28 @@ public function accordion_blocks_global_settings_section_callback() {}
/**
* Callback function for load scripts globally setting
*/
public function load_scripts_globablly_setting_callback() {
$load_scripts_globablly = get_option('accordion_blocks_load_scripts_globablly'); ?>
public function load_scripts_globally_setting_callback() {
$load_scripts_globally = $this->should_load_scripts_globally(); ?>
<fieldset>
<legend class="screen-reader-text">
<span><?php _e('Scripts and Styles', 'accordion-blocks'); ?></span>
</legend>
<label for="accordion_blocks_load_scripts_globablly">
<label for="accordion_blocks_load_scripts_globally">
<input
type="checkbox"
id="accordion_blocks_load_scripts_globablly"
name="accordion_blocks_load_scripts_globablly"
aria-describedby="load-scripts-globablly"
<?php checked($load_scripts_globablly == 'on'); ?>
id="accordion_blocks_load_scripts_globally"
name="accordion_blocks_load_scripts_globally"
aria-describedby="load-scripts-globally"
<?php checked($load_scripts_globally); ?>
>
<?php _e('Load scripts and styles globablly', 'accordion-blocks'); ?>
<?php _e('Load scripts and styles globally', 'accordion-blocks'); ?>
</label>
<div id="load-scripts-globablly">
<div id="load-scripts-globally">
<p class="description">
<?php _e('Turning this off may cause accordions to stop working in some instances.', 'accordion-blocks'); ?>
</p>
<p class="description">
<?php _e('Leave this on if you use accordions outside of the main content editor, or are adding accordions programatically.', 'accordion-blocks'); ?>
<?php _e('Turn this on if you use accordions outside of the main content editor, or are adding accordions programatically.', 'accordion-blocks'); ?>
</p>
</div>
</fieldset>
Expand Down
46 changes: 11 additions & 35 deletions languages/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Accordion Blocks\n"
"POT-Creation-Date: 2021-04-08 09:52-0400\n"
"POT-Creation-Date: 2021-05-27 12:31-0400\n"
"PO-Revision-Date: 2020-04-06 18:05-0400\n"
"Last-Translator: Phil Buchanan <info@philbuchanan.com>\n"
"Language-Team: Phil Buchanan\n"
Expand All @@ -25,60 +25,36 @@ msgstr ""
msgid "Donate"
msgstr ""

#: ../accordion-blocks.php:291 ../accordion-blocks.php:310
#: ../accordion-blocks.php:312 ../accordion-blocks.php:331
msgid "Accordion Blocks Settings"
msgstr ""

#: ../accordion-blocks.php:292
#: ../accordion-blocks.php:313
msgid "Accordion Blocks"
msgstr ""

#: ../accordion-blocks.php:306 ../inc/admin-page.php:24
#: ../accordion-blocks.php:327
msgid "You do not have sufficient permissions to access this page."
msgstr ""

#: ../accordion-blocks.php:329
#: ../accordion-blocks.php:350
msgid "Global Settings"
msgstr ""

#: ../accordion-blocks.php:336 ../accordion-blocks.php:363
#: ../accordion-blocks.php:357 ../accordion-blocks.php:384
msgid "Scripts and Styles"
msgstr ""

#: ../accordion-blocks.php:373
msgid "Load scripts and styles globablly"
#: ../accordion-blocks.php:394
msgid "Load scripts and styles globally"
msgstr ""

#: ../accordion-blocks.php:377
#: ../accordion-blocks.php:398
msgid "Turning this off may cause accordions to stop working in some instances."
msgstr ""

#: ../accordion-blocks.php:380
msgid "Leave this on if you use accordions outside of the main content editor, or are adding accordions programatically."
msgstr ""

#: ../inc/admin-page.php:8 ../inc/admin-page.php:9 ../inc/admin-page.php:28
msgid "Theme Settings"
msgstr ""

#: ../inc/admin-page.php:47
msgid "Google Maps Settings"
msgstr ""

#: ../inc/admin-page.php:54
msgid "Google Maps API Key"
msgstr ""

#: ../inc/admin-page.php:65
msgid "Google Maps Pin Color"
msgstr ""

#: ../inc/admin-page.php:110
msgid "Learn how to get a Google Maps API key"
msgstr ""

#: ../inc/admin-page.php:137
msgid "A hex color value (e.g. #acd123) to use as the default Google Maps marker pin color."
#: ../accordion-blocks.php:401
msgid "Turn this on if you use accordions outside of the main content editor, or are adding accordions programatically."
msgstr ""

#: ../src/block/edit.js:161 ../src/block/edit.js:171
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "accordion-blocks",
"version": "1.3.4",
"version": "1.3.5",
"description": "Gutenberg blocks for creating responsive accordion drop-downs.",
"main": "src/index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate Link: https://philbuchanan.com/donate/
Tags: accordion, accordions, gutenberg, block, responsive
Requires at least: 5.5
Tested up to: 5.7
Stable tag: 1.3.4
Stable tag: 1.3.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -89,6 +89,9 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
2. Accordion block in the editor

== Changelog ==
= 1.3.5 =
* Fixed: An issue where the global loading of scripts and styles checkbox was checked when the setting was actually off.

= 1.3.4 =
* Fixed: Made turning off global loading of scripts and styles an explicit setting. You can turn off this off in Settings > Accordion Blocks.

Expand Down Expand Up @@ -172,6 +175,9 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
* All new plugin to support the new WordPress Gutenberg editor.

== Upgrade Notice ==
= 1.3.5 =
Fixed an issue where the global loading of scripts and styles checkbox was checked when the setting was actually off.

= 1.3.4 =
Made turning off global loading of scripts and styles an explicit setting. You can turn off this off in Settings > Accordion Blocks.

Expand Down

0 comments on commit 4a2f9e8

Please sign in to comment.