From 1188212881d1e9557d12f7c2b98d713673dfdfce Mon Sep 17 00:00:00 2001 From: Adam Walter Date: Thu, 19 Jan 2017 17:13:51 -0500 Subject: [PATCH] Cher 2.0 --- README.md | 21 +- assets/css/cher-admin.css | 8 + assets/js/cher-frontend.js | 58 +++++ cher.css | 90 -------- cher.php | 337 +++-------------------------- includes/class-plugin.php | 189 ++++++++++++++++ includes/class-settings.php | 356 +++++++++++++++++++++++++++++++ includes/lib/class-admin-api.php | 314 +++++++++++++++++++++++++++ index.php | 3 + public/functions.php | 144 +++++++++++++ uninstall.php | 28 +++ 11 files changed, 1146 insertions(+), 402 deletions(-) mode change 100755 => 100644 README.md create mode 100644 assets/css/cher-admin.css create mode 100644 assets/js/cher-frontend.js delete mode 100644 cher.css mode change 100644 => 100755 cher.php create mode 100755 includes/class-plugin.php create mode 100755 includes/class-settings.php create mode 100755 includes/lib/class-admin-api.php create mode 100755 index.php create mode 100644 public/functions.php create mode 100755 uninstall.php diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 757dca8..7d4c078 --- a/README.md +++ b/README.md @@ -1,7 +1,22 @@ # Cher -WordPress plugin for adding simple, lightweight social sharing buttons +WordPress plugin for central management of your website's social network profiles. -Add the share buttons to templates using the tag ``. You can also use the shortcode `[share-buttons]` in the editor. +## Usage -![](http://news.sagacom.com/wp-content/blogs.dir/3/files/2014/08/cher-620x400.jpg) +Refer to plugin settings pages for instructions. + +## Features +### Global Social Profile URLs +Manage your profile URLs in one place and print them into your templates with a simple tag. + +![Customizing profile URLs](http://i.imgur.com/JQVPpkJ.png) + +### Customizable Share Links +Lightweight, bare-bones share links that you can customize and style to your heart's content. + +![Customizing share links](http://i.imgur.com/Ad40hBy.png) + +## I got you babe. + +![Cher](http://i.imgur.com/exbh6aF.jpg) \ No newline at end of file diff --git a/assets/css/cher-admin.css b/assets/css/cher-admin.css new file mode 100644 index 0000000..d7190e0 --- /dev/null +++ b/assets/css/cher-admin.css @@ -0,0 +1,8 @@ +.settings_page_cher_settings .checkbox_multi { + margin-right: 1.5em; +} + +.settings_page_cher_settings .description-bottom { + display: block; + margin-top: 0.75em; +} diff --git a/assets/js/cher-frontend.js b/assets/js/cher-frontend.js new file mode 100644 index 0000000..b26cd09 --- /dev/null +++ b/assets/js/cher-frontend.js @@ -0,0 +1,58 @@ +(function() { + var links; + + /** + * Open share link popup + */ + function openPopup(event) { + var width, height, + id = this.id, + url = this.href; + + switch (id) { + + case 'cher-link-twitter': + width = 500; + height = 442; + break; + + case 'cher-link-linkedin': + width = 500; + height = 516; + break; + + case 'cher-link-googleplus': + width = 400; + height = 600; + break; + + case 'cher-link-pinterest': + width = 752; + height = 620; + break; + + default: + width = 550; + height = 330; + } + + if (id !== 'cher-link-email') { + event.preventDefault(); + window.open(url, id, 'status=no,height=' + height + ',width=' + width + ',resizable=yes,toolbar=no,menubar=no,scrollbars=no,location=no,directories=no'); + } + } + + function onDocumentReady() { + + // Click event for share links + links = document.querySelectorAll('.cher-link'); + for (var i = 0; i < links.length; i++) { + links[i].addEventListener('click', openPopup); + } + } + + document.addEventListener('DOMContentLoaded', function() { + onDocumentReady(); + }); + +})(); \ No newline at end of file diff --git a/cher.css b/cher.css deleted file mode 100644 index 8f1c892..0000000 --- a/cher.css +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Cher Default Styles - */ - -#cher-buttons { - margin: 0; - text-align: center; -} -#cher-buttons li { - margin: .25em .4em; -} -#cher-buttons .cher-button { - display: inline-block; -} -#cher-buttons .cher-link { - display: block; - padding: .8em 1.125em .7em; - border-radius: 3px; - color: #fff; - font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; - font-size: .875em; - font-weight: bold; - line-height: 1; - text-decoration: none; - transition: all 100ms ease-in-out; -} -#cher-buttons .cher-link:before { - position: relative; - top: -1px; - margin-right: .375em; - vertical-align: middle; - speak: none; - font-family: 'cher-icons'; - font-size: 1.5em; - font-style: normal; - font-weight: normal; - font-variant: normal; - text-transform: none; - line-height: 1; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} -#cher-buttons .cher-button-twitter .cher-link { - background: #02adee; -} -#cher-buttons .cher-button-twitter .cher-link:hover { - background: #0288bb; -} -#cher-buttons .cher-button-twitter .cher-link:before { - content: "\e600"; -} -#cher-buttons .cher-button-facebook .cher-link { - background: #3b5a99; -} -#cher-buttons .cher-button-facebook .cher-link:hover { - background: #2d4474; -} -#cher-buttons .cher-button-facebook .cher-link:before { - content: "\e601"; -} -#cher-buttons .cher-button-googleplus .cher-link { - background: #de4b39; -} -#cher-buttons .cher-button-googleplus .cher-link:hover { - background: #c33221; -} -#cher-buttons .cher-button-googleplus .cher-link:before { - content: "\e602"; -} -#cher-buttons .cher-button-linkedin .cher-link { - background: #017cb7; -} -#cher-buttons .cher-button-linkedin .cher-link:hover { - background: #015a84; -} -#cher-buttons .cher-button-linkedin .cher-link:before { - content: "\e603"; -} - -/** - * Cher Icons - */ - -@font-face { - font-family: 'cher-icons'; - src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMggi/LkAAAC8AAAAYGNtYXAaVcxaAAABHAAAAExnYXNwAAAAEAAAAWgAAAAIZ2x5Zg27EpwAAAFwAAAEzGhlYWQBLOFHAAAGPAAAADZoaGVhA84B6QAABnQAAAAkaG10eAkAAG0AAAaYAAAAIGxvY2EDmgLSAAAGuAAAABJtYXhwAA0ArgAABswAAAAgbmFtZfGkCwgAAAbsAAABTnBvc3QAAwAAAAAIPAAAACAAAwIAAZAABQAAAUwBZgAAAEcBTAFmAAAA9QAZAIQAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADmAwHg/+D/4AHgACAAAAABAAAAAAAAAAAAAAAgAAAAAAACAAAAAwAAABQAAwABAAAAFAAEADgAAAAKAAgAAgACAAEAIOYD//3//wAAAAAAIOYA//3//wAB/+MaBAADAAEAAAAAAAAAAAAAAAEAAf//AA8AAQAAAAAAAAAAAAIAADc5AQAAAAABAAAAAAAAAAAAAgA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BsAGEAcgB2AHQAbABzAGgAYQByAGUARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format('truetype'), - url(data:application/font-woff;charset=utf-8;base64,d09GRk9UVE8AAAasAAoAAAAABmQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABDRkYgAAAA9AAAAw0AAAMNj1OshE9TLzIAAAQEAAAAYAAAAGAIIvy5Y21hcAAABGQAAABMAAAATBpVzFpnYXNwAAAEsAAAAAgAAAAIAAAAEGhlYWQAAAS4AAAANgAAADYBLOFHaGhlYQAABPAAAAAkAAAAJAPOAelobXR4AAAFFAAAACAAAAAgCQAAbW1heHAAAAU0AAAABgAAAAYACFAAbmFtZQAABTwAAAFOAAABTvGkCwhwb3N0AAAGjAAAACAAAAAgAAMAAAEABAQAAQEBCXZ0bHNoYXJlAAECAAEAOvgcAvgbA/gYBB4KABlT/4uLHgoAGVP/i4sMB4tr+JT4dAUdAAAAiw8dAAAAkBEdAAAACR0AAAMEEgAJAQEJERMVGB0iJyx2dGxzaGFyZXZ0bHNoYXJldTB1MXUyMHVFNjAwdUU2MDF1RTYwMnVFNjAzAAACAYkABgAIAgABAAQABwAKAA0AlwD3Ae0CYPyUDvyUDvyUDvuUDviA+AwVeYR5hneIn5eanpKieYB2g3WGep5xl3CLVYtgYItVi4SMg4yEO49EslvFg32Geot6CItpnG2lenuMfI9+kouLi4qLi4tcrWS3goOJgoqCi4WLhYuFjZhkrm+2imlyYnteiwiDi4OMg4u2cL57wov3RYvt9yeL9xSLj4qPi4+emZycmJ4IDvg5+FcV+96LBW2LcnKLbQiL+98Fi22kcqmLCPc7i4v3MlaLi9DAi4utBYvAsrW9iwi8i4s9X4sFgIuIhYuCCItnxYuLRlGLi/sy3osFqYukpIupCIv33wWLqXKkbYsIDr736xWLZZhvpHuffqOJmIuOi42LjYuLi4dynnEI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gB0AGwAcwBoAGEAcgBlAFYAZQByAHMAaQBvAG4AIAAxAC4AMAB2AHQAbABzAGgAYQByAGV2dGxzaGFyZQB2AHQAbABzAGgAYQByAGUAUgBlAGcAdQBsAGEAcgB2AHQAbABzAGgAYQByAGUARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format('woff'); - font-weight: normal; - font-style: normal; -} \ No newline at end of file diff --git a/cher.php b/cher.php old mode 100644 new mode 100755 index 3dc3cbf..db54dad --- a/cher.php +++ b/cher.php @@ -1,320 +1,39 @@ -
-

Share Buttons Settings

-

Add the share buttons to templates using the tag <?php if (function_exists('share_buttons')) { share_buttons(); } ?>. You can also use the shortcode [share-buttons] in the editor.

-
- -
-
- 1, - 'show_facebook' => 1, - 'show_googleplus' => 1, - 'show_linkedin' => 1 - ); - return apply_filters( 'cher_default_display_options', $defaults ); -} - -function cher_init_display_options() { - - if ( false == get_option( 'cher_display_options' ) ) { - add_option( 'cher_display_options', apply_filters( 'cher_default_display_options', cher_default_display_options() ) ); - } - - add_settings_section( - 'cher_display_options_section', - 'Display Options', - 'cher_display_options_callback', - 'cher_display_options' - ); - - add_settings_field( - 'show_twitter', - 'Twitter', - 'cher_show_twitter_callback', - 'cher_display_options', - 'cher_display_options_section' - ); - - add_settings_field( - 'show_facebook', - 'Facebook', - 'cher_show_facebook_callback', - 'cher_display_options', - 'cher_display_options_section' - ); - - add_settings_field( - 'show_googleplus', - 'Google+', - 'cher_show_googleplus_callback', - 'cher_display_options', - 'cher_display_options_section' - ); - - add_settings_field( - 'show_linkedin', - 'LinkedIn', - 'cher_show_linkedin_callback', - 'cher_display_options', - 'cher_display_options_section' - ); - - register_setting( - 'cher_options', - 'cher_display_options' - ); - -} -add_action( 'admin_init', 'cher_init_display_options' ); - - -/* Style Options - -------------------------------------------------------------------------- */ - -function cher_default_style_options() { - - $defaults = array( - 'output_css' => 1 - ); - return apply_filters( 'cher_default_style_options', $defaults ); -} - -function cher_init_style_options() { - - if ( false == get_option( 'cher_style_options' ) ) { - add_option( 'cher_style_options', apply_filters( 'cher_default_style_options', cher_default_style_options() ) ); - } - - add_settings_section( - 'cher_style_options_section', - 'Style Options', - 'cher_style_options_callback', - 'cher_style_options' - ); - - add_settings_field( - 'output_css', - 'Output CSS', - 'cher_output_css_callback', - 'cher_style_options', - 'cher_style_options_section', - array( - 'Uncheck this box to remove all default button styles', - ) - ); - - register_setting( - 'cher_options', - 'cher_style_options' - ); - -} -add_action( 'admin_init', 'cher_init_style_options' ); - - -/* ========================================================================== - SECTION CALLBACKS - ========================================================================== */ - -/* Display Options - -------------------------------------------------------------------------- */ - -function cher_display_options_callback() { - echo '

Select which buttons to display

'; -} - -/* Style Options - -------------------------------------------------------------------------- */ - -function cher_style_options_callback() {} - - -/* ========================================================================== - FIELD CALLBACKS - ========================================================================== */ - -/* Display Options - -------------------------------------------------------------------------- */ - -function cher_show_twitter_callback($args) { - $options = get_option('cher_display_options'); - $html = ''; - echo $html; -} - -function cher_show_facebook_callback($args) { - $options = get_option('cher_display_options'); - $html = ''; - echo $html; -} - -function cher_show_googleplus_callback($args) { - $options = get_option('cher_display_options'); - $html = ''; - echo $html; -} - -function cher_show_linkedin_callback($args) { - $options = get_option('cher_display_options'); - $html = ''; - echo $html; -} - -/* Style Options - -------------------------------------------------------------------------- */ - -function cher_output_css_callback() { - $options = get_option('cher_style_options'); - - $html = ''; - $html .= ''; - $html .= '    '; - $html .= ''; - $html .= ''; - $html .= '

Set this option to "No" to disable default button styles.

'; - - echo $html; -} - - -/* ========================================================================== - ENQUEUE PLUGIN FILES - ========================================================================== */ - -function cher_enqueuer() { - - $style_options = get_option('cher_style_options'); - - if ( !is_admin() && 1 == $style_options['output_css'] ) { - wp_enqueue_style( 'cher_css', plugins_url('cher.css', __FILE__), null, '1.0'); - } -} - -add_action('wp_enqueue_scripts', 'cher_enqueuer'); - - -/* ========================================================================== - INITIALIZE AND RENDER BUTTONS - ========================================================================== */ - -function share_buttons() { - - $display_options = get_option('cher_display_options'); - $item_toggles = null; - - global $post; - $post_title_encoded = urlencode( get_the_title() ); - $post_excerpt_encoded = urlencode( get_the_excerpt() ); - $post_url_encoded = urlencode( get_permalink($post->ID) ); - - $share_items = array (); - - $twitter_btn = array( - "class" => "twitter", - "href" => "https://twitter.com/share?text={$post_title_encoded}&url={$post_url_encoded}&via=Vital_Design", - "text" => "Share on Twitter" - ); - $facebook_btn = array( - "class" => "facebook", - "href" => "https://www.facebook.com/sharer.php?u={$post_url_encoded}&t={$post_title_encoded}", - "text" => "Share on Facebook" - ); - $googleplus_btn = array( - "class" => "googleplus", - "href" => "https://plus.google.com/share?url={$post_url_encoded}", - "text" => "Share on Google+" - ); - $linkedin_btn = array( - "class" => "linkedin", - "href" => "https://www.linkedin.com/shareArticle?mini=true&url={$post_url_encoded}&title={$post_title_encoded}&summary={$post_excerpt_encoded}&source={$post_url_encoded}", - "text" => "Share on LinkedIn" - ); - - if ( isset( $display_options['show_twitter'] ) && $display_options[ 'show_twitter' ] ) { - array_push( $share_items, $twitter_btn ); - } - if ( isset( $display_options['show_facebook'] ) && $display_options[ 'show_facebook' ] ) { - array_push( $share_items, $facebook_btn ); - } - if ( isset( $display_options['show_googleplus'] ) && $display_options[ 'show_googleplus' ] ) { - array_push( $share_items, $googleplus_btn ); - } - if ( isset( $display_options['show_linkedin'] ) && $display_options[ 'show_linkedin' ] ) { - array_push( $share_items, $linkedin_btn ); - } - - if ( !empty($share_items) ) { - - $share_output = ""; - echo $share_output; - } - -} +/** + * Returns the main instance of the plugin to prevent the need to use globals. + */ +function Cher() { + $instance = Cher_Plugin_Template::instance( __FILE__, '1.0.0' ); -// add shortcode to output buttons -function cher_shortcode( $content = null ) { + if ( is_null( $instance->settings ) ) { + $instance->settings = Cher_Settings::instance( $instance ); + } - ob_start(); - share_buttons(); - $output_string = ob_get_contents(); - ob_end_clean(); - return force_balance_tags( $output_string ); + return $instance; } -add_shortcode( 'share-buttons', 'cher_shortcode' ); -?> \ No newline at end of file +Cher(); \ No newline at end of file diff --git a/includes/class-plugin.php b/includes/class-plugin.php new file mode 100755 index 0000000..0cc1481 --- /dev/null +++ b/includes/class-plugin.php @@ -0,0 +1,189 @@ +_version = $version; + $this->_token = 'cher'; + + // Load plugin environment variables + $this->file = $file; + $this->dir = dirname( $this->file ); + $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; + $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) ); + + $this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + register_activation_hook( $this->file, array( $this, 'install' ) ); + + // Load admin CSS + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 10, 1 ); + + // Load frontend JS + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10 ); + + // Load API for generic admin functions + if ( is_admin() ) { + $this->admin = new Cher_Admin_API(); + } + + } // End __construct () + + /** + * Load admin CSS. + * @access public + * @since 1.0.0 + * @return void + */ + public function admin_enqueue_styles ( $hook = '' ) { + wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/cher-admin.css', array(), $this->_version ); + wp_enqueue_style( $this->_token . '-admin' ); + } // End admin_enqueue_styles () + + /** + * Load frontend Javascript. + * @access public + * @since 1.0.0 + * @return void + */ + public function enqueue_scripts () { + wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/cher-frontend' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version ); + wp_enqueue_script( $this->_token . '-frontend' ); + } // End enqueue_scripts () + + /** + * Main Cher_Plugin_Template Instance + * + * Ensures only one instance of Cher_Plugin_Template is loaded or can be loaded. + * + * @since 1.0.0 + * @static + * @see Cher_Plugin_Template() + * @return Main Cher_Plugin_Template instance + */ + public static function instance ( $file = '', $version = '1.0.0' ) { + if ( is_null( self::$_instance ) ) { + self::$_instance = new self( $file, $version ); + } + return self::$_instance; + } // End instance () + + /** + * Cloning is forbidden. + * + * @since 1.0.0 + */ + public function __clone () { + _doing_it_wrong( __FUNCTION__, __( 'Invalid request.' ), $this->_version ); + } // End __clone () + + /** + * Unserializing instances of this class is forbidden. + * + * @since 1.0.0 + */ + public function __wakeup () { + _doing_it_wrong( __FUNCTION__, __( 'Invalid request.' ), $this->_version ); + } // End __wakeup () + + /** + * Installation. Runs on activation. + * @access public + * @since 1.0.0 + * @return void + */ + public function install () { + $this->_log_version_number(); + } // End install () + + /** + * Log the plugin version number. + * @access public + * @since 1.0.0 + * @return void + */ + private function _log_version_number () { + update_option( $this->_token . '_version', $this->_version ); + } // End _log_version_number () + +} \ No newline at end of file diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100755 index 0000000..a49a0d7 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,356 @@ +parent = $parent; + + $this->base = 'cher_'; + + // Initialise settings + add_action( 'init', array( $this, 'init_settings' ), 11 ); + + // Register plugin settings + add_action( 'admin_init' , array( $this, 'register_settings' ) ); + + // Add settings page to menu + add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); + + // Add settings link to plugins page + add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ) , array( $this, 'add_settings_link' ) ); + } + + /** + * Initialise settings + * @return void + */ + public function init_settings () { + $this->settings = $this->settings_fields(); + } + + /** + * Add settings page to admin menu + * @return void + */ + public function add_menu_item () { + $page = add_options_page( __( 'Cher', 'cher' ) , __( 'Cher', 'cher' ) , 'manage_options' , $this->parent->_token . '_settings' , array( $this, 'settings_page' ) ); + } + + /** + * Add settings link to plugin list table + * @param array $links Existing links + * @return array Modified links + */ + public function add_settings_link ( $links ) { + $settings_link = '' . __( 'Settings', 'cher' ) . ''; + array_unshift( $links, $settings_link ); + return $links; + } + + /** + * Build settings fields + * @return array Fields to be displayed on settings page + */ + private function settings_fields () { + + $settings['profile_urls'] = array( + 'title' => __( 'Profiles', 'cher' ), + 'description' => __( 'Set the URLs for your social profiles. Use the PHP tags to print your URLs in your page templates.', 'cher' ), + 'fields' => array( + array( + 'id' => 'twitter_url', + 'label' => __( 'Twitter' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('twitter'); ?>", 'cher' ), + 'type' => 'url', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'facebook_url', + 'label' => __( 'Facebook' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('facebook'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'linkedin_url', + 'label' => __( 'LinkedIn' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('linkedin'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'googleplus_url', + 'label' => __( 'Google+' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('googleplus'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'youtube_url', + 'label' => __( 'YouTube' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('youtube'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'vimeo_url', + 'label' => __( 'Vimeo' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('vimeo'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'instagram_url', + 'label' => __( 'Instagram' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('instagram'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'pinterest_url', + 'label' => __( 'Pinterest' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('pinterest'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + array( + 'id' => 'houzz_url', + 'label' => __( 'Houzz' , 'cher' ), + 'description' => __( "<?php echo cher_profile_url('houzz'); ?>", 'cher' ), + 'type' => 'text', + 'default' => '', + 'placeholder' => __( '', 'cher' ) + ), + ) + ); + + $settings['cher_links'] = array( + 'title' => __( 'Share Links', 'cher' ), + 'description' => __( "Add the share links to templates using the tag <?php cher_links(); ?>. You can also use the shortcode [cher-links] in the editor.", 'cher' ), + 'fields' => array( + array( + 'id' => 'show_links', + 'label' => __( 'Show Links', 'cher' ), + 'description' => __( 'Select which links to display.', 'cher' ), + 'type' => 'checkbox_multi', + 'options' => array( 'twitter' => 'Twitter', 'facebook' => 'Facebook', 'linkedin' => 'LinkedIn', 'googleplus' => 'Google+', 'pinterest' => 'Pinterest', 'email' => 'Email' ), + 'default' => array() + ) + ) + ); + + $settings['settings'] = array( + 'title' => __( 'Settings', 'cher' ), + 'description' => __( '', 'cher' ), + 'fields' => array( + array( + 'id' => 'delete_options', + 'label' => __( 'Delete Plugin Settings', 'cher' ), + 'description' => __( 'Delete plugin settings on deactivation.', 'cher' ), + 'type' => 'checkbox', + 'default' => '' + ) + ) + ); + + $settings = apply_filters( $this->parent->_token . '_settings_fields', $settings ); + + return $settings; + } + + /** + * Register plugin settings + * @return void + */ + public function register_settings () { + if ( is_array( $this->settings ) ) { + + // Check posted/selected tab + $current_section = ''; + if ( isset( $_POST['tab'] ) && $_POST['tab'] ) { + $current_section = $_POST['tab']; + } else { + if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { + $current_section = $_GET['tab']; + } + } + + foreach ( $this->settings as $section => $data ) { + + if ( $current_section && $current_section != $section ) continue; + + // Add section to page + add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), $this->parent->_token . '_settings' ); + + foreach ( $data['fields'] as $field ) { + + // Validation callback for field + $validation = ''; + if ( isset( $field['callback'] ) ) { + $validation = $field['callback']; + } + + // Register field + $option_name = $this->base . $field['id']; + register_setting( $this->parent->_token . '_settings', $option_name, $validation ); + + // Add field to page + add_settings_field( $field['id'], $field['label'], array( $this->parent->admin, 'display_field' ), $this->parent->_token . '_settings', $section, array( 'field' => $field, 'prefix' => $this->base ) ); + } + + if ( ! $current_section ) break; + } + } + } + + public function settings_section ( $section ) { + $html = '

' . $this->settings[ $section['id'] ]['description'] . '

' . "\n"; + echo $html; + } + + /** + * Load settings page content + * @return void + */ + public function settings_page () { + + // Build page HTML + $html = '
' . "\n"; + $html .= '

' . __( 'Cher' , 'cher' ) . '

' . "\n"; + + $tab = ''; + if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { + $tab .= $_GET['tab']; + } + + // Show page tabs + if ( is_array( $this->settings ) && 1 < count( $this->settings ) ) { + + $html .= '' . "\n"; + } + + $html .= '
' . "\n"; + + // Get settings fields + ob_start(); + settings_fields( $this->parent->_token . '_settings' ); + do_settings_sections( $this->parent->_token . '_settings' ); + $html .= ob_get_clean(); + + $html .= '

' . "\n"; + $html .= '' . "\n"; + $html .= '' . "\n"; + $html .= '

' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + echo $html; + } + + /** + * Main Cher_Settings Instance + * + * Ensures only one instance of Cher_Settings is loaded or can be loaded. + * + * @since 1.0.0 + * @static + * @see WordPress_Plugin_Template() + * @return Main Cher_Settings instance + */ + public static function instance ( $parent ) { + if ( is_null( self::$_instance ) ) { + self::$_instance = new self( $parent ); + } + return self::$_instance; + } // End instance() + + /** + * Cloning is forbidden. + * + * @since 1.0.0 + */ + public function __clone () { + _doing_it_wrong( __FUNCTION__, __( 'Invalid request.' ), $this->parent->_version ); + } // End __clone() + + /** + * Unserializing instances of this class is forbidden. + * + * @since 1.0.0 + */ + public function __wakeup () { + _doing_it_wrong( __FUNCTION__, __( 'Invalid request.' ), $this->parent->_version ); + } // End __wakeup() + +} \ No newline at end of file diff --git a/includes/lib/class-admin-api.php b/includes/lib/class-admin-api.php new file mode 100755 index 0000000..48c3ad7 --- /dev/null +++ b/includes/lib/class-admin-api.php @@ -0,0 +1,314 @@ +ID, $field['id'], true ); + + // Get data to display in field + if ( isset( $option ) ) { + $data = $option; + } + + } else { + + // Get saved option + $option_name .= $field['id']; + $option = get_option( $option_name ); + + // Get data to display in field + if ( isset( $option ) ) { + $data = $option; + } + + } + + // Show default data if no option saved and default is supplied + if ( $data === false && isset( $field['default'] ) ) { + $data = $field['default']; + } elseif ( $data === false ) { + $data = ''; + } + + $html = ''; + + switch( $field['type'] ) { + + case 'text': + case 'email': + case 'url': + $html .= '' . "\n"; + break; + + case 'password': + case 'number': + case 'hidden': + $min = ''; + if ( isset( $field['min'] ) ) { + $min = ' min="' . esc_attr( $field['min'] ) . '"'; + } + + $max = ''; + if ( isset( $field['max'] ) ) { + $max = ' max="' . esc_attr( $field['max'] ) . '"'; + } + $html .= '' . "\n"; + break; + + case 'text_secret': + $html .= '' . "\n"; + break; + + case 'textarea': + $html .= '
'. "\n"; + break; + + case 'checkbox': + $checked = ''; + if ( $data && 'on' == $data ) { + $checked = 'checked="checked"'; + } + $html .= '' . "\n"; + break; + + case 'checkbox_multi': + foreach ( $field['options'] as $k => $v ) { + $checked = false; + if ( in_array( $k, (array) $data ) ) { + $checked = true; + } + $html .= ' '; + } + break; + + case 'radio': + foreach ( $field['options'] as $k => $v ) { + $checked = false; + if ( $k == $data ) { + $checked = true; + } + $html .= ' '; + } + break; + + case 'select': + $html .= ' '; + break; + + case 'select_multi': + $html .= ' '; + break; + + case 'image': + $image_thumb = ''; + if ( $data ) { + $image_thumb = wp_get_attachment_thumb_url( $data ); + } + $html .= '
' . "\n"; + $html .= '' . "\n"; + $html .= '' . "\n"; + $html .= '
' . "\n"; + break; + + case 'color': + ?>
+ +
+
+ ' . $field['description'] . ''; + break; + + default: + if ( ! $post ) { + $html .= '' . "\n"; + } + break; + } + + if ( ! $echo ) { + return $html; + } + + echo $html; + + } + + /** + * Validate form field + * @param string $data Submitted value + * @param string $type Type of field to validate + * @return string Validated value + */ + public function validate_field ( $data = '', $type = 'text' ) { + + switch( $type ) { + case 'text': $data = esc_attr( $data ); break; + case 'url': $data = esc_url( $data ); break; + case 'email': $data = is_email( $data ); break; + } + + return $data; + } + + /** + * Add meta box to the dashboard + * @param string $id Unique ID for metabox + * @param string $title Display title of metabox + * @param array $post_types Post types to which this metabox applies + * @param string $context Context in which to display this metabox ('advanced' or 'side') + * @param string $priority Priority of this metabox ('default', 'low' or 'high') + * @param array $callback_args Any axtra arguments that will be passed to the display function for this metabox + * @return void + */ + public function add_meta_box ( $id = '', $title = '', $post_types = array(), $context = 'advanced', $priority = 'default', $callback_args = null ) { + + // Get post type(s) + if ( ! is_array( $post_types ) ) { + $post_types = array( $post_types ); + } + + // Generate each metabox + foreach ( $post_types as $post_type ) { + add_meta_box( $id, $title, array( $this, 'meta_box_content' ), $post_type, $context, $priority, $callback_args ); + } + } + + /** + * Display metabox content + * @param object $post Post object + * @param array $args Arguments unique to this metabox + * @return void + */ + public function meta_box_content ( $post, $args ) { + + $fields = apply_filters( $post->post_type . '_custom_fields', array(), $post->post_type ); + + if ( ! is_array( $fields ) || 0 == count( $fields ) ) return; + + echo '
' . "\n"; + + foreach ( $fields as $field ) { + + if ( ! isset( $field['metabox'] ) ) continue; + + if ( ! is_array( $field['metabox'] ) ) { + $field['metabox'] = array( $field['metabox'] ); + } + + if ( in_array( $args['id'], $field['metabox'] ) ) { + $this->display_meta_box_field( $field, $post ); + } + + } + + echo '
' . "\n"; + + } + + /** + * Dispay field in metabox + * @param array $field Field data + * @param object $post Post object + * @return void + */ + public function display_meta_box_field ( $field = array(), $post ) { + + if ( ! is_array( $field ) || 0 == count( $field ) ) return; + + $field = '

' . $this->display_field( $field, $post, false ) . '

' . "\n"; + + echo $field; + } + + /** + * Save metabox fields + * @param integer $post_id Post ID + * @return void + */ + public function save_meta_boxes ( $post_id = 0 ) { + + if ( ! $post_id ) return; + + $post_type = get_post_type( $post_id ); + + $fields = apply_filters( $post_type . '_custom_fields', array(), $post_type ); + + if ( ! is_array( $fields ) || 0 == count( $fields ) ) return; + + foreach ( $fields as $field ) { + if ( isset( $_REQUEST[ $field['id'] ] ) ) { + update_post_meta( $post_id, $field['id'], $this->validate_field( $_REQUEST[ $field['id'] ], $field['type'] ) ); + } else { + update_post_meta( $post_id, $field['id'], '' ); + } + } + } + +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100755 index 0000000..c051246 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ +'; + + echo $html; + + } + + function cher_shortcode($content = null) { + ob_start(); + cher_buttons(); + $output_string = ob_get_contents(); + ob_end_clean(); + return force_balance_tags($output_string); + } + + add_shortcode('cher-buttons', 'cher_shortcode'); + +} \ No newline at end of file diff --git a/uninstall.php b/uninstall.php new file mode 100755 index 0000000..5f3e284 --- /dev/null +++ b/uninstall.php @@ -0,0 +1,28 @@ +query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'cher_%'"); +} + +$cher_delete_options = get_option('cher_delete_options', false); + +if ($cher_delete_options === 'on') { + cher_delete_options(); +} + +// Do something here if plugin is being uninstalled.