Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Models\Traits;
use \WP_Ultimo\Objects\Note;
use WP_Ultimo\Objects\Note;
/**
* Singleton trait.
@ -33,14 +33,11 @@ trait Notable {
public function get_notes() {
if ($this->notes === null) {
$this->notes = get_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', false);
} // end if;
}
return $this->notes;
} // end get_notes;
}
/**
* Adds a new note to this model.
@ -52,25 +49,20 @@ trait Notable {
*/
public function add_note($note) {
if (!is_a($note, 'Note')) {
if ( ! is_a($note, 'Note')) {
$note = new Note($note);
} // end if;
}
$status = $note->validate();
if (is_wp_error($status)) {
return $status;
} // end if;
}
$status = add_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', $note, false);
return $status;
} // end add_note;
}
/**
* Remove all notes related to this model.
@ -83,8 +75,7 @@ trait Notable {
$status = delete_metadata($this->get_meta_data_table_name(), $this->get_id(), 'wu_note', '', true);
return $status;
} // end clear_notes;
}
/**
* Remove one note related to this model.
@ -104,9 +95,7 @@ trait Notable {
$mid = false;
foreach ($notes as $note) {
if ($note->note_id && $note->note_id === $note_id) {
global $wpdb;
$prefix = $wpdb->base_prefix;
@ -116,36 +105,27 @@ trait Notable {
$column_name = "wu_{$model}_id";
if ($model === 'site') {
$table_name = "{$wpdb->base_prefix}blogmeta";
$column_name = 'blog_id';
} // end if;
}
$mid = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM $table_name WHERE $column_name = %d AND meta_key = %s AND meta_value = %s", $this->get_id(), 'wu_note', maybe_serialize($note)), ARRAY_A); // phpcs:ignore
}
}
} // end if;
} // end foreach;
if (!$mid) {
if ( ! $mid) {
return false;
} // end if;
}
$status = delete_metadata_by_mid("wu_{$model}", $mid['meta_id']);
if ($model === 'site') {
$status = delete_metadata_by_mid('blog', $mid['meta_id']);
} // end if;
}
return $status;
} // end delete_note;
}
/**
* Returns the meta data meta table.
@ -160,12 +140,10 @@ trait Notable {
$query_class = new $this->query_class();
// Maybe apply table prefix
$table = !empty($query_class->prefix)
$table = ! empty($query_class->prefix)
? "{$query_class->prefix}_{$query_class->item_name}"
: $query_class->item_name;
return $table;
} // end get_meta_data_table_name;
} // end trait Notable;
}
}