It is straightforward to implement the listings expiry and never expire as a bulk upload option for the listings on the Directorist.
Anyone can do it by following the steps described below -
Copy and paste the following code at the end of the "functions.php" currently activated theme folder.
1. functions.php
2. Custom code
- add_filter('bulk_edit_custom_box', 'directorist_custom_box_never_expire', 10, 2);
- function directorist_custom_box_never_expire($column_name, $post_type)
- {
- if (('atbdp_expiry_date' === $column_name) && (ATBDP_POST_TYPE == $post_type)) {
- ?>
- <fieldset class="inline-edit-col-right" style="margin-top: 0;">
- <div class="misc-pub-section misc-pub-atbdp-never-expires">
- <label>
- <input type="checkbox" name="never_expire" value="1" />
- <strong>Never Expires</strong>
- </label>
- <div class="atbdp_expiry_date">
- <label><strong>Expiry Date</strong></label>
- <input type="datetime-local" name="expiry_date" />
- </div>
- </div>
- </fieldset>
- <?php
- };
- }
- add_action('save_post', 'directorist_custom_box_never_expire_save');
- function directorist_custom_box_never_expire_save($post_id)
- {
- if (!is_admin()) {
- return;
- }
- if (get_post_type($post_id) !== ATBDP_POST_TYPE) {
- return;
- }
- // if our current user can't edit this post, bail
- if (!current_user_can('edit_posts')) {
- return;
- }
- // Make sure that it is set.
- if (isset($_REQUEST['never_expire']) && !empty($_REQUEST['never_expire'])) {
- update_post_meta($post_id, '_never_expire', sanitize_text_field($_REQUEST['never_expire']));
- }
- if (isset($_REQUEST['expiry_date']) && !empty($_REQUEST['expiry_date'])) {
- update_post_meta($post_id, '_expiry_date', sanitize_text_field($_REQUEST['expiry_date']));
- update_post_meta($post_id, '_never_expire', 0);
- }
- }
- add_action('admin_footer', function(){
- ?>
- <script>
- jQuery(document).ready(function($){
- $('.misc-pub-atbdp-never-expires input[name="never_expire"]').change(function(){
- if( $(this).is(":checked") ){
- $('.misc-pub-atbdp-never-expires .atbdp_expiry_date').hide();
- $('.misc-pub-atbdp-never-expires input[name="expiry_date"]').val('');
- }else{
- $('.misc-pub-atbdp-never-expires .atbdp_expiry_date').show();
- }
- });
- });
- </script>
- <?php
- });
This should export results like the following image -
Simple, is not it? Please comment below if you have any questions regarding this.
No comments:
Post a Comment