Plugin Directory

Changeset 2052012

Timestamp:
03/17/2019 11:03:42 AM (5 years ago)
Author:
danieltj
Message:

Update Unlist My Post to v3.0

Location:
unlist-my-post
Files:
6 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • unlist-my-post/trunk/README.md

    r1866569 r2052012  
    33[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.
    44
    5 ## Donate
    6 
    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 
    95## Useful Links
    106
    117- [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)
    139- [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  
    11=== Unlist My Post ===
    22Contributors: danieltj
    3 Tags: posts, unlisted, archive, hide, content
    4 Requires at least: 4.0
    5 Tested up to: 5.0
    6 Stable tag: 2.7
     3Tags: post
     4Requires at least: 4.
     5Tested up to: 5.
     6Stable tag:
    77License: GNU GPL v3
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
    9 Donate link: https://www.paypal.me/dtj27
    109
    1110Unlist your posts so you'll need a link to read them.
     
    1716= Developers =
    1817
    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).
     18iki on the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post/wiki).
    2019
    2120== Installation ==
     
    5453== Changelog ==
    5554
    56 Refer to the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post/releases) for more information on version history and updates.
     55Refer to the [GitHub repository](https://github.com/danieltj27/Unlist-My-Post.
  • unlist-my-post/trunk/unlist-my-post.php

    r2018591 r2052012  
    55 * Plugin URI: https://wordpress.org/plugins/unlist-my-post/
    66 * Description: Unlist your posts so you'll need a link to read them.
     7
    78 * Author: Daniel James
    89 * Author URI: https://danieltj.uk/
    910 * Text Domain: unlist-my-post
    10  * Version: 2.7
    1111 */
    1212
     
    2929
    3030if ( ! defined( 'ABSPATH' ) ) {
     31
    3132    die();
     33
    3234}
    3335
    34 $Unlist_My_Post = new Unlist_My_Post;
     36new Unlist_My_Post;
    3537
    3638class Unlist_My_Post {
    3739
    3840    /**
    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.
    5442     *
    5543     * @return void
     
    5745    public function __construct() {
    5846
    59         add_action( 'plugins_loaded', array( __CLASS__, 'load_text_domain' ), 10, 0 );
    6047        add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ), 10, 0 );
    6148        add_action( 'save_post', array( __CLASS__, 'save_meta_value' ), 10, 1 );
     
    6451        add_action( 'manage_pages_custom_column', array( __CLASS__, 'show_unlisted_column' ), 10, 2 );
    6552
    66         add_filter( 'plugin_action_links', array( __CLASS__, 'add_donate_link' ), 10, 2 );
    6753        add_filter( 'manage_posts_columns', array( __CLASS__, 'add_unlisted_column' ), 10, 1 );
    6854        add_filter( 'manage_pages_columns', array( __CLASS__, 'add_unlisted_column' ), 10, 1 );
     
    7662
    7763    /**
    78      * Load the plugin text domain.
    79      *
    80      * @since 1.0
    81      *
    82      * @return void
    83      */
    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.2
    94      * @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 links
    98      * @param string $file  The current plugin file.
    99      *
    100      * @return array $links
    101      */
    102     public static function add_donate_link( $links, $file ) {
    103 
    104         // Check if this is the current plugin
    105         if ( 'unlist-my-post/unlist-my-post.php' == $file ) {
    106 
    107             // Create the donate link
    108             $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 array
    111             array_unshift( $links, $donate_link );
    112 
    113         }
    114 
    115         return $links;
    116 
    117     }
    118 
    119     /**
    12064     * Gets the list of unlisted posts from the database.
    12165     *
     
    12468     * elegant than doing database queries in each function.
    12569     *
    126      * @since 1.0
    127      *
    12870     * @return array $unlisted An array of unlisted posts
    12971     */
     
    13274        global $wpdb;
    13375
    134         // Get a list of all the unlisted posts
     76        // Get a
    13577        $get_posts = $wpdb->get_results(
    13678            $wpdb->prepare(
     
    14183        );
    14284
    143         // Create an array for our posts
    14485        $unlisted_posts = array();
    14586
    146         // Loop through each post from the query
    14787        foreach ( $get_posts as $post ) {
    14888
    149             // Add the post to the array
    15089            array_push( $unlisted_posts, $post->post_id );
    15190
     
    15998     * Checks if a post is unlisted.
    16099     *
    161      * @since 1.0
    162      *
    163100     * @param string $post_id The post id to check.
    164101     *
     
    167104    public static function is_post_unlisted( $post_id ) {
    168105
    169         // Get the meta value
    170106        $get_post_meta = get_post_meta( $post_id, 'post_list_status', true );
    171107
    172         // Check if this post is unlisted
     108        //
    173109        if ( 'on' == $get_post_meta ) {
    174110
     
    184120
    185121    /**
    186      * Gets all the public post types.
    187      *
    188      * @since 2.4
     122     * Get all the public post types.
    189123     *
    190124     * @return array $post_types An array of post types.
     
    192126    public static function get_post_types() {
    193127
    194         // Fetch any custom post types
     128        // Fetch a
    195129        $get_custom_types = get_post_types(
    196130            array(
     
    203137        );
    204138
    205         // Setup the blank array
    206139        $post_types = array();
    207140
    208         // Add the built in types
    209141        $post_types[] = 'post';
    210142        $post_types[] = 'page';
    211143
    212         // Loop through each custom post type
    213144        foreach ( $get_custom_types as $key => $value ) {
    214145
    215             // Add the custom post type
    216146            $post_types[] = $value;
    217147
     
    234164
    235165    /**
    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.
    242167     *
    243168     * @return void
     
    245170    public static function add_meta_box() {
    246171
    247         // Get the post types
    248172        $post_types = self::get_post_types();
    249173
    250         // Create the new meta box
    251174        add_meta_box(
    252175            'unlist_my_post',
    253176            esc_html__('Listings', 'unlist-my-post'),
    254             array(
    255                 __CLASS__,
    256                 'meta_box_content'
    257             ),
     177            array( __CLASS__, 'meta_box_content' ),
    258178            $post_types,
    259179            'side',
    260180            'default',
    261             array(
    262                 '__block_editor_compatible_meta_box' => true
    263             )
     181            array( '__block_editor_compatible_meta_box' => true )
    264182        );
    265183
     
    267185
    268186    /**
    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.
    274188     *
    275189     * @param object $post WP_Post object of the current post.
     
    279193    public static function meta_box_content( $post ) {
    280194
    281         // Create the nonce
    282195        $unlist_my_post_nonce = wp_create_nonce('unlist_my_post_nonce');
    283196
    284         // Get the post type object
    285197        $post_type = get_post_type_object( $post->post_type );
    286198
     
    300212
    301213    /**
    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.
    307215     *
    308216     * @param string $post_id Current post ID that is being saved.
     
    312220    public static function save_meta_value( $post_id ) {
    313221
    314         // Get the nonce value and sanitise
     222        //
    315223        $unlist_my_post_nonce = isset( $_POST['unlist_my_post_nonce'] ) ? sanitize_text_field( $_POST['unlist_my_post_nonce'] ) : '';
    316224
    317         // Check the nonce is valid
     225        //
    318226        if ( wp_verify_nonce( $unlist_my_post_nonce, 'unlist_my_post_nonce' ) ) {
    319227
    320             // Set the value of the option
    321228            $post_list_status = isset ( $_POST['unlist_my_post_option'] ) ? 'on' : 'off';
    322229
    323             // Save the setting
    324230            update_post_meta( $post_id, 'post_list_status', $post_list_status );
    325231
     
    329235
    330236    /**
    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.
    336238     *
    337239     * @param string $column  The current column.
     
    342244    public static function show_unlisted_column( $column, $post_id ) {
    343245
    344         // Check the current column is 'unlisted'
     246        // Check the current column
    345247        if ( 'unlisted' == $column ) {
    346248
    347             // See if the current post been unlisted
    348249            if ( true === self::is_post_unlisted( $post_id ) ) {
    349250
     
    363264
    364265    /**
    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.
    369267     *
    370268     * @param array $columns The array of registered columns.
     
    385283     * because we don't want to filter people's custom queries.
    386284     *
    387      * @since 1.0
    388      * @since 2.1 Changed the use of not empty to not false.
    389      *
    390285     * @param object $query The query object for fetching posts.
    391286     *
     
    394289    public static function filter_unlisted_posts( $query ) {
    395290
    396         // Get the unlisted posts
    397291        $unlisted_posts = self::get_unlisted_posts();
    398292
     
    407301        if ( false !== $unlisted_posts && $query->is_main_query() && ! is_admin() && ! is_single() && ! is_page() ) {
    408302
    409             // Exclude in the query
    410303            $query->set( 'post__not_in', $unlisted_posts );
    411304
     
    434327     * Filter the post title.
    435328     *
    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.
    444332     *
    445333     * @param string $post_title The post title.
     
    450338    public static function filter_post_title( $post_title, $post_id ) {
    451339
    452         // Make sure the post is unlisted
    453340        if ( ! is_admin() && false !== self::is_post_unlisted( $post_id ) ) {
    454341
    455             // Get the real title
    456342            $get_post = get_post( $post_id );
    457343            $real_title = $get_post->post_title;
    458344
    459             // Generate the new title
    460345            $new_title = sprintf( esc_html__('Unlisted: %s', 'unlist-my-post'), $real_title );
    461346
     
    484369     * See the function above, `filter_unlisted_posts` for more information.
    485370     *
    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()
    490372     *
    491373     * @param array $args Arguments for filtering posts in the widget.
     
    497379        $unlisted_posts = self::get_unlisted_posts();
    498380
    499         // Make sure we have at least one post
    500381        if ( false !== $unlisted_posts ) {
    501382
    502             // In case it's not set already
    503383            if ( ! isset( $args['post__not_in'] ) ) {
    504384
     
    507387            }
    508388
    509             // Add the the blacklist
    510389            $args['post__not_in'] = array_merge( $args['post__not_in'], $unlisted_posts );
    511390
     
    534413     * for some reason and expects a comma seperated string of page IDs.
    535414     *
    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()
    541416     *
    542417     * @param array $args Arguments for filtering pages in the widget.
     
    548423        $unlisted_posts = self::get_unlisted_posts();
    549424
    550         // Ensure we have at least one unlisted page
    551425        if ( false !== $unlisted_posts ) {
    552426
    553             // Convert the array into a string
    554427            $unlisted_posts = implode( ', ', $unlisted_posts );
    555428
    556             // Concatenate the existing list to the new list
    557429            $args['exclude'] .= ',' . $unlisted_posts;
    558430
     
    574446    /**
    575447     * Filter out unlisted posts from the REST API.
    576      *
    577      * @since 2.5
    578448     *
    579449     * @param array  $args    The post query arguments.
     
    586456        $unlisted_posts = self::get_unlisted_posts();
    587457
    588         // Ensure we have at least one unlisted page
    589458        if ( false !== $unlisted_posts ) {
    590459
    591             // In case it's not set already
    592460            if ( ! isset( $args['post__not_in'] ) ) {
    593461
     
    596464            }
    597465
    598             // Add the the blacklist
    599466            $args['post__not_in'] = array_merge( $args['post__not_in'], $unlisted_posts );
    600467
     
    615482
    616483}
    617 
Note: See TracChangeset for help on using the changeset viewer.