Changeset 2052012
- Timestamp:
- 03/17/2019 11:03:42 AM (5 years ago)
- Location:
- unlist-my-post
- Files:
-
- 6 added
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
unlist-my-post/trunk/README.md
r1866569 r2052012 3 3 [Unlist My Post](https://wordpress.org/plugins/unlist-my-post/) lets you unlist posts on your website but still keeps them accessible to people who have the permalink. 4 4 5 ## Donate6 7 In case you really like using this plugin and would like to support me, please consider [donating via PayPal](https://www.paypal.me/dtj27). Any amount is hugely appreciated and allows me to develop the plugin further. Thank you!8 9 5 ## Useful Links 10 6 11 7 - [Download Plugin](https://wordpress.org/plugins/unlist-my-post/) 12 - [ Help with Translations](https://translate.wordpress.org/projects/wp-plugins/unlist-my-post)8 - [](https://translate.wordpress.org/projects/wp-plugins/unlist-my-post) 13 9 - [GitHub Repository](https://github.com/danieltj27/Unlist-My-Post) 14 - [Personal Blog](https://www.danieltj.co.uk/)15 -
unlist-my-post/trunk/readme.txt
r2018591 r2052012 1 1 === Unlist My Post === 2 2 Contributors: danieltj 3 Tags: post s, unlisted, archive, hide, content4 Requires at least: 4. 05 Tested up to: 5. 06 Stable tag: 2.73 Tags: post 4 Requires at least: 4. 5 Tested up to: 5. 6 Stable tag: 7 7 License: GNU GPL v3 8 8 License URI: https://www.gnu.org/licenses/gpl-3.0.html 9 Donate link: https://www.paypal.me/dtj2710 9 11 10 Unlist your posts so you'll need a link to read them. … … 17 16 = Developers = 18 17 19 There are lots of action and filter hooks available to extend the functionality of this plugin. If you'd like more information on how to use them, take a look at the plugin Wiki on the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post/wiki).18 iki on the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post/wiki). 20 19 21 20 == Installation == … … 54 53 == Changelog == 55 54 56 Refer to the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post /releases) for more information on version history and updates.55 Refer to the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post. -
unlist-my-post/trunk/unlist-my-post.php
r2018591 r2052012 5 5 * Plugin URI: https://wordpress.org/plugins/unlist-my-post/ 6 6 * Description: Unlist your posts so you'll need a link to read them. 7 7 8 * Author: Daniel James 8 9 * Author URI: https://danieltj.uk/ 9 10 * Text Domain: unlist-my-post 10 * Version: 2.711 11 */ 12 12 … … 29 29 30 30 if ( ! defined( 'ABSPATH' ) ) { 31 31 32 die(); 33 32 34 } 33 35 34 $Unlist_My_Post =new Unlist_My_Post;36 new Unlist_My_Post; 35 37 36 38 class Unlist_My_Post { 37 39 38 40 /** 39 * The plugin version. 40 * 41 * @since 2.3 42 * 43 * @var string 44 */ 45 protected static $version = '2.7'; 46 47 /** 48 * Just plug it in. 49 * 50 * @since 1.0 51 * @since 1.2 Added the donate link filter. 52 * @since 2.0 Added post title filter. 53 * @since 2.5 Added REST API filters. 41 * Hook into WordPress. 54 42 * 55 43 * @return void … … 57 45 public function __construct() { 58 46 59 add_action( 'plugins_loaded', array( __CLASS__, 'load_text_domain' ), 10, 0 );60 47 add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ), 10, 0 ); 61 48 add_action( 'save_post', array( __CLASS__, 'save_meta_value' ), 10, 1 ); … … 64 51 add_action( 'manage_pages_custom_column', array( __CLASS__, 'show_unlisted_column' ), 10, 2 ); 65 52 66 add_filter( 'plugin_action_links', array( __CLASS__, 'add_donate_link' ), 10, 2 );67 53 add_filter( 'manage_posts_columns', array( __CLASS__, 'add_unlisted_column' ), 10, 1 ); 68 54 add_filter( 'manage_pages_columns', array( __CLASS__, 'add_unlisted_column' ), 10, 1 ); … … 76 62 77 63 /** 78 * Load the plugin text domain.79 *80 * @since 1.081 *82 * @return void83 */84 public static function load_text_domain() {85 86 load_plugin_textdomain( 'unlist-my-post', false, untrailingslashit( dirname( __FILE__ ) ) . '/languages' );87 88 }89 90 /**91 * Adds a donate link to the plugins table.92 *93 * @since 1.294 * @since 2.0.1 Removed unnecessary code and updated translation strings.95 * @since 2.5 Updated variable names and updated l10n functions.96 *97 * @param array $links A list of plugin links98 * @param string $file The current plugin file.99 *100 * @return array $links101 */102 public static function add_donate_link( $links, $file ) {103 104 // Check if this is the current plugin105 if ( 'unlist-my-post/unlist-my-post.php' == $file ) {106 107 // Create the donate link108 $donate_link = '<a href="https://www.paypal.me/dtj27" target="_blank">' . esc_html__('Donate', 'unlist-my-post') . '</a>';109 110 // Add the link to the array111 array_unshift( $links, $donate_link );112 113 }114 115 return $links;116 117 }118 119 /**120 64 * Gets the list of unlisted posts from the database. 121 65 * … … 124 68 * elegant than doing database queries in each function. 125 69 * 126 * @since 1.0127 *128 70 * @return array $unlisted An array of unlisted posts 129 71 */ … … 132 74 global $wpdb; 133 75 134 // Get a list of all the unlisted posts76 // Get a 135 77 $get_posts = $wpdb->get_results( 136 78 $wpdb->prepare( … … 141 83 ); 142 84 143 // Create an array for our posts144 85 $unlisted_posts = array(); 145 86 146 // Loop through each post from the query147 87 foreach ( $get_posts as $post ) { 148 88 149 // Add the post to the array150 89 array_push( $unlisted_posts, $post->post_id ); 151 90 … … 159 98 * Checks if a post is unlisted. 160 99 * 161 * @since 1.0162 *163 100 * @param string $post_id The post id to check. 164 101 * … … 167 104 public static function is_post_unlisted( $post_id ) { 168 105 169 // Get the meta value170 106 $get_post_meta = get_post_meta( $post_id, 'post_list_status', true ); 171 107 172 // Check if this post is unlisted108 // 173 109 if ( 'on' == $get_post_meta ) { 174 110 … … 184 120 185 121 /** 186 * Gets all the public post types. 187 * 188 * @since 2.4 122 * Get all the public post types. 189 123 * 190 124 * @return array $post_types An array of post types. … … 192 126 public static function get_post_types() { 193 127 194 // Fetch a ny custom post types128 // Fetch a 195 129 $get_custom_types = get_post_types( 196 130 array( … … 203 137 ); 204 138 205 // Setup the blank array206 139 $post_types = array(); 207 140 208 // Add the built in types209 141 $post_types[] = 'post'; 210 142 $post_types[] = 'page'; 211 143 212 // Loop through each custom post type213 144 foreach ( $get_custom_types as $key => $value ) { 214 145 215 // Add the custom post type216 146 $post_types[] = $value; 217 147 … … 234 164 235 165 /** 236 * Adds the meta to the post screens. 237 * 238 * @since 1.0 239 * @since 2.4 Remove the post type fetching. 240 * @since 2.5 Updated l10n functions. 241 * @since 2.7 Added block editor compatible flag. 166 * Add meta box to post screen. 242 167 * 243 168 * @return void … … 245 170 public static function add_meta_box() { 246 171 247 // Get the post types248 172 $post_types = self::get_post_types(); 249 173 250 // Create the new meta box251 174 add_meta_box( 252 175 'unlist_my_post', 253 176 esc_html__('Listings', 'unlist-my-post'), 254 array( 255 __CLASS__, 256 'meta_box_content' 257 ), 177 array( __CLASS__, 'meta_box_content' ), 258 178 $post_types, 259 179 'side', 260 180 'default', 261 array( 262 '__block_editor_compatible_meta_box' => true 263 ) 181 array( '__block_editor_compatible_meta_box' => true ) 264 182 ); 265 183 … … 267 185 268 186 /** 269 * Prints the setting on the post screens. 270 * 271 * @since 1.0 272 * @since 2.4 Updated the name of the checkbox field. 273 * @since 2.5 Updated l10n functions and added post type name. 187 * Print the meta box HTML. 274 188 * 275 189 * @param object $post WP_Post object of the current post. … … 279 193 public static function meta_box_content( $post ) { 280 194 281 // Create the nonce282 195 $unlist_my_post_nonce = wp_create_nonce('unlist_my_post_nonce'); 283 196 284 // Get the post type object285 197 $post_type = get_post_type_object( $post->post_type ); 286 198 … … 300 212 301 213 /** 302 * Save the choice for the listing option. 303 * 304 * @since 1.0 305 * @since 2.2 Added sanitisation to nonce as precaution. 306 * @since 2.4 Changed the name of the unlisted field option. 214 * Save the meta box form data. 307 215 * 308 216 * @param string $post_id Current post ID that is being saved. … … 312 220 public static function save_meta_value( $post_id ) { 313 221 314 // Get the nonce value and sanitise222 // 315 223 $unlist_my_post_nonce = isset( $_POST['unlist_my_post_nonce'] ) ? sanitize_text_field( $_POST['unlist_my_post_nonce'] ) : ''; 316 224 317 // Check the nonce is valid225 // 318 226 if ( wp_verify_nonce( $unlist_my_post_nonce, 'unlist_my_post_nonce' ) ) { 319 227 320 // Set the value of the option321 228 $post_list_status = isset ( $_POST['unlist_my_post_option'] ) ? 'on' : 'off'; 322 229 323 // Save the setting324 230 update_post_meta( $post_id, 'post_list_status', $post_list_status ); 325 231 … … 329 235 330 236 /** 331 * Show the unlisted post value in the column. 332 * 333 * @since 1.0 334 * @since 2.2 Added Dashicon to column. 335 * @since 2.5 Updated l10n functions. 237 * Print the value in the post table column. 336 238 * 337 239 * @param string $column The current column. … … 342 244 public static function show_unlisted_column( $column, $post_id ) { 343 245 344 // Check the current column is 'unlisted'246 // Check the current column 345 247 if ( 'unlisted' == $column ) { 346 248 347 // See if the current post been unlisted348 249 if ( true === self::is_post_unlisted( $post_id ) ) { 349 250 … … 363 264 364 265 /** 365 * Add the new column to the current list. 366 * 367 * @since 1.0 368 * @since 2.5 Updated l10n functions. 266 * Add the unlisted column to the post table. 369 267 * 370 268 * @param array $columns The array of registered columns. … … 385 283 * because we don't want to filter people's custom queries. 386 284 * 387 * @since 1.0388 * @since 2.1 Changed the use of not empty to not false.389 *390 285 * @param object $query The query object for fetching posts. 391 286 * … … 394 289 public static function filter_unlisted_posts( $query ) { 395 290 396 // Get the unlisted posts397 291 $unlisted_posts = self::get_unlisted_posts(); 398 292 … … 407 301 if ( false !== $unlisted_posts && $query->is_main_query() && ! is_admin() && ! is_single() && ! is_page() ) { 408 302 409 // Exclude in the query410 303 $query->set( 'post__not_in', $unlisted_posts ); 411 304 … … 434 327 * Filter the post title. 435 328 * 436 * Filter the post title to add a prefix to it like how 437 * prefixes are added to private and protected posts. This 438 * function includes the `unlisted_title_format()` filter 439 * to remove this if it's not wanted. 440 * 441 * @since 2.0 442 * @since 2.5 Updated l10n functions. 443 * @since 2.5.2 Updated prefix filter docs. 329 * Filter the post title to add a prefix to it like how prefixes are 330 * added to private and protected posts. This function includes the 331 * `unlisted_title_format()` filter to remove this if it's not wanted. 444 332 * 445 333 * @param string $post_title The post title. … … 450 338 public static function filter_post_title( $post_title, $post_id ) { 451 339 452 // Make sure the post is unlisted453 340 if ( ! is_admin() && false !== self::is_post_unlisted( $post_id ) ) { 454 341 455 // Get the real title456 342 $get_post = get_post( $post_id ); 457 343 $real_title = $get_post->post_title; 458 344 459 // Generate the new title460 345 $new_title = sprintf( esc_html__('Unlisted: %s', 'unlist-my-post'), $real_title ); 461 346 … … 484 369 * See the function above, `filter_unlisted_posts` for more information. 485 370 * 486 * @see (function) filter_unlisted_posts 487 * 488 * @since 1.0 489 * @since 2.1 Changed the use of not empty to not false. 371 * @see filter_unlisted_posts() 490 372 * 491 373 * @param array $args Arguments for filtering posts in the widget. … … 497 379 $unlisted_posts = self::get_unlisted_posts(); 498 380 499 // Make sure we have at least one post500 381 if ( false !== $unlisted_posts ) { 501 382 502 // In case it's not set already503 383 if ( ! isset( $args['post__not_in'] ) ) { 504 384 … … 507 387 } 508 388 509 // Add the the blacklist510 389 $args['post__not_in'] = array_merge( $args['post__not_in'], $unlisted_posts ); 511 390 … … 534 413 * for some reason and expects a comma seperated string of page IDs. 535 414 * 536 * @see (function) wp_list_pages 537 * 538 * @since 1.0 539 * @since 2.1 Changed the use of not empty to not false. 540 * @since 2.2 Return the arguments straight from the filter. 415 * @see wp_list_pages() 541 416 * 542 417 * @param array $args Arguments for filtering pages in the widget. … … 548 423 $unlisted_posts = self::get_unlisted_posts(); 549 424 550 // Ensure we have at least one unlisted page551 425 if ( false !== $unlisted_posts ) { 552 426 553 // Convert the array into a string554 427 $unlisted_posts = implode( ', ', $unlisted_posts ); 555 428 556 // Concatenate the existing list to the new list557 429 $args['exclude'] .= ',' . $unlisted_posts; 558 430 … … 574 446 /** 575 447 * Filter out unlisted posts from the REST API. 576 *577 * @since 2.5578 448 * 579 449 * @param array $args The post query arguments. … … 586 456 $unlisted_posts = self::get_unlisted_posts(); 587 457 588 // Ensure we have at least one unlisted page589 458 if ( false !== $unlisted_posts ) { 590 459 591 // In case it's not set already592 460 if ( ! isset( $args['post__not_in'] ) ) { 593 461 … … 596 464 } 597 465 598 // Add the the blacklist599 466 $args['post__not_in'] = array_merge( $args['post__not_in'], $unlisted_posts ); 600 467 … … 615 482 616 483 } 617
Note: See TracChangeset
for help on using the changeset viewer.