Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all actions and filters from Options class to wrapper functions #3687

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions includes/Database/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public function get_all_options() {
$this->ydb->set_option($name, yourls_maybe_unserialize($value));
}

yourls_apply_filter('get_all_options', 'deprecated');

return true;
}

Expand Down Expand Up @@ -172,7 +170,7 @@ public function update($name, $newvalue) {

// Cache option value to save a DB query if needed later
$this->ydb->set_option($name, $newvalue);
yourls_do_action( 'update_option', $name, $oldvalue, $newvalue );

return true;
}

Expand Down Expand Up @@ -217,7 +215,6 @@ public function add($name, $value) {

// Cache option value to save a DB query if needed later
$this->ydb->set_option($name, $value);
yourls_do_action('add_option', $name, $_value);

return true;
}
Expand Down Expand Up @@ -246,7 +243,6 @@ public function delete($name) {
return false;
}

yourls_do_action('delete_option', $name);
$this->ydb->delete_option($name);
return true;
}
Expand Down
18 changes: 14 additions & 4 deletions includes/functions-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ function yourls_get_all_options() {
// Allow plugins to short-circuit all options. (Note: regular plugins are loaded after all options)
$pre = yourls_apply_filter( 'shunt_all_options', false );
if ( false !== $pre ) {
return $pre;
return;
}

$options = new \YOURLS\Database\Options(yourls_get_db());
$value = $options->get_all_options();

if ($options->get_all_options() === false) {
if ($value === false) {
// Zero option found but no unexpected error so far: YOURLS isn't installed
yourls_set_installed(false);
return;
}

yourls_do_action( 'get_all_options', $value );

yourls_set_installed(true);
}

Expand All @@ -67,8 +70,11 @@ function yourls_get_all_options() {
* @return bool False if value was not updated, true otherwise.
*/
function yourls_update_option( $option_name, $newvalue ) {
$option = new \YOURLS\Database\Options(yourls_get_db());
$update = $option->update($option_name, $newvalue);
$option = new \YOURLS\Database\Options(yourls_get_db());
$update = $option->update($option_name, $newvalue);
$oldvalue = $oldvalue = yourls_get_option($option_name);

yourls_do_action( 'update_option', $option_name, $oldvalue, $newvalue, $update );

return $update;
}
Expand All @@ -87,6 +93,8 @@ function yourls_add_option( $name, $value = '' ) {
$option = new \YOURLS\Database\Options(yourls_get_db());
$add = $option->add($name, $value);

yourls_do_action( 'add_option', $name, $value, $add );

return $add;
}

Expand All @@ -103,6 +111,8 @@ function yourls_delete_option( $name ) {
$option = new \YOURLS\Database\Options(yourls_get_db());
$delete = $option->delete($name);

yourls_do_action( 'delete_option', $name, $delete );

return $delete;
}

Expand Down