Skip to content

Commit

Permalink
fix for new installation with autorefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Feb 2, 2024
1 parent 2b10baa commit f995898
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '83a72e27f0da141aa26b');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '94f22d7c390e2dee9f8b');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions simpletoc-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function simpletoc_register_settings() {
$accordion_enabled_filter = apply_filters('simpletoc_accordion_enabled', null);
$smooth_enabled_filter = apply_filters('simpletoc_smooth_enabled', null);
$absolute_urls_enabled_filter = apply_filters('simpletoc_absolute_urls_enabled', null);
$autoupdate_enabled_filter = apply_filters('simpletoc_autoupdate_enabled', null);

if ($wrapper_enabled_filter === null) {
register_setting('simpletoc_settings', 'simpletoc_wrapper_enabled');
Expand All @@ -56,14 +57,8 @@ function simpletoc_register_settings() {
register_setting('simpletoc_settings', 'simpletoc_absolute_urls_enabled');
}

// Register setting for autoupdate feature
$autoupdate_enabled_filter = apply_filters('simpletoc_autoupdate_enabled', null);
if ($autoupdate_enabled_filter === null) {
$defaults = array(
'show_in_rest' => true,
'default' => true
);
register_setting('simpletoc_settings', 'simpletoc_autoupdate_enabled', $defaults );
register_setting('simpletoc_settings', 'simpletoc_autoupdate_enabled', array( 'show_in_rest' => true ) );
}

// Add settings sections and fields
Expand Down Expand Up @@ -109,7 +104,7 @@ function simpletoc_register_settings() {
// Add the autoupdate settings field
add_settings_field(
'simpletoc_autoupdate_enabled',
__('Enable TOC Autoupdate', 'simpletoc'),
__('Force no auto refresh', 'simpletoc'),
'simpletoc_autoupdate_enabled_callback',
'simpletoc',
'simpletoc_wrapper_section'
Expand Down Expand Up @@ -168,7 +163,7 @@ function simpletoc_absolute_urls_enabled_callback()

function simpletoc_autoupdate_enabled_callback()
{
$autoupdate_enabled = get_option('simpletoc_autoupdate_enabled', true);
$autoupdate_enabled = get_option('simpletoc_autoupdate_enabled', false);
echo '<input type="checkbox" name="simpletoc_autoupdate_enabled" id="simpletoc_autoupdate_enabled" value="1" ' . checked(1, $autoupdate_enabled, false) . ' />';
echo '<label for="simpletoc_autoupdate_enabled" class="description">' . __('Automatic updating of the table of contents.', 'simpletoc') . '</label>';
echo '<label for="simpletoc_autoupdate_enabled" class="description">' . __('Deactivate the automatic table of contents refresh feature.', 'simpletoc') . '</label>';
}
7 changes: 5 additions & 2 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ import './accordion.css';
export default function Edit( { attributes, setAttributes } ) {
const blockProps = useBlockProps();

// Get the current option value.
// Get the autoupdate option from WordPress php.
const autoupdateOption = useSelect( ( select ) => {
const optionValue =
select( 'core' ).getSite()?.simpletoc_autoupdate_enabled;
return Boolean( optionValue ); // or use !!optionValue
if ( optionValue !== 1 ) {
return true;
}
return false;
}, [] );

const { autoupdate } = attributes;
Expand Down

0 comments on commit f995898

Please sign in to comment.