Skip to content

Instantly share code, notes, and snippets.

View engelen's full-sized avatar

Jesper van Engelen engelen

  • Leiden, The Netherlands
View GitHub Profile
@engelen
engelen / argmax.js
Last active March 7, 2023 01:32
Single-line ArgMax for JavaScript
/**
* Retrieve the array key corresponding to the largest element in the array.
*
* @param {Array.<number>} array Input array
* @return {number} Index of array element with largest value
*/
function argMax(array) {
return array.map((x, i) => [x, i]).reduce((r, a) => (a[0] > r[0] ? a : r))[1];
}
/*
Plugin Name: Admin Columns - Yoast SEO Title Column Editability
Version: 1.0
Author URI: AUTHOR_URL
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
add_filter( 'cac/editable/is_column_editable/column=wpseo-title', '__return_true' );
add_filter( 'cac/editable/editables_data', 'my_plugin_column_seo_title_editability', 10, 2 );
<?php
add_filter( 'cac/storage_models', 'myplugin_cpac_storage_models' );
function myplugin_cpac_storage_models( $storage_models ) {
if ( isset( $storage_models['mycpt'] ) ) {
unset( $storage_models['mycpt'] );
}
return $storage_models;
}
<?php
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/**
* Enqueue Dashicons style for frontend use when enqueuing your theme's style sheet
*/
function mytheme_scripts() {
wp_enqueue_style( 'mytheme-style', get_stylesheet_uri(), 'dashicons' );
}
@engelen
engelen / gist:9df926bd9f3957394d89
Last active November 17, 2017 15:57
Use WordPress dashicons in your theme on the frontend.
<?php
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/**
* Enqueue Dashicons style for frontend use
*/
function mytheme_scripts() {
wp_enqueue_style( 'dashicons' );
}
@engelen
engelen / myplugin.php
Last active August 29, 2015 14:03
Code is poetry. An implementation of a plugin class structure that allows you to access a plugin class instance without using singletons and without storing a reference to the instance in the global namespace.
<?php
/*
Plugin Name: My Plugin
*/
/**
* Main plugin class
*/
class MyPlugin {
<?php
add_filter( 'cac/settings/tab_contents', 'myplugin_cac_tab_contents', 10, 2 ); // All tabs
?>
<?php
add_filter( 'cac/settings/tab_contents/tab=[tabid]', 'myplugin_cac_tab_contents_mytab' ); // Only the [tabid] tab
?>
<?php
add_filter( 'cac/settings/tabs', 'myplugin_cac_settings_tabs' );
/**
* Add the tab
*/
function myplugin_cac_settings_tabs( $tabs ) {
// Add a tab to the list of Admin Columns settings tabs
$tabs['myplugin-information'] = __( 'Am I a wizard?', 'myplugin_textdomain' );
<?php
add_filter( 'cac/settings/tabs', 'myplugin_cac_settings_tabs' );
function myplugin_cac_settings_tabs( $tabs ) {
// Possibly modify $tabs
return $tabs;
}
?>