X-Git-Url: https://git.danix.xyz/?p=danixland-wporg-stats.git;a=blobdiff_plain;f=danixland-wporg-stats.php;h=f904dff18719feb37d899770b15876515c62deb6;hp=bad3d5cb099cb74ad603aaf65dd8544496fd4003;hb=HEAD;hpb=38cb3d1da942201ae9efb1318e81be77325e2037 diff --git a/danixland-wporg-stats.php b/danixland-wporg-stats.php index bad3d5c..f904dff 100644 --- a/danixland-wporg-stats.php +++ b/danixland-wporg-stats.php @@ -324,4 +324,122 @@ class dnx_WPOrg extends WP_Widget { } } +// Add Shortcode +function dnxwporg_stats_shortcode() { + + $author = sanitize_user(get_option('dnxwporg_author'), true); + $description = get_option('dnxwporg_description'); + $desc_content = get_option('dnxwporg_desc_content'); + $linkto = get_option('dnxwporg_linkto'); + $use_icons = get_option('dnxwporg_use_icons'); + + /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */ + $option_stats = get_option('dnxwporg_plugins_stats'); + $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats ); + + ob_start(); ?> + +
+ +
+ +

%s plugin with %s total downloads and an average rating of %s', '%s contributed %s plugins with %s total downloads and an average rating of %s', $plugins['total_plugins'], 'dnxwporg' ), $author, $plugins['total_plugins'], $plugins['total_downloads'], $plugins['average_rating'] ); ?>

+ +

+ +
+ +
+ +
+
+ + 0, + 'avg_dloads' => 0, + 'pl_count' => 0, + ), + $atts + ); + + /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */ + $option_stats = get_option('dnxwporg_plugins_stats'); + $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats ); + + // Build the $output variable + $output = ""; + + if ($a['total_dl']) { + $output = $plugins['total_downloads']; + } elseif ($a['avg_dloads']) { + $output = $plugins['average_rating']; + } elseif ($a['pl_count']) { + $output = $plugins['total_plugins']; + } + + return $output; + +} +add_shortcode( 'dnxwporg_single_stat', 'dnxwporg_single_stats_shortcode' ); + +/** + * Shortcode that returns the plugin icon if existing + */ +function dnxwporg_plugin_icon( $atts ) { + + // Attributes + $a = shortcode_atts( + array( + 'plugin_name' => '', + ), + $atts + ); + + /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */ + $option_stats = get_option('dnxwporg_plugins_stats'); + $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats ); + + $name = $a['plugin_name']; + + // Build the $output variable + $output = ""; + + if (array_key_exists($name, $plugins) && ! empty($plugins[$name]['icon'])) { + $output = $plugins[$name]['icon']; + } else { + $output = ""; + } + + return $output; + +} +add_shortcode( 'plugin_icon', 'dnxwporg_plugin_icon' ); ?>