├── .bowerrc ├── assets ├── images │ └── ajax-loader.gif └── js │ ├── cmb2-remote-img-sel.min.js │ └── cmb2-remote-img-sel.js ├── .gitmodules ├── bower.json ├── package.json ├── .yo-rc.json ├── languages └── cmb2-remote-img-sel.pot ├── readme.txt ├── README.md ├── .gitignore ├── Gruntfile.js └── cmb2-remote-img-sel.php /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "assets/bower" 3 | } -------------------------------------------------------------------------------- /assets/images/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WebDevStudios/CMB2-Remote-Image-Select-Field/HEAD/assets/images/ajax-loader.gif -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "includes/wds-image-grabber"] 2 | path = includes/wds-image-grabber 3 | url = git@github.com:WebDevStudios/WDS-Image-Grabber.git 4 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cmb2-remote-img-sel", 3 | "description": "A radical new plugin for WordPress!", 4 | "license": "GPLv2", 5 | "authors": [ 6 | "WebDevStudios" 7 | ], 8 | "private": true, 9 | "ignore": [ 10 | "**/.*", 11 | "node_modules", 12 | "bower_components", 13 | "test", 14 | "tests" 15 | ], 16 | "dependencies": { 17 | } 18 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cmb2-remote-img-sel", 3 | "title": "CMB2 Remote Image Select", 4 | "version": "0.1.0", 5 | "description": "A radical new plugin for WordPress!", 6 | "author": { 7 | "name": "WebDevStudios", 8 | "url": "http://webdevstudios.com" 9 | }, 10 | "license": "GPLv2", 11 | "devDependencies": { 12 | "grunt": "latest", 13 | "grunt-contrib-jshint": "^0.11.2", 14 | "grunt-contrib-uglify": "^0.9.1", 15 | "grunt-contrib-watch": "latest", 16 | "grunt-wp-i18n": "latest", 17 | "load-grunt-tasks": "latest" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-plugin-wp": { 3 | "name": "CMB2 Remote Image Select", 4 | "homepage": "http://webdevstudios.com", 5 | "description": "A radical new plugin for WordPress!", 6 | "version": "0.1.0", 7 | "author": "WebDevStudios", 8 | "authoremail": "contact@webdevstudios.com", 9 | "authorurl": "http://webdevstudios.com", 10 | "license": "GPLv2", 11 | "slug": "cmb2-remote-img-sel", 12 | "classname": "CMB2_Remote_Image_Select", 13 | "classprefix": "CMB2RIS_", 14 | "prefix": "cmb2_remote_img_sel", 15 | "year": 2015 16 | } 17 | } -------------------------------------------------------------------------------- /languages/cmb2-remote-img-sel.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 WebDevStudios 2 | # This file is distributed under the same license as the WDS Image Grabber package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: WDS Image Grabber 0.1\n" 6 | "Report-Msgid-Bugs-To: " 7 | "http://wordpress.org/support/plugin/cmb2-remote-img-sel\n" 8 | "POT-Creation-Date: 2015-06-12 14:52:09+00:00\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=utf-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "X-Generator: grunt-wp-i18n 0.5.2\n" 16 | 17 | #. Plugin Name of the plugin/theme 18 | msgid "WDS Image Grabber" 19 | msgstr "" 20 | 21 | #. Author URI of the plugin/theme 22 | msgid "http://webdevstudios.com/" 23 | msgstr "" 24 | 25 | #. Description of the plugin/theme 26 | msgid "Class to grab images from website's body." 27 | msgstr "" 28 | 29 | #. Author of the plugin/theme 30 | msgid "WebDevStudios" 31 | msgstr "" -------------------------------------------------------------------------------- /assets/js/cmb2-remote-img-sel.min.js: -------------------------------------------------------------------------------- 1 | /** CMB2 Remote Image Select - v0.1.0 - 2015-06-12 | http://webdevstudios.com | Copyright (c) 2015; | Licensed GPLv2+ **/ 2 | window.CMB2_Remote_Image_Select=function(a,b,c,d){"use strict";var e={},f=cmb2_remote_img_sel||{};e.cache=function(){e.$window=c(a),e.$body=c(b.body),e.$button=c(".cmb2-remote-image-select.search.button"),e.$url=c(".cmb2-remote-image-select.url"),e.$placeholder=c(".cmb2-remote-image-select.images.placeholder"),e.$loader=c(".cmb2-remote-image-select.images-loading-icon")},e.init=function(){return f.ajaxurl&&f.nonce&&f.action?(e.cache(),void c("body").on("click",".cmb2-remote-image-select.search.button",e.search)):!1},e.search=function(a){a.preventDefault(),e.$loader.show(),jQuery.ajax({url:f.ajaxurl,method:"POST",timeout:3e4,data:{nonce:f.nonce,action:f.action,field_name:e.$url.attr("name"),field_id:e.$url.attr("id").replace("-url",""),url:e.$url.val()},dataType:"json"}).done(e.finished_request).fail(e.failed_request)},e.finished_request=function(a,b,c){e.$loader.hide(),e.$placeholder.html(""),a.success?(e.$placeholder.append(a.data),e.$placeholder.show()):e.log(a)},e.failed_request=function(a,b,c){e.$loader.hide(),e.log(c)},e.log=function(b){a.console&&f.script_debug&&a.console.log(b)},jQuery(b).ready(e.init)}(window,document,jQuery); -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === CMB2 Remote Image Select === 2 | Contributors: Mamaduka,phyrax,webdevstudios 3 | Donate link: http://webdevstudios.com 4 | Tags: facebook,image select,metabox,cmb2 5 | Requires at least: 3.6.0 6 | Tested up to: 4.2.2 7 | Stable tag: 0.1.0 8 | License: GPLv2 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | 12 | == Description == 13 | 14 | Allows users to enter a URL in a text field and select a single image for use in post meta. Similar to Facebook's featured image selector. 15 | 16 | **Note**: This field may not support repetition, repeatable fields/groups is untested 17 | 18 | = Usage = 19 | ``` 20 | $cmb->add_field( array( 21 | 'name' => __( 'Select an Image', 'textdomain' ), 22 | 'id' => 'images', 23 | 'type' => 'remote_image_select', 24 | ) ); 25 | ``` 26 | 27 | == Installation == 28 | 29 | = Manual Installation = 30 | 31 | 1. Upload the entire `/cmb2-remote-img-sel` directory to the `/wp-content/plugins/` directory. 32 | 2. Activate CMB2 Remote Image Select through the 'Plugins' menu in WordPress. 33 | 34 | == Frequently Asked Questions == 35 | 36 | 37 | == Screenshots == 38 | 39 | 40 | == Changelog == 41 | 42 | = 0.1.0 = 43 | * First release 44 | 45 | == Upgrade Notice == 46 | 47 | = 0.1.0 = 48 | First Release 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CMB2 Remote Image Select # 2 | **Version:** 0.1.0 3 | **Contributors:** [George Mamadashvili](https://profiles.wordpress.org/Mamaduka/), [Jay Wood](https://profiles.wordpress.org/phyrax/) 4 | **Author:** [WebDevStudios](http://webdevstudios.com) 5 | **Author URI:** http://webdevstudios.com/ 6 | **Requires at least:** 3.6.0 7 | **Tested up to:** 4.2.2 8 | **Stable tag:** 0.1.0 9 | **License:** GPLv2 10 | **License URI:** http://www.gnu.org/licenses/gpl-2.0.html 11 | 12 | ## Description ## 13 | 14 | Allows users to enter a URL in a text field and select a single image for use in post meta. Similar to Facebook's featured image selector. 15 | 16 | **Note**: This field may not support repetition, repeatable fields/groups is untested 17 | 18 | ### Usage ### 19 | ```php 20 | $cmb->add_field( array( 21 | 'name' => __( 'Select an Image', 'textdomain' ), 22 | 'id' => 'images', 23 | 'type' => 'remote_image_select', 24 | ) ); 25 | ``` 26 | 27 | ## Installation ## 28 | 29 | ### Manual Installation ### 30 | 31 | 1. Upload the entire `/cmb2-remote-img-sel` directory to the `/wp-content/plugins/` directory. 32 | 2. Activate CMB2 Remote Image Select through the 'Plugins' menu in WordPress. 33 | 34 | ## Frequently Asked Questions ## 35 | 36 | * None as of yet 37 | 38 | ## Changelog ## 39 | 40 | ### 0.1.0 ### 41 | * First release 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear on external disk 14 | .Spotlight-V100 15 | .Trashes 16 | 17 | # Directories potentially created on remote AFP share 18 | .AppleDB 19 | .AppleDesktop 20 | Network Trash Folder 21 | Temporary Items 22 | .apdisk 23 | 24 | 25 | ### Bower ### 26 | bower_components 27 | .bower-cache 28 | .bower-registry 29 | .bower-tmp 30 | 31 | 32 | ### Node ### 33 | # Logs 34 | logs 35 | *.log 36 | 37 | # Runtime data 38 | pids 39 | *.pid 40 | *.seed 41 | 42 | # Directory for instrumented libs generated by jscoverage/JSCover 43 | lib-cov 44 | 45 | # Coverage directory used by tools like istanbul 46 | coverage 47 | 48 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 49 | .grunt 50 | 51 | # node-waf configuration 52 | .lock-wscript 53 | 54 | # Compiled binary addons (http://nodejs.org/api/addons.html) 55 | build/Release 56 | 57 | # Dependency directory 58 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 59 | node_modules 60 | 61 | 62 | ### Composer ### 63 | composer.phar 64 | vendor/ 65 | 66 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 67 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 68 | # composer.lock 69 | 70 | ### Sass ### 71 | .sass-cache 72 | 73 | -------------------------------------------------------------------------------- /assets/js/cmb2-remote-img-sel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CMB2 Remote Image Select 3 | * http://webdevstudios.com 4 | * 5 | * Licensed under the GPLv2+ license. 6 | */ 7 | 8 | window.CMB2_Remote_Image_Select = ( function( window, document, $, undefined ) { 9 | 'use strict'; 10 | 11 | var app = {}, 12 | cmb2_ris = cmb2_remote_img_sel || {}; 13 | 14 | app.cache = function() { 15 | app.$window = $( window ); 16 | app.$body = $( document.body ); 17 | app.$button = $( '.cmb2-remote-image-select.search.button' ); 18 | app.$url = $( '.cmb2-remote-image-select.url' ); 19 | app.$placeholder = $( '.cmb2-remote-image-select.images.placeholder' ); 20 | app.$loader = $( '.cmb2-remote-image-select.images-loading-icon' ); 21 | }; 22 | 23 | app.init = function() { 24 | 25 | if ( ! cmb2_ris.ajaxurl || ! cmb2_ris.nonce || ! cmb2_ris.action ) { 26 | return false; 27 | } 28 | 29 | app.cache(); 30 | 31 | $( 'body' ).on( 'click', '.cmb2-remote-image-select.search.button', app.search ); 32 | }; 33 | 34 | app.search = function( evt ){ 35 | evt.preventDefault(); 36 | app.$loader.show(); 37 | jQuery.ajax({ 38 | url: cmb2_ris.ajaxurl, 39 | method: 'POST', 40 | timeout: 30000, 41 | data: { 42 | nonce: cmb2_ris.nonce, 43 | action: cmb2_ris.action, 44 | field_name: app.$url.attr( 'name' ), 45 | field_id: app.$url.attr( 'id' ).replace( '-url', '' ), 46 | url: app.$url.val() 47 | }, 48 | dataType: 'json' 49 | } ).done( app.finished_request ).fail( app.failed_request ); 50 | }; 51 | 52 | app.finished_request = function( data, textStatus, jqXHR ) { 53 | app.$loader.hide(); 54 | app.$placeholder.html( '' ); 55 | if ( data.success ) { 56 | app.$placeholder.append( data.data ); 57 | app.$placeholder.show(); 58 | } else { 59 | app.log( data ); 60 | } 61 | }; 62 | 63 | app.failed_request = function( jqXHR, textStatus, errorThrown ){ 64 | app.$loader.hide(); 65 | app.log( errorThrown ); 66 | }; 67 | 68 | app.log = function ( log_item ) { 69 | if ( window.console && cmb2_ris.script_debug ) { 70 | window.console.log( log_item ); 71 | } 72 | }; 73 | 74 | jQuery( document ).ready( app.init ); 75 | 76 | } ) ( window, document, jQuery ); 77 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | require('load-grunt-tasks')(grunt); 3 | var pkg = grunt.file.readJSON('package.json'); 4 | var bannerTemplate = '/**\n' + ' * <%= pkg.title %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + ' * <%= pkg.author.url %>\n' + ' *\n' + ' * Copyright (c) <%= grunt.template.today("yyyy") %>;\n' + ' * Licensed GPLv2+\n' + ' */\n'; 5 | var compactBannerTemplate = '/** ' + '<%= pkg.title %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> | <%= pkg.author.url %> | Copyright (c) <%= grunt.template.today("yyyy") %>; | Licensed GPLv2+' + ' **/\n'; 6 | // Project configuration 7 | grunt.initConfig({ 8 | pkg: pkg, 9 | watch: { 10 | styles: { 11 | files: [ 12 | 'assets/**/*.css', 13 | 'assets/**/*.scss' 14 | ], 15 | tasks: ['styles'], 16 | options: { 17 | spawn: false, 18 | livereload: true, 19 | debounceDelay: 500 20 | } 21 | }, 22 | scripts: { 23 | files: ['assets/**/*.js'], 24 | tasks: ['scripts'], 25 | options: { 26 | spawn: false, 27 | livereload: true, 28 | debounceDelay: 500 29 | } 30 | }, 31 | php: { 32 | files: [ 33 | '**/*.php', 34 | '!vendor/**.*.php' 35 | ], 36 | tasks: ['php'], 37 | options: { 38 | spawn: false, 39 | debounceDelay: 500 40 | } 41 | } 42 | }, 43 | makepot: { 44 | dist: { 45 | options: { 46 | domainPath: '/languages/', 47 | potFilename: pkg.name + '.pot', 48 | type: 'wp-plugin' 49 | } 50 | } 51 | }, 52 | addtextdomain: { 53 | dist: { 54 | options: { textdomain: pkg.name }, 55 | target: { files: { src: ['**/*.php'] } } 56 | } 57 | }, 58 | jshint: { 59 | all: [ 60 | 'assets/js/**/*.js', 61 | '!**/*.min.js' 62 | ], 63 | options: { 64 | browser: true, 65 | predef: [ 66 | 'document', 67 | 'window', 68 | 'jQuery', 69 | 'undefined' 70 | ] 71 | } 72 | }, 73 | uglify: { 74 | dist: { 75 | files: { 'assets/js/cmb2-remote-img-sel.min.js': 'assets/js/cmb2-remote-img-sel.js' }, 76 | options: { banner: compactBannerTemplate } 77 | } 78 | } 79 | }); 80 | // Default task. 81 | grunt.registerTask('scripts', [ 82 | 'jshint', 83 | 'uglify' 84 | ]); 85 | grunt.registerTask('styles', []); 86 | grunt.registerTask('php', [ 87 | 'addtextdomain', 88 | 'makepot' 89 | ]); 90 | grunt.registerTask('default', [ 91 | 'styles', 92 | 'scripts', 93 | 'php' 94 | ]); 95 | grunt.util.linefeed = '\n'; 96 | }; -------------------------------------------------------------------------------- /cmb2-remote-img-sel.php: -------------------------------------------------------------------------------- 1 | basename = plugin_basename( __FILE__ ); 140 | $this->url = plugin_dir_url( __FILE__ ); 141 | $this->path = plugin_dir_path( __FILE__ ); 142 | 143 | $this->plugin_classes(); 144 | $this->hooks(); 145 | } 146 | 147 | /** 148 | * Attach other plugin classes to the base plugin class. 149 | * 150 | * @since 0.1.0 151 | * @return null 152 | */ 153 | function plugin_classes() { 154 | // Attach other plugin classes to the base plugin class. 155 | // $this->admin = new CMB2RIS_Admin( $this ); 156 | } 157 | 158 | /** 159 | * Add hooks and filters 160 | * 161 | * @since 0.1.0 162 | * @return null 163 | */ 164 | public function hooks() { 165 | register_activation_hook( __FILE__, array( $this, '_activate' ) ); 166 | register_deactivation_hook( __FILE__, array( $this, '_deactivate' ) ); 167 | 168 | add_action( 'cmb2_render_remote_image_select', array( $this, 'remote_image_select' ), 10, 5 ); 169 | add_action( 'cmb2_sanitize_remote_image_select', array( $this, 'sanitize_remote_image_select' ), 10, 2 ); 170 | add_action( 'init', array( $this, 'init' ) ); 171 | 172 | // Ajax stuffs 173 | add_action( 'wp_ajax_nopriv_cmb2_remote_img_sel', array( $this, 'handle_ajax' ) ); 174 | add_action( 'wp_ajax_cmb2_remote_img_sel', array( $this, 'handle_ajax' ) ); 175 | } 176 | 177 | /** 178 | * Activate the plugin 179 | * 180 | * @since 0.1.0 181 | * @return null 182 | */ 183 | function _activate() { 184 | // Make sure any rewrite functionality has been loaded 185 | flush_rewrite_rules(); 186 | } 187 | 188 | /** 189 | * Deactivate the plugin 190 | * Uninstall routines should be in uninstall.php 191 | * 192 | * @since 0.1.0 193 | * @return null 194 | */ 195 | function _deactivate() {} 196 | 197 | /** 198 | * Init hooks 199 | * 200 | * @since 0.1.0 201 | * @return null 202 | */ 203 | public function init() { 204 | 205 | $min = defined( "SCRIPT_DEBUG" ) && SCRIPT_DEBUG ? '' : '.min'; 206 | if ( $this->check_requirements() ) { 207 | load_plugin_textdomain( 'cmb2-remote-img-sel', false, dirname( $this->basename ) . '/languages/' ); 208 | 209 | wp_register_script( 'cmb2-remote-img-sel', $this->url( "assets/js/cmb2-remote-img-sel{$min}.js"), array( 'jquery' ), self::VERSION, true ); 210 | wp_localize_script( 'cmb2-remote-img-sel', 'cmb2_remote_img_sel', array( 211 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), 212 | 'action' => 'cmb2_remote_img_sel', 213 | 'nonce' => wp_create_nonce( $this->nonce ), 214 | 'script_debug' => defined( 'SCRIPT_DEBUG' ) ? SCRIPT_DEBUG : false 215 | ) ); 216 | } 217 | } 218 | 219 | public function remote_image_select( $field, $escaped_value, $object_id, $object_type, $field_type_object ) { 220 | 221 | // @TODO: add checks here for PHPCS 222 | $config_array = $field_type_object->value(); 223 | $field_name = $field_type_object->_name(); 224 | $field_id = $field_type_object->_id(); 225 | 226 | echo $field_type_object->input( array( 227 | 'type' => 'text', 228 | 'class' => 'cmb2-remote-image-select url', 229 | 'id' => $field_id, 230 | 'name' => $field_name.'[url]', 231 | 'desc' => '', 232 | 'placeholder' => 'http://', 233 | ) ); 234 | 235 | echo ""; 236 | echo "
"; 237 | echo $field_type_object->_desc( true ); 238 | 239 | // Loaded images 240 | $output = ""; 241 | 242 | echo $output; 243 | 244 | wp_enqueue_script( 'cmb2-remote-img-sel' ); 245 | } 246 | 247 | public function sanitize_remote_image_select( $override = '', $value = array() ) { 248 | // Sanitize the data. 249 | if ( ! isset( $value['image'] ) || ! isset( $value['url'] ) ) { 250 | return ''; 251 | } 252 | 253 | return array( 254 | 'image' => ! empty( $value['image'] ) ? esc_url( $value['image'] ) : '', 255 | 'url' => ! empty( $value['url'] ) ? esc_url( $value['url'] ) : '', 256 | ); 257 | } 258 | 259 | public function handle_ajax() { 260 | if ( ! class_exists( 'WDS_Image_Grabber' ) ) { 261 | require_once 'includes/wds-image-grabber/wds-image-grabber.php'; 262 | } 263 | 264 | $args = wp_parse_args( $_POST, array( 265 | 'nonce' => '', 266 | 'field_id' => '', 267 | 'field_name' => '', 268 | 'url' => '', 269 | ) ); 270 | 271 | if ( ! wp_verify_nonce( $args['nonce'], $this->nonce ) ) { 272 | wp_send_json_error( __( "Verification error.", 'cmb2-remote-img-sel' ) ); 273 | } 274 | 275 | if ( empty( $args['field_id'] ) || empty( $args['url'] ) || empty( $args['field_name'] ) ) { 276 | wp_send_json_error( __( "Required fields not met.", 'cmb2-remote-img-sel' ) ); 277 | } 278 | 279 | $grabber = new WDS_Image_Grabber( $args['url'] ); 280 | $images = $grabber->get_images(); 281 | if ( empty( $images ) ) { 282 | wp_send_json_error( __( "No qualifying images were available for use.", 'cmb2-remote-img-sel' ) ); 283 | } 284 | 285 | $output = ''; 286 | $count = 0; 287 | $field_name = str_replace( '[url]', '', $args['field_name'] ); 288 | $output .= ""; 297 | 298 | wp_send_json_success( $output ); 299 | } 300 | 301 | /** 302 | * Check that all plugin requirements are met 303 | * 304 | * @since 0.1.0 305 | * @return boolean 306 | */ 307 | public static function meets_requirements() { 308 | // Do checks for required classes / functions 309 | // function_exists('') & class_exists('') 310 | return true; 311 | } 312 | 313 | /** 314 | * Check if the plugin meets requirements and 315 | * disable it if they are not present. 316 | * 317 | * @since 0.1.0 318 | * @return boolean result of meets_requirements 319 | */ 320 | public function check_requirements() { 321 | if ( ! $this->meets_requirements() ) { 322 | // Display our error 323 | echo '
'; 324 | echo '

' . sprintf( __( 'CMB2 Remote Image Select is missing requirements and has been deactivated. Please make sure all requirements are available.', 'cmb2-remote-img-sel' ), admin_url( 'plugins.php' ) ) . '

'; 325 | echo '
'; 326 | // Deactivate our plugin 327 | deactivate_plugins( $this->basename ); 328 | 329 | return false; 330 | } 331 | 332 | return true; 333 | } 334 | 335 | /** 336 | * Magic getter for our object. 337 | * 338 | * @since 0.1.0 339 | * @param string $field 340 | * @throws Exception Throws an exception if the field is invalid. 341 | * @return mixed 342 | */ 343 | public function __get( $field ) { 344 | switch ( $field ) { 345 | case 'version': 346 | return self::VERSION; 347 | case 'basename': 348 | case 'url': 349 | case 'path': 350 | return $this->$field; 351 | default: 352 | throw new Exception( 'Invalid '. __CLASS__ .' property: ' . $field ); 353 | } 354 | } 355 | 356 | /** 357 | * Include a file from the includes directory 358 | * 359 | * @since 0.1.0 360 | * @param string $filename Name of the file to be included 361 | * @return bool Result of include call. 362 | */ 363 | public static function include_file( $filename ) { 364 | $file = self::dir( 'includes/'. $filename .'.php' ); 365 | if ( file_exists( $file ) ) { 366 | return include_once( $file ); 367 | } 368 | return false; 369 | } 370 | 371 | /** 372 | * This plugin's directory 373 | * 374 | * @since 0.1.0 375 | * @param string $path (optional) appended path 376 | * @return string Directory and path 377 | */ 378 | public static function dir( $path = '' ) { 379 | static $dir; 380 | $dir = $dir ? $dir : trailingslashit( dirname( __FILE__ ) ); 381 | return $dir . $path; 382 | } 383 | 384 | /** 385 | * This plugin's url 386 | * 387 | * @since 0.1.0 388 | * @param string $path (optional) appended path 389 | * @return string URL and path 390 | */ 391 | public static function url( $path = '' ) { 392 | static $url; 393 | $url = $url ? $url : trailingslashit( plugin_dir_url( __FILE__ ) ); 394 | return $url . $path; 395 | } 396 | } 397 | 398 | /** 399 | * Grab the CMB2_Remote_Image_Select object and return it. 400 | * Wrapper for CMB2_Remote_Image_Select::get_instance() 401 | * 402 | * @since 0.1.0 403 | * @return CMB2_Remote_Image_Select Singleton instance of plugin class. 404 | */ 405 | function cmb2_remote_img_sel() { 406 | return CMB2_Remote_Image_Select::get_instance(); 407 | } 408 | 409 | // Kick it off 410 | cmb2_remote_img_sel(); 411 | --------------------------------------------------------------------------------