├── .bowerrc ├── includes └── README.md ├── assets └── README.md ├── phpunit.xml ├── bower.json ├── .travis.yml ├── tests ├── test-base.php └── bootstrap.php ├── package.json ├── .yo-rc.json ├── readme.txt ├── README.md ├── .gitignore ├── Gruntfile.js ├── bin └── install-wp-tests.sh └── wds-cmb2-customizer.php /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "assets/bower" 3 | } -------------------------------------------------------------------------------- /includes/README.md: -------------------------------------------------------------------------------- 1 | # WDS CMB2 Customizer Includes # 2 | http://webdevstudios.com 3 | Copyright (c) 2015 WebDevStudios 4 | Licensed under the GPLv2 license. 5 | 6 | Additional PHP functionality goes here. -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # WDS CMB2 Customizer Assets # 2 | http://webdevstudios.com 3 | Copyright (c) 2015 WebDevStudios 4 | Licensed under the GPLv2 license. 5 | 6 | Assets such as styles, javascript, and images. -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wds-cmb2-customizer", 3 | "description": "Use CMB2 to easily generate fields for the Customizer in 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 | } 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | notifications: 4 | email: 5 | on_success: never 6 | on_failure: change 7 | 8 | php: 9 | - 5.3 10 | - 5.5 11 | 12 | env: 13 | - WP_VERSION=latest WP_MULTISITE=0 14 | 15 | matrix: 16 | include: 17 | - php: 5.3 18 | env: WP_VERSION=latest WP_MULTISITE=1 19 | 20 | before_script: 21 | - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION 22 | 23 | script: phpunit 24 | -------------------------------------------------------------------------------- /tests/test-base.php: -------------------------------------------------------------------------------- 1 | assertTrue( true ); 8 | } 9 | 10 | function test_class_exists() { 11 | $this->assertTrue( class_exists( 'WDS_CMB2_Customizer') ); 12 | } 13 | 14 | function test_get_instance() { 15 | $this->assertTrue( wds_cmb2_customizer() instanceof WDS_CMB2_Customizer ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + 9 | ' * <%= pkg.author.url %>\n' + 10 | ' *\n' + 11 | ' * Copyright (c) <%= grunt.template.today("yyyy") %>;\n' + 12 | ' * Licensed GPLv2+\n' + 13 | ' */\n'; 14 | 15 | var compactBannerTemplate = '/** ' + 16 | '<%= pkg.title %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> | <%= pkg.author.url %> | Copyright (c) <%= grunt.template.today("yyyy") %>; | Licensed GPLv2+' + 17 | ' **/\n'; 18 | 19 | // Project configuration 20 | grunt.initConfig( { 21 | 22 | pkg: pkg, 23 | 24 | 25 | watch: { 26 | styles: { 27 | files: ['assets/**/*.css','assets/**/*.scss'], 28 | tasks: ['styles'], 29 | options: { 30 | spawn: false, 31 | livereload: true, 32 | debounceDelay: 500 33 | } 34 | }, 35 | scripts: { 36 | files: ['assets/**/*.js'], 37 | tasks: ['scripts'], 38 | options: { 39 | spawn: false, 40 | livereload: true, 41 | debounceDelay: 500 42 | } 43 | }, 44 | php: { 45 | files: ['**/*.php', '!vendor/**.*.php'], 46 | tasks: ['php'], 47 | options: { 48 | spawn: false, 49 | debounceDelay: 500 50 | } 51 | } 52 | }, 53 | 54 | makepot: { 55 | dist: { 56 | options: { 57 | domainPath: '/languages/', 58 | potFilename: pkg.name + '.pot', 59 | type: 'wp-plugin' 60 | } 61 | } 62 | }, 63 | 64 | addtextdomain: { 65 | dist: { 66 | options: { 67 | textdomain: pkg.name 68 | }, 69 | target: { 70 | files: { 71 | src: ['**/*.php'] 72 | } 73 | } 74 | } 75 | } 76 | 77 | } ); 78 | 79 | // Default task. 80 | grunt.registerTask( 'scripts', [] ); 81 | grunt.registerTask( 'styles', [] ); 82 | grunt.registerTask( 'php', [ 'addtextdomain', 'makepot' ] ); 83 | grunt.registerTask( 'default', ['styles', 'scripts', 'php'] ); 84 | 85 | grunt.util.linefeed = '\n'; 86 | }; 87 | -------------------------------------------------------------------------------- /bin/install-wp-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # To install temp. test suite 3 | # bash tests/bin/install-wp-tests.sh wordpress_test root '' localhost latest 4 | 5 | if [ $# -lt 3 ]; then 6 | echo "usage: $0 [db-host] [wp-version]" 7 | exit 1 8 | fi 9 | 10 | DB_NAME=$1 11 | DB_USER=$2 12 | DB_PASS=$3 13 | DB_HOST=${4-localhost} 14 | WP_VERSION=${5-latest} 15 | 16 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} 17 | WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} 18 | 19 | set -ex 20 | 21 | download() { 22 | if [ `which curl` ]; then 23 | curl -s "$1" > "$2"; 24 | elif [ `which wget` ]; then 25 | wget -nv -O "$2" "$1" --no-check-certificate 26 | fi 27 | } 28 | 29 | install_wp() { 30 | 31 | if [ -d $WP_CORE_DIR ]; then 32 | return; 33 | fi 34 | 35 | mkdir -p $WP_CORE_DIR 36 | 37 | if [ $WP_VERSION == 'latest' ]; then 38 | local ARCHIVE_NAME='latest' 39 | else 40 | local ARCHIVE_NAME="wordpress-$WP_VERSION" 41 | fi 42 | 43 | download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz 44 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR 45 | 46 | download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php 47 | } 48 | 49 | install_test_suite() { 50 | # portable in-place argument for both GNU sed and Mac OSX sed 51 | if [[ $(uname -s) == 'Darwin' ]]; then 52 | local ioption='-i .bak' 53 | else 54 | local ioption='-i' 55 | fi 56 | 57 | # set up testing suite if it doesn't yet exist 58 | if [ ! -d $WP_TESTS_DIR ]; then 59 | # set up testing suite 60 | mkdir -p $WP_TESTS_DIR 61 | svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ $WP_TESTS_DIR/includes 62 | fi 63 | 64 | cd $WP_TESTS_DIR 65 | 66 | if [ ! -f wp-tests-config.php ]; then 67 | download https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php 68 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php 69 | sed $ioption "s:define( 'WP_DEBUG', true );:define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );:" wp-tests-config.php 70 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php 71 | sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php 72 | sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php 73 | sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php 74 | fi 75 | 76 | } 77 | 78 | install_db() { 79 | # parse DB_HOST for port or socket references 80 | local PARTS=(${DB_HOST//\:/ }) 81 | local DB_HOSTNAME=${PARTS[0]}; 82 | local DB_SOCK_OR_PORT=${PARTS[1]}; 83 | local EXTRA="" 84 | 85 | if ! [ -z $DB_HOSTNAME ] ; then 86 | if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then 87 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" 88 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then 89 | EXTRA=" --socket=$DB_SOCK_OR_PORT" 90 | elif ! [ -z $DB_HOSTNAME ] ; then 91 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" 92 | fi 93 | fi 94 | 95 | # create database 96 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA 97 | } 98 | 99 | install_wp 100 | install_test_suite 101 | install_db 102 | -------------------------------------------------------------------------------- /wds-cmb2-customizer.php: -------------------------------------------------------------------------------- 1 | basename = plugin_basename( __FILE__ ); 132 | $this->url = plugin_dir_url( __FILE__ ); 133 | $this->path = plugin_dir_path( __FILE__ ); 134 | 135 | $this->plugin_classes(); 136 | } 137 | 138 | /** 139 | * Attach other plugin classes to the base plugin class. 140 | * 141 | * @since 0.1.0 142 | * @return null 143 | */ 144 | public function plugin_classes() { 145 | // Attach other plugin classes to the base plugin class. 146 | // $this->admin = new WDSCMB2C_Admin( $this ); 147 | } 148 | 149 | /** 150 | * Add hooks and filters 151 | * 152 | * @since 0.1.0 153 | * @return null 154 | */ 155 | public function hooks() { 156 | register_activation_hook( __FILE__, array( $this, '_activate' ) ); 157 | register_deactivation_hook( __FILE__, array( $this, '_deactivate' ) ); 158 | 159 | add_action( 'init', array( $this, 'init' ) ); 160 | } 161 | 162 | /** 163 | * Activate the plugin 164 | * 165 | * @since 0.1.0 166 | * @return null 167 | */ 168 | function _activate() { 169 | // Make sure any rewrite functionality has been loaded 170 | flush_rewrite_rules(); 171 | } 172 | 173 | /** 174 | * Deactivate the plugin 175 | * Uninstall routines should be in uninstall.php 176 | * 177 | * @since 0.1.0 178 | * @return null 179 | */ 180 | function _deactivate() {} 181 | 182 | /** 183 | * Init hooks 184 | * 185 | * @since 0.1.0 186 | * @return null 187 | */ 188 | public function init() { 189 | if ( $this->check_requirements() ) { 190 | load_plugin_textdomain( 'wds-cmb2-customizer', false, dirname( $this->basename ) . '/languages/' ); 191 | } 192 | } 193 | 194 | /** 195 | * Check that all plugin requirements are met 196 | * 197 | * @since 0.1.0 198 | * @return boolean 199 | */ 200 | public static function meets_requirements() { 201 | // Do checks for required classes / functions 202 | // function_exists('') & class_exists('') 203 | 204 | // We have met all requirements 205 | return true; 206 | } 207 | 208 | /** 209 | * Check if the plugin meets requirements and 210 | * disable it if they are not present. 211 | * 212 | * @since 0.1.0 213 | * @return boolean result of meets_requirements 214 | */ 215 | public function check_requirements() { 216 | if ( ! $this->meets_requirements() ) { 217 | 218 | // Add a dashboard notice 219 | add_action( 'all_admin_notices', array( $this, 'requirements_not_met_notice' ) ); 220 | 221 | // Deactivate our plugin 222 | deactivate_plugins( $this->basename ); 223 | 224 | return false; 225 | } 226 | 227 | return true; 228 | } 229 | 230 | /** 231 | * Adds a notice to the dashboard if the plugin requirements are not met 232 | * 233 | * @since 0.1.0 234 | * @return null 235 | */ 236 | public function requirements_not_met_notice() { 237 | // Output our error 238 | echo '
'; 239 | echo '

' . sprintf( __( 'WDS CMB2 Customizer is missing requirements and has been deactivated. Please make sure all requirements are available.', 'wds-cmb2-customizer' ), admin_url( 'plugins.php' ) ) . '

'; 240 | echo '
'; 241 | } 242 | 243 | /** 244 | * Magic getter for our object. 245 | * 246 | * @since 0.1.0 247 | * @param string $field 248 | * @throws Exception Throws an exception if the field is invalid. 249 | * @return mixed 250 | */ 251 | public function __get( $field ) { 252 | switch ( $field ) { 253 | case 'version': 254 | return self::VERSION; 255 | case 'basename': 256 | case 'url': 257 | case 'path': 258 | return $this->$field; 259 | default: 260 | throw new Exception( 'Invalid '. __CLASS__ .' property: ' . $field ); 261 | } 262 | } 263 | 264 | /** 265 | * Include a file from the includes directory 266 | * 267 | * @since 0.1.0 268 | * @param string $filename Name of the file to be included 269 | * @return bool Result of include call. 270 | */ 271 | public static function include_file( $filename ) { 272 | $file = self::dir( 'includes/'. $filename .'.php' ); 273 | if ( file_exists( $file ) ) { 274 | return include_once( $file ); 275 | } 276 | return false; 277 | } 278 | 279 | /** 280 | * This plugin's directory 281 | * 282 | * @since 0.1.0 283 | * @param string $path (optional) appended path 284 | * @return string Directory and path 285 | */ 286 | public static function dir( $path = '' ) { 287 | static $dir; 288 | $dir = $dir ? $dir : trailingslashit( dirname( __FILE__ ) ); 289 | return $dir . $path; 290 | } 291 | 292 | /** 293 | * This plugin's url 294 | * 295 | * @since 0.1.0 296 | * @param string $path (optional) appended path 297 | * @return string URL and path 298 | */ 299 | public static function url( $path = '' ) { 300 | static $url; 301 | $url = $url ? $url : trailingslashit( plugin_dir_url( __FILE__ ) ); 302 | return $url . $path; 303 | } 304 | } 305 | 306 | /** 307 | * Grab the WDS_CMB2_Customizer object and return it. 308 | * Wrapper for WDS_CMB2_Customizer::get_instance() 309 | * 310 | * @since 0.1.0 311 | * @return WDS_CMB2_Customizer Singleton instance of plugin class. 312 | */ 313 | function wds_cmb2_customizer() { 314 | return WDS_CMB2_Customizer::get_instance(); 315 | } 316 | 317 | // Kick it off 318 | add_action( 'plugins_loaded', array( wds_cmb2_customizer(), 'hooks' ) ); 319 | --------------------------------------------------------------------------------