{"id":421,"date":"2025-10-02T05:11:23","date_gmt":"2025-10-02T05:11:23","guid":{"rendered":"https:\/\/ska-blocks.com\/docs\/?p=421"},"modified":"2025-10-02T13:52:25","modified_gmt":"2025-10-02T13:52:25","slug":"filtering-options","status":"publish","type":"post","link":"https:\/\/ska-blocks.com\/docs\/filtering-options\/","title":{"rendered":"Filtering options"},"content":{"rendered":"\n<p>The <code>ska_plugin_get_options_{slug}<\/code> filter can be used to filter plugin and theme options:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Filtering ska-blocks plugin options<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">add_filter('ska_plugin_get_options_ska_blocks', function($options) {\n\tif(defined('WP_DEBUG') &amp;&amp; WP_DEBUG &amp;&amp; !is_admin() &amp;&amp; !wp_is_rest_endpoint()) {\n\t\t$options&#91;'styleCacheMode'] = 'off';\n\t}\n\treturn $options;\n});<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n\n\n\n<p>Note that the filter will also apply on the admin settings page, so with the <code>styleCacheMode<\/code> being set to <code>off<\/code>, the next time you edit and save settings the value will be written to the database &#8211; this is why the code also checks for <code>!is_admin() &amp;&amp; !wp_is_rest_endpoint()<\/code> to prevent that from happening.<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Filtering ska-theme theme options<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">add_filter('ska_plugin_get_options_ska_theme', function($options) {\n\t\/** Incorrect usage (always overrides the option value): *\/\n\t\/\/ $options&#91;'trackScrollPosition'] = is_singular('page') &amp;&amp; get_the_ID() === 123;\n\t\/** Correct usage (only overrides the option value when applicable): *\/\n\tif(is_singular('page') &amp;&amp; get_the_ID() === 123) {\t\n\t\t$options&#91;'trackScrollPosition'] = true;\n\t}\n\treturn $options;\n});<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The ska_plugin_get_options_{slug} filter can be used to filter plugin and theme options: Note that the filter will also apply on the admin settings page, so with the styleCacheMode being set to off, the next time you edit and save settings the value will be written to the database &#8211; this is why the code also&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/comments?post=421"}],"version-history":[{"count":3,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/421\/revisions"}],"predecessor-version":[{"id":425,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/421\/revisions\/425"}],"wp:attachment":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/media?parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/categories?post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/tags?post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}