Title: Using php with your plugin
Last modified: July 1, 2020

---

# Using php with your plugin

 *  Resolved [Chuckie](https://wordpress.org/support/users/ajtruckle/)
 * (@ajtruckle)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/)
 * Hi!
 * I have read the documentation and know that I can use the following shortcode
   syntax to obtain the download count for a given item:
 * `[sdm_show_download_info id="123" download_info="download_count"]`
 * I have three downloads so I can have three shortcode references. No problem with
   that.
 * My issue is that I need to come up with a new shortcode code that basically does
   this:
 *     ```
       WorkOutDownloadAsPercentage(download id)
           total_msa = get-download-total-for-msa
           total_pts = get-download-total-for-pts
           total_vrr = get-download-total-for-vrr
           total = total_msa + total_pts + total_vrr;
           percent_msa = (100 / total) * total_msa
           percent_pts = (100 / total) * total_pts
           percent_vrr = (100 / total) * total_vrr
   
          if(download id is msa)
              return percent_msa
          else if(download id is pts)
              return percent_pts
          else if(download id is vrr)
             return percent_vrr
   
           return 0
       ```
   
 * Some thing like the above in to a shortcode, so I can call:
 * `[sdm_get_download_as_percent id=xxx]`
 * I appreciate this can’t be part of your plugin and just custom snippet at my 
   end.
 * Thanks for help.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Contributor [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13072783)
 * Hi, I have submitted a message to the developers to investigate further your 
   request.
 * Thank you
 *  Thread Starter [Chuckie](https://wordpress.org/support/users/ajtruckle/)
 * (@ajtruckle)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13072820)
 * Thank you.
 *  Plugin Author [mra13](https://wordpress.org/support/users/mra13/)
 * (@mra13)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13075202)
 * You will need to create a custom shortcode for this in a custom little plugin(
   or addon). It will probably turn out to be a 2-3 hour custom coding job. So I
   am not sure how I can provide help for this for free.
 *  Thread Starter [Chuckie](https://wordpress.org/support/users/ajtruckle/)
 * (@ajtruckle)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13075379)
 * Hi
 * All I want to know is how I can call one of your short codes (above) and store
   it’s value to a variable. Is it by using do_shortcode(…)?
 *  Thread Starter [Chuckie](https://wordpress.org/support/users/ajtruckle/)
 * (@ajtruckle)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13076637)
 * Worked it out 😀
 *  Thread Starter [Chuckie](https://wordpress.org/support/users/ajtruckle/)
 * (@ajtruckle)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13078520)
 * My code:
 *     ```
       function xxx_download_percentage($attr)
       {
       	$id_aaa = aaa;
       	$id_bbb = bbb;
       	$id_ccc = ccc;
   
       	$args = shortcode_atts( array(
                   'download_id' => 'aaa'
               ), $attr );
   
           $aaa_DownloadCount = do_shortcode('[sdm_show_download_info id="aaa" download_info="download_count"]');
           $bbb_DownloadCount = do_shortcode('[sdm_show_download_info id="bbb" download_info="download_count"]');
           $ccc_DownloadCount = do_shortcode('[sdm_show_download_info id="ccc" download_info="download_count"]');
   
           $total_DownloadCount = $aaa_DownloadCount + $bbb_DownloadCount + $ccc_DownloadCount;
   
       	if($args['download_id'] == $id_aaa)
       	{
       		$aaa_Percent = (100 / $total_DownloadCount) * $aaa_DownloadCount;
       		return round($aaa_Percent, 0, PHP_ROUND_HALF_UP);
       	}
       	elseif($args['download_id'] == $id_bbb)
       	{
       		$bbb_Percent = (100 / $total_DownloadCount) * $bbb_DownloadCount;
       		return round($bbb_Percent, 0, PHP_ROUND_HALF_UP);
       	}
       	elseif($args['download_id'] == $id_ccc)
       	{
       		$ccc_Percent = (100 / $total_DownloadCount) * $ccc_DownloadCount;
       		return round($ccc_Percent, 0, PHP_ROUND_HALF_UP);
       	}
   
           return 0;
       }
       add_shortcode( 'zz_download_percent', 'xxx_download_percentage' );
       ```
   
 * Where `aaa`, `bbb` and `ccc` are specific **Download ID** values.
 * Then you can use it:
 * `[zz_download_percent download_id="aaa"]`
    -  This reply was modified 5 years, 9 months ago by [Chuckie](https://wordpress.org/support/users/ajtruckle/).
 *  Plugin Contributor [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13080602)
 * Hi, thank you for sharing your code. I am sure your code will help other trying
   to achieve the same as you.
 * Kind regards

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Using php with your plugin’ is closed to new replies.

 * ![](https://ps.w.org/simple-download-monitor/assets/icon-128x128.png?rev=973803)
 * [Simple Download Monitor](https://wordpress.org/plugins/simple-download-monitor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-download-monitor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-download-monitor/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-download-monitor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-download-monitor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-download-monitor/reviews/)

## Tags

 * [custom shortcode](https://wordpress.org/support/topic-tag/custom-shortcode/)

 * 7 replies
 * 3 participants
 * Last reply from: [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/using-php-with-your-plugin/#post-13080602)
 * Status: resolved