Skip to content

Instantly share code, notes, and snippets.

View bonny's full-sized avatar
🇺🇦
StandWithUkraine

Pär Thernström bonny

🇺🇦
StandWithUkraine
View GitHub Profile
@bonny
bonny / dabblet.css
Created December 17, 2011 21:58
This is my dabblet!
/**
* This is my dabblet!
*/
background: red;
#background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
@bonny
bonny / gist:3830056
Created October 3, 2012 21:42
example: simple_fields_get_post_value
<?
/**
* get all values or just the from a field in a field group
* @param $post_id
* @param $field_name_or_id name as string or field group id and field id as array.
* for example array(3,2) to fetch field 2 from field group 3
* @param $single bool return a single (the first) value or all values (as array)
* @return string or array
*/
/**
* get all values or just the from a field in a field group
* @param $post_id
* @param $field_name_or_id name as string or field group id and field id as array.
* for example array(3,2) to fetch field 2 from field group 3
* @param $single bool return a single (the first) value or all values (as array)
* @return string or array
*/
simple_fields_get_post_value($post_id, $field_name_or_id, $single = true)
@bonny
bonny / gist:3847600
Created October 7, 2012 09:07
Simple Fields minimal field extension example
<?php
add_action("plugins_loaded", "init_simple_fields_field_minimalexample");
function init_simple_fields_field_minimalexample() {
class simple_fields_field_minimalexample extends simple_fields_field {
public $key = "minimalexample", $name = "Minimalistic example field";
@bonny
bonny / gist:3847654
Created October 7, 2012 09:30
Simple Fields Extension API Example
<?php
/**
* This is an example field type extension for Simple Fields
* Use this as base or inspiration for your own fields
*/
// Make sure simple fields have loaded before we try to do anything. Will get errors otherwise.
add_action("plugins_loaded", "init_simple_fields_field_example");
@bonny
bonny / 1-simple-fields-register-field-group-small-example.php
Last active July 14, 2022 11:34
Simple Fields simple_fields_register_field_group(), simple_fields_register_post_connector(), simple_fields_register_post_type_default() examplesSee http://simple-fields.com/ for more info.
<?php
// Minimal amount of code
// to create a new field group
// with one field
simple_fields_register_field_group('attachment', array(
'name' => 'Attachment',
'fields' => array(
array(
'name' => 'File',
@bonny
bonny / simple_fields_set_value_example.php
Last active October 11, 2015 11:27
Simple Fields function simple_fields_set_value()
<?php
/**
* Update/Set a value for a field for a post
* Warning: Highly untested!
*
* @param int $post_id
* @param string $field_slug field key
* @param int $numInSet if field is repeatable this tells what position it should be stored at. Default is null = add new
* @param mixed $post_connector string __none__, __inherit__, or int id of post connector to use for this post, if no connector is defined already
@bonny
bonny / gist:3851566
Created October 8, 2012 09:16
Simple Fields getting values
/**
* Gets a single value.
* The first value if field group is repeatable
*
* @param string $field_slug
* @param int $post_id ID of post or null to use current post in loop
* @param array $options Array or query string of options to send to field type
* @return mixed string or array, depending on the field type
*/
function simple_fields_value($field_slug = NULL, $post_id = NULL, $options = NULL) {
@bonny
bonny / gist:3905768
Created October 17, 2012 14:21
WordPress: Filter to wrap teaser content with a div so we can style the teaser content
/**
* If a page has the more-tag added then wrap the content before the more-tag in a div with the class
* .entry-content-teaser
* this makes it easy for us to style the teaser, like making in bold.
* we hook onto prio 9 instead of 10 so it run before the content has got the tags added
*/
add_filter("the_content", "teasify_the_content", 9);
function teasify_the_content($content) {
@bonny
bonny / gist:3923092
Created October 20, 2012 11:41
File Field, Extended Return Values
Array
(
[id] => 14
[is_image] => 1
[url] => http://example.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg
[mime] => image/jpeg
[link] => Array
(
[full] => <a href='http://example.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg' title='product-cat-2'><img width="1024" height="768" src="http://example.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg" class="attachment-full" alt="product-cat-2" title="product-cat-2" /></a>
[thumbnail] => <a href='http://example.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg' title='product-cat-2'><img width="150" height="112" src="http://example.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg" class="attachment-thumbnail" alt="product-cat-2" title="product-cat-2" /></a>