Skip to content

Instantly share code, notes, and snippets.

View annalinneajohansson's full-sized avatar
🐱

Anna annalinneajohansson

🐱
  • Frontwalker Group AB
  • Sweden
  • 23:42 (UTC +02:00)
View GitHub Profile
@annalinneajohansson
annalinneajohansson / ajax.js
Last active December 31, 2023 05:50
Basic AJAX function in WordPress
jQuery(document).ready(function($){
var ajaxurl = object.ajaxurl;
var data = {
action: 'my_action', // wp_ajax_my_action / wp_ajax_nopriv_my_action in ajax.php. Can be named anything.
foobar: 'some value', // translates into $_POST['foobar'] in PHP
};
$.post(ajaxurl, data, function(response) {
alert("Server returned this:" + response);
});
});
@annalinneajohansson
annalinneajohansson / plugin-settings.php
Last active February 23, 2023 04:42
A base for a WordPress plugin settings page, using the Settings API #add_options_page #add_action #admin_init #register_setting #add_settings_section
<?php
# http://kovshenin.com/2012/the-wordpress-settings-api/
# http://codex.wordpress.org/Settings_API
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_options_page( __('My Plugin Options', 'textdomain' ), __('My Plugin Options', 'textdomain' ), 'manage_options', 'my-plugin', 'my_options_page' );
}
add_action( 'admin_init', 'my_admin_init' );
@annalinneajohansson
annalinneajohansson / change_acf_color_picker.php
Created October 21, 2015 12:00
Adds client custom colors to WYSIWYG editor and ACF color picker. #wordpress
<?php
function change_acf_color_picker() {
$client_colors = array(
"#DD3333",
"#81D742",
"#1E73BE",
"#8224E3",
"#DD9933",
"#EEEE22"
@annalinneajohansson
annalinneajohansson / add_meta_box.php
Created October 24, 2013 07:28
Example that adds a custom meta box to the post and page editing screens. From http://codex.wordpress.org/Function_Reference/add_meta_box
<?php
/**
* Adds a box to the main column on the Post and Page edit screens.
*/
function myplugin_add_custom_box() {
$screens = array( 'post', 'page' );
foreach ( $screens as $screen ) {
@annalinneajohansson
annalinneajohansson / hip_has_shortcode.php
Created December 6, 2013 18:18
Allow array check for shortcode (based on has_shortcode)
<?php
function hip_has_shortcode( $content, $tags ) {
if( is_array( $tags ) ) {
foreach ( $tags as $tag ) {
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) )
return false;
foreach ( $matches as $shortcode ) {
if ( $tag === $shortcode[2] )
@annalinneajohansson
annalinneajohansson / gist:19305c168af7510fd2e269731a052761
Created July 22, 2021 14:50
Dynamically / programmatically creating multi file upload field in Gravity Forms
When dynamically creating a fileupload field with multiple files option enabled
you must also run the gform_post_multifile_upload filter on the field for it to work properly
https://docs.gravityforms.com/gform_multifile_upload_field/
@annalinneajohansson
annalinneajohansson / current-desktop.sh
Last active February 8, 2020 02:50
Match the first character of $desktop
#!/bin/bash
desktops=$(wmctrl -d | awk '{ print $2":"$10 }')
for desktop in $desktops
do
# example output of $desktop: -Work or *Leisure
if [[ $(echo $desktop | cut -c1-1) = '*' ]]; then
echo $desktop | cut -c3-
fi
done
<?php
function hip_auto_login() {
/* emails with + will not work "properly", then wont be logged in with this filter */
if( isset( $_GET['u'] ) && isset( $_GET['plux'] ) && isset( $_GET['post_id'] ) ) {
$email = wp_kses( $_GET['u'],array() );
$checksum = wp_kses( $_GET['plux'],array() );
$post_id = wp_kses( $_GET['post_id'],array() );
if (!is_user_logged_in() && !empty($checksum) && !empty($email)) {
@annalinneajohansson
annalinneajohansson / new-ssh-shortcut.sh
Last active February 8, 2020 02:36
Generate a xfce4 panel shortcut (.desktop file). Change "launcher-10" to whatever launcher is used.
#!/bin/bash
echo "Enter host (defined in ~/.ssh/config):"
read host
if [ -z "${host}" ]; then
echo "No host given. Exiting."
else
@annalinneajohansson
annalinneajohansson / gist:5b67e5926bf6350a69cb08ec9793c905
Last active February 8, 2020 01:38
Iterate Jpg images in folder and add Dropbox share link to csv
#!/bin/bash
rm -rf images.csv
for file in *; do
if [[ $file == *.jpg ]]
then
sharelink=$(dropbox sharelink "$file")
sharelink=${sharelink/dl=0/dl=1} ## replace dl=0 with dl=1 in the sharelinks
filename=$(basename "$file")