• Resolved joker333

    (@joker333)


    Good evening and thank you for the fantastic plugin (practical and lightweight) that you have made available in the WordPress community.

    I really like the plugin, I plan to use it in some of my websites however I need to know how do I get the download count for each file based on the lana-id. Surely it can be done via a simple php snippet.

    Another thing I would like to ask is the following. Could you add a connection with the database that would allow us to manually change the download count directly in the back-end?
    Personal tip: other plugins like this offer this option, it’s better if you don’t fall behind.

    Once again thank you for the plugin and keep up the hard work.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Lana Codes

    (@lanacodes)

    You have two options to query the value of the counter:

    <?php echo lana_downloads_manager_get_download_count( $post_id ); ?>

    this function has more checks, for example you can use it even without $post_id if the global post is set.
    You can find the post id on the right in the download information metabox, this is the download identification.

    Another option is to query the post meta:

    $lana_download_count = get_post_meta( $post->ID, 'lana_download_count', true );

    Note: if this has never been downloaded by anyone, its value will be “null” instead of 0.

    Plugin Author Lana Codes

    (@lanacodes)

    Editing the download counter is a really good idea. I will definitely make an addon plugin that will allow this and will publish it on my own website to make it available to everyone.

    Or maybe I’m going to upgrade to the Lana Downloads Manager plugin, I still have to think about it. I don’t know which would be the better solution.

    I don’t think most users would need to edit the download counter, but for example it makes sense that if you import the data, the number of downloads also has a default value.

    Thread Starter joker333

    (@joker333)

    Hi lana, thanks for the quick response. I just tried it and “$download_count = lana_downloads_manager_get_download_count( $post_id );” works perfectly.

    I went to see what’s going on in the database and you have nothing to envy other plugins of this type. You did a great job, clean and effective. If I understand correctly, your custom post type is treated as a normal post and therefore I could extract its post meta… Did you happen to create some other function like “lana_downloads_manager_get_download_count();”?

    For example I can see a meta key called lana_download_file_url with which I could extract the file url. Is there a function like “lana_downloads_manager_get_download_count();” with which I could extract the file url or do I have to use “get_post_meta()”?

    And a small problem I see is that I can’t insert custom fields in the back-end. However other file download plugins have bigger problems ??

    I think in the next update of the plugin you could solve this little problem very easily.

    Again thanks for the quick response, wish all plugins developers were this quick and effective.

    Thread Starter joker333

    (@joker333)

    The download number editor might help in some situations, such as resetting the number once a month, in case you want to keep track of monthly downloads. Another example might be resetting the number after an attack by bots.

    I think it is a useful function.

    Regarding the addon plugin… I don’t think it’s a good idea. It is not such a “substantial” feature that people will buy it. Perhaps something like an addon to protect attacks by bots would be a good idea. This could be a “substantial” feature that people could pay for.

    Regarding the download number editor I think the best idea is to upgrade the plugin.

    Friend I got you some work ?? … custom fields in the back-end and download number editor

    Plugin Author Lana Codes

    (@lanacodes)

    Another example might be resetting the number after an attack by bots.

    There is some flood protection in the plugin. But yeah, the example is understandable and absolutely true.

    I want to publish the addon plugin for free. It will definitely be free, any solution.

    But I can solve the editing in the core plugin by clicking on a separate icon to change the counter to an input field. So that the primary goal is not for users to modify the counter.

    Plugin Author Lana Codes

    (@lanacodes)

    And a small problem I see is that I can’t insert custom fields in the back-end.

    You can add custom field support with the following code:

    /**
     * Add custom fields to lana download post type
     *
     * @param $args
     *
     * @return array
     */
    function lana_downloads_manager_add_custom_fields_to_lana_download_post_type( $args ) {
    
    	$args['supports'][] = 'custom-fields';
    
    	return $args;
    }
    
    add_filter( 'lana_downloads_manager_lana_download_post_type_args', 'lana_downloads_manager_add_custom_fields_to_lana_download_post_type' );

    Most people use the ACF plugin for this purpose.

    Otherwise, it is possible to modify the counter if you enable custom fields.

    Custom fields metabox is not enabled by default because file selection has more functions in the background, for example inserting the file id, which helps in user-friendly operation. Therefore, it would only be confusing for the average user. Advanced users, on the other hand, can add it with the code snippet above.

    Plugin Author Lana Codes

    (@lanacodes)

    There is a function that you can use to get the download url:

    $download_ url = esc_url( lana_downloads_manager_get_download_url( $post_id ) );

    In the same way, you can use it even without $post_id if the global post is set.

    You can get the direct url of the file, but you cannot use it because it is a protected file (if you upload it from the plugin download post tpye and not from an external service provider like Dropbox). Due to security and normal operation (counter, log operation), the file is protected and cannot be downloaded bypassing the download manager.

    $file_url = get_post_meta( $post->ID, 'lana_download_file_url', true );

    Note: as I said, you cannot use this direct file url. It will not work.

    Thread Starter joker333

    (@joker333)

    Perfect, clear as in previous answers. I enabled the custom fields without any problems and it is true that the average user might get confused. By default it is best to leave them disabled.

    Apparently you have done a good job as far as file protection is concerned, so good, nothing to add.

    Regarding the download counter, I thought it would be much easier. You have many doubts to the respect, it is your plugin and you certainly know more about it than I do. In these cases, it is best to take your time; you are not in a hurry.

    Clearly by enabling custom fields I can change the count directly in the back-end. I asked you for that reason as well, but not only that. This way I can add fields that will later be retrieved in my custom shortcodes.

    Finally, I can only say thank you for the fast and effective support and wish you the best as a wordpress developer.

    Plugin Author Lana Codes

    (@lanacodes)

    After much deliberation, we have decided not to develop an option to edit the counter in the plugin at the moment.

    For admin it is possible to modify the counter if you enable custom fields. Thus, this problem can be solved with the core function.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Improvements regarding the download count’ is closed to new replies.