How to add a default value to get_option if it’s used as a variable?

So I originally suggested normalizing the options array; i.e. merging saved values with the default values. And this does solve the “undefined index” notice: $my_options = wp_parse_args( get_option( ‘my_options’ ), [ ‘my_background_color_option’ => ‘#000’, // … other args. ] ); But to make sure that an option is not empty (e.g. not ”, false, null, … Read more

When to call add_filter

Yes, you can do this like that. You can call foo_init_setup on init or on wp hook and it will work just fine. I would call it as late as possible, I guess. This way you won’t affect loading time for requests that don’t end with page rendering (for example when template_redirect is used for … Read more

Prevent shortcode from being wrapped in tags

Instead of trying to remove the automatically added paragraphs before or after the fact, you can try removing the wpautop filter from the_content within your shortcode (and re-adding it to maintain consistency for other plugins etc.): add_shortcode( ‘test’, ‘test_sc’ ); function test_sc( $atts ){ remove_filter( ‘the_content’, ‘wpautop’ ); $content = apply_filters( ‘the_content’, ‘$\frac{15}{5} = 3$’ … Read more

Duplicate Settings Plugin, Independent & Separate by Tab

Essentially what you can do is add an identifier for each ‘tab’ and then save it in a multidimensional array, this is a neat trick that inputs can do and works great for WordPress plugins that uses tabs. <form id=”form_1″> <div class=”tab_1″> <input type=”text” name=”tab1[‘fieldname_0’]” value=”tab_1_0″> <input type=”text” name=”tab1[‘fieldname_1’]” value=”tab_1_1″> <input type=”text” name=”tab1[‘fieldname_2’]” value=”tab_1_2″> <input … Read more