Changeset 3318276
- Timestamp:
- 06/26/2025 01:16:03 PM (9 months ago)
- Location:
- post-descriptions
- Files:
-
- 17 added
- 19 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
assets/icon-256x256.png (modified) (previous)
-
tags/1.2.0/inc/add-post-states.php (modified) (1 diff)
-
tags/1.2.0/inc/add-quick-edit.php (modified) (1 diff)
-
tags/1.2.0/inc/register-admin-columns.php (modified) (1 diff)
-
tags/1.2.1/inc/add-post-states.php (modified) (1 diff)
-
tags/1.2.1/inc/add-quick-edit.php (modified) (1 diff)
-
tags/1.2.1/inc/register-admin-columns.php (modified) (1 diff)
-
tags/1.3.0 (added)
-
tags/1.3.0/LICENSE (added)
-
tags/1.3.0/README.md (added)
-
tags/1.3.0/inc (added)
-
tags/1.3.0/inc/add-post-states.php (added)
-
tags/1.3.0/inc/add-quick-edit.php (added)
-
tags/1.3.0/inc/admin-columns.php (added)
-
tags/1.3.0/inc/index.php (added)
-
tags/1.3.0/inc/init.php (added)
-
tags/1.3.0/inc/register-admin-columns.php (added)
-
tags/1.3.0/inc/settings.php (added)
-
tags/1.3.0/inc/update-post-states.php (added)
-
tags/1.3.0/js (added)
-
tags/1.3.0/js/color-picker.js (added)
-
tags/1.3.0/languages (added)
-
tags/1.3.0/post-descriptions.php (added)
-
tags/1.3.0/readme.txt (added)
-
trunk/README.md (modified) (1 diff)
-
trunk/inc/add-post-states.php (modified) (3 diffs)
-
trunk/inc/add-quick-edit.php (modified) (3 diffs)
-
trunk/inc/admin-columns.php (modified) (2 diffs)
-
trunk/inc/register-admin-columns.php (modified) (1 diff)
-
trunk/inc/settings.php (modified) (6 diffs)
-
trunk/inc/update-post-states.php (modified) (1 diff)
-
trunk/js/color-picker.js (modified) (1 diff)
-
trunk/post-descriptions.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-descriptions/tags/1.2.0/inc/add-post-states.php
r2535676 r3318276 29 29 $important_value = get_post_meta( $post->ID, 'important', true ); 30 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', 'post descriptions' ) . '</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>'; 32 32 echo $html_output; 33 33 } -
post-descriptions/tags/1.2.0/inc/add-quick-edit.php
r2535689 r3318276 16 16 </label> 17 17 <label class="align-left"> 18 <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post descriptions' ) . '18 <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post-descriptions' ) . ' 19 19 </label></div></fieldset>'; 20 20 } -
post-descriptions/tags/1.2.0/inc/register-admin-columns.php
r2535676 r3318276 5 5 function postdescriptions_add_description_column( $columns ) { 6 6 $new_columns = array( 7 '_description' => esc_html__('Description', 'post descriptions'),7 '_description' => esc_html__('Description', 'post-descriptions'), 8 8 ); 9 9 return array_merge( $columns, $new_columns ); -
post-descriptions/tags/1.2.1/inc/add-post-states.php
r2535689 r3318276 29 29 $important_value = get_post_meta( $post->ID, 'important', true ); 30 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', 'post descriptions' ) . '</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>'; 32 32 echo $html_output; 33 33 } -
post-descriptions/tags/1.2.1/inc/add-quick-edit.php
r2535689 r3318276 16 16 </label> 17 17 <label class="align-left"> 18 <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post descriptions' ) . '18 <input type="checkbox" id="important" name="important" value="1"/>' . __( 'Make your description important', 'post-descriptions' ) . ' 19 19 </label></div></fieldset>'; 20 20 } -
post-descriptions/tags/1.2.1/inc/register-admin-columns.php
r2535689 r3318276 5 5 function postdescriptions_add_description_column( $columns ) { 6 6 $new_columns = array( 7 '_description' => esc_html__('Description', 'post descriptions'),7 '_description' => esc_html__('Description', 'post-descriptions'), 8 8 ); 9 9 return array_merge( $columns, $new_columns ); -
post-descriptions/trunk/README.md
r2535672 r3318276 1 1 # Post Descriptions 2 2 3 A very lightweight WordPress plugin that uses Post Status as a short description/to-do for your posts and pages.3 Add lightweight descriptions and reminders to your posts and pages — perfect for notes, to-do’s, and team collaboration in the WordPress admin. 4 4 5 5 ## What does it do? 6 6 7 Post Descriptions lets you a dd 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.7 Post 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. 8 8 9 9 ## How does it work? 10 10 11 ### Adding post descriptions11 ### Adding Post Descriptions 12 12 13 Post descriptions can be added from two places:13 You can add descriptions in two ways: 14 14 15 1. TheEdit screen16 2. The Quick Edit screen15 1. From the full Edit screen 16 2. From the Quick Edit menu in the post/page overview 17 17 18 ### Checking Post Descriptions18 ### Viewing Post Descriptions 19 19 20 You can check your post descriptionsin two places:20 Descriptions are visible in two places: 21 21 22 1. In the column from your posts or pages admin overview23 2. As a post state (the bold text next to your page or post title)22 1. In a dedicated column in the Posts or Pages admin view 23 2. As a post state — the bold label next to your post title 24 24 25 ### Enabling/disabling Post States25 ### Customizing Display Options 26 26 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 1 1 <?php 2 2 /** 3 * This function will add the post states 4 */ 3 * Adds and manages post descriptions as post meta. 4 * 5 * @package PostDescriptions 6 */ 7 8 defined( 'ABSPATH' ) or die; 9 10 /** 11 * Adds custom field support to all public post types, excluding system types. 12 */ 5 13 function 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 } 8 28 } 9 29 add_action( 'init', 'postdescriptions_add_states' ); 10 30 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 */ 12 37 function 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' 21 43 ); 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 } 22 60 } 23 61 add_action( 'add_meta_boxes', 'postdescriptions_add_states_post_meta' ); 24 62 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 */ 26 68 function postdescriptions_post_description_meta_callback( $post ) { 27 69 wp_nonce_field( 'post_description_save_data', 'post_description_nonce' ); 28 70 $desc_value = get_post_meta( $post->ID, 'post_description', true ); 29 71 $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>'; 32 74 echo $html_output; 33 75 } 34 76 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 */ 36 82 function postdescriptions_save_postdescription( $post_id ) { 37 // Checks the nonce for extra security38 83 if ( ! isset( $_POST['post_description_nonce'] ) ) { 39 84 return; 40 85 } 86 41 87 if ( ! wp_verify_nonce( $_POST['post_description_nonce'], 'post_description_save_data' ) ) { 42 88 return; 43 89 } 44 90 45 // Doesn't save on autosave46 91 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 47 92 return; 48 93 } 49 94 50 // Checks if user has the right capability to edit the page or post51 95 if ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) { 52 96 if ( ! current_user_can( 'edit_page', $post_id ) ) { … … 59 103 } 60 104 61 // Checks if there is input62 105 if ( isset( $_POST['post_description'] ) ) { 63 // Sanitizes the input and saves it to the post meta64 106 $post_description = sanitize_text_field( $_POST['post_description'] ); 65 107 update_post_meta( $post_id, 'post_description', $post_description ); … … 67 109 68 110 if ( isset( $_POST['important-desc'] ) ) { 69 // Saves the important checkbox value70 111 update_post_meta( $post_id, 'important', $_POST['important-desc'] ); 71 112 } else { -
post-descriptions/trunk/inc/add-quick-edit.php
r2735723 r3318276 1 1 <?php 2 2 /** 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 8 defined( '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 */ 5 16 function postdescriptions_add_quick_edit( $column_name, $post_type ) { 6 17 if ( '_description' !== $column_name ) { 7 18 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>';20 19 } 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>'; 21 32 } 22 33 add_action( 'quick_edit_custom_box', 'postdescriptions_add_quick_edit', 10, 2 ); 23 34 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 */ 25 40 function postdescriptions_quick_edit_save( $post_id ) { 26 // Checks the nonce for extra security27 41 if ( ! isset( $_POST['post_description_nonce'] ) ) { 28 42 return; 29 43 } 44 30 45 if ( ! wp_verify_nonce( $_POST['post_description_nonce'], 'post_description_quick_edit' ) ) { 31 46 return; 32 47 } 33 // Doesn't save on autosave 48 34 49 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 35 50 return; 36 51 } 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'] ) { 39 54 if ( ! current_user_can( 'edit_page', $post_id ) ) { 40 55 return; … … 46 61 } 47 62 48 // Checks if there is input49 63 if ( isset( $_POST['_description'] ) ) { 50 // Sanitizes the input and saves it to the post meta51 64 $post_description = sanitize_text_field( $_POST['_description'] ); 52 65 update_post_meta( $post_id, 'post_description', $post_description ); 53 66 } 67 54 68 if ( isset( $_POST['important'] ) ) { 55 69 update_post_meta( $post_id, 'important', $_POST['important'] ); … … 58 72 } 59 73 } 60 add_action( 'save_post_post', 'postdescriptions_quick_edit_save' );61 add_action( 'save_post_page', 'postdescriptions_quick_edit_save' );62 74 63 // Populate the custom field values at the quick edit box using Javascript 75 /** 76 * Registers save_post hooks for Quick Edit support. 77 */ 78 function 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 } 88 add_action( 'init', 'postdescriptions_register_quick_edit_hooks' ); 89 90 /** 91 * Outputs JavaScript to populate Quick Edit fields with post meta values. 92 */ 64 93 function postdescriptions_populate_quick_edit() { 65 94 $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-' ) ) { 67 96 return; 68 97 } 98 69 99 wp_enqueue_script( 'jquery' ); 70 100 ?> 71 101 <script type="text/javascript"> 72 102 jQuery( function( $ ) { 73 let $postdescriptions_inline_editor= inlineEditPost.edit;103 const $original_inline_edit = inlineEditPost.edit; 74 104 inlineEditPost.edit = function( id ) { 75 $postdescriptions_inline_editor.apply( this, arguments ); 105 $original_inline_edit.apply( this, arguments ); 106 76 107 let $post_id = 0; 77 if ( 'object' == typeof( id )) {108 if ( typeof id === 'object' ) { 78 109 $post_id = parseInt( this.getId( id ) ); 79 110 } 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(); 88 117 $( ':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 ); 92 125 } 93 126 } 94 127 } 95 } );128 }); 96 129 </script> 97 130 <?php -
post-descriptions/trunk/inc/admin-columns.php
r2735723 r3318276 1 1 <?php 2 2 /** 3 * Populate the description column 3 * Populates the custom column with post description data. 4 * 5 * @package PostDescriptions 6 */ 7 8 defined( '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. 4 15 */ 5 16 function postdescriptions_fill_description_column( $column, $post_id ) { … … 7 18 return; 8 19 } 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'; 17 24 $escaped_description = esc_html( $description ); 18 25 $important = get_post_meta( $post_id, 'important', true ); 26 19 27 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>'; 21 29 } else { 22 30 echo '<span>' . $escaped_description . '</span>'; 23 31 } 24 32 } 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 */ 37 function 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 } 46 add_action( 'init', 'postdescriptions_register_column_output_hooks' ); -
post-descriptions/trunk/inc/register-admin-columns.php
r2735723 r3318276 1 1 <?php 2 2 /** 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 8 defined( '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 */ 5 16 function postdescriptions_add_description_column( $columns ) { 17 $column_title = get_option( 'column-title', __( 'Description', 'post-descriptions' ) ); 18 6 19 $new_columns = array( 7 '_description' => esc_html __( 'Description', 'postdescriptions'),20 '_description' => esc_html( $column_title ), 8 21 ); 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 9 32 return array_merge( $columns, $new_columns ); 10 33 } 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 */ 38 function 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 } 47 add_action( 'init', 'postdescriptions_register_description_column_filters' ); -
post-descriptions/trunk/inc/settings.php
r2735723 r3318276 1 1 <?php 2 2 /** 3 * Custom options and settings 3 * Register and render settings for the Post Descriptions plugin. 4 * 5 * @package PostDescriptions 6 */ 7 8 defined( 'ABSPATH' ) or die; 9 10 /** 11 * Registers plugin settings, sections, and fields. 4 12 */ 5 13 function postdescriptions_settings_init() { 6 // Register settings7 14 register_setting( 'postdescriptions', 'description-states' ); 8 15 register_setting( 'postdescriptions', 'important-color' ); 9 // Adds settings sections 16 register_setting( 'postdescriptions', 'column-title' ); 17 10 18 add_settings_section( 11 19 'postdescriptions_general', … … 14 22 'postdescriptions' 15 23 ); 16 // Adds settings fields 24 17 25 add_settings_field( 18 26 'postdescriptions_show_state', … … 27 35 ) 28 36 ); 37 29 38 add_settings_field( 30 39 'postdescriptions_important_color', … … 39 48 ) 40 49 ); 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 ); 41 63 } 42 64 add_action( 'admin_init', 'postdescriptions_settings_init' ); 43 65 44 // A description for the settings section. 66 /** 67 * Displays a description for the settings section. 68 * 69 * @param array $args Section arguments. 70 */ 45 71 function postdescriptions_general_cb( $args ) { 46 72 ?> 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> 48 76 <?php 49 77 } 50 78 51 // Callback for the state option 79 /** 80 * Renders the checkbox for showing post states. 81 * 82 * @param array $args Field arguments. 83 */ 52 84 function postdescriptions_show_state_cb( $args ) { 53 85 ?> 54 86 <label for="postdescriptions_show_state"> 55 87 <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' ); ?> 57 89 </label> 58 90 <?php 59 91 } 60 92 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 */ 62 98 function postdescriptions_important_color_cb( $args ) { 63 99 $color = get_option( 'important-color' ); 64 100 ?> 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> 71 103 <?php 72 104 } 73 105 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 */ 111 function 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 */ 75 122 function postdescriptions_options_page() { 76 123 add_submenu_page( … … 85 132 add_action( 'admin_menu', 'postdescriptions_options_page' ); 86 133 87 // Top level menu callback function 134 /** 135 * Renders the settings page HTML. 136 */ 88 137 function postdescriptions_options_page_html() { 89 // Check user capabilities90 138 if ( ! current_user_can( 'manage_options' ) ) { 91 139 return; 92 140 } 93 // Show error/update messages 141 94 142 settings_errors( 'postdescriptions_messages' ); 95 143 ?> … … 106 154 <?php 107 155 } 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 */ 162 function 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 } 176 add_action( 'admin_enqueue_scripts', 'postdescriptions_enqueue_color_picker' ); -
post-descriptions/trunk/inc/update-post-states.php
r2735723 r3318276 1 1 <?php 2 2 /** 3 * This function will update the post states 4 */ 3 * Updates the post states to include post descriptions. 4 * 5 * @package PostDescriptions 6 */ 5 7 8 defined( '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 */ 6 17 function postdescriptions_update_states( $post_states, $post ) { 7 18 $post_description = get_post_meta( $post->ID, 'post_description', true ); 8 19 $is_important = get_post_meta( $post->ID, 'important', true ); 9 20 $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>'; 15 27 } 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 ); 27 38 } 28 39 add_filter( 'display_post_states', 'postdescriptions_update_states', 10, 2 ); -
post-descriptions/trunk/js/color-picker.js
r2735723 r3318276 1 1 (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 2 2 /** 3 3 * 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 6 7 * Author: Tom de Visser 7 * Author URI: https:// profiles.wordpress.org/tomjdevisser/8 * Author URI: https://tomdevisser.dev/ 8 9 * License: GPLv2 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 9 11 * Text Domain: post-descriptions 10 12 * Domain Path: /languages 13 * Requires at least: 4.9 14 * Tested up to: 6.8 15 * Requires PHP: 5.6 16 * 17 * @package PostDescriptions 11 18 */ 12 19 13 20 defined( 'ABSPATH' ) or die; 14 21 15 add_action( 16 'plugins_loaded', 17 function() { 18 load_plugin_textdomain( 'post-descriptions', false, __DIR__ ); 19 } 20 ); 22 define( 'POSTDESCRIPTIONS_VERSION', '1.3.0' ); 23 define( 'POSTDESCRIPTIONS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 24 define( 'POSTDESCRIPTIONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 25 define( 'POSTDESCRIPTIONS_PLUGIN_FILE', __FILE__ ); 26 define( 'POSTDESCRIPTIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 21 27 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 */ 28 include 'inc/init.php'; 49 29 include 'inc/settings.php'; 50 30 include 'inc/add-post-states.php'; -
post-descriptions/trunk/readme.txt
r2735725 r3318276 1 1 === Post Descriptions === 2 Contributors: tom jdevisser2 Contributors: tomdevisser 3 3 Tags: admin, ui, posts, pages, organize 4 4 Requires at least: 4.9.0 5 Tested up to: 6. 05 Tested up to: 6.8 6 6 Requires PHP: 5.6.0 7 Stable tag: 1. 2.27 Stable tag: 1.3.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A very lightweight WordPress plugin that uses Post Status as a short description/to-do for your posts and pages.11 A 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. 12 12 13 13 == Description == 14 14 = What does it do? = 15 Post Descriptions lets you a dd 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.15 Post 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. 16 16 17 17 = How does it work? = 18 **Adding post descriptions**19 Post descriptions can be added from two places:20 1. TheEdit screen21 2. The Quick Edit screen18 **Adding Post Descriptions** 19 You can add a description in two ways: 20 1. From the full Edit screen 21 2. From the Quick Edit option on the posts/pages overview 22 22 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 overview26 2. As a post state (the bold text next to your page or post title)23 **Viewing Post Descriptions** 24 Descriptions are visible: 25 1. In a dedicated column on the posts or pages overview — with a customizable column title 26 2. As a post state — the small bold label next to the post title 27 27 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** 29 By 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. 30 30 31 31 == Installation == … … 39 39 40 40 == 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 41 53 = 1.2.2 = 42 54 * 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.