Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Make 'string' the default $type and do not save the default. This reduces the number of options/meta rows substantially compared to v1.x.
  • Loading branch information
knutsp authored May 13, 2023
1 parent ef839b2 commit 5ccfca6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core-ticket-55942.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: Set data type in db for options/meta
* Description: Demo add/updating and getting options/meta as proposed by knutsp in https://core.trac.wordpress.org/ticket/55942#comment:78.
* Plugin URI: https://nettvendt.no/
* Version: 1.1
* Version: 2.0
* Author: Knut Sparhell
* Author URI: https://profiles.wordpress.org/knutsp/
* Requires at least: 6.2
Expand Down Expand Up @@ -265,7 +265,7 @@
<input type="checkbox" name="values[]" value="123"/> 123<br/>
<input type="checkbox" name="values[]" value="0246"/> 0246<br/>
<input type="checkbox" name="values[]" value="<?php echo \pi(); ?>" title="pi"/> <?php echo \pi(); ?><br/>
<input type="checkbox" name="values[]" value="4-four"/> '4-four'<br/>
<input type="checkbox" name="values[]" value="4-four"/> 4-four<br/>
<input type="checkbox" name="values[]" value="E12"/> E12<br/>
<input type="checkbox" name="values[]" value="some text"/> some text<br/>
<label>
Expand Down
6 changes: 3 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function update_option( string $option, $value, $autoload = null, ?string $type
}
$upd = \update_option( $option, $value, $autoload );

if ( $upd && $type ) {
if ( $upd && ! \str_contains( $type, 'str' ) ) {
\update_option( $type_prefix . $option, $type, $autoload );
}
return (bool) $upd;
Expand Down Expand Up @@ -98,7 +98,7 @@ function add_term_meta( int $term_id, string $meta_key, $meta_value, bool $uniqu
}
$res = \add_term_meta( $term_id, $meta_key, $meta_value );

if ( $no_pre && ! \is_wp_error( $res ) && $type ) {
if ( $no_pre && ! \is_wp_error( $res ) && ! \str_contains( $type, 'str' ) ) {
\update_term_meta( $term_id, $type_prefix . $meta_key, $type );
}
return $res;
Expand All @@ -117,7 +117,7 @@ function update_term_meta( int $term_id, string $meta_key, $meta_value, ?string
}
$res = \update_term_meta( $term_id, $meta_key, $meta_value, $prev_value );

if ( ! \is_wp_error( $res ) && $type ) {
if ( ! \is_wp_error( $res ) && ! \str_contains( $type, 'str' ) ) {
\update_term_meta( $term_id, $type_prefix . $meta_key, $type );
}
return $res;
Expand Down

0 comments on commit 5ccfca6

Please sign in to comment.