Plugin Directory

Changeset 3318276


Ignore:
Timestamp:
06/26/2025 01:16:03 PM (9 months ago)
Author:
tomdevisser
Message:

Rebrand, modularize code, improve CPT support, and add column title setting

Location:
post-descriptions
Files:
17 added
19 edited

Legend:

Unmodified
Added
Removed
  • post-descriptions/tags/1.2.0/inc/add-post-states.php

    r2535676 r3318276  
    2929    $important_value = get_post_meta( $post->ID, 'important', true );
    3030    $html_output = '<textarea rows="5" class="components-form-token-field__input-container" name="post_description" style="margin-top: 16px;" placeholder="' . __('Your post description', 'post-descriptions') . '">' . esc_attr( $desc_value ) . '</textarea>';
    31     $html_output .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Make your description important', 'postdescriptions' ) . '</label>';
     31    $html_output .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Make your description important', 'post-descriptions' ) . '</label>';
    3232    echo $html_output;
    3333}
  • post-descriptions/tags/1.2.0/inc/add-quick-edit.php

    r2535689 r3318276  
    1616                    </label>
    1717                    <label class="align-left">
    18                     <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'postdescriptions' ) . '
     18                    <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post-descriptions' ) . '
    1919                    </label></div></fieldset>';
    2020    }
  • post-descriptions/tags/1.2.0/inc/register-admin-columns.php

    r2535676 r3318276  
    55function postdescriptions_add_description_column( $columns ) {
    66    $new_columns = array(
    7         '_description' => esc_html__('Description', 'postdescriptions'),
     7        '_description' => esc_html__('Description', 'post-descriptions'),
    88    );
    99    return array_merge( $columns, $new_columns );
  • post-descriptions/tags/1.2.1/inc/add-post-states.php

    r2535689 r3318276  
    2929    $important_value = get_post_meta( $post->ID, 'important', true );
    3030    $html_output = '<textarea rows="5" class="components-form-token-field__input-container" name="post_description" style="margin-top: 16px;" placeholder="' . __('Your post description', 'post-descriptions') . '">' . esc_attr( $desc_value ) . '</textarea>';
    31     $html_output .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Make your description important', 'postdescriptions' ) . '</label>';
     31    $html_output .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Make your description important', 'post-descriptions' ) . '</label>';
    3232    echo $html_output;
    3333}
  • post-descriptions/tags/1.2.1/inc/add-quick-edit.php

    r2535689 r3318276  
    1616                    </label>
    1717                    <label class="align-left">
    18                     <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'postdescriptions' ) . '
     18                    <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post-descriptions' ) . '
    1919                    </label></div></fieldset>';
    2020    }
  • post-descriptions/tags/1.2.1/inc/register-admin-columns.php

    r2535689 r3318276  
    55function postdescriptions_add_description_column( $columns ) {
    66    $new_columns = array(
    7         '_description' => esc_html__('Description', 'postdescriptions'),
     7        '_description' => esc_html__('Description', 'post-descriptions'),
    88    );
    99    return array_merge( $columns, $new_columns );
  • post-descriptions/trunk/README.md

    r2535672 r3318276  
    11# Post Descriptions
    22
    3 A very lightweight WordPress plugin that uses Post Status as a short description/to-do for your posts and pages.
     3Add lightweight descriptions and reminders to your posts and pages — perfect for notes, to-do’s, and team collaboration in the WordPress admin.
    44
    55## What does it do?
    66
    7 Post Descriptions lets you add descriptions to posts and pages, which lets you do things like adding small to-do's or don't-forget's for your team members or yourself.
     7Post Descriptions lets you attach short notes or descriptions to posts and pages — ideal for internal reminders, content planning, or small to-do's. Use it solo or with your team to stay organized directly in the WordPress admin.
    88
    99## How does it work?
    1010
    11 ### Adding post descriptions
     11### Adding Post Descriptions
    1212
    13 Post descriptions can be added from two places:
     13You can add descriptions in two ways:
    1414
    15 1. The Edit screen
    16 2. The Quick Edit screen
     151. From the full Edit screen
     162. From the Quick Edit menu in the post/page overview
    1717
    18 ### Checking Post Descriptions
     18### Viewing Post Descriptions
    1919
    20 You can check your post descriptions in two places:
     20Descriptions are visible in two places:
    2121
    22 1. In the column from your posts or pages admin overview
    23 2. As a post state (the bold text next to your page or post title)
     221. In a dedicated column in the Posts or Pages admin view
     232. As a post state — the bold label next to your post title
    2424
    25 ### Enabling/disabling Post States
     25### Customizing Display Options
    2626
    27 When you add longer descriptions, your admin might get a bit cluttered. In those cases you could disable showing post descriptions in post states with a simple checkbox.
    28 
    29 ### Enabling/disabling description columns
    30 
    31 When you only use short descriptions, you might not want the extra column. You can hide this column by clicking the "Screen Options" box in the top right of your screen and unchecking "Description".
     27- **Post States:** You can toggle whether descriptions appear as post states using a checkbox under Settings > Post Descriptions.
     28- **Column Visibility:** If you prefer a cleaner view, hide the Description column using the “Screen Options” tab in the top-right corner of your post/page list.
  • post-descriptions/trunk/inc/add-post-states.php

    r2735723 r3318276  
    11<?php
    22/**
    3 * This function will add the post states
    4 */
     3 * Adds and manages post descriptions as post meta.
     4 *
     5 * @package PostDescriptions
     6 */
     7
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Adds custom field support to all public post types, excluding system types.
     12 */
    513function postdescriptions_add_states() {
    6     add_post_type_support( 'post', 'custom-fields' );
    7     add_post_type_support( 'page', 'custom-fields' );
     14    $post_types = get_post_types(
     15        array(
     16            'show_ui' => true,
     17        ),
     18        'names'
     19    );
     20
     21    $excluded = array( 'attachment', 'revision', 'nav_menu_item', 'customize_changeset', 'custom_css' );
     22
     23    foreach ( $post_types as $post_type ) {
     24        if ( ! in_array( $post_type, $excluded, true ) ) {
     25            add_post_type_support( $post_type, 'custom-fields' );
     26        }
     27    }
    828}
    929add_action( 'init', 'postdescriptions_add_states' );
    1030
    11 // Add custom post meta
     31/**
     32 * Registers the meta box for post descriptions.
     33 */
     34/**
     35 * Registers the meta box for post descriptions.
     36 */
    1237function postdescriptions_add_states_post_meta() {
    13     add_meta_box(
    14         'post-description',
    15         __( 'Post Description', 'post-descriptions' ),
    16         'postdescriptions_post_description_meta_callback',
    17         array( 'post', 'page' ),
    18         'side',
    19         'default',
    20         null
     38    $post_types = get_post_types(
     39        array(
     40            'show_ui'  => true,
     41        ),
     42        'names'
    2143    );
     44
     45    $excluded = array( 'attachment', 'revision', 'nav_menu_item', 'customize_changeset', 'custom_css' );
     46
     47    foreach ( $post_types as $post_type ) {
     48        if ( ! in_array( $post_type, $excluded, true ) ) {
     49            add_meta_box(
     50                'post-description',
     51                __( 'Post Description', 'post-descriptions' ),
     52                'postdescriptions_post_description_meta_callback',
     53                $post_type,
     54                'side',
     55                'default',
     56                null
     57            );
     58        }
     59    }
    2260}
    2361add_action( 'add_meta_boxes', 'postdescriptions_add_states_post_meta' );
    2462
    25 // Custom post meta callbacks
     63/**
     64 * Outputs the post description meta box HTML.
     65 *
     66 * @param WP_Post $post The current post object.
     67 */
    2668function postdescriptions_post_description_meta_callback( $post ) {
    2769    wp_nonce_field( 'post_description_save_data', 'post_description_nonce' );
    2870    $desc_value      = get_post_meta( $post->ID, 'post_description', true );
    2971    $important_value = get_post_meta( $post->ID, 'important', true );
    30     $html_output     = '<textarea rows="5" class="components-form-token-field__input-container" name="post_description" style="margin-top: 16px;" placeholder="' . __( 'Your post description', 'post-descriptions' ) . '">' . esc_attr( $desc_value ) . '</textarea>';
    31     $html_output    .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Make your description important', 'postdescriptions' ) . '</label>';
     72    $html_output     = '<textarea rows="5" class="components-form-token-field__input-container" name="post_description" style="margin-top: 16px;" placeholder="' . __( 'Add a short description or note for this post', 'post-descriptions' ) . '">' . esc_attr( $desc_value ) . '</textarea>';
     73    $html_output    .= '<label for="important"><input type="checkbox" id="important" class="components-form-token-field__input-container" name="important-desc" value="1" ' . checked( 1, $important_value, false ) . ' />' . __( 'Highlight this description as important', 'post-descriptions' ) . '</label>';
    3274    echo $html_output;
    3375}
    3476
    35 // Save custom post description
     77/**
     78 * Saves the post description meta when the post is saved.
     79 *
     80 * @param int $post_id The ID of the post being saved.
     81 */
    3682function postdescriptions_save_postdescription( $post_id ) {
    37     // Checks the nonce for extra security
    3883    if ( ! isset( $_POST['post_description_nonce'] ) ) {
    3984        return;
    4085    }
     86
    4187    if ( ! wp_verify_nonce( $_POST['post_description_nonce'], 'post_description_save_data' ) ) {
    4288        return;
    4389    }
    4490
    45     // Doesn't save on autosave
    4691    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    4792        return;
    4893    }
    4994
    50     // Checks if user has the right capability to edit the page or post
    5195    if ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) {
    5296        if ( ! current_user_can( 'edit_page', $post_id ) ) {
     
    59103    }
    60104
    61     // Checks if there is input
    62105    if ( isset( $_POST['post_description'] ) ) {
    63         // Sanitizes the input and saves it to the post meta
    64106        $post_description = sanitize_text_field( $_POST['post_description'] );
    65107        update_post_meta( $post_id, 'post_description', $post_description );
     
    67109
    68110    if ( isset( $_POST['important-desc'] ) ) {
    69         // Saves the important checkbox value
    70111        update_post_meta( $post_id, 'important', $_POST['important-desc'] );
    71112    } else {
  • post-descriptions/trunk/inc/add-quick-edit.php

    r2735723 r3318276  
    11<?php
    22/**
    3 * Add post descriptions to the quick edit menu
    4 */
     3 * Adds support for editing post descriptions via the Quick Edit menu.
     4 *
     5 * @package PostDescriptions
     6 */
     7
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Adds post descriptions to the Quick Edit UI.
     12 *
     13 * @param string $column_name The name of the column to edit.
     14 * @param string $post_type   The current post type.
     15 */
    516function postdescriptions_add_quick_edit( $column_name, $post_type ) {
    617    if ( '_description' !== $column_name ) {
    718        return;
    8     } else {
    9         wp_nonce_field( 'post_description_quick_edit', 'post_description_nonce' );
    10         echo '<fieldset class="inline-edit-col-left">
    11                     <legend class="inline-edit-legend">' . __( 'Post Descriptions', 'post-descriptions' ) . '</legend>
    12                     <div class="inline-edit-col">
    13                     <label class="alignleft" style="width: 100%;">
    14                     <span class="title">' . __( 'Description', 'post-descriptions' ) . '</span>
    15                     <span class="input-text-wrap"><input type="text" name="' . $column_name . '" value="" style="width: 100%;"></span>
    16                     </label>
    17                     <label class="align-left">
    18                     <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'postdescriptions' ) . '
    19                     </label></div></fieldset>';
    2019    }
     20
     21    wp_nonce_field( 'post_description_quick_edit', 'post_description_nonce' );
     22    echo '<fieldset class="inline-edit-col-left">
     23        <legend class="inline-edit-legend">' . __( 'Post Descriptions', 'post-descriptions' ) . '</legend>
     24        <div class="inline-edit-col">
     25        <label class="alignleft" style="width: 100%;">
     26        <span class="title">' . __( 'Description', 'post-descriptions' ) . '</span>
     27        <span class="input-text-wrap"><input type="text" name="_description" value="" style="width: 100%;"></span>
     28        </label>
     29        <label class="alignleft">
     30        <input type="checkbox" name="important" value="1"/>' . __( 'Mark this description as important', 'post-descriptions' ) . '
     31        </label></div></fieldset>';
    2132}
    2233add_action( 'quick_edit_custom_box', 'postdescriptions_add_quick_edit', 10, 2 );
    2334
    24 // Save the custom field value from the quick edit box
     35/**
     36 * Saves post description data from the Quick Edit form.
     37 *
     38 * @param int $post_id The ID of the post being saved.
     39 */
    2540function postdescriptions_quick_edit_save( $post_id ) {
    26     // Checks the nonce for extra security
    2741    if ( ! isset( $_POST['post_description_nonce'] ) ) {
    2842        return;
    2943    }
     44
    3045    if ( ! wp_verify_nonce( $_POST['post_description_nonce'], 'post_description_quick_edit' ) ) {
    3146        return;
    3247    }
    33     // Doesn't save on autosave
     48
    3449    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    3550        return;
    3651    }
    37     // Checks if user has the right capability to edit the page or post
    38     if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
     52
     53    if ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) {
    3954        if ( ! current_user_can( 'edit_page', $post_id ) ) {
    4055            return;
     
    4661    }
    4762
    48     // Checks if there is input
    4963    if ( isset( $_POST['_description'] ) ) {
    50         // Sanitizes the input and saves it to the post meta
    5164        $post_description = sanitize_text_field( $_POST['_description'] );
    5265        update_post_meta( $post_id, 'post_description', $post_description );
    5366    }
     67
    5468    if ( isset( $_POST['important'] ) ) {
    5569        update_post_meta( $post_id, 'important', $_POST['important'] );
     
    5872    }
    5973}
    60 add_action( 'save_post_post', 'postdescriptions_quick_edit_save' );
    61 add_action( 'save_post_page', 'postdescriptions_quick_edit_save' );
    6274
    63 // Populate the custom field values at the quick edit box using Javascript
     75/**
     76 * Registers save_post hooks for Quick Edit support.
     77 */
     78function postdescriptions_register_quick_edit_hooks() {
     79    $post_types = get_post_types( array( 'show_ui' => true ), 'names' );
     80    $excluded   = array( 'attachment', 'revision', 'nav_menu_item', 'customize_changeset', 'custom_css' );
     81
     82    foreach ( $post_types as $post_type ) {
     83        if ( ! in_array( $post_type, $excluded, true ) ) {
     84            add_action( "save_post_{$post_type}", 'postdescriptions_quick_edit_save' );
     85        }
     86    }
     87}
     88add_action( 'init', 'postdescriptions_register_quick_edit_hooks' );
     89
     90/**
     91 * Outputs JavaScript to populate Quick Edit fields with post meta values.
     92 */
    6493function postdescriptions_populate_quick_edit() {
    6594    $current_screen = get_current_screen();
    66     if ( 'edit-post' !== $current_screen->id && 'edit-page' !== $current_screen->id ) {
     95    if ( false === strpos( $current_screen->id, 'edit-' ) ) {
    6796        return;
    6897    }
     98
    6999    wp_enqueue_script( 'jquery' );
    70100    ?>
    71101    <script type="text/javascript">
    72102        jQuery( function( $ ) {
    73             let $postdescriptions_inline_editor = inlineEditPost.edit;
     103            const $original_inline_edit = inlineEditPost.edit;
    74104            inlineEditPost.edit = function( id ) {
    75                 $postdescriptions_inline_editor.apply( this, arguments );
     105                $original_inline_edit.apply( this, arguments );
     106
    76107                let $post_id = 0;
    77                 if ( 'object' == typeof( id ) ) {
     108                if ( typeof id === 'object' ) {
    78109                    $post_id = parseInt( this.getId( id ) );
    79110                }
    80                 if ( 0 != $post_id ) {
    81                     let $edit_row = $( '#edit-' + $post_id );
    82                     let $post_row = $( '#post-' + $post_id );
    83                     let $post_state = $( '.post-state', $post_row )[0];
    84                     let $description = $( 'td.column-_description' );
    85                     console.log( $description[0].children[0] );
    86                     console.log( typeof $description );
    87                     let $descriptionText = $('.column-_description', $post_row ).text();
     111
     112                if ( $post_id > 0 ) {
     113                    const $edit_row = $( '#edit-' + $post_id );
     114                    const $post_row = $( '#post-' + $post_id );
     115                    const $descriptionCell = $( 'td.column-_description', $post_row );
     116                    const $descriptionText = $descriptionCell.text().trim();
    88117                    $( ':input[name="_description"]', $edit_row ).val( $descriptionText );
    89                     // Check if there is a post state, and if the post state contains a span with the 'important-state' class, or if the post states are disabled if the description has an 'important-state' class
    90                     if ( ( $description[0].children[0].classList.contains( 'important-state' ) || 'undefined' !== typeof $post_state && $post_state.children[0].classList.contains( 'important-state') ) ) {
    91                         $( ':input[name="important"]', $edit_row ).attr( 'checked', true );
     118
     119                    const isImportant = (
     120                        $descriptionCell.find('.important-state').length > 0 ||
     121                        $post_row.find('.post-state .important-state').length > 0
     122                    );
     123                    if ( isImportant ) {
     124                        $( ':input[name="important"]', $edit_row ).prop( 'checked', true );
    92125                    }
    93126                }
    94127            }
    95         } );
     128        });
    96129    </script>
    97130    <?php
  • post-descriptions/trunk/inc/admin-columns.php

    r2735723 r3318276  
    11<?php
    22/**
    3  * Populate the description column
     3 * Populates the custom column with post description data.
     4 *
     5 * @package PostDescriptions
     6 */
     7
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Outputs the post description in the custom column for posts and pages.
     12 *
     13 * @param string $column  The name of the column being displayed.
     14 * @param int    $post_id The ID of the current post.
    415 */
    516function postdescriptions_fill_description_column( $column, $post_id ) {
     
    718        return;
    819    }
    9     $description  = get_post_meta( $post_id, 'post_description', true );
    10     $custom_color = get_option( 'important-color' );
    11     $important_color;
    12     if ( $custom_color ) {
    13         $important_color = $custom_color;
    14     } else {
    15         $important_color = '#cc0000';
    16     }
     20
     21    $description         = get_post_meta( $post_id, 'post_description', true );
     22    $custom_color        = get_option( 'important-color' );
     23    $important_color     = $custom_color ? $custom_color : '#cc0000';
    1724    $escaped_description = esc_html( $description );
    1825    $important           = get_post_meta( $post_id, 'important', true );
     26
    1927    if ( '1' === $important ) {
    20         echo '<span class="important-state" style="color:' . $important_color . '; font-weight: bold;">' . $escaped_description . '</span>';
     28        echo '<span class="important-state" style="color:' . esc_attr( $important_color ) . '; font-weight: bold;">' . $escaped_description . '</span>';
    2129    } else {
    2230        echo '<span>' . $escaped_description . '</span>';
    2331    }
    2432}
    25 add_action( 'manage_posts_custom_column', 'postdescriptions_fill_description_column', 10, 2 );
    26 add_action( 'manage_page_posts_custom_column', 'postdescriptions_fill_description_column', 10, 2 );
     33
     34/**
     35 * Registers custom column content actions for supported post types.
     36 */
     37function postdescriptions_register_column_output_hooks() {
     38    $post_types = get_post_types( array( 'show_ui' => true ), 'names' );
     39    $post_types[] = 'post';
     40    $post_types[] = 'page';
     41
     42    foreach ( $post_types as $post_type ) {
     43        add_action( "manage_{$post_type}_posts_custom_column", 'postdescriptions_fill_description_column', 10, 2 );
     44    }
     45}
     46add_action( 'init', 'postdescriptions_register_column_output_hooks' );
  • post-descriptions/trunk/inc/register-admin-columns.php

    r2735723 r3318276  
    11<?php
    22/**
    3 * Adds a description column in the page and post overview
    4 */
     3 * Registers a custom column to display post descriptions in the admin overview.
     4 *
     5 * @package PostDescriptions
     6 */
     7
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Adds a description column to the post and page admin lists.
     12 *
     13 * @param array $columns Existing columns in the admin list.
     14 * @return array Modified columns including the description column.
     15 */
    516function postdescriptions_add_description_column( $columns ) {
     17    $column_title = get_option( 'column-title', __( 'Description', 'post-descriptions' ) );
     18
    619    $new_columns = array(
    7         '_description' => esc_html__( 'Description', 'postdescriptions' ),
     20        '_description' => esc_html( $column_title ),
    821    );
     22
     23    /**
     24     * Filter the columns added by Post Descriptions.
     25     *
     26     * @since 1.3.0
     27     *
     28     * @param array $new_columns Array of new columns to be added.
     29     */
     30    $new_columns = apply_filters( 'postdescriptions_new_columns', $new_columns );
     31
    932    return array_merge( $columns, $new_columns );
    1033}
    11 add_filter( 'manage_post_posts_columns', 'postdescriptions_add_description_column' );
    12 add_filter( 'manage_page_posts_columns', 'postdescriptions_add_description_column' );
     34
     35/**
     36 * Registers admin column filters for supported post types.
     37 */
     38function postdescriptions_register_description_column_filters() {
     39    $post_types = get_post_types( array( 'show_ui' => true ), 'names' );
     40    $post_types[] = 'post';
     41    $post_types[] = 'page';
     42
     43    foreach ( $post_types as $post_type ) {
     44        add_filter( "manage_{$post_type}_posts_columns", 'postdescriptions_add_description_column' );
     45    }
     46}
     47add_action( 'init', 'postdescriptions_register_description_column_filters' );
  • post-descriptions/trunk/inc/settings.php

    r2735723 r3318276  
    11<?php
    22/**
    3  * Custom options and settings
     3 * Register and render settings for the Post Descriptions plugin.
     4 *
     5 * @package PostDescriptions
     6 */
     7
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Registers plugin settings, sections, and fields.
    412 */
    513function postdescriptions_settings_init() {
    6     // Register settings
    714    register_setting( 'postdescriptions', 'description-states' );
    815    register_setting( 'postdescriptions', 'important-color' );
    9     // Adds settings sections
     16    register_setting( 'postdescriptions', 'column-title' );
     17
    1018    add_settings_section(
    1119        'postdescriptions_general',
     
    1422        'postdescriptions'
    1523    );
    16     // Adds settings fields
     24
    1725    add_settings_field(
    1826        'postdescriptions_show_state',
     
    2735        )
    2836    );
     37
    2938    add_settings_field(
    3039        'postdescriptions_important_color',
     
    3948        )
    4049    );
     50
     51    add_settings_field(
     52        'postdescriptions_column_title',
     53        __( 'Column Title', 'post-descriptions' ),
     54        'postdescriptions_column_title_cb',
     55        'postdescriptions',
     56        'postdescriptions_general',
     57        array(
     58            'label_for'                    => 'postdescriptions_column_title',
     59            'class'                        => 'postdescriptions_row',
     60            'postdescriptions_custom_data' => 'custom',
     61        )
     62    );
    4163}
    4264add_action( 'admin_init', 'postdescriptions_settings_init' );
    4365
    44 // A description for the settings section.
     66/**
     67 * Displays a description for the settings section.
     68 *
     69 * @param array $args Section arguments.
     70 */
    4571function postdescriptions_general_cb( $args ) {
    4672    ?>
    47     <p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Customize the way you want to display post descriptions.', 'post-descriptions' ); ?></p>
     73    <p id="<?php echo esc_attr( $args['id'] ); ?>">
     74        <?php esc_html_e( 'Customize how post descriptions behave and appear in your WordPress admin. Tweak the settings below to fit your workflow.', 'post-descriptions' ); ?>
     75    </p>
    4876    <?php
    4977}
    5078
    51 // Callback for the state option
     79/**
     80 * Renders the checkbox for showing post states.
     81 *
     82 * @param array $args Field arguments.
     83 */
    5284function postdescriptions_show_state_cb( $args ) {
    5385    ?>
    5486    <label for="postdescriptions_show_state">
    5587    <input type="checkbox" name="description-states" value="1" id="postdescriptions_show_state" <?php checked( 1, get_option( 'description-states' ), true ); ?>>
    56     <?php _e( 'If this box is checked, the post description will show up in a bold font behind the page or post title.', 'post-descriptions' ); ?>
     88    <?php _e( 'Show post descriptions as a bold post state next to the title. This is off by default, but you can enable it here.', 'post-descriptions' ); ?>
    5789    </label>
    5890    <?php
    5991}
    6092
    61 // Callback for the important color option
     93/**
     94 * Renders the input field for selecting an important color.
     95 *
     96 * @param array $args Field arguments.
     97 */
    6298function postdescriptions_important_color_cb( $args ) {
    6399    $color = get_option( 'important-color' );
    64100    ?>
    65     <input id="postdescriptions_important_color" class="color-picker" name="important-color" type="text" value="
    66     <?php
    67     if ( $color ) {
    68         echo $color;}
    69     ?>
    70     " />
     101    <input id="postdescriptions_important_color" class="color-picker" name="important-color" type="text" value="<?php echo esc_attr( $color ); ?>" />
     102    <p class="description"><?php esc_html_e( 'Set the text color for descriptions marked as important.', 'post-descriptions' ); ?></p>
    71103    <?php
    72104}
    73105
    74 // Add the menu page as a submenu to Settings
     106/**
     107 * Renders the input field for customizing the column title.
     108 *
     109 * @param array $args Field arguments.
     110 */
     111function postdescriptions_column_title_cb( $args ) {
     112    $title = get_option( 'column-title', __( 'Description', 'post-descriptions' ) );
     113    ?>
     114    <input id="postdescriptions_column_title" name="column-title" type="text" value="<?php echo esc_attr( $title ); ?>" class="regular-text" />
     115    <p class="description"><?php esc_html_e( 'Set a custom title for the admin column displaying post descriptions.', 'post-descriptions' ); ?></p>
     116    <?php
     117}
     118
     119/**
     120 * Adds the Post Descriptions submenu to the Settings menu.
     121 */
    75122function postdescriptions_options_page() {
    76123    add_submenu_page(
     
    85132add_action( 'admin_menu', 'postdescriptions_options_page' );
    86133
    87 // Top level menu callback function
     134/**
     135 * Renders the settings page HTML.
     136 */
    88137function postdescriptions_options_page_html() {
    89     // Check user capabilities
    90138    if ( ! current_user_can( 'manage_options' ) ) {
    91139        return;
    92140    }
    93     // Show error/update messages
     141
    94142    settings_errors( 'postdescriptions_messages' );
    95143    ?>
     
    106154    <?php
    107155}
     156
     157/**
     158 * Enqueue the color picker script and style on the settings page.
     159 *
     160 * @param string $hook_suffix The current admin page hook suffix.
     161 */
     162function postdescriptions_enqueue_color_picker( $hook_suffix ) {
     163    if ( 'settings_page_postdescriptions' !== $hook_suffix ) {
     164        return;
     165    }
     166
     167    wp_enqueue_style( 'wp-color-picker' );
     168    wp_enqueue_script(
     169        'color-picker-script',
     170        POSTDESCRIPTIONS_PLUGIN_URL . 'js/color-picker.js',
     171        array( 'wp-color-picker' ),
     172        false,
     173        true
     174    );
     175}
     176add_action( 'admin_enqueue_scripts', 'postdescriptions_enqueue_color_picker' );
  • post-descriptions/trunk/inc/update-post-states.php

    r2735723 r3318276  
    11<?php
    22/**
    3 * This function will update the post states
    4 */
     3 * Updates the post states to include post descriptions.
     4 *
     5 * @package PostDescriptions
     6 */
    57
     8defined( 'ABSPATH' ) or die;
     9
     10/**
     11 * Adds a post description as a post state, styled by importance.
     12 *
     13 * @param array   $post_states Existing post states.
     14 * @param WP_Post $post        The current post object.
     15 * @return array Modified post states with description included.
     16 */
    617function postdescriptions_update_states( $post_states, $post ) {
    718    $post_description = get_post_meta( $post->ID, 'post_description', true );
    819    $is_important     = get_post_meta( $post->ID, 'important', true );
    920    $custom_color     = get_option( 'important-color' );
    10     $important_color;
    11     if ( $custom_color ) {
    12         $important_color = $custom_color;
    13     } else {
    14         $important_color = '#cc0000';
     21    $important_color  = $custom_color ? $custom_color : '#cc0000';
     22
     23    if ( '1' === $is_important && $post_description ) {
     24        $post_states['description'] = '<span class="important-state" style="color:' . esc_attr( $important_color ) . ';">' . esc_html( $post_description ) . '</span>';
     25    } elseif ( $post_description ) {
     26        $post_states['description'] = '<span class="normal-state">' . esc_html( $post_description ) . '</span>';
    1527    }
    16     if ( '1' === $is_important ) {
    17         if ( $post_description ) {
    18             // Add the important-state class, which lets JavaScript see if it's important when populating the Quick Edit fields
    19             $post_states['description'] = '<span class="important-state" style="color:' . $important_color . ';">' . $post_description . '</span>';
    20         }
    21     } else {
    22         if ( $post_description ) {
    23             $post_states['description'] = '<span class="normal-state">' . $post_description . '</span>';
    24         }
    25     }
    26     return $post_states;
     28
     29    /**
     30     * Filter the post states after adding post descriptions.
     31     *
     32     * @since 1.3.0
     33     *
     34     * @param array   $post_states The post states array.
     35     * @param WP_Post $post        The current post object.
     36     */
     37    return apply_filters( 'postdescriptions_post_states', $post_states, $post );
    2738}
    2839add_filter( 'display_post_states', 'postdescriptions_update_states', 10, 2 );
  • post-descriptions/trunk/js/color-picker.js

    r2735723 r3318276  
    11(function ($) {
    2     // Add Color Picker to all inputs that have 'color-field' class
    3     $(function () {
    4         $('.color-picker').wpColorPicker();
    5     });
    6 })(jQuery);
     2  $(function () {
     3    $(".color-picker").wpColorPicker();
     4  });
     5})(jQuery);
  • post-descriptions/trunk/post-descriptions.php

    r2735723 r3318276  
    22/**
    33 * Plugin Name: Post Descriptions
    4  * Description: A very lightweight plugin to add short descriptions and to-do's to your posts and pages. A nice way to remind yourself and others of small tasks or post purposes.
    5  * Version: 1.2.2
     4 * Plugin URI: https://wordpress.org/plugins/post-descriptions/
     5 * Description: Add lightweight descriptions and reminders to your posts and pages — perfect for notes, to-do’s, and team collaboration in the WordPress admin.
     6 * Version: 1.3.0
    67 * Author: Tom de Visser
    7  * Author URI: https://profiles.wordpress.org/tomjdevisser/
     8 * Author URI: https://tomdevisser.dev/
    89 * License: GPLv2
     10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    911 * Text Domain: post-descriptions
    1012 * Domain Path: /languages
     13 * Requires at least: 4.9
     14 * Tested up to: 6.8
     15 * Requires PHP: 5.6
     16 *
     17 * @package PostDescriptions
    1118 */
    1219
    1320defined( 'ABSPATH' ) or die;
    1421
    15 add_action(
    16     'plugins_loaded',
    17     function() {
    18         load_plugin_textdomain( 'post-descriptions', false, __DIR__ );
    19     }
    20 );
     22define( 'POSTDESCRIPTIONS_VERSION', '1.3.0' );
     23define( 'POSTDESCRIPTIONS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     24define( 'POSTDESCRIPTIONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
     25define( 'POSTDESCRIPTIONS_PLUGIN_FILE', __FILE__ );
     26define( 'POSTDESCRIPTIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    2127
    22 // Add a settings link
    23 function postdescriptions_settings_link( $links ) {
    24     $url           = get_admin_url() . 'options-general.php?page=postdescriptions';
    25     $settings_link = '<a href="' . $url . '">' . __( 'Settings', 'post-descriptions' ) . '</a>';
    26     array_unshift( $links, $settings_link );
    27     return $links;
    28 }
    29 
    30 function postdescriptions_after_setup_theme() {
    31     add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'postdescriptions_settings_link' );
    32 }
    33 add_action( 'after_setup_theme', 'postdescriptions_after_setup_theme' );
    34 
    35 // Register the color picker from jQuery to choose your own important color
    36 function postdescriptions_enqueue_color_picker( $hook_suffix ) {
    37     if ( 'settings_page_postdescriptions' !== $hook_suffix ) {
    38         return;
    39     }
    40     // first check that $hook_suffix is appropriate for your admin page
    41     wp_enqueue_style( 'wp-color-picker' );
    42     wp_enqueue_script( 'color-picker-script', plugins_url( '/js/color-picker.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
    43 }
    44 add_action( 'admin_enqueue_scripts', 'postdescriptions_enqueue_color_picker' );
    45 
    46 /**
    47  * Load all necessary files.
    48  */
     28include 'inc/init.php';
    4929include 'inc/settings.php';
    5030include 'inc/add-post-states.php';
  • post-descriptions/trunk/readme.txt

    r2735725 r3318276  
    11=== Post Descriptions ===
    2 Contributors: tomjdevisser
     2Contributors: tomdevisser
    33Tags: admin, ui, posts, pages, organize
    44Requires at least: 4.9.0
    5 Tested up to: 6.0
     5Tested up to: 6.8
    66Requires PHP: 5.6.0
    7 Stable tag: 1.2.2
     7Stable tag: 1.3.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A very lightweight WordPress plugin that uses Post Status as a short description/to-do for your posts and pages.
     11A lightweight WordPress plugin that lets you add quick descriptions or personal notes to your posts and pages — perfect for reminders, to-do's, or internal notes for your team.
    1212
    1313== Description ==
    1414= What does it do? =
    15 Post Descriptions lets you add descriptions to posts and pages, which lets you do things like add small to-do's or don't-forget's for your team members or yourself.
     15Post Descriptions lets you attach short notes or descriptions to posts and pages — ideal for internal reminders, content planning, or small to-do's. Use it solo or with your team to stay organized directly in the WordPress admin.
    1616
    1717= How does it work? =
    18 **Adding post descriptions**
    19 Post descriptions can be added from two places:
    20 1. The Edit screen
    21 2. The Quick Edit screen
     18**Adding Post Descriptions**
     19You can add a description in two ways:
     201. From the full Edit screen
     212. From the Quick Edit option on the posts/pages overview
    2222
    23 **Checking Post Descriptions**
    24 You can check your post descriptions in two places:
    25 1. In the column from your posts or pages admin overview
    26 2. As a post state (the bold text next to your page or post title)
     23**Viewing Post Descriptions**
     24Descriptions are visible:
     251. In a dedicated column on the posts or pages overview — with a customizable column title
     262. As a post state — the small bold label next to the post title
    2727
    28 **Enabling/disabling Post States**
    29 When you add longer descriptions, your admin might get a bit cluttered. In those cases you could disable showing post descriptions in post states with a simple checkbox.
     28**Post State Toggle**
     29By default, post descriptions are not shown as post states (the bold label next to your post title). You can enable this in Settings > Post Descriptions. If enabled, longer descriptions might clutter your view — you can toggle it off again in the settings.
    3030
    3131== Installation ==
     
    3939
    4040== Changelog ==
     41= 1.3.0 =
     42* Rebranded the plugin
     43* Cleaned up all code comments and replaced them with WPCS-compliant docblocks
     44* Modularized functionality across multiple files
     45* Improved plugin description, readme, and settings screen copy
     46* Clarified default behavior for Post States
     47* Fixed asset path issues by centralizing plugin URL handling
     48* Defined plugin constants for consistent paths and URLs
     49* Added setting to customize the column title for post descriptions
     50* Ensured meta boxes and columns work with custom post types, including ACF
     51* Improved Quick Edit layout consistency across post types
     52
    4153= 1.2.2 =
    4254* I'm back! Adding new features soon, let me know if you have any wishes. For now I made the code more solid, and changed it to follow WPCS.
Note: See TracChangeset for help on using the changeset viewer.