Plugin Directory

Changeset 3001366


Ignore:
Timestamp:
11/24/2023 07:31:28 PM (2 years ago)
Author:
kusimo
Message:

Optimised resource loading: CSS and JavaScript files are now only loaded when the Quick Download Button is present on the page.

Location:
quick-download-button/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • quick-download-button/trunk/quick-download-button.php

    r2901151 r3001366  
    55 * Plugin URI: https://github.com/kusimo/quick-download-button
    66 * Description: Use to add download button link to post or page.
    7  * Version: 1.2.5
     7 * Version: 1.2.6
    88 * Author: Abidemi Kusimo
    99 *
     
    8282    );
    8383
    84     // Register the block editor stylesheet.
    85     wp_register_style(
    86         'quick-download-button-editor-styles',                      // label
    87         plugins_url( 'css/editor.css', __FILE__ ),                    // CSS file
    88         array( 'wp-edit-blocks' ),                                    // dependencies
    89         filemtime( plugin_dir_path( __FILE__ ) . 'css/editor.css' )     // set version as file last modified time
    90     );
    91 
    92     // Register the front-end stylesheet. FRONTEND.
    93     wp_register_style(
    94         'quick-download-button-front-end-styles',                     // label
    95         plugins_url( 'css/minified/style.min.css', __FILE__ ),                       // CSS file
    96         array(),                                                      // dependencies
    97         filemtime( plugin_dir_path( __FILE__ ) . 'css/style.css' )        // set version as file last modified time
    98     );
    99 
    10084    //Register blocks script and styles
    10185    register_block_type(
     
    119103}
    120104
    121 
     105function qdbu_enqueue_block_editor_assets() {
     106    // Enqueue editor-specific styles
     107    wp_enqueue_style(
     108        'quick-download-button-editor-styles',                      // Handle for editor styles
     109        plugins_url('css/editor.css', __FILE__),                    // Editor CSS file
     110        array('wp-edit-blocks'),                                    // Dependencies
     111        filemtime(plugin_dir_path(__FILE__) . 'css/editor.css')     // Version: file last modified time
     112    );
     113
     114    // Enqueue frontend styles as well
     115    wp_enqueue_style(
     116        'quick-download-button-front-end-styles',                   
     117        plugins_url('css/minified/style.min.css', __FILE__),       
     118        array(),                                                   
     119        filemtime(plugin_dir_path(__FILE__) . 'css/style.css')     
     120    );
     121}
     122
     123add_action('enqueue_block_editor_assets', 'qdbu_enqueue_block_editor_assets');
     124
     125
     126function has_quick_download_button($post_id) {
     127    $post = get_post($post_id);
     128    $content = $post ? $post->post_content : '';
     129
     130    // Check for shortcode
     131    if (has_shortcode($content, 'quick_download_button')) {
     132        return true;
     133    }
     134
     135    // Check for Gutenberg block
     136    if (has_block('quick-download-button/download-button', $post_id)) {
     137        return true;
     138    }
     139
     140    return false;
     141}
     142
     143/**
     144 * Front end CSS
     145 */
     146function qdbu_enqueue_download_button_styles() {
     147    global $post;
     148
     149    if (is_a($post, 'WP_Post') && has_quick_download_button($post->ID)) {
     150        wp_enqueue_style(
     151            'quick-download-button-front-end-styles',                     // label
     152            plugins_url('css/minified/style.min.css', __FILE__),         // CSS file
     153            array(),                                                      // dependencies
     154            filemtime(plugin_dir_path(__FILE__) . 'css/style.css')       // set version as file last modified time
     155        );
     156    }
     157}
     158add_action('wp_enqueue_scripts', 'qdbu_enqueue_download_button_styles');
    122159
    123160/**
    124161 * Front end Script
    125162 */
    126 
    127 
    128163function qdbu_button_front_end_script() {
    129 
     164        global $post;
     165        if (is_a($post, 'WP_Post') && has_quick_download_button($post->ID)) {
    130166        wp_enqueue_script(
    131             'quick-download-button-frontend-script',                    // label
    132             plugins_url( 'frontend/minified/frontend.js', __FILE__ ),            // script file
    133             array(),        // dependencies
    134             filemtime( plugin_dir_path( __FILE__ ) . 'frontend/frontend.js' ),        // set version as file last modified time
     167            'quick-download-button-frontend-script',                   
     168            plugins_url( 'frontend/minified/frontend.js', __FILE__ ),   
     169            array(),       
     170            filemtime( plugin_dir_path( __FILE__ ) . 'frontend/frontend.js' ),   
    135171            true
    136172        );
     
    146182            )
    147183        );
     184    }
    148185
    149186}
  • quick-download-button/trunk/readme.txt

    r2901151 r3001366  
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html
    77Requires at least: 3.0.1
    8 Tested up to: 6.0.2
    9 Stable tag: 1.2.5
     8Tested up to: 6.4.1
     9Stable tag: 1.2.6
    1010Requires PHP: 5.6
    1111License: GPLv3
     
    1515
    1616== Description ==
    17 Quick download button is a download button for WordPress. You can easily add a better download link to your post with this plugin. Some of the features include countdown timer, 4 button styles, colors, hide/show file size and extension. Support for wordpress block and shortcodes.
     17The Quick Download Button plugin for WordPress allows you to easily integrate a simple but sophisticated download button into your posts and pages. This versatile plugin offers a range of features like a countdown timer, multiple button styles, and the ability to hide or show file size and extension. It supports both WordPress blocks and shortcodes, making it highly adaptable to your website's needs.
    1818
    1919
     
    2424== Features ==
    2525
    26 * Display file size and file extension
    27 * Create a download button link with shortcode with options
    28 * Customize your download button to suit your site brand
    29 * Link your download button to anywhere on the web where it's publicly available.
    30 * Allow free music download, video download, PDF download, spreadsheet file download and more.
    31 * Hide download link
    32 * Countdown - Wait before download, you can specify how many seconds you want the user to wait before download starts.
    33 * Show the user a message while waiting for the download to start.
    34 * Support for external download link
    35 * Shows download file extension for 'pdf','mp3','mov','zip','txt','doc','xml','mp4','ppt' and images ( png, gif, jpg, jpeg, bmp)
    36 * Support for htm, html, ps, tex, xml, txt, csv, xlsx (Microsoft Excel), pptx (Microsoft PowerPoint), js, css, php
     26* Display file size and extension.
     27* Create customizable download buttons via shortcode.
     28* Link your download button to any publicly accessible web location.
     29* Support for a wide range of file types including music, video, PDFs, spreadsheets, and more.
     30* Option to hide the download link for added security.
     31* Countdown feature to specify a waiting time before the download starts.
     32* Customizable waiting message for user engagement.
     33* Support for external download links.
     34* Shows download file extension for 'pdf','mp3','mov','zip','txt','doc','xml','mp4','ppt' and images ( png, gif, jpg, jpeg, bmp).
     35* Support for htm, html, ps, tex, xml, txt, csv, xlsx (Microsoft Excel), pptx (Microsoft PowerPoint), js, css, php.
    3736* Open external download in new tab or same window.
    38 * Force file download
    39 * Control access to download using users' role and logged in.
    40 * Support for WordPress Gutenberg
     37* Force file download.
     38* Access control based on user roles and login status.
     39* WordPress Gutenberg block support for easy integration.
    4140
    4241
    4342 == Basic Usage ==
    4443
    45 
    4644** Shortcode **
    47 Open the post or page you want to add a download button to, paste the shortcode example below
     45To add a download button, open the post or page editor and paste the following shortcode example:
    4846
    4947`
    5048[quick_download_button title="Download" url="http://yoursite/wp-content/upload/fileto_download.pdf"]
    5149`
    52 The url value needs to be replaced with your media link URL. To change the title, enter a different text in the title value. The default value is Download.
     50Replace the url value with your file's URL. Change the title value to customize the button text.
    5351
    5452
     
    5755** Open link in a new window **
    5856
    59 To open the download link in a new window (tab), set attribute 'open_new_window" to true. To open link in the same window set the attribute to 'false' See example below:
     57Set open_new_window to true to open the download link in a new tab, or false to open it in the same window.
    6058
    6159`
     
    6361`
    6462
    65 ** Set the button background color (color_bg="#ffc107"), set waiting timer (wait=15) and waiting message (msg="Please wait 15 seconds") **
     63** Set the button background color (color_bg="#ffc107"), waiting timer (wait=15) and a custom message (msg="Please wait 15 seconds") **
    6664
    6765`
     
    6967`
    7068
    71 ** Link to external URL **
    72 
    73 To use external url, add url_external attribute
     69** Link to an External URL **
     70
     71To use external url, add url_external attribute.
    7472
    7573`
     
    7775`
    7876
    79 ** Auto calculates file size. **
    80 
    81 To let the plugin generate file size, make sure the file URL link is in the WordPress upload directory when using with shortcode e.g wp-content/upload and change filesize value to 1 like below
     77** Auto Calculate File Size **
     78
     79To have the plugin automatically generate the file size, ensure the file URL is in the WordPress upload directory and set file_size to 1.
    8280
    8381`
     
    8583`
    8684
    87 ** Add file size manually **
    88 
    89 The plugin can calculate the file size for you by entering 1 in the filesize value. You don't have to enter it manually but in case, enter the file size value in the filesize attribute like below.
     85** Manually Add File Size **
     86
     87You can manually specify the file size in the file_size attribute.
    9088
    9189`
     
    9492
    9593
    96 ** Hide icon for file extension **
    97 To hide icon image for the file extension, set the extension value to 0. Note, this will also hide file extension text.
     94** Hide File Extension Icon **
     95
     96To display both the file extension icon and text, set extension and extension_text to 1.
    9897
    9998`
     
    101100`
    102101
    103 ** Show icon image and file extension text **
    104 
    105 To show both file extension icon and text,  set extension value to 1 and extension_text to 1
     102** Display File Extension Icon and Text **
     103
     104To showcase both the file extension icon and its text, set both the extension and extension_text attributes to 1.
    106105
    107106`
     
    109108`
    110109
    111 ** Gutenberg Block **
    112 
    113 1. Open the post you want to add a download link to, click on add block icon (+).
    114 2. Under Media, click on the Download Button icon.
    115 3. Click on the button to change the title, click on the download icon next to the button to upload a file for download.
    116 4. Enter a suitable title in the text box, the default title is download. All done!
    117 
    118 ** More Gutenberg Usage **
    119 To hide the file size, use the advanced option in the Gutenberg settings. Click on the Additional CSS class(es) and add 'hide-size' to the class.
    120 
    121 
    122 == To use in a theme file (Developers) ==
    123 
    124 To use in your theme file, add the code below with necessary attributes and values.
     110** Using the Gutenberg Block **
     111
     1121. Open the post where you wish to add a download link and click on the 'Add Block' icon (+).
     1132. Look for 'Download Button' under the Media category and click to add it.
     1143. Click on the button to edit its title and the adjacent download icon to upload the file for download.
     1154. Provide a custom title in the text box if desired. The default title is 'Download'. That's it!
     116
     117** Advanced Gutenberg Usage **
     118To hide the file size in the Gutenberg editor, utilize the 'Additional CSS class(es)' field in the block settings. Add 'hide-size' to this field to apply the effect.
     119
     120
     121== For Developers: Integrating in a Theme File ==
     122
     123To incorporate the download button within a theme file, use the following code with your specified attributes and values:
    125124
    126125`
     
    130129== Donations ==
    131130
    132 Would you like to support the advancement of this plugin? [Donate](https://www.buymeacoffee.com/kusimo)
     131If you find this plugin helpful and would like to support its ongoing development, please consider [Donate](https://www.buymeacoffee.com/kusimo)
    133132
    134133
     
    138137== Frequently Asked Questions ==
    139138
    140 = Can this plugin be used to hide (protect) download link on my site? =
    141 
    142 Yes.
    143 
    144 = Can I use the plugin in Classic Editor =
    145 
    146 Yes. You can use this plugin with shortcodes.
     139= Can this plugin be used to hide (protect) download links on my site? =
     140
     141Yes, it can.
     142
     143= Can I use the plugin in the Classic Editor? =
     144
     145Yes, you can use this plugin with shortcodes in the Classic Editor.
    147146
    148147= Can this plugin be used to display download file size on my site? =
    149148
    150 Yes.
    151 
    152 = Can I hide the 'Please wait...' message for countdown timer? =
    153 
    154 If using shortcode, in  leave the attribute 'msg' blank. For example:
     149Yes, it displays the download file size.
     150
     151= Can I hide the 'Please wait...' message for the countdown timer? =
     152
     153For shortcodes, leave the msg attribute blank. Example:
    155154`
    156155[quick_download_button button_type="small" msg="" title="Download Now" url_external="http://external-url-here/"]
    157156`
    158157
    159 If using block, under the 'Countdown Settings', select time to wait (E.g 15 for 15 seconds) and the message box will show up. Remove the default message.
     158For blocks, under 'Countdown Settings', select the time to wait (e.g., 15 for 15 seconds) and remove the default message from the message box.
    160159
    161160= What are the shortcode attributes? =
     
    180179* 'padding'
    181180
    182 Example: Change button style with 'button_type'
     181Change button style with 'button_type':
    183182`
    184183[quick_download_button button_type="small" title="Download Now" url_external="http://external-url-here/"]
    185184`
    186185
    187 Example: Add file from your WordPress site with 'url'
     186Add file from your WordPress site with url:
    188187`
    189188[quick_download_button button_type="mid" title="Download Now" url="http://yoursite/wp-content/uploads/yourfile.pdf"]
    190189`
    191190
    192 Example: Add border radius with 'border_radius'
     191Add border radius with 'border_radius':
    193192`
    194193[quick_download_button button_type="small" border_radius="9" title="Download Now" url_external="http://external-url-here/"]
    195194`
    196195
    197 Example: Change icon color from dark to light with 'color_icon_dark'
     196Change icon color with color_icon_dark:
    198197`
    199198[quick_download_button button_type="large" color_icon_dark="false" color_bg="black" color_font="#FFF" title="Download Now" url_external="http://external-url-here/"]
    200199`
    201200
    202 Example: Add countdown and wait message with 'wait' and 'msg'
     201Add countdown and wait message with wait and msg:
    203202`
    204203[quick_download_button button_type="basic" wait="10" msg="Please wait..."  title="Download Now" url_external="http://external-url-here/"]
    205204`
    206205
    207 Example: Add file size manually with 'file_size' - This is useful for external download lik
     206Manually add file size with file_size:
    208207`
    209208[quick_download_button button_type="basic" wait="10" msg="Please wait..." file_size="40MB"  title="Download Now" url_external="http://external-url-here/"]
    210209`
    211210
    212 Example: Hide file extension (icon) with 'extension'
     211Hide file extension with extension:
    213212`
    214213[quick_download_button button_type="basic" extension="0"  title="Download Now" url_external="http://external-url-here/"]
    215214`
    216215
    217 Example: Add border style
     216Add border style:
    218217`
    219218[quick_download_button button_type="small" border_width="2" border_style="solid" border_color="black"  title="Download Now" url_external="http://external-url-here/"]
    220219`
    221220
    222 Example: By default, the button is position at the center of the page. Change alignment with 'align'
     221Change alignment with align:
    223222`
    224223[quick_download_button button_type="small" align="left"  title="Download Now" url_external="http://external-url-here/"]
     
    231230
    232231== Changelog ==
     232
     233= 1.2.6 - November 23rd, 2023 =
     234* Optimised resource loading: CSS and JavaScript files are now only loaded when the Quick Download Button is present on the page.
    233235
    234236= 1.2.5 April 19th, 2023 =
     
    258260== Upgrade Notice ==
    259261
    260 = 1.0.9 August 27th, 2022  =
    261 * Add 3 extra buttons - small, medium and basic.
    262 * Add button alignment - center, left or right.
    263 
    264 = 1.0.8 August 13th, 2022  =
    265 * Fixed message not showing up when user is waiting for download.
    266 
    267 = 1.0.7 August 6th, 2022  =
    268 * Support for multi site.
    269 * Add background color, waiting time and waiting message to shortcode.
    270 
    271 = 1.0.5 July 23rd, 2022  =
    272 * Remove jQuery dependencies
    273 * Open external download link in a new window.
     262= 1.2.6 - November 23rd, 2023 =
     263* Optimised resource loading: CSS and JavaScript files are now only loaded when the Quick Download Button is present on the page.
     264
     265= 1.2.5 April 19th, 2023 =
     266* Minor fixes of 404 error that occurs when quick download button page is deleted. After deletion of the QDB page, please deactivate and reactive the plugin.
     267
     268= 1.2.4 March 13th, 2023 =
     269* Fixed the error nonce did not verify when download link is external URL
Note: See TracChangeset for help on using the changeset viewer.