Disabling shortcodes
Hello!
I'm trying to add an option to disable shortcodes using admin panel, here is my code from /extensions/shortcodes/hooks.php:
function _filter_disable_unyson_shortcodes( $to_disable ) {
$to_disable[] = 'call_to_action';
$to_disable[] = 'icon';
$to_disable[] = 'icon_box';
$to_disable[] = 'team_member';
$to_disable[] = 'notification';
$to_disable = array_merge( $to_disable, fw_get_db_settings_option( 'disabled_unyson_shortcodes' ) );
return $to_disable;
}
add_filter( 'fw_ext_shortcodes_disable_shortcodes', '_filter_disable_unyson_shortcodes' );
this code causes an error: Undefined option type: table in admin panel, but if i remove this string, all works fine:
$to_disable = array_merge( $to_disable, fw_get_db_settings_option( 'disabled_unyson_shortcodes' ) );
it seems it is impossible to use fw_get_db_settings_option function in disable shortcodes hook?
Thank you in advance
Please add fw_print($to_disable); before return $to_disable; and provide the screenshot (or the output code).
Hi, MoldCraft!
Please look at screenshots, the first is a result of following code:
//$to_disable[] = 'calendar';
$to_disable[] = 'call_to_action';
$to_disable[] = 'icon';
$to_disable[] = 'icon_box';
$to_disable[] = 'team_member';
$to_disable[] = 'notification';
fw_print($to_disable);
return $to_disable;
the second:
//$to_disable[] = 'calendar';
$to_disable[] = 'call_to_action';
$to_disable[] = 'icon';
$to_disable[] = 'icon_box';
$to_disable[] = 'team_member';
$to_disable[] = 'notification';
$to_disable = array_merge( $to_disable, fw_get_db_settings_option( 'disabled_unyson_shortcodes' ) );
fw_print($to_disable);
return $to_disable;

- Do you use option-type
tablein Theme Settings? - It will be faster if I will debug the code. Can you send me your admin and ftp credentials to
moldcraft[at]email.com?
No, i don't use Table option type in theme settings, i have table shortcode overridden only, but if i remove it from framework-customizations directory, the problem remains.
I develop website locally, so sorry, i can't get FTP access
- This happens with default WP theme?
- Can you zip your theme and send me the download link to
moldcraft[at]email.com?
Sorry for a long-time response, it is possible that we work in different time zones :)
I have uploaded test theme with a minimal code to reproduce, please download it here
How to reproduce an error:
- Activate "Test" theme
- Go to Appearance > Theme settings and disable "Widget area" shortcode
- Go to Pages screen and try to edit any page or create new one

@moldcraft could you take a look at my previous message please
- Here shortcodes are not loaded yet.
- In filter you call
fw_get_db_settings_option()which requires option-types and option-types are initialized. - Here the shortcodes are loaded (the
tableshortcode too). But this action in table shortcode will never be executed because option-types were already loaded. tableshortcode has in optionstableoption-type which causes the warning.
Thinking a solution...
@moldcraft thank you for looking! Maybe it will be better to use get_option instead of fw_get_db_settings_option
That definitely will work. I don't have any idea at the moment how to fix this
Thank you for your time, @moldcraft
If someone else needs a solution:
Theme options code:
'disabled_shortcodes' => array(
'type' => 'multi-select',
'value' => array(),
'label' => __('Disable Shortcodes', 'textdomain'),
'desc' => __('Check shortcodes to disable', 'textdomain'),
'population' => 'array',
'source' => '',
'prepopulate' => false,
'choices' => array(
'widget-area' => __('Widget area', 'textdomain')
),
'fw-storage' => array(
'type' => 'wp-option',
'wp-option' => 'disabled_shortcodes',
),
),
shortcodes hooks.php
function _filter_disable_unyson_shortcodes( $to_disable ) {
//$to_disable[] = 'calendar';
$to_disable[] = 'call_to_action';
$to_disable[] = 'icon';
$to_disable[] = 'icon_box';
$to_disable[] = 'team_member';
$to_disable[] = 'notification';
$to_disable = array_merge( $to_disable, get_option('disabled_shortcodes') );
return $to_disable;
}
add_filter( 'fw_ext_shortcodes_disable_shortcodes', '_filter_disable_unyson_shortcodes' );
Nice!
One note: The option name is very general disabled_shortcodes and it can conflict with some plugin. Better prefix it with your theme slug, so it will affect only your theme:
fw()->theme->manifest->get_id() .':disabled_shortcodes'
or
get_template() .':disabled_shortcodes'