Skip to content

Commit 3260303

Browse files
committed
Add Options::getOption returning an OptionData
This can be used to replace the logic in getValue and getBlobValue.
1 parent 0ca2f57 commit 3260303

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/Options.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,43 @@ public static function seedOptions(
390390
}
391391
}
392392

393+
public static function getOption(
394+
OptionSpec $option_spec,
395+
): OptionData {
396+
$name = $option_spec->name;
397+
$option_lookups = ( $name !== 'debugLogging' );
398+
WsLog::l(
399+
"Getting value of option: $name",
400+
$level = 'debug',
401+
$option_lookups = $option_lookups,
402+
);
403+
404+
global $wpdb;
405+
406+
$table_name = self::getTableName();
407+
408+
$sql = $wpdb->prepare(
409+
"SELECT value,blob_value FROM $table_name WHERE name=%s",
410+
$name
411+
);
412+
413+
$row = $wpdb->get_row( $sql );
414+
415+
if ( $row ) {
416+
return new OptionData(
417+
$option_spec,
418+
$row->blob_value,
419+
$row->value,
420+
);
421+
} else {
422+
return new OptionData(
423+
$option_spec,
424+
null,
425+
null,
426+
);
427+
}
428+
}
429+
393430
/**
394431
* Get option value by name
395432
* Works for core options, but doesn't recognize addon options.

0 commit comments

Comments
 (0)