Last active
April 26, 2020 15:31
-
-
Save krasenslavov/6d6941cfd412db341706b5c298f02092 to your computer and use it in GitHub Desktop.
WordPress.org plugin tracker dashboard widget. Visit blog post https://bit.ly/2xy3dSj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('admin_enqueue_scripts', function() { | |
wp_add_inline_style('dashboard', ' | |
.plugin-box-container { | |
display: flex; | |
flex-wrap: wrap; | |
max-height: 288px; | |
overflow-y: auto; | |
} | |
.plugin-box-container .box { | |
flex: 0 0 calc(100% / 2 - 1rem); | |
padding: .5rem; | |
} | |
.plugin-box-container .box p { | |
display: flex; | |
justify-content: space-between; | |
} | |
'); | |
}, 10, 1); | |
add_action('wp_dashboard_setup', function () { | |
add_meta_box('dashboard_plugin_tracker', 'Plugin Tracker', 'plugin_tracker', 'dashboard', 'side', 'high'); | |
}, 10, 1); | |
function plugin_tracker() { | |
$content = file_get_contents('https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[author]=automattic'); | |
$content_arr = json_decode($content); | |
$plugins = $content_arr->plugins; | |
echo '<div class="plugin-box-container">'; | |
foreach($plugins as $plugin) { | |
echo "<div class='box'> | |
<h3>{$plugin->name}</h3> | |
<hr /> | |
<p><strong>Raiting:</strong> <span>{$plugin->rating}%</span></p> | |
<p><strong>Number of Ratings:</strong> <span>{$plugin->num_ratings}</span></p> | |
<p><strong>Active Installs:</strong> <span>{$plugin->active_installs}</span></p> | |
<p><strong>Downloaded:</strong> <span>{$plugin->downloaded} times</span></p> | |
<p><strong>Support Threads:</strong> <span>{$plugin->support_threads}</span></p> | |
</div>"; | |
} | |
echo "</div>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment