Skip to content

Instantly share code, notes, and snippets.

@bhubbard
Created November 27, 2024 21:12
Show Gist options
  • Save bhubbard/21fd3a9bacbe27c5343e5585733e3d04 to your computer and use it in GitHub Desktop.
Save bhubbard/21fd3a9bacbe27c5343e5585733e3d04 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WP Things URL Scheme
* Plugin URI: https://example.com/wp-things-url-scheme
* Description: A WordPress plugin that integrates with Things app using its URL Scheme.
* Version: 1.0.0
* Author: Your Name
* Author URI: https://example.com
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-things-url-scheme
* Domain Path: /languages
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WP_Things_URL_Scheme' ) ) :
/**
* Main WP_Things_URL_Scheme Class.
*
* @since 1.0.0
*/
final class WP_Things_URL_Scheme {
/**
* Version of the plugin.
*
* @var string
*/
public $version = '1.0.0';
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin public actions.
*/
private function __construct() {
// Load plugin text domain.
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Register any necessary hooks or actions.
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wp-things-url-scheme', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Magic getter for our object. Allows getting but not setting.
*
* @param string $field
* @return mixed
*/
public function __get( $field ) {
return $this->$field;
}
/**
* Create a new to-do in Things.
*
* @param string $title The title of the to-do.
* @param string $notes Optional notes for the to-do.
* @param string $list Optional list to add the to-do to.
* @param string $when Optional due date or scheduling information (e.g., "today", "tomorrow", "someday").
* @return bool True if the URL was opened successfully, false otherwise.
*/
public function create_to_do( $title, $notes = '', $list = '', $when = '' ) {
$url = 'things:///add?title=' . urlencode( $title );
if ( $notes ) {
$url .= '&notes=' . urlencode( $notes );
}
if ( $list ) {
$url .= '&list=' . urlencode( $list );
}
if ( $when ) {
$url .= '&when=' . urlencode( $when );
}
return wp_redirect( $url );
}
// Add other helper methods for other Things URL Scheme actions, e.g.:
// public function open_list( $list_name ) { ... }
// public function show_quick_entry() { ... }
// ... and so on
}
endif;
/**
* Returns the main instance of WP_Things_URL_Scheme.
*
* @return WP_Things_URL_Scheme The main instance.
*/
function WP_Things_URL_Scheme() {
return WP_Things_URL_Scheme::get_instance();
}
// Get WP_Things_URL_Scheme Running.
WP_Things_URL_Scheme();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment