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 / simple-note-osx-app-restorer.php
Last active July 24, 2017 12:48
PHP script to list and retrieve notes from the OS X Simple Notes app. Nice to have since import/sync seems buggy in first version of the app (It deleted two months of notes for me anyway, because of a crash during import.) How to: Find the file "Simplenote.storedata.xml" that is located perhaps here or in your time machine or Arq or similar: ~/L…
<meta charset="utf-8">
<title>SimpleNote Restorer</title>
<style>
body {
font-family: sans-serif;
background-color: #f5f5f5;
color: #111;
font-size: 14px;
}
li {
@bonny
bonny / simple_fields-set-post-connector-with-code.php
Last active May 9, 2016 18:49
Simple Fields examples: - how to hide post connector drop down on edit post screen using PHP - how to select post connector for a post using PHP
<?php
/**
* Set post connector for a post using PHP.
*
* This way it's possible to select a post connector for posts based on their ID, categories, tags, post type, and so on
*
* This function is using the filter simple_fields_get_selected_connector_for_post that is called when
* simple fields determines what connector it should use for each post.
* It passes the connector slug and the post object and you should return the slug of the conector that you want to use.
@bonny
bonny / ep_noindex_password_protected_pages.php
Created June 13, 2013 08:42
WordPress function that uses filter "wp_head" to add meta robots noindex for password protected pages
<?php
// if current page is password protected then kindly tell google (aka search engines) to not index the current page
function ep_noindex_password_protected_pages() {
global $wp_the_query;
if ( $wp_the_query->is_singular && post_password_required( $wp_the_query->get_queried_object ) ) {
wp_no_robots();
}
@bonny
bonny / ep_exclude_password_protected_pages.php
Created June 13, 2013 08:15
WordPress function that uses filter "get_pages" to add argument "exclude_password_protected=1" Adding that argument will exclude password protected pages from for example wp_list_pages. If a user has entered correct password then the page will be visible.
<?php
// modify get_pages so we can add "exclude_password_protected=1" to exclude password protected
// pages from for example wp_list_pages
// if user has entered correct password then the page will be visible
function ep_exclude_password_protected_pages($pages, $r) {
if ( isset( $r["exclude_password_protected"] ) && $r["exclude_password_protected"] ) {
for ($i = 0; $i < sizeof($pages); $i++) {
@bonny
bonny / gist:5764511
Created June 12, 2013 11:27
Example how to use Simple Fields together with WP API. Just a quick example, modify to suit your own needs.
<?php
function simple_fields_wp_api_json_prepare_post( $_post, $post, $fields ) {
// we dont't get the post id
$post_id = $_post["ID"];
$field_values = simple_fields_get_all_fields_and_values_for_post($post_id);
$field_values_for_json = array(
"field_groups" => array()
@bonny
bonny / date-time-picker-field.php
Last active December 17, 2015 16:09
simple_fields_register_field_group with date & timepicker 2 (for WordPress Simple Fields plugin)
<?php
simple_fields_register_field_group('date_field_group',
array (
'name' => 'Test field group for date picker',
'fields' => array(
array(
'slug' => "my_date2_field_slug",
'name' => 'Test date selector',
'type' => 'date_v2',
@bonny
bonny / plugin-stats.php
Last active December 16, 2015 07:59
WordPress Plugin Download Stats for Panic Status Board Original blog post: http://simple-fields.com/2013/status-board-panel-to-show-wordpress-plugin-downloads/
<?php
// Read the original blog post here to understand what this is:
// http://simple-fields.com/2013/status-board-panel-to-show-wordpress-plugin-downloads/
define('WP_USE_THEMES', false);
define("WP_CACHE", false); // i get 404 if enabled
require('../wordpress/wp-blog-header.php');
class panic_dashboard_wp_plugin_stats {
<?php
// Loop through a wp query obj
$wp_query_obj = new wp_query('post_type=regions&posts_per_page=3&orderby=title&order=asc');
with_posts($wp_query_obj, function($post, $arr_info) {
echo "<p>I am post number" . $arr_info["current_post"] . " of " . $arr_info["post_count"] " found post(s).</p>";
echo "<p>My title is: " . get_the_title() . "</p>";
echo "<p>And my slug is: " . $post->post_name . "</p>";
});
?>
<?php
// Get the pages 1,2 and 3 and do some things with them
with_posts("1,2,3'", function() {
echo "<p>Found a post with title: " . get_the_title() . "</p>";
});
?>
<?php
// Setup a wp_query object that gets the pages with id 1,2 and 3
$query = new wp_query('post_type=page&post__in=1,2,3');
while ($query->have_posts() ) :
$query->the_post();
echo "<p>Found a post with title: " . get_the_title() . "</p>";
endwhile;
wp_reset_postdata();
?>