Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for this interesting suggestion. I’d like to learn a bit more about what you have in mind?

    Publishing posts and pages is performed by logic within WordPress that uses the combination of post_date and post_status fields to distinguish between “publish” and “future” posts. Attachments use post_date as the upload date and always set post_status to “inherit” (or “trash” if you enable trash for attachments). There’s no logic in WordPress for scheduling attachments.

    What would that mean, exactly? Are you trying to control the date and time at which the attachment would be uploaded (tough to do) or when it starts appearing in [gallery] and [mla_gallery] displays?

    If you want to schedule “display” date and time, I can consider an enhancement to [mla_gallery] that would support the “Date Parameters” found in the WP_Query class on which [mla_gallery] is based. I have never had a request for this feature, but perhaps it’s time (so to speak).

    Depending on what you want to do, you might be able to use the filters provided by MLA to remove “future” attachments from gallery display based on a date/time value stored in a custom field. I could sketch this out if that would work for you.

    If I have not understood your question, please give me some additional details so I can consider an enhancement that would meet your needs. Thanks for your interest in the plugin.

    Thread Starter Ruriko

    (@ruriko)

    I want to control on which attachments can start appearing in [mla_gallery] or to the public

    Plugin Author David Lingren

    (@dglingren)

    Thanks for supplying the additional detail. I can work on a solution that will let you control which attachments appear in the [mla_gallery] output. I am not sure what else you mean when you say “or to the public“.

    I have done some initial work on this, but I concluded that it will require upgrading the [mla_gallery] parameters, the gallery filters or both. I will work on this, but it may take some time, since I will be out of the country and away from my development system for two weeks.

    I will post an update to this topic when I have progress to report. Thanks for your patience and your understanding.

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your patience while I’ve been away from home. I am happy to report that you can use the current MLA version to control the visibility of Media Library items based on date. First, you must define a custom field and make it available for editing:

    1. Navigate to the Settings/Media Library Assistant “Custom Fields” tab.
    2. Make sure the “Enable custom field mapping when adding new media” box is checked. If not, check the box, scroll down to the bottom of the page and click “Save Changes”.
    3. Scroll down to the “Add a new Field and Mapping Rule” area.
    4. In the first text box, give your field a name, e.g., “Archive Date”
    5. From the Data Source dropdown list, select “upload_date”. This is the date and time the item was added to the Media Library. It will be the default value – you can change it for any particular items later.
    6. In the “Existing Text” dropdown list, select “Replace”.
    7. In the “Format” dropdown list, select “Native”.
    8. Click the “MLA Column”, “Quick Edit” and “Bulk Edit” check boxes to make the field available in the Media/Assistant submenu table, the Quick Edit area and the Bulk Edit area.
    9. In the “Option:” dropdown list, select “Text”.
    10. Click the “Delete NULL Values” checkbox.
    11. Click the “Add Field and Map All Attachments” button to save your work and create the “Archive Date” value for the items already in your Media Library.

    Once you’ve set up the custom field, you can use the Quick Edit and Bulk Edit areas to change the value from the upload date and time to some point in the future (or past). Go to the Media/Assistant submenu table, then click the Quick Edit rollover action to edit one item or use the checkboxes to select several items, select “Edit” from the Bulk Actions dropdown list and click “Apply”. For bulk editing, the Archive Date text box will be blank. Make sure the date and time you enter is in the proper format (YYYY-MM-DD HH:MM:SS).

    You can use the meta_query parameter to filter your [mla_gallery] items by the Archive Date custom field. For example, to display all items uploaded after 2013-06-30 you can code:

    [mla_gallery post_parent=all orderby="date DESC" meta_query="array( array( 'key' => 'Archive Date', 'value' => '2013-06-30', 'compare' => '>' ) )"]

    You can code just the date, or the complete date and time if that’s important. Complete documentation of the “meta query” syntax can be found in the WordPress Codex documentation for WP_Query.

    If you want to automatically filter all of your [mla_gallery] shortcodes based on the current date and time you will need to use one of the “MLA Gallery Filters and Actions (Hooks)”, described in the Settings/Media Library Assistant Documentation tab. You can add your code to the sample plugin that comes with MLA or put your filter in your theme’s functions.php file.

    Here is an example that adds a parameter to every [mla_gallery] shortcode:

    public static function mla_gallery_query_arguments_filter( $all_query_parameters ) {
    
    	$now = date( 'Y-m-d H:i:s'); // current date and time, e.g., 2013-07-01 10:05:18
    	$all_query_parameters['meta_query'] = "array( array( 'key' => 'Archive Date', 'value' => '{$now}', 'compare' => '<=' ) )";
    
    	self::$all_query_parameters = $all_query_parameters;
    	return $all_query_parameters;
    } // mla_gallery_query_arguments_filter

    The first line of the filter creates a string version of the current date and time in the same format as the values stored in the Archive Date custom field. The next line adds the meta_query parameter to the array containing all the other parameters you coded in the [mla_gallery] shortcode. This code will eliminate any item with an Archive Date value in the future from the gallery display. You might want to add some code that does not add the parameter to any shortcode that already has one; let me know if you need help with that. Don’t forget the add_filter statement that registers the filter with WordPress. In the example plugin, it looks like:

    add_filter( 'mla_gallery_query_arguments', 'MLAGalleryHooksExample::mla_gallery_query_arguments_filter', 10, 1 );

    I hope this gives you the “schedule posts” (attachments) logic you need for your application. I am going to mark this topic resolved, but please update it if you have any problems or further questions. Thanks for your interest in the plugin and for a question that many people should find interesting.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Schedule attachment’ is closed to new replies.