Add an additional field at "Actions" #3575
Replies: 2 comments
-
|
I would like to ask for the same thing. Is there a plugin that could achieve this or could one be made for it? Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
YOURLS doesn't have a built-in "Notes" field, but you can add one through a custom plugin using YOURLS's hook system. This involves three things: storing the extra field in the database, hooking into the edit form to display it, and hooking into the save action to persist it. Step 1 — Create the database columnThe notes value needs somewhere to live. YOURLS's Step 2 — The complete pluginCreate the folder <?php
/*
Plugin Name: Notes Field
Plugin URI: https://yourls.org/
Description: Adds a Notes field to the URL add/edit form
Version: 1.0
Author: You
*/
if ( !defined( 'YOURLS_ABSPATH' ) ) die();
// --- Activation: add the column if it doesn't exist ---
yourls_add_action( 'activated_plugin', 'notes_field_activate' );
function notes_field_activate() {
global $ydb;
$table = YOURLS_DB_TABLE_URL;
$ydb->query( "ALTER TABLE `$table` ADD COLUMN IF NOT EXISTS `notes` TEXT DEFAULT NULL" );
}
// --- Display: inject the Notes field into the Edit modal ---
yourls_add_action( 'edit_link_form_pre_submit', 'notes_field_edit_form' );
function notes_field_edit_form( $args ) {
$keyword = $args[0];
$notes = yourls_get_keyword_notes( $keyword );
echo '<label for="edit-notes">Notes</label>';
echo '<textarea id="edit-notes" name="edit_notes" rows="3" style="width:100%">'
. esc_html( $notes )
. '</textarea>';
}
// --- Save: persist the Notes field when a link is edited ---
yourls_add_action( 'edit_link', 'notes_field_save' );
function notes_field_save( $args ) {
global $ydb;
$keyword = $args[0];
$notes = isset( $_POST['edit_notes'] ) ? sanitize_text_field( $_POST['edit_notes'] ) : '';
$table = YOURLS_DB_TABLE_URL;
$ydb->query(
$ydb->prepare(
"UPDATE `$table` SET `notes` = %s WHERE `keyword` = %s",
$notes,
$keyword
)
);
}
// --- Helper: fetch notes for a given keyword ---
function yourls_get_keyword_notes( $keyword ) {
global $ydb;
$table = YOURLS_DB_TABLE_URL;
$row = $ydb->get_row(
$ydb->prepare(
"SELECT `notes` FROM `$table` WHERE `keyword` = %s",
$keyword
)
);
return $row ? $row->notes : '';
}Step 3 — Install and activate
Step 4 — Verify it works
How it works (summary)
Hope this helps — if it answers your question, would you mind clicking "Mark as answer" so others searching for the same thing can find it quickly? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello together,
Can someone help me to add a 4th field in URL editing?
The URL editing has 3 fields:
Long URL
Short-URL
Title
+new field "Notes"
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions