3 Plugin Name: Site Plugin for danixland.net
4 Description: Site specific code changes for danixland.net
8 * Disable admin bar sitewide
10 show_admin_bar(__return_false());
13 * Allow Shortcodes inside the html widget
15 add_filter( 'widget_text', 'do_shortcode' );
18 * make sure the links menu in the admin is visible
20 add_filter( 'pre_option_link_manager_enabled', '__return_true' );
23 * The gravatar shortcode
25 * @param email $email email address used to retrieve the gravatar image
26 * @return string HTML the image tag which will display the gravatar image.
29 function danix_gravatar( $atts ) {
30 extract(shortcode_atts(array(
40 $output = get_avatar($email, $size, $default, $alt);
44 add_shortcode('gravatar', 'danix_gravatar');
47 * The download button shortcode
49 * @param url $link link address.
50 * @param string $linkname text that will be displayed by the button.
51 * @return string HTML the link tag that will be rendered to the page.
54 function danix_download_button( $atts ) {
55 extract(shortcode_atts(array(
64 '<a href="%s" class="download_button">%s</a>',
71 add_shortcode('download', 'danix_download_button');
74 * The google analytics code
77 function danix_google_anal() {?
>
78 <!-- Global site
tag (gtag
.js
) - Google Analytics
-->
79 <script async src
="https://www.googletagmanager.com/gtag/js?id=UA-23882460-1"></script
>
81 window
.dataLayer
= window
.dataLayer ||
[];
82 function gtag(){dataLayer
.push(arguments
);}
83 gtag('js', new Date());
85 gtag('config', 'UA-23882460-1');
88 add_action('wp_head', 'danix_google_anal', 10);
91 * The googlemaps shortcode
93 * @param width the width of the returned map
94 * @param height the height of the returned map
95 * @param src the url of the map you want to display
96 * @return string HTML the map object
100 function danix_gmaps($atts, $content = null) {
101 extract(shortcode_atts(array(
106 return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&output=embed" ></iframe>';
108 add_shortcode("googlemaps", "danix_gmaps");
110 function danix_get_plugins_stats() {
111 $url = 'https://api.wordpress.org/plugins/info/1.0/';
113 'downloaded' => true,
115 'description' => false,
116 'short_description' => false,
117 'donate_link' => false,
122 'last_updated' => false,
123 'compatibility' => false,
126 'downloadlink' => false,
128 $args = (object) array( 'author' => 'danixland', 'fields' => $fields );
129 $request = array( 'action' => 'query_plugins', 'timeout' => 15, 'request' => serialize( $args) );
130 $response = wp_remote_post( $url, array( 'body' => $request ) );
131 $plugins_info = unserialize( $response['body'] );
134 if ( isset( $plugins_info ) ) {
135 # let's build our array of data to return
136 foreach ($plugins_info->plugins
as $plugin) {
137 $pl_name = $plugin->slug
;
138 $pl_dirlink = 'https://wordpress.org/plugins/' . $pl_name;
139 $pl_download = $plugin->download_link
;
140 $pl_downloaded = $plugin->downloaded
;
141 $pl_voters = $plugin->num_ratings
;
142 $pl_stars = $plugin->ratings
;
143 $avg_vote = ($pl_stars[1] +
$pl_stars[2] * 2 +
$pl_stars[3] * 3 +
$pl_stars[4] * 4 +
$pl_stars[5] * 5) / $pl_voters;
144 $pl_avg_vote = ( ! is_int($avg_vote) ?
0 : $avg_vote );
145 $result[$pl_name] = array(
146 'dir_link' => $pl_dirlink,
147 'dl_link' => $pl_download,
148 'downloaded' => $pl_downloaded,
149 'voters' => $pl_voters,
150 'avg_rating' => $pl_avg_vote
152 $total_dl +
= $pl_downloaded;
154 $result['total_plugins'] = count($plugins_info->plugins
);
155 $result['total_downloads'] = $total_dl;
162 function danix_save_plugins_stats() {
164 $plugins = danix_get_plugins_stats();
165 update_option( 'danix_plugins_stats', $plugins );
167 add_action( 'danix_save_plugins_stats', 'danix_save_plugins_stats' );
170 if ( ! wp_next_scheduled( 'danix_save_plugins_stats' ) ) :
171 wp_schedule_event( 1407110400, 'daily', 'danix_save_plugins_stats' ); // 1407110400 is 08 / 4 / 2014 @ 0:0:0 UTC
175 * The dotOrg plugins stats shortcode
177 * @param url $link link address.
178 * @param string $linkname text that will be displayed by the button.
179 * @return string HTML the link tag that will be rendered to the page.
182 function danix_display_plugins_stats() {
183 $option_stats = get_option('danix_plugins_stats');
184 $plugins = ( false === $option_stats ?
danix_get_plugins_stats() : $option_stats );
186 foreach ($plugins as $plugin) {
187 $average +
= $plugin['avg_rating'];
189 $average = $average / $plugins['total_plugins'];
192 <dt
><?php
_e("Plugins", 'sog_simplify'); ?
></dt
>
193 <dd
><?php
printf( _n('I created %s plugin', 'I created %s plugins', $plugins['total_plugins'], 'sog_simplify' ), $plugins['total_plugins'] ); ?
></dd
><br
/>
194 <?php
foreach ($plugins as $name => $data) {
195 if (is_array($data) ) : ?
>
196 <dd
><a href
="<?php echo $data['dir_link']; ?>"><?php
echo $name; ?
></a
></dd
>
199 <dt
><?php
_e('Total Downloads', 'sog_simplify'); ?
></dt
>
200 <dd
><?php
echo $plugins['total_downloads']; ?
></dd
>
203 add_shortcode('dotOrgStats', 'danix_display_plugins_stats');