| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Plugin Name: Hide Titles | |
| 4 | + * Plugin Name: MM Title Manager | |
| 5 | 5 | * Plugin URI: https://wordpress.org/plugins/hide-titles/ |
| 6 | 6 | * Description: Remove Titles from Posts and Single Pages on WordPress. |
| 7 | - * Version: 1.8.7 | |
| 7 | + * Version: 1.10 | |
| 8 | 8 | * Requires at least: 4.4 |
| 9 | - * Requires PHP: 7.0 | |
| 10 | - * Tested up to: 6.8 | |
| 9 | + * Requires PHP: 5.6 | |
| 10 | + * Tested up to: 7.0 | |
| 11 | 11 | * Author: Mehraz Morshed |
| 12 | 12 | * Author URI: https://profiles.wordpress.org/mehrazmorshed/ |
| 13 | 13 | * License: GPL v2 or later |
| 14 | 14 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| @@ -43,64 +43,91 @@ | ||
| 43 | 43 | add_action( 'init', 'hide_titles_load_textdomain' ); |
| 44 | 44 | |
| 45 | 45 | function hide_titles_option_page() { |
| 46 | 46 | |
| 47 | - add_menu_page( 'Hide Titles', 'Hide Titles', 'manage_options', 'hide-titles', 'hide_titles_create_page', 'dashicons-admin-plugins', 101 ); | |
| 47 | + add_menu_page( __( 'MM Title Manager', 'hide-titles' ), __( 'MM Title Manager', 'hide-titles' ), 'manage_options', 'hide-titles', 'hide_titles_create_page', 'dashicons-heading', 101 ); | |
| 48 | 48 | } |
| 49 | 49 | add_action( 'admin_menu', 'hide_titles_option_page' ); |
| 50 | 50 | |
| 51 | -function hide_titles_style_settings() { | |
| 51 | +function hide_titles_style_settings( $hook_suffix ) { | |
| 52 | 52 | |
| 53 | - wp_enqueue_style( 'hide-titles-settings', plugins_url( 'css/hide-titles-settings.css', __FILE__ ), false, "1.0.0" ); | |
| 53 | + $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| 54 | + if ( ! $screen ) { | |
| 55 | + return; | |
| 56 | + } | |
| 57 | + | |
| 58 | + $screens = array( 'toplevel_page_hide-titles', 'post', 'page' ); | |
| 59 | + if ( ! in_array( $screen->id, $screens, true ) ) { | |
| 60 | + return; | |
| 61 | + } | |
| 62 | + | |
| 63 | + wp_enqueue_style( 'hide-titles-admin', plugins_url( 'css/hide-titles-settings.css', __FILE__ ), array(), '1.9.2' ); | |
| 54 | 64 | } |
| 55 | 65 | add_action( 'admin_enqueue_scripts', 'hide_titles_style_settings' ); |
| 56 | 66 | |
| 57 | 67 | function hide_titles_create_page() { |
| 68 | + $current = get_option( 'hide-titles-option', 'nothing' ); | |
| 58 | 69 | ?> |
| 59 | 70 | <div class="hide_titles_main"> |
| 60 | 71 | <div class="hide_titles_body hide_titles_common"> |
| 61 | - <h1 id="page-title"><?php esc_attr_e( 'Settings', 'hide-titles' ); ?></h1> | |
| 62 | - <form action="options.php" method="post"> | |
| 72 | + <header class="ht-mm-hero"> | |
| 73 | + <p class="ht-mm-hero__eyebrow"><?php esc_html_e( 'MM Title Manager', 'hide-titles' ); ?></p> | |
| 74 | + <h1 class="ht-mm-hero__title" id="page-title"><?php esc_html_e( 'Title visibility', 'hide-titles' ); ?></h1> | |
| 75 | + <p class="ht-mm-hero__lead"><?php esc_html_e( 'Control titles on single posts and pages. Navigation menus always keep their labels.', 'hide-titles' ); ?></p> | |
| 76 | + </header> | |
| 77 | + | |
| 78 | + <form class="ht-mm-form" action="options.php" method="post"> | |
| 63 | 79 | <?php wp_nonce_field( 'update-options' ); ?> |
| 64 | 80 | |
| 65 | - <!-- Hide Titles --> | |
| 66 | - <label for="hide-titles-option"><?php esc_attr_e( 'Hide Titles Option:', 'hide-titles' ); ?></label> | |
| 81 | + <fieldset class="ht-mm-fieldset"> | |
| 82 | + <legend class="ht-mm-fieldset__legend"><?php esc_html_e( 'Global behavior', 'hide-titles' ); ?></legend> | |
| 83 | + <p class="ht-mm-fieldset__hint"><?php esc_html_e( 'Applies site-wide unless you override per post or page in the editor.', 'hide-titles' ); ?></p> | |
| 67 | 84 | |
| 68 | - <label class="radios"> | |
| 69 | - <input type="radio" name="hide-titles-option" id="hide-titles-option-nothing" value="nothing" <?php if( get_option( 'hide-titles-option' ) == 'nothing' ) { echo 'checked="checked"'; } ?>> | |
| 70 | - <span><?php _e( 'Show All Titles', 'hide-titles' ); ?></span> | |
| 71 | - </label> | |
| 85 | + <div class="ht-mm-options"> | |
| 86 | + <label class="ht-mm-card"> | |
| 87 | + <input type="radio" name="hide-titles-option" id="hide-titles-option-nothing" value="nothing" <?php checked( $current, 'nothing' ); ?>> | |
| 88 | + <span class="ht-mm-card__icon dashicons dashicons-visibility" aria-hidden="true"></span> | |
| 89 | + <span class="ht-mm-card__text"> | |
| 90 | + <strong class="ht-mm-card__title"><?php esc_html_e( 'Show all titles', 'hide-titles' ); ?></strong> | |
| 91 | + <span class="ht-mm-card__desc"><?php esc_html_e( 'Default WordPress title output everywhere.', 'hide-titles' ); ?></span> | |
| 92 | + </span> | |
| 93 | + </label> | |
| 72 | 94 | |
| 73 | - <label class="radios"> | |
| 74 | - <input type="radio" name="hide-titles-option" id="hide-titles-option-all" value="all" <?php if( get_option( 'hide-titles-option' ) == 'all' ) { echo 'checked="checked"'; } ?>> | |
| 75 | - <span><?php _e( 'Hide All Titles', 'hide-titles' ); ?></span> | |
| 76 | - </label> | |
| 95 | + <label class="ht-mm-card"> | |
| 96 | + <input type="radio" name="hide-titles-option" id="hide-titles-option-all" value="all" <?php checked( $current, 'all' ); ?>> | |
| 97 | + <span class="ht-mm-card__icon dashicons dashicons-no-alt" aria-hidden="true"></span> | |
| 98 | + <span class="ht-mm-card__text"> | |
| 99 | + <strong class="ht-mm-card__title"><?php esc_html_e( 'Hide all titles', 'hide-titles' ); ?></strong> | |
| 100 | + <span class="ht-mm-card__desc"><?php esc_html_e( 'Removes titles in templates; menus still show link text.', 'hide-titles' ); ?></span> | |
| 101 | + </span> | |
| 102 | + </label> | |
| 103 | + </div> | |
| 104 | + </fieldset> | |
| 77 | 105 | |
| 78 | - <!-- --> | |
| 79 | 106 | <input type="hidden" name="action" value="update"> |
| 80 | 107 | <input type="hidden" name="page_options" value="hide-titles-option"> |
| 81 | 108 | |
| 82 | - <input class="button button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'hide-titles' ) ?>"> | |
| 109 | + <p class="ht-mm-actions"> | |
| 110 | + <button type="submit" name="submit" class="button button-primary button-hero ht-mm-submit"><?php esc_html_e( 'Save changes', 'hide-titles' ); ?></button> | |
| 111 | + </p> | |
| 83 | 112 | </form> |
| 84 | 113 | |
| 85 | - <br> | |
| 86 | - <hr> | |
| 87 | - <br> | |
| 88 | - <label class=""> | |
| 89 | - <span> | |
| 90 | - <?php _e( '🎉 New Feature 🎉 Hide Title From Single Post / Page:', 'hide-titles' ); ?> | |
| 91 | - </span> | |
| 92 | - </label> | |
| 93 | - <img class="screenshot" src="<?php print plugin_dir_url( __FILE__ ) . '/img/single.png'; ?>"> | |
| 114 | + <section class="ht-mm-tip" aria-labelledby="ht-mm-per-post-heading"> | |
| 115 | + <h2 id="ht-mm-per-post-heading" class="ht-mm-tip__title"><?php esc_html_e( 'Per post or page', 'hide-titles' ); ?></h2> | |
| 116 | + <p class="ht-mm-tip__text"><?php esc_html_e( 'Edit any post or page and use the Hide Titles box in the sidebar to hide only that item’s title. Menu labels stay visible.', 'hide-titles' ); ?></p> | |
| 117 | + <figure class="ht-mm-tip__figure"> | |
| 118 | + <img class="screenshot" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . 'img/single.png' ); ?>" alt=""> | |
| 119 | + </figure> | |
| 120 | + </section> | |
| 94 | 121 | </div> |
| 95 | 122 | <div class="hide_titles_aside hide_titles_common"> |
| 96 | 123 | <!-- about plugin author --> |
| 97 | - <h2 class="aside-title"><?php esc_attr_e( 'About Plugin Author', 'hide-titles' ); ?></h2> | |
| 124 | + <h2 class="aside-title"><?php esc_html_e( 'About Plugin Author', 'hide-titles' ); ?></h2> | |
| 98 | 125 | <div class="author-card"> |
| 99 | 126 | <a class="link" href="https://profiles.wordpress.org/mehrazmorshed/" target="_blank"> |
| 100 | - <img class="center" src="<?php print plugin_dir_url( __FILE__ ) . '/img/author.png'; ?>" width="128px"> | |
| 101 | - <h3 class="author-title"><?php esc_attr_e( 'Mehraz Morshed', 'hide-titles' ); ?></h3> | |
| 102 | - <h4 class="author-title"><?php esc_attr_e( 'WordPress Developer', 'hide-titles' ); ?></h4> | |
| 127 | + <img class="center" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . 'img/author.png' ); ?>" width="128" height="128" alt=""> | |
| 128 | + <h3 class="author-title"><?php esc_html_e( 'Mehraz Morshed', 'hide-titles' ); ?></h3> | |
| 129 | + <h4 class="author-title"><?php esc_html_e( 'WordPress Developer', 'hide-titles' ); ?></h4> | |
| 103 | 130 | </a> |
| 104 | 131 | <h1 class="author-title"> |
| 105 | 132 | <a class="link" href="https://www.facebook.com/mehrazmorshed" target="_blank"><span class="dashicons dashicons-facebook"></span></a> |
| 106 | 133 | <a class="link" href="https://twitter.com/mehrazmorshed" target="_blank"><span class="dashicons dashicons-twitter"></span></a> |
| @@ -108,9 +135,9 @@ | ||
| 108 | 135 | <a class="link" href="https://www.youtube.com/@mehrazmorshed" target="_blank"><span class="dashicons dashicons-youtube"></span></a> |
| 109 | 136 | </h1> |
| 110 | 137 | </div> |
| 111 | 138 | <!-- other useful plugins --> |
| 112 | - <h3 class="aside-title"><?php esc_attr_e( 'Other Useful Plugins', 'hide-titles' ); ?></h3> | |
| 139 | + <h3 class="aside-title"><?php esc_html_e( 'Other Useful Plugins', 'hide-titles' ); ?></h3> | |
| 113 | 140 | <div class="author-card"> |
| 114 | 141 | <a class="link" href="https://wordpress.org/plugins/turn-off-comments/" target="_blank"> |
| 115 | 142 | <span class="dashicons dashicons-admin-plugins"></span> <b><?php _e( 'Disable Comments', 'hide-titles' ) ?></b> |
| 116 | 143 | </a> |
| @@ -123,15 +150,15 @@ | ||
| 123 | 150 | <span class="dashicons dashicons-admin-plugins"></span> <b><?php _e( 'Simple Author Box', 'hide-titles' ) ?></b> |
| 124 | 151 | </a> |
| 125 | 152 | </div> |
| 126 | 153 | <!-- donate to this plugin --> |
| 127 | - <h3 class="aside-title"><?php esc_attr_e( 'Hide Titles', 'hide-titles' ); ?></h3> | |
| 128 | - <a class="link" href="https://www.buymeacoffee.com/mehrazmorshed" target="_blank"> | |
| 129 | - <button class="button button-primary btn"><?php esc_attr_e( 'Donate To This Plugin', 'hide-titles' ); ?></button> | |
| 154 | + <h3 class="aside-title"><?php esc_html_e( 'Support', 'hide-titles' ); ?></h3> | |
| 155 | + <a class="link" href="https://www.buymeacoffee.com/mehrazmorshed" target="_blank" rel="noopener noreferrer"> | |
| 156 | + <button type="button" class="button button-primary btn"><?php esc_html_e( 'Donate to this plugin', 'hide-titles' ); ?></button> | |
| 130 | 157 | </a> |
| 131 | - <p style="text-align: center;"><b>OR</b></p> | |
| 132 | - <a class="link" href="https://wordpress.org/support/plugin/hide-titles/reviews/?filter=5#new-post" target="_blank"> | |
| 133 | - <button class="button button-primary btn"><?php esc_attr_e( 'Leave a Review', 'hide-titles' ); ?></button> | |
| 158 | + <p class="ht-mm-or"><span><?php esc_html_e( 'or', 'hide-titles' ); ?></span></p> | |
| 159 | + <a class="link" href="https://wordpress.org/support/plugin/hide-titles/reviews/#new-post" target="_blank" rel="noopener noreferrer"> | |
| 160 | + <button type="button" class="button button-secondary btn"><?php esc_html_e( 'Leave a review', 'hide-titles' ); ?></button> | |
| 134 | 161 | </a> |
| 135 | 162 | </div> |
| 136 | 163 | </div> |
| 137 | 164 | |
| @@ -169,34 +196,88 @@ | ||
| 169 | 196 | add_action( 'admin_init', 'hide_titles_plugin_redirect' ); |
| 170 | 197 | /*********************************************************************/ |
| 171 | 198 | add_action('add_meta_boxes', 'hide_titles_meta_box'); |
| 172 | 199 | add_action('save_post', 'hide_titles_save_meta'); |
| 173 | -add_filter('the_title', 'hide_titles_filter_title', 10, 2); | |
| 200 | +add_filter( 'the_title', 'hide_titles_filter_title', 10, 2 ); | |
| 201 | +add_filter( 'nav_menu_item_title', 'hide_titles_restore_nav_menu_title', 10, 4 ); | |
| 174 | 202 | |
| 203 | +/** | |
| 204 | + * Restore menu link text when titles are hidden via the_title. | |
| 205 | + * | |
| 206 | + * WordPress runs post titles through `the_title` when building menu items | |
| 207 | + * (see wp_setup_nav_menu_item). Without this, hidden titles become blank | |
| 208 | + * or “no title” in menus. We keep the stored navigation label or the raw | |
| 209 | + * post title for display in menus only. | |
| 210 | + * | |
| 211 | + * @param string $title The menu item’s title. | |
| 212 | + * @param object $menu_item The menu item object. | |
| 213 | + * @param stdClass $args An object of wp_nav_menu() arguments. | |
| 214 | + * @param int $depth Depth of menu item. | |
| 215 | + * @return string | |
| 216 | + */ | |
| 217 | +function hide_titles_restore_nav_menu_title( $title, $menu_item, $args, $depth ) { | |
| 218 | + | |
| 219 | + if ( ! is_object( $menu_item ) || 'post_type' !== $menu_item->type || empty( $menu_item->object_id ) ) { | |
| 220 | + return $title; | |
| 221 | + } | |
| 222 | + | |
| 223 | + $object_id = (int) $menu_item->object_id; | |
| 224 | + if ( $object_id < 1 ) { | |
| 225 | + return $title; | |
| 226 | + } | |
| 227 | + | |
| 228 | + $hide_globally = ( get_option( 'hide-titles-option' ) === 'all' ); | |
| 229 | + $hide_per_post = ( get_post_meta( $object_id, '_hide_title', true ) === 'on' ); | |
| 230 | + | |
| 231 | + if ( ! $hide_globally && ! $hide_per_post ) { | |
| 232 | + return $title; | |
| 233 | + } | |
| 234 | + | |
| 235 | + if ( isset( $menu_item->post_title ) && '' !== $menu_item->post_title ) { | |
| 236 | + return $menu_item->post_title; | |
| 237 | + } | |
| 238 | + | |
| 239 | + $raw = get_post_field( 'post_title', $object_id, 'raw' ); | |
| 240 | + | |
| 241 | + return ( is_string( $raw ) && '' !== $raw ) ? $raw : $title; | |
| 242 | +} | |
| 243 | + | |
| 175 | 244 | // Add meta box to hide title |
| 176 | 245 | function hide_titles_meta_box() { |
| 177 | - add_meta_box('hide-title-meta-box', 'Hide Titles', 'hide_titles_meta_box_callback', ['post', 'page'], 'side', 'default'); | |
| 246 | + add_meta_box( 'hide-title-meta-box', __( 'MM Title Manager', 'hide-titles' ), 'hide_titles_meta_box_callback', array( 'post', 'page' ), 'side', 'default' ); | |
| 178 | 247 | } |
| 179 | 248 | |
| 180 | 249 | // Meta box callback function |
| 181 | 250 | function hide_titles_meta_box_callback($post) { |
| 182 | 251 | $value = get_post_meta($post->ID, '_hide_title', true); |
| 252 | + wp_nonce_field( 'hide_titles_meta_save', 'hide_titles_meta_nonce' ); | |
| 183 | 253 | ?> |
| 184 | - <label for="hide-titles-checkbox"> | |
| 185 | - <input type="checkbox" id="hide-titles-checkbox" name="hide_titles_checkbox" <?php checked($value, 'on'); ?> /> | |
| 186 | - Hide The Title | |
| 187 | - </label> | |
| 188 | - <br><br> | |
| 189 | - <p><small>This option comes from the <b>Hide Titles</b> plugin. <a href="https://wordpress.org/support/plugin/hide-titles/reviews/?filter=5#new-post"><strong>Please consider leaving a review</strong></a> to share your experience with us.</small></p> | |
| 254 | + <div class="ht-mm-meta"> | |
| 255 | + <label class="ht-mm-meta__toggle" for="hide-titles-checkbox"> | |
| 256 | + <input type="checkbox" id="hide-titles-checkbox" name="hide_titles_checkbox" <?php checked( $value, 'on' ); ?> /> | |
| 257 | + <span class="ht-mm-meta__label"><?php esc_html_e( 'Hide title on this page', 'hide-titles' ); ?></span> | |
| 258 | + </label> | |
| 259 | + <p class="ht-mm-meta__hint"><?php esc_html_e( 'Hides the title in the content area only. Navigation menus and the admin list keep their titles.', 'hide-titles' ); ?></p> | |
| 260 | + <p class="ht-mm-meta__review"><a href="https://wordpress.org/support/plugin/hide-titles/reviews/#new-post" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Leave a review', 'hide-titles' ); ?></a></p> | |
| 261 | + </div> | |
| 190 | 262 | <?php |
| 191 | 263 | } |
| 192 | 264 | |
| 193 | 265 | // Save meta box data |
| 194 | 266 | function hide_titles_save_meta($post_id) { |
| 195 | - if (array_key_exists('hide_titles_checkbox', $_POST)) { | |
| 196 | - update_post_meta($post_id, '_hide_title', 'on'); | |
| 267 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
| 268 | + return; | |
| 269 | + } | |
| 270 | + if ( ! isset( $_POST['hide_titles_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['hide_titles_meta_nonce'] ), 'hide_titles_meta_save' ) ) { | |
| 271 | + return; | |
| 272 | + } | |
| 273 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
| 274 | + return; | |
| 275 | + } | |
| 276 | + if ( array_key_exists( 'hide_titles_checkbox', $_POST ) ) { | |
| 277 | + update_post_meta( $post_id, '_hide_title', 'on' ); | |
| 197 | 278 | } else { |
| 198 | - delete_post_meta($post_id, '_hide_title'); | |
| 279 | + delete_post_meta( $post_id, '_hide_title' ); | |
| 199 | 280 | } |
| 200 | 281 | } |
| 201 | 282 | |
| 202 | 283 | // Filter the title to hide it |
| @@ -239,9 +320,9 @@ | ||
| 239 | 320 | } |
| 240 | 321 | register_uninstall_hook(__FILE__, 'hide_titles_uninstall'); |
| 241 | 322 | |
| 242 | 323 | /** |
| 243 | - * Show migration notice for installations before Aug 30, 2025 | |
| 324 | + * Show migration notice for installations before Oct 30, 2025 | |
| 244 | 325 | */ |
| 245 | 326 | function ht_show_migration_notice() { |
| 246 | 327 | // Only show if new plugin is not active |
| 247 | 328 | if (is_plugin_active('daisy-titles/daisy-titles.php')) { |
| @@ -252,10 +333,10 @@ | ||
| 252 | 333 | $install_date = get_option('hide_titles_installed'); |
| 253 | 334 | |
| 254 | 335 | // Only show notice if: |
| 255 | 336 | // 1. There is NO install date (new installation) OR |
| 256 | - // 2. Installation date is BEFORE Aug 30, 2025 | |
| 257 | - if ($install_date && strtotime($install_date) >= strtotime('2025-08-30')) { | |
| 337 | + // 2. Installation date is BEFORE Oct 30, 2025 | |
| 338 | + if ($install_date && strtotime($install_date) >= strtotime('2025-10-30')) { | |
| 258 | 339 | return; |
| 259 | 340 | } |
| 260 | 341 | |
| 261 | 342 | // Get install/activate URLs |