├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── README.md ├── Tax-meta-class ├── Tax-meta-class.php ├── css │ └── Tax-meta-class.css ├── images │ ├── add.png │ ├── delete-16.png │ ├── edit.png │ └── remove.png ├── js │ └── tax-meta-clss.js ├── lang │ ├── default.mo │ ├── default.po │ ├── fr_FR.mo │ └── fr_FR.po └── migration │ └── tax_to_term_meta.php ├── class-usage-demo.php └── license.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | # Gitpod docker image for WordPress | https://github.com/luizbills/gitpod-wordpress 2 | # License: MIT (c) 2019 Luiz Paulo "Bills" 3 | # Version: 0.5 4 | FROM gitpod/workspace-mysql 5 | 6 | ### General Settings ### 7 | ENV PHP_VERSION="7.4" 8 | ENV APACHE_DOCROOT="public_html" 9 | 10 | ### Setups, Node, NPM ### 11 | USER gitpod 12 | ADD https://api.wordpress.org/secret-key/1.1/salt /dev/null 13 | RUN git clone https://github.com/luizbills/gitpod-wordpress $HOME/gitpod-wordpress && \ 14 | cat $HOME/gitpod-wordpress/conf/.bashrc.sh >> $HOME/.bashrc && \ 15 | . $HOME/.bashrc && \ 16 | bash -c ". .nvm/nvm.sh && nvm install --lts" 17 | 18 | ### MailHog ### 19 | USER root 20 | RUN go get github.com/mailhog/MailHog && \ 21 | go get github.com/mailhog/mhsendmail && \ 22 | cp $GOPATH/bin/MailHog /usr/local/bin/mailhog && \ 23 | cp $GOPATH/bin/mhsendmail /usr/local/bin/mhsendmail && \ 24 | ln $GOPATH/bin/mhsendmail /usr/sbin/sendmail && \ 25 | ln $GOPATH/bin/mhsendmail /usr/bin/mail &&\ 26 | ### Apache ### 27 | apt-get -y install apache2 && \ 28 | chown -R gitpod:gitpod /var/run/apache2 /var/lock/apache2 /var/log/apache2 && \ 29 | echo "include ${HOME}/gitpod-wordpress/conf/apache.conf" > /etc/apache2/apache2.conf && \ 30 | echo ". ${HOME}/gitpod-wordpress/conf/apache.env.sh" > /etc/apache2/envvars && \ 31 | ### PHP ### 32 | add-apt-repository ppa:ondrej/php && \ 33 | apt-get update && \ 34 | apt-get -y install \ 35 | libapache2-mod-php \ 36 | php${PHP_VERSION} \ 37 | php${PHP_VERSION}-common \ 38 | php${PHP_VERSION}-cli \ 39 | php${PHP_VERSION}-mbstring \ 40 | php${PHP_VERSION}-curl \ 41 | php${PHP_VERSION}-gd \ 42 | php${PHP_VERSION}-intl \ 43 | php${PHP_VERSION}-mysql \ 44 | php${PHP_VERSION}-xml \ 45 | php${PHP_VERSION}-json \ 46 | php${PHP_VERSION}-zip \ 47 | php${PHP_VERSION}-soap \ 48 | php${PHP_VERSION}-bcmath \ 49 | php${PHP_VERSION}-opcache \ 50 | php-xdebug && \ 51 | apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* && \ 52 | cat /home/gitpod/gitpod-wordpress/conf/php.ini >> /etc/php/${PHP_VERSION}/apache2/php.ini && \ 53 | a2dismod php* && \ 54 | a2dismod mpm_* && \ 55 | a2enmod mpm_prefork && \ 56 | a2enmod php${PHP_VERSION} && \ 57 | ### WP-CLI ### 58 | wget -q https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O $HOME/wp-cli.phar && \ 59 | wget -q https://raw.githubusercontent.com/wp-cli/wp-cli/v2.3.0/utils/wp-completion.bash -O $HOME/wp-cli-completion.bash && \ 60 | chmod +x $HOME/wp-cli.phar && \ 61 | mv $HOME/wp-cli.phar /usr/local/bin/wp && \ 62 | chown gitpod:gitpod /usr/local/bin/wp 63 | 64 | ### WordPress, Adminer ### 65 | USER gitpod 66 | ADD https://api.wordpress.org/secret-key/1.1/salt /dev/null 67 | RUN wget -q https://wordpress.org/latest.zip -O $HOME/wordpress.zip && \ 68 | unzip -qn $HOME/wordpress.zip -d $HOME && \ 69 | unlink $HOME/wordpress.zip && \ 70 | cp $HOME/gitpod-wordpress/conf/.htaccess $HOME/wordpress/.htaccess && \ 71 | mkdir $HOME/wordpress/database/ && \ 72 | wget -q https://www.adminer.org/latest.php -O $HOME/wordpress/database/index.php && \ 73 | mkdir $HOME/wordpress/phpinfo/ && \ 74 | echo "" > $HOME/wordpress/phpinfo/index.php -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.dockerfile 3 | 4 | ports: 5 | - port: 8080 6 | onOpen: open-preview 7 | - port: 3306 8 | onOpen: ignore 9 | - port: 8025 10 | onOpen: ignore 11 | - port: 1025 12 | onOpen: ignore 13 | 14 | tasks: 15 | - init: wp-setup-plugin # or wp-setup-theme 16 | command: apache2ctl start # start Apache server 17 | 18 | # start MailHog (SMTP testing tool) 19 | - command: mailhog -api-bind-addr 127.0.0.1:8025 -ui-bind-addr 127.0.0.1:8025 -smtp-bind-addr 127.0.0.1:1025 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tax Meta Class 2 | ======================= 3 | Contributors: bainternet 4 | Requires at least: 3.5 5 | Tested up to: 4.0 6 | [![Analytics](https://ga-beacon.appspot.com/UA-50573135-3/tax-meta-class/main)](https://github.com/bainternet/Tax-Meta-Class) 7 | 8 | Description 9 | ----------- 10 | The Tax Meta Class is used by including it in your plugin r theme files and using its methods to 11 | Add meta fields for WordPress Taxonomies (categories,tags and custom taxonomies). It is meant to be very simple and 12 | straightforward. 13 | 14 | This class is derived from My-Meta-Box (https://github.com/bainternet/My-Meta-Box script) which is 15 | a class for creating custom meta boxes for WordPress. 16 | 17 | Usage 18 | -------- 19 | Take a look at the `class-usage-demo.php` file which can also be tested as a WordPress Plugin. 20 | Other options are available for each field which can be see in the 'Tax-meta-class.php' file, 21 | 22 | Changelog 23 | --------- 24 | 2.1.0 25 | Added support for WordPress 4.4 native term meta table 26 | added migration class 27 | 28 | 2.0.2 29 | Fixed jquery ui not loading theme and better jquery ui to WP version handling. 30 | Added a filter hook to change jQuery ui theme `tmc_jquery_ui_theme`. 31 | Better preBind jQuery plgin included. 32 | 33 | 2.0.1 34 | Fixed #93. 35 | 36 | 2.0.0 37 | Too many changes to list :) 38 | major ones are around the image and file fields which no use `url` instead of `src` and allow multiple images/files that are stored in two fields of urls and ids split by a pipe `|`. 39 | 40 | 1.9.9 41 | Fix references for the class for PHP 5.4 compatibility 42 | 43 | 1.9.8 44 | fixed issue #49 45 | 46 | 1.9.7 47 | see issue #44 48 | 49 | 1.9.6 50 | Added WYSIWYG in repater support and most other fields which never worked in the repeate block, now should work. issue #42 51 | 52 | 1.9.5 53 | Fixed Typo in validation call Props @Screenfeed. 54 | 55 | 1.9.4 56 | Added textdomain for l18n #39 57 | 58 | 1.9.3 59 | Fixed issue #38 props to Nicola Peluchetti for finding it and giving my an idea of how to fix it. 60 | 61 | 1.9.2 62 | Pull #36 63 | 64 | 1.9.1 65 | Fixed Upload field issues. 66 | 67 | 1.9.0 68 | Added 'multiple' => false to all field types as defualt. 69 | 70 | = 1.8.9 = 71 | fixed issue #27 (again). 72 | fixed issues #28, #29 , #30. 73 | 74 | 75 | = 1.8.8 = 76 | fixed issue #27. 77 | 78 | = 1.8.7 = 79 | fixed issue #26. 80 | 81 | = 1.8.6 = 82 | fixed issue #25. 83 | 84 | = 1.8.5 = 85 | fixed issue #21. 86 | 87 | = 1.8.4 = 88 | Renamed delete_taxonomy_metadata function to delete term meta on term deletion. pull #20. 89 | 90 | = 1.8.3 = 91 | Cleaned up Media uploader to simplify things. (parisholley)[https://github.com/parisholley] 92 | Change the replacement of "INSERT TO POST" and is now done on client side. 93 | 94 | = 1.8.2 = 95 | Replaced get_stylesheet_directory_uri with get_template_directory_uri to work better with child themes. 96 | Once again thanks to oobi. issue 17 97 | 98 | = 1.8.1 = 99 | added mete deletion on term deletion thanks to oobi 100 | 101 | = 1.8 = 102 | fixed issue 12 103 | fixed issue 13 104 | fixed issue 14 105 | fixed issue 15 106 | changed "insert into post" on media uploader. 107 | 108 | = 1.7.4 = 109 | Fixed bug caused by issue 2 fix. 110 | 111 | = 1.7.3 = 112 | Fixed issue #2. 113 | 114 | = 1.7.2 = 115 | Fixed issue #11. 116 | 117 | = 1.7.1 = 118 | Fixed typo. 119 | 120 | = 1.7 = 121 | Added strip slashes and get_tax_meta_strip function to avoid WordPress's native escape slashes. 122 | 123 | = 1.6 = 124 | Fixed file field issues. 125 | 126 | = 1.5 = 127 | Fixed repeater delete meta bug 128 | 129 | = 1.4 = 130 | updated addPosts in demo 131 | and add_thickbox 132 | 133 | = 1.3 = 134 | Fixed WP debug errors 135 | 136 | = 1.2= 137 | Fixed debug Errors 138 | 139 | = 1.0 = 140 | * First Release 141 | 142 | 143 | -------------------------------------------------------------------------------- /Tax-meta-class/Tax-meta-class.php: -------------------------------------------------------------------------------- 1 | _meta_box = $meta_box; 108 | $this->_prefix = (isset($meta_box['prefix'])) ? $meta_box['prefix'] : ''; 109 | $this->_fields = $this->_meta_box['fields']; 110 | $this->_Local_images = (isset($meta_box['local_images'])) ? true : false; 111 | $this->add_missed_values(); 112 | if (isset($meta_box['use_with_theme'])){ 113 | if ($meta_box['use_with_theme'] === true){ 114 | $this->SelfPath = get_template_directory_uri() . '/Tax-meta-class'; 115 | }elseif($meta_box['use_with_theme'] === false){ 116 | $this->SelfPath = plugins_url( 'Tax-meta-class', plugin_basename( dirname( __FILE__ ) ) ); 117 | }else{ 118 | $this->SelfPath = $meta_box['use_with_theme']; 119 | } 120 | }else{ 121 | $this->SelfPath = plugins_url( 'Tax-meta-class', plugin_basename( dirname( __FILE__ ) ) ); 122 | } 123 | 124 | 125 | // Add Actions 126 | add_action( 'admin_init', array( $this, 'add' ) ); 127 | 128 | // Load common js, css files 129 | // Must enqueue for all pages as we need js for the media upload, too. 130 | add_action( 'admin_print_styles', array( $this, 'load_scripts_styles' ) ); 131 | 132 | //overwrite insert into post button 133 | 134 | //delete term meta on term deletion 135 | add_action('delete_term', array($this,'delete_taxonomy_metadata'), 10,2); 136 | } 137 | 138 | /** 139 | * Load all Javascript and CSS 140 | * 141 | * @since 1.0 142 | * @access public 143 | */ 144 | public function load_scripts_styles() { 145 | 146 | // Get Plugin Path 147 | $plugin_path = $this->SelfPath; 148 | //only load styles and js when needed 149 | /* 150 | * since 1.0 151 | */ 152 | $taxnow = isset($_REQUEST['taxonomy'])? $_REQUEST['taxonomy'] : ''; 153 | if (in_array($taxnow,$this->_meta_box['pages'])){ 154 | // Check for special fields and add needed actions for them. 155 | $this->check_field_upload(); 156 | $this->check_field_color(); 157 | $this->check_field_date(); 158 | $this->check_field_time(); 159 | // Enqueue Meta Box Style 160 | wp_enqueue_style( 'tax-meta-clss', $plugin_path . '/css/Tax-meta-class.css' ); 161 | // Enqueue Meta Box Scripts 162 | wp_enqueue_script( 'tax-meta-clss', $plugin_path . '/js/tax-meta-clss.js', array( 'jquery' ), null, true ); 163 | 164 | } 165 | 166 | } 167 | 168 | /** 169 | * Check the Field Upload, Add needed Actions 170 | * 171 | * @since 1.0 172 | * @access public 173 | */ 174 | public function check_field_upload() { 175 | 176 | // Check if the field is an image or file. If not, return. 177 | if ( ! $this->has_field( 'image' ) && ! $this->has_field( 'file' ) ) 178 | return; 179 | 180 | // Make upload feature work event when custom post type doesn't support 'editor' 181 | wp_enqueue_script( 'jquery-ui-core' ); 182 | wp_enqueue_script( 'jquery-ui-sortable' ); 183 | } 184 | 185 | /** 186 | * Check Field Color 187 | * 188 | * @since 1.0 189 | * @access public 190 | */ 191 | public function check_field_color() { 192 | 193 | if ( $this->has_field( 'color' ) && $this->is_edit_page() ) { 194 | // Enqueu built-in script and style for color picker. 195 | wp_enqueue_style( 'wp-color-picker' ); 196 | wp_enqueue_script( 'wp-color-picker' ); 197 | } 198 | 199 | } 200 | 201 | /** 202 | * Check Field Date 203 | * 204 | * @since 1.0 205 | * @access public 206 | */ 207 | public function check_field_date() { 208 | 209 | if ( $this->has_field( 'date' ) && $this->is_edit_page() ) { 210 | // Enqueu JQuery UI, use proper version. 211 | $this->enqueue_jqueryui(); 212 | } 213 | 214 | } 215 | 216 | /** 217 | * Check Field Time 218 | * 219 | * @since 1.0 220 | * @access public 221 | */ 222 | public function check_field_time() { 223 | 224 | if ( $this->has_field( 'time' ) && $this->is_edit_page() ) { 225 | 226 | // Enqueu JQuery UI, use proper version. 227 | $this->enqueue_jqueryui(); 228 | wp_enqueue_script( 'at-timepicker', '//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/jquery-ui-timepicker-addon.min.js', array( 'tmc-jquery-ui' ),false,true ); 229 | } 230 | } 231 | 232 | /** 233 | * Add Meta Box for multiple post types. 234 | * 235 | * @since 1.0 236 | * @access public 237 | */ 238 | public function add() { 239 | 240 | // Loop through array 241 | foreach ( $this->_meta_box['pages'] as $page ) { 242 | //add fields to edit form 243 | add_action($page.'_edit_form_fields',array( $this, 'show_edit_form' )); 244 | //add fields to add new form 245 | add_action($page.'_add_form_fields',array( $this, 'show_new_form' )); 246 | // this saves the edit fields 247 | add_action( 'edited_'.$page, array( $this, 'save' ), 10, 2); 248 | // this saves the add fields 249 | add_action('created_'.$page,array( $this, 'save' ), 10, 2); 250 | } 251 | // Delete all attachments when delete custom post type. 252 | add_action( 'wp_ajax_at_delete_file', array( $this, 'delete_file' ) ); 253 | add_action( 'wp_ajax_at_reorder_images', array( $this, 'reorder_images' ) ); 254 | // Delete file via Ajax 255 | add_action( 'wp_ajax_at_delete_mupload', array( $this, 'wp_ajax_delete_image' ) ); 256 | 257 | } 258 | 259 | /** 260 | * Callback function to show fields on add new taxonomy term form. 261 | * 262 | * @since 1.0 263 | * @access public 264 | */ 265 | public function show_new_form($term_id){ 266 | $this->_form_type = 'new'; 267 | add_action('admin_footer',array($this,'footer_js')); 268 | $this->show($term_id); 269 | } 270 | 271 | /** 272 | * Callback function to show fields on term edit form. 273 | * 274 | * @since 1.0 275 | * @access public 276 | */ 277 | public function show_edit_form($term_id){ 278 | $this->_form_type = 'edit'; 279 | $this->show($term_id); 280 | } 281 | 282 | 283 | 284 | /** 285 | * Callback function to show fields in meta box. 286 | * 287 | * @since 1.0 288 | * @access public 289 | */ 290 | public function show($term_id) { 291 | $term_id = is_object($term_id)? $term_id->term_id: $term_id; 292 | wp_nonce_field( basename(__FILE__), 'tax_meta_class_nonce' ); 293 | 294 | foreach ( $this->_fields as $field ) { 295 | $multiple = isset($field['multiple'])? $field['multiple'] : false; 296 | $name = $field['id']; 297 | //wordpress 4.4 term meta support 298 | if ( function_exists('get_term_meta')){ 299 | $meta = get_term_meta($term_id, $name, !$multiple ); 300 | }else{ 301 | $meta = $this->get_tax_meta( $term_id, $name, !$multiple ); 302 | } 303 | $meta = ( $meta !== '' ) ? $meta : (isset($field['std'])? $field['std'] : ''); 304 | if ('image' != $field['type'] && $field['type'] != 'repeater') 305 | $meta = is_array( $meta ) ? array_map( 'esc_attr', $meta ) : esc_attr( $meta ); 306 | 307 | echo ''; 308 | // Call Separated methods for displaying each type of field. 309 | call_user_func ( array( $this, 'show_field_' . $field['type'] ), $field, is_array($meta)? $meta : stripslashes($meta) ); 310 | echo ''; 311 | } 312 | echo ''; 313 | } 314 | 315 | /** 316 | * Show Repeater Fields. 317 | * 318 | * @param string $field 319 | * @param string $meta 320 | * @since 1.0 321 | * @access public 322 | */ 323 | public function show_field_repeater( $field, $meta ) { 324 | // Get Plugin Path 325 | $plugin_path = $this->SelfPath; 326 | $this->show_field_begin( $field, $meta ); 327 | echo "
"; 328 | 329 | $c = 0; 330 | 331 | if (count($meta) > 0 && is_array($meta) ){ 332 | foreach ($meta as $me){ 333 | //for labling toggles 334 | $mmm = isset($me[$field['fields'][0]['id']])? $me[$field['fields'][0]['id']]: ""; 335 | echo '
'.$mmm.'
'; 336 | if ($field['inline']){ 337 | echo ''; 338 | } 339 | foreach ($field['fields'] as $f){ 340 | //reset var $id for repeater 341 | $id = ''; 342 | $id = $field['id'].'['.$c.']['.$f['id'].']'; 343 | $m = isset($me[$f['id']])? $me[$f['id']]: ''; 344 | $m = ( $m !== '' ) ? $m : $f['std']; 345 | if ('image' != $f['type'] && $f['type'] != 'repeater') 346 | $m = is_array( $m) ? array_map( 'esc_attr', $m ) : esc_attr( $m); 347 | 348 | //set new id for field in array format 349 | $f['id'] = $id; 350 | if (!$field['inline']){ 351 | echo ''; 352 | } 353 | if ($f['type'] == 'wysiwyg') 354 | call_user_func ( array( $this, 'show_field_' . $f['type'] ), $f, is_array($m)? $m : stripslashes($m),true); 355 | else 356 | call_user_func ( array( $this, 'show_field_' . $f['type'] ), $f, is_array($m)? $m : stripslashes($m)); 357 | 358 | if (!$field['inline']){ 359 | echo ''; 360 | } 361 | } 362 | if ($field['inline']){ 363 | echo ''; 364 | } 365 | echo ' 366 | Edit 373 | '.__('Remove','tax-meta').'
'; 380 | $c = $c + 1; 381 | 382 | } 383 | $this->show_field_end( $field, $meta ); 384 | } 385 | 386 | echo ''.__('Add','tax-meta').'
'; 393 | 394 | //create all fields once more for js function and catch with object buffer 395 | ob_start(); 396 | echo '
'; 397 | if ($field['inline']){ 398 | echo ''; 399 | } 400 | foreach ($field['fields'] as $f){ 401 | //reset var $id for repeater 402 | $id = ''; 403 | $id = $field['id'].'[CurrentCounter]['.$f['id'].']'; 404 | $f['id'] = $id; 405 | if (!$field['inline']){ 406 | echo ''; 407 | } 408 | if ($f['type'] == 'wysiwyg') 409 | call_user_func ( array( $this, 'show_field_' . $f['type'] ), $f, '',true); 410 | else 411 | call_user_func ( array( $this, 'show_field_' . $f['type'] ), $f, ''); 412 | 413 | if (!$field['inline']){ 414 | echo ''; 415 | } 416 | } 417 | if ($field['inline']){ 418 | echo ''; 419 | } 420 | echo '
'.__('Remove','tax-meta').'
'; 427 | $counter = 'countadd_'.$field['id']; 428 | $js_code = ob_get_clean (); 429 | $js_code = str_replace("\n","",$js_code); 430 | $js_code = str_replace("\r","",$js_code); 431 | $js_code = str_replace("'","\"",$js_code); 432 | $js_code = str_replace("CurrentCounter","' + ".$counter." + '",$js_code); 433 | echo ''; 446 | echo '
'; 454 | $this->show_field_end($field, $meta); 455 | } 456 | 457 | /** 458 | * Begin Field. 459 | * 460 | * @param string $field 461 | * @param string $meta 462 | * @since 1.0 463 | * @access public 464 | */ 465 | public function show_field_begin( $field, $meta) { 466 | if (isset($field['group'])){ 467 | if ($field['group'] == "start"){ 468 | echo ""; 469 | } 470 | }else{ 471 | if ($this->_form_type == 'edit'){ 472 | echo ''; 473 | }else{ 474 | echo '
'; 475 | } 476 | } 477 | if ( $field['name'] != '' || $field['name'] != FALSE ) { 478 | //echo "
"; 479 | echo ""; 480 | //echo "
"; 481 | } 482 | if ($this->_form_type == 'edit'){ 483 | echo ''; 484 | } 485 | } 486 | 487 | /** 488 | * End Field. 489 | * 490 | * @param string $field 491 | * @param string $meta 492 | * @since 1.0 493 | * @access public 494 | */ 495 | public function show_field_end( $field, $meta=NULL ,$group = false) { 496 | if (isset($field['group'])){ 497 | if ($group == 'end'){ 498 | if ( isset($field['desc']) && $field['desc'] != '' ) { 499 | echo "

{$field['desc']}

"; 500 | } else { 501 | echo ""; 502 | } 503 | }else { 504 | if ( isset($field['desc']) && $field['desc'] != '' ) { 505 | echo "

{$field['desc']}


"; 506 | }else{ 507 | echo '
'; 508 | } 509 | } 510 | }else{ 511 | if ( isset($field['desc']) && $field['desc'] != '' ) { 512 | echo "

{$field['desc']}

"; 513 | } 514 | if ($this->_form_type == 'edit'){ 515 | echo ''; 516 | }else{ 517 | echo '
'; 518 | } 519 | } 520 | } 521 | 522 | /** 523 | * Show Field Text. 524 | * 525 | * @param string $field 526 | * @param string $meta 527 | * @since 1.0 528 | * @access public 529 | */ 530 | public function show_field_text( $field, $meta) { 531 | $this->show_field_begin( $field, $meta ); 532 | echo ""; 533 | $this->show_field_end( $field, $meta ); 534 | } 535 | 536 | /** 537 | * Show Field hidden. 538 | * 539 | * @param string $field 540 | * @param string|mixed $meta 541 | * @since 0.1.3 542 | * @access public 543 | */ 544 | public function show_field_hidden( $field, $meta) { 545 | //$this->show_field_begin( $field, $meta ); 546 | echo ""; 547 | //$this->show_field_end( $field, $meta ); 548 | } 549 | 550 | /** 551 | * Show Field Paragraph. 552 | * 553 | * @param string $field 554 | * @since 0.1.3 555 | * @access public 556 | */ 557 | public function show_field_paragraph( $field) { 558 | //$this->show_field_begin( $field, $meta ); 559 | echo "

".$field['value']."

"; 560 | //$this->show_field_end( $field, $meta ); 561 | } 562 | 563 | /** 564 | * Show Field Textarea. 565 | * 566 | * @param string $field 567 | * @param string $meta 568 | * @since 1.0 569 | * @access public 570 | */ 571 | public function show_field_textarea( $field, $meta ) { 572 | $this->show_field_begin( $field, $meta ); 573 | echo ""; 574 | $this->show_field_end( $field, $meta ); 575 | } 576 | 577 | /** 578 | * Show Field Select. 579 | * 580 | * @param string $field 581 | * @param string $meta 582 | * @since 1.0 583 | * @access public 584 | */ 585 | public function show_field_select( $field, $meta ) { 586 | 587 | if ( ! is_array( $meta ) ) 588 | $meta = (array) $meta; 589 | 590 | $this->show_field_begin( $field, $meta ); 591 | echo ""; 596 | $this->show_field_end( $field, $meta ); 597 | 598 | } 599 | 600 | /** 601 | * Show Radio Field. 602 | * 603 | * @param string $field 604 | * @param string $meta 605 | * @since 1.0 606 | * @access public 607 | */ 608 | public function show_field_radio( $field, $meta ) { 609 | 610 | if ( ! is_array( $meta ) ) 611 | $meta = (array) $meta; 612 | 613 | $this->show_field_begin( $field, $meta ); 614 | foreach ( $field['options'] as $key => $value ) { 615 | echo " {$value}"; 616 | } 617 | $this->show_field_end( $field, $meta ); 618 | } 619 | 620 | /** 621 | * Show Checkbox Field. 622 | * 623 | * @param string $field 624 | * @param string $meta 625 | * @since 1.0 626 | * @access public 627 | */ 628 | public function show_field_checkbox( $field, $meta ) { 629 | 630 | $this->show_field_begin($field, $meta); 631 | echo ""; 632 | $this->show_field_end( $field, $meta ); 633 | } 634 | 635 | /** 636 | * Show Wysiwig Field. 637 | * 638 | * @param string $field 639 | * @param string $meta 640 | * @since 1.0 641 | * @access public 642 | */ 643 | public function show_field_wysiwyg( $field, $meta ,$in_repeater = false) { 644 | $this->show_field_begin( $field, $meta ); 645 | // Add TinyMCE script for WP version < 3.3 646 | global $wp_version; 647 | 648 | if ( version_compare( $wp_version, '3.2.1' ) < 1 || $in_repeater) { 649 | echo ""; 650 | }else{ 651 | // Use new wp_editor() since WP 3.3 652 | wp_editor( stripslashes(html_entity_decode($meta)), $field['id'], array( 'editor_class' => 'at-wysiwyg' ) ); 653 | } 654 | $this->show_field_end( $field, $meta ); 655 | } 656 | 657 | /** 658 | * Show File Field. 659 | * 660 | * @param string $field 661 | * @param string $meta 662 | * @since 1.0 663 | * @access public 664 | */ 665 | public function show_field_file( $field, $meta ) { 666 | $this->show_field_begin( $field, $meta ); 667 | wp_enqueue_script('jquery-ui-sortable'); 668 | wp_enqueue_media(); 669 | $std = isset($field['std'])? $field['std'] : array('id' => '', 'url' => ''); 670 | $multiple = isset($field['multiple'])? $field['multiple'] : false; 671 | $multiple = ($multiple)? "multiFile '" : ""; 672 | $name = esc_attr( $field['id'] ); 673 | $value = isset($meta['id']) ? $meta : $std; 674 | $has_file = (empty($value['url']))? false : true; 675 | $type = isset($field['mime_type'])? $field['mime_type'] : ''; 676 | $ext = isset($field['ext'])? $field['ext'] : ''; 677 | $type = (is_array($type)? implode("|",$type) : $type); 678 | $ext = (is_array($ext)? implode("|",$ext) : $ext); 679 | $id = $field['id']; 680 | $li = ($has_file)? "
  • {$value['url']}
  • ": ""; 681 | 682 | echo ""; 683 | echo ""; 684 | echo ""; 685 | if ($has_file) 686 | echo ""; 687 | else 688 | echo ""; 689 | $this->show_field_end( $field, $meta ); 690 | } 691 | 692 | /** 693 | * Show Image Field. 694 | * 695 | * @param array $field 696 | * @param array $meta 697 | * @since 1.0 698 | * @access public 699 | */ 700 | public function show_field_image( $field, $meta ) { 701 | $this->show_field_begin( $field, $meta ); 702 | wp_enqueue_script('jquery-ui-sortable'); 703 | wp_enqueue_media(); 704 | $std = isset($field['std'])? $field['std'] : array('id' => '', 'url' => ''); 705 | $name = esc_attr( $field['id'] ); 706 | $value = isset($meta['id']) ? $meta : $std; 707 | //backwords capability 708 | if (!isset($value['url'])) 709 | $value['url'] = ''; 710 | if (!isset($value['id'])) 711 | $value['id'] = ''; 712 | $value['url'] = isset($value['src'])? $value['src']: $value['url']; 713 | $has_image = empty($value['url'])? false : true; 714 | $w = isset($field['width'])? $field['width'] : 'auto'; 715 | $h = isset($field['height'])? $field['height'] : 'auto'; 716 | $PreviewStyle = "style='width: $w; height: $h;". ( (!$has_image)? "display: none;'": "'"); 717 | $id = $field['id']; 718 | $multiple = isset($field['multiple'])? $field['multiple'] : false; 719 | $multiple = ($multiple)? "multiFile " : ""; 720 | 721 | echo "
    "; 722 | echo ""; 723 | echo ""; 724 | if ($has_image) 725 | echo ""; 726 | else 727 | echo ""; 728 | $this->show_field_end( $field, $meta ); 729 | } 730 | 731 | /** 732 | * Show Color Field. 733 | * 734 | * @param string $field 735 | * @param string $meta 736 | * @since 1.0 737 | * @access public 738 | */ 739 | public function show_field_color( $field, $meta ) { 740 | 741 | if ( empty( $meta ) ) 742 | $meta = '#'; 743 | 744 | $this->show_field_begin( $field, $meta ); 745 | echo ''; 746 | $this->show_field_end($field, $meta); 747 | 748 | } 749 | 750 | /** 751 | * Show Checkbox List Field 752 | * 753 | * @param string $field 754 | * @param string $meta 755 | * @since 1.0 756 | * @access public 757 | */ 758 | public function show_field_checkbox_list( $field, $meta ) { 759 | 760 | if ( ! is_array( $meta ) ) 761 | $meta = (array) $meta; 762 | 763 | $this->show_field_begin($field, $meta); 764 | 765 | $html = array(); 766 | 767 | foreach ($field['options'] as $key => $value) { 768 | $html[] = " {$value}"; 769 | } 770 | 771 | echo implode( '
    ' , $html ); 772 | 773 | $this->show_field_end($field, $meta); 774 | 775 | } 776 | 777 | /** 778 | * Show Date Field. 779 | * 780 | * @param string $field 781 | * @param string $meta 782 | * @since 1.0 783 | * @access public 784 | */ 785 | public function show_field_date( $field, $meta ) { 786 | $this->show_field_begin( $field, $meta ); 787 | echo ""; 788 | $this->show_field_end( $field, $meta ); 789 | } 790 | 791 | /** 792 | * Show time field. 793 | * 794 | * @param string $field 795 | * @param string $meta 796 | * @since 1.0 797 | * @access public 798 | */ 799 | public function show_field_time( $field, $meta ) { 800 | $this->show_field_begin( $field, $meta ); 801 | echo ""; 802 | $this->show_field_end( $field, $meta ); 803 | } 804 | 805 | /** 806 | * Show Posts field. 807 | * used creating a posts/pages/custom types checkboxlist or a select dropdown 808 | * @param string $field 809 | * @param string $meta 810 | * @since 1.0 811 | * @access public 812 | */ 813 | public function show_field_posts($field, $meta) { 814 | global $post; 815 | 816 | if (!is_array($meta)) $meta = (array) $meta; 817 | $this->show_field_begin($field, $meta); 818 | $options = $field['options']; 819 | $posts = get_posts($options['args']); 820 | 821 | // checkbox_list 822 | if ('checkbox_list' == $options['type']) { 823 | foreach ($posts as $p) { 824 | echo "ID, $meta), true, false) . " /> $p->post_title
    "; 825 | } 826 | } 827 | // select 828 | else { 829 | echo ""; 834 | } 835 | 836 | $this->show_field_end($field, $meta); 837 | } 838 | 839 | /** 840 | * Show Taxonomy field. 841 | * used creating a category/tags/custom taxonomy checkboxlist or a select dropdown 842 | * @param string $field 843 | * @param string $meta 844 | * @since 1.0 845 | * @access public 846 | * 847 | * @uses get_terms() 848 | */ 849 | public function show_field_taxonomy($field, $meta) { 850 | global $post; 851 | 852 | if (!is_array($meta)) $meta = (array) $meta; 853 | $this->show_field_begin($field, $meta); 854 | $options = $field['options']; 855 | $terms = get_terms($options['taxonomy'], $options['args']); 856 | 857 | // checkbox_list 858 | if ('checkbox_list' == $options['type']) { 859 | foreach ($terms as $term) { 860 | echo "slug, $meta), true, false) . " /> $term->name
    "; 861 | } 862 | } 863 | // select 864 | else { 865 | echo ""; 870 | } 871 | 872 | $this->show_field_end($field, $meta); 873 | } 874 | 875 | /** 876 | * Save Data from Metabox 877 | * 878 | * @param string $term_id 879 | * @since 1.0 880 | * @access public 881 | */ 882 | public function save( $term_id ) { 883 | 884 | // check if the we are coming from quick edit issue #38 props to Nicola Peluchetti. 885 | if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save-tax') { 886 | return $term_id; 887 | } 888 | 889 | if ( ! isset( $term_id ) // Check Revision 890 | || ( ! isset( $_POST['taxonomy'] ) ) // Check if current taxonomy type is set. 891 | || ( ! in_array( $_POST['taxonomy'], $this->_meta_box['pages'] ) ) // Check if current taxonomy type is supported. 892 | || ( ! check_admin_referer( basename( __FILE__ ), 'tax_meta_class_nonce') ) // Check nonce - Security 893 | || ( ! current_user_can('manage_categories') ) ) // Check permission 894 | { 895 | return $term_id; 896 | } 897 | 898 | foreach ( $this->_fields as $field ) { 899 | 900 | $name = $field['id']; 901 | $type = $field['type']; 902 | $multiple = isset($field['multiple'])? $field['multiple']: false; 903 | //wordpress 4.4 term meta support 904 | if ( function_exists('get_term_meta')){ 905 | $old = get_term_meta($term_id, $name, !$multiple ); 906 | }else{ 907 | $old = $this->get_tax_meta( $term_id, $name, !$multiple ); 908 | } 909 | $new = ( isset( $_POST[$name] ) ) ? $_POST[$name] : ( ( $multiple ) ? array() : '' ); 910 | 911 | 912 | // Validate meta value 913 | if ( class_exists( 'Tax_Meta_Validate' ) && method_exists( 'Tax_Meta_Validate', $field['validate_func'] ) ) { 914 | $new = call_user_func( array( 'Tax_Meta_Validate', $field['validate_func'] ), $new ); 915 | } 916 | 917 | //skip on Paragraph field 918 | if ($type != "paragraph"){ 919 | 920 | // Call defined method to save meta value, if there's no methods, call common one. 921 | $save_func = 'save_field_' . $type; 922 | if ( method_exists( $this, $save_func ) ) { 923 | call_user_func( array( $this, 'save_field_' . $type ), $term_id, $field, $old, $new ); 924 | } else { 925 | $this->save_field( $term_id, $field, $old, $new ); 926 | } 927 | } 928 | 929 | } // End foreach 930 | } 931 | 932 | /** 933 | * Common function for saving fields. 934 | * 935 | * @param string $term_id 936 | * @param string $field 937 | * @param string $old 938 | * @param string|mixed $new 939 | * @since 1.0 940 | * @access public 941 | */ 942 | public function save_field( $term_id, $field, $old, $new ) { 943 | $name = $field['id']; 944 | //wordpress 4.4 term meta support 945 | if ( function_exists('get_term_meta')){ 946 | delete_term_meta($term_id, $name); 947 | }else{ 948 | $this->delete_tax_meta( $term_id, $name ); 949 | } 950 | if ( $new === '' || $new === array() ) 951 | return; 952 | 953 | if ( function_exists('update_term_meta')){ 954 | update_term_meta( $term_id, $name, $new ); 955 | }else{ 956 | $this->update_tax_meta( $term_id, $name, $new ); 957 | } 958 | } 959 | 960 | /** 961 | * function for saving image field. 962 | * 963 | * @param string $term_id 964 | * @param string $field 965 | * @param string $old 966 | * @param string|mixed $new 967 | * @since 1.0 968 | * @access public 969 | */ 970 | public function save_field_image( $term_id, $field, $old, $new ) { 971 | $name = $field['id']; 972 | if ( function_exists('delete_term_meta')){ 973 | delete_term_meta($term_id, $name); 974 | }else{ 975 | $this->delete_tax_meta( $term_id, $name ); 976 | } 977 | 978 | if ( $new === '' || $new === array() || $new['id'] == '' || $new['url'] == '') 979 | return; 980 | 981 | if ( function_exists('update_term_meta')){ 982 | update_term_meta( $term_id, $name, $new ); 983 | }else{ 984 | $this->update_tax_meta( $term_id, $name, $new ); 985 | } 986 | } 987 | 988 | /* 989 | * Save Wysiwyg Field. 990 | * 991 | * @param string $term_id 992 | * @param string $field 993 | * @param string $old 994 | * @param string $new 995 | * @since 1.0 996 | * @access public 997 | */ 998 | public function save_field_wysiwyg( $term_id, $field, $old, $new ) { 999 | $this->save_field( $term_id, $field, $old, $new ); 1000 | } 1001 | 1002 | /** 1003 | * Save repeater Fields. 1004 | * 1005 | * @param string $term_id 1006 | * @param string $field 1007 | * @param string|mixed $old 1008 | * @param string|mixed $new 1009 | * @since 1.0 1010 | * @access public 1011 | */ 1012 | public function save_field_repeater( $term_id, $field, $old, $new ) { 1013 | if (is_array($new) && count($new) > 0){ 1014 | foreach ($new as $n){ 1015 | foreach ( $field['fields'] as $f ) { 1016 | $type = $f['type']; 1017 | switch($type) { 1018 | case 'wysiwyg': 1019 | $n[$f['id']] = wpautop( $n[$f['id']] ); 1020 | break; 1021 | case 'file': 1022 | $n[$f['id']] = $this->save_field_file_repeater($term_id,$f,'',$n[$f['id']]); 1023 | break; 1024 | default: 1025 | break; 1026 | } 1027 | } 1028 | if(!$this->is_array_empty($n)) 1029 | $temp[] = $n; 1030 | } 1031 | if (isset($temp) && count($temp) > 0 && !$this->is_array_empty($temp)){ 1032 | if ( function_exists('update_term_meta')){ 1033 | update_term_meta( $term_id,$field['id'],$temp ); 1034 | }else{ 1035 | $this->update_tax_meta( $term_id,$field['id'],$temp ); 1036 | } 1037 | }else{ 1038 | // remove old meta if exists 1039 | if ( function_exists('delete_term_meta')){ 1040 | delete_term_meta($term_id, $field['id']); 1041 | }else{ 1042 | $this->delete_tax_meta($term_id,$field['id']); 1043 | } 1044 | } 1045 | }else{ 1046 | // remove old meta if exists 1047 | if ( function_exists('delete_term_meta')){ 1048 | delete_term_meta($term_id, $field['id']); 1049 | }else{ 1050 | $this->delete_tax_meta($term_id,$field['id']); 1051 | } 1052 | } 1053 | } 1054 | 1055 | /** 1056 | * Save File Field. 1057 | * 1058 | * @param string $term_id 1059 | * @param string $field 1060 | * @param string $old 1061 | * @param string $new 1062 | * @since 1.0 1063 | * @access public 1064 | */ 1065 | public function save_field_file( $term_id, $field, $old, $new ) { 1066 | 1067 | $name = $field['id']; 1068 | if ( function_exists('delete_term_meta')){ 1069 | delete_term_meta($term_id, $name); 1070 | }else{ 1071 | $this->delete_tax_meta($term_id,$name); 1072 | } 1073 | if ( $new === '' || $new === array() || $new['id'] == '' || $new['url'] == '') 1074 | return; 1075 | 1076 | if ( function_exists('update_term_meta')){ 1077 | update_term_meta( $term_id, $name, $new); 1078 | }else{ 1079 | $this->update_tax_meta( $term_id, $name, $new ); 1080 | } 1081 | } 1082 | 1083 | 1084 | /** 1085 | * Add missed values for meta box. 1086 | * 1087 | * @since 1.0 1088 | * @access public 1089 | */ 1090 | public function add_missed_values() { 1091 | 1092 | // Default values for meta box 1093 | $this->_meta_box = array_merge( array( 'context' => 'normal', 'priority' => 'high', 'pages' => array( 'post' ) ),(array)$this->_meta_box ); 1094 | 1095 | // Default values for fields 1096 | foreach ( (array)$this->_fields as $field ) { 1097 | 1098 | $multiple = in_array( $field['type'], array( 'checkbox_list', 'file', 'image' ) ); 1099 | $std = $multiple ? array() : ''; 1100 | $format = 'date' == $field['type'] ? 'yy-mm-dd' : ( 'time' == $field['type'] ? 'hh:mm' : '' ); 1101 | 1102 | $field = array_merge( array( 'multiple' => $multiple, 'std' => $std, 'desc' => '', 'format' => $format, 'validate_func' => '' ), $field ); 1103 | 1104 | } // End foreach 1105 | 1106 | } 1107 | 1108 | /** 1109 | * Check if field with $type exists. 1110 | * 1111 | * @param string $type 1112 | * @since 1.0 1113 | * @access public 1114 | */ 1115 | public function has_field( $type ) { 1116 | foreach ( $this->_fields as $field ) { 1117 | if ( $type == $field['type'] ) 1118 | return true; 1119 | elseif('repeater' == $field['type'] ){ 1120 | foreach((array)$field["fields"] as $repeater_field) { 1121 | if($type == $repeater_field["type"]) return true; 1122 | } 1123 | } 1124 | } 1125 | return false; 1126 | } 1127 | 1128 | /** 1129 | * Check if current page is edit page. 1130 | * 1131 | * @since 1.0 1132 | * @access public 1133 | */ 1134 | public function is_edit_page() { 1135 | global $pagenow; 1136 | return ( $pagenow == 'edit-tags.php' ); 1137 | } 1138 | 1139 | /** 1140 | * Fixes the odd indexing of multiple file uploads. 1141 | * 1142 | * Goes from the format: 1143 | * $_FILES['field']['key']['index'] 1144 | * to 1145 | * The More standard and appropriate: 1146 | * $_FILES['field']['index']['key'] 1147 | * 1148 | * @param string $files 1149 | * @since 1.0 1150 | * @access public 1151 | */ 1152 | public function fix_file_array( &$files ) { 1153 | 1154 | $output = array(); 1155 | 1156 | foreach ( $files as $key => $list ) { 1157 | foreach ( $list as $index => $value ) { 1158 | $output[$index][$key] = $value; 1159 | } 1160 | } 1161 | 1162 | return $files = $output; 1163 | 1164 | } 1165 | 1166 | /** 1167 | * Get proper JQuery UI version. 1168 | * 1169 | * Used in order to not conflict with WP Admin Scripts. 1170 | * 1171 | * @since 1.0 1172 | * @access public 1173 | */ 1174 | public function get_jqueryui_ver() { 1175 | 1176 | global $wp_version; 1177 | 1178 | if ( version_compare( $wp_version, '4.0', '>=') ) { 1179 | return '1.11.2'; 1180 | } 1181 | if ( version_compare( $wp_version, '3.9', '>=') ) { 1182 | return '1.10.4'; 1183 | } 1184 | if ( version_compare( $wp_version, '3.8', '>=') ) { 1185 | return '1.10.3'; 1186 | } 1187 | if ( version_compare( $wp_version, '3.5', '>=') ) { 1188 | return '1.9.2'; 1189 | } 1190 | if ( version_compare( $wp_version, '3.1', '>=') ) { 1191 | return '1.8.10'; 1192 | } 1193 | 1194 | return '1.7.3'; 1195 | } 1196 | 1197 | /** 1198 | * Enqueue JQuery UI version. 1199 | * 1200 | * @since 2.0.2 1201 | * @access public 1202 | */ 1203 | public function enqueue_jqueryui(){ 1204 | wp_enqueue_style( 'tmc-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/'.apply_filters('tmc_jquery_ui_theme','smoothness').'/jquery-ui.css' ); 1205 | wp_enqueue_script( 'tmc-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array( 'jquery' ) ); 1206 | } 1207 | 1208 | /** 1209 | * Add Field to meta box (generic function) 1210 | * @author Ohad Raz 1211 | * @since 1.0 1212 | * @access public 1213 | * @param $id string field id, i.e. the meta key 1214 | * @param $args mixed|array 1215 | */ 1216 | public function addField($id,$args){ 1217 | $new_field = array('id'=> $id,'std' => '','desc' => '','style' =>'','multiple' => false); 1218 | $new_field = array_merge($new_field, $args); 1219 | $this->_fields[] = $new_field; 1220 | } 1221 | 1222 | /** 1223 | * Add Text Field to meta box 1224 | * @author Ohad Raz 1225 | * @since 1.0 1226 | * @access public 1227 | * @param $id string field id, i.e. the meta key 1228 | * @param $args mixed|array 1229 | * 'name' => // field name/label string optional 1230 | * 'desc' => // field description, string optional 1231 | * 'std' => // default value, string optional 1232 | * 'style' => // custom style for field, string optional 1233 | * 'validate_func' => // validate function, string optional 1234 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1235 | */ 1236 | public function addText($id,$args,$repeater=false){ 1237 | $new_field = array('type' => 'text','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Text Field','multiple' => false); 1238 | $new_field = array_merge($new_field, $args); 1239 | if(false === $repeater){ 1240 | $this->_fields[] = $new_field; 1241 | }else{ 1242 | return $new_field; 1243 | } 1244 | } 1245 | /** 1246 | * Add Hidden Field to meta box 1247 | * @author Ohad Raz 1248 | * @since 0.1.3 1249 | * @access public 1250 | * @param $id string field id, i.e. the meta key 1251 | * @param $args mixed|array 1252 | * 'name' => // field name/label string optional 1253 | * 'desc' => // field description, string optional 1254 | * 'std' => // default value, string optional 1255 | * 'style' => // custom style for field, string optional 1256 | * 'validate_func' => // validate function, string optional 1257 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1258 | */ 1259 | public function addHidden($id,$args,$repeater=false){ 1260 | $new_field = array('type' => 'hidden','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Text Field', 'multiple' => false); 1261 | $new_field = array_merge($new_field, $args); 1262 | if(false === $repeater){ 1263 | $this->_fields[] = $new_field; 1264 | }else{ 1265 | return $new_field; 1266 | } 1267 | } 1268 | 1269 | /** 1270 | * Add Paragraph to meta box 1271 | * @author Ohad Raz 1272 | * @since 0.1.3 1273 | * @access public 1274 | * @param $id string field id, i.e. the meta key 1275 | * @param $value paragraph html 1276 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1277 | */ 1278 | public function addParagraph($id,$args,$repeater=false){ 1279 | $new_field = array('type' => 'paragraph','id'=> $id,'value' => '','style' =>'', 'std' => '', 'multiple' => false); 1280 | $new_field = array_merge($new_field, $args); 1281 | if(false === $repeater){ 1282 | $this->_fields[] = $new_field; 1283 | }else{ 1284 | return $new_field; 1285 | } 1286 | } 1287 | 1288 | /** 1289 | * Add Checkbox Field to meta box 1290 | * @author Ohad Raz 1291 | * @since 1.0 1292 | * @access public 1293 | * @param $id string field id, i.e. the meta key 1294 | * @param $args mixed|array 1295 | * 'name' => // field name/label string optional 1296 | * 'desc' => // field description, string optional 1297 | * 'std' => // default value, string optional 1298 | * 'validate_func' => // validate function, string optional 1299 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1300 | */ 1301 | public function addCheckbox($id,$args,$repeater=false){ 1302 | $new_field = array('type' => 'checkbox','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Checkbox Field','multiple' => false); 1303 | $new_field = array_merge($new_field, $args); 1304 | if(false === $repeater){ 1305 | $this->_fields[] = $new_field; 1306 | }else{ 1307 | return $new_field; 1308 | } 1309 | } 1310 | 1311 | /** 1312 | * Add CheckboxList Field to meta box 1313 | * @author Ohad Raz 1314 | * @since 1.0 1315 | * @access public 1316 | * @param $id string field id, i.e. the meta key 1317 | * @param $options (array) array of key => value pairs for select options 1318 | * @param $args mixed|array 1319 | * 'name' => // field name/label string optional 1320 | * 'desc' => // field description, string optional 1321 | * 'std' => // default value, string optional 1322 | * 'validate_func' => // validate function, string optional 1323 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1324 | * 1325 | * @return : remember to call: $checkbox_list = $this->get_tax_meta(get_the_ID(), 'meta_name', false); 1326 | * which means the last param as false to get the values in an array 1327 | */ 1328 | public function addCheckboxList($id,$options,$args,$repeater=false){ 1329 | $new_field = array('type' => 'checkbox_list','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Checkbox List Field', 'multiple' => false); 1330 | $new_field = array_merge($new_field, $args); 1331 | if(false === $repeater){ 1332 | $this->_fields[] = $new_field; 1333 | }else{ 1334 | return $new_field; 1335 | } 1336 | } 1337 | 1338 | /** 1339 | * Add Textarea Field to meta box 1340 | * @author Ohad Raz 1341 | * @since 1.0 1342 | * @access public 1343 | * @param $id string field id, i.e. the meta key 1344 | * @param $args mixed|array 1345 | * 'name' => // field name/label string optional 1346 | * 'desc' => // field description, string optional 1347 | * 'std' => // default value, string optional 1348 | * 'style' => // custom style for field, string optional 1349 | * 'validate_func' => // validate function, string optional 1350 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1351 | */ 1352 | public function addTextarea($id,$args,$repeater=false){ 1353 | $new_field = array('type' => 'textarea','id'=> $id,'std' => '','desc' => '','style' =>'','name' => 'Textarea Field','multiple' => false); 1354 | $new_field = array_merge($new_field, $args); 1355 | if(false === $repeater){ 1356 | $this->_fields[] = $new_field; 1357 | }else{ 1358 | return $new_field; 1359 | } 1360 | } 1361 | 1362 | /** 1363 | * Add Select Field to meta box 1364 | * @author Ohad Raz 1365 | * @since 1.0 1366 | * @access public 1367 | * @param $id string field id, i.e. the meta key 1368 | * @param $options (array) array of key => value pairs for select options 1369 | * @param $args mixed|array 1370 | * 'name' => // field name/label string optional 1371 | * 'desc' => // field description, string optional 1372 | * 'std' => // default value, (array) optional 1373 | * 'multiple' => // select multiple values, optional. Default is false. 1374 | * 'validate_func' => // validate function, string optional 1375 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1376 | */ 1377 | public function addSelect($id,$options,$args,$repeater=false){ 1378 | $new_field = array('type' => 'select','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Select Field','multiple' => false,'options' => $options); 1379 | $new_field = array_merge($new_field, $args); 1380 | if(false === $repeater){ 1381 | $this->_fields[] = $new_field; 1382 | }else{ 1383 | return $new_field; 1384 | } 1385 | } 1386 | 1387 | 1388 | /** 1389 | * Add Radio Field to meta box 1390 | * @author Ohad Raz 1391 | * @since 1.0 1392 | * @access public 1393 | * @param $id string field id, i.e. the meta key 1394 | * @param $options (array) array of key => value pairs for radio options 1395 | * @param $args mixed|array 1396 | * 'name' => // field name/label string optional 1397 | * 'desc' => // field description, string optional 1398 | * 'std' => // default value, string optional 1399 | * 'validate_func' => // validate function, string optional 1400 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1401 | */ 1402 | public function addRadio($id,$options,$args,$repeater=false){ 1403 | $new_field = array('type' => 'radio','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Radio Field','options' => $options,'multiple' => false); 1404 | $new_field = array_merge($new_field, $args); 1405 | if(false === $repeater){ 1406 | $this->_fields[] = $new_field; 1407 | }else{ 1408 | return $new_field; 1409 | } 1410 | } 1411 | 1412 | /** 1413 | * Add Date Field to meta box 1414 | * @author Ohad Raz 1415 | * @since 1.0 1416 | * @access public 1417 | * @param $id string field id, i.e. the meta key 1418 | * @param $args mixed|array 1419 | * 'name' => // field name/label string optional 1420 | * 'desc' => // field description, string optional 1421 | * 'std' => // default value, string optional 1422 | * 'validate_func' => // validate function, string optional 1423 | * 'format' => // date format, default yy-mm-dd. Optional. Default "'d MM, yy'" See more formats here: http://goo.gl/Wcwxn 1424 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1425 | */ 1426 | public function addDate($id,$args,$repeater=false){ 1427 | $new_field = array('type' => 'date','id'=> $id,'style' =>'','std' => '','desc' => '','format'=>'d MM, yy','name' => 'Date Field','multiple' => false); 1428 | $new_field = array_merge($new_field, $args); 1429 | if(false === $repeater){ 1430 | $this->_fields[] = $new_field; 1431 | }else{ 1432 | return $new_field; 1433 | } 1434 | } 1435 | 1436 | /** 1437 | * Add Time Field to meta box 1438 | * @author Ohad Raz 1439 | * @since 1.0 1440 | * @access public 1441 | * @param $id string- field id, i.e. the meta key 1442 | * @param $args mixed|array 1443 | * 'name' => // field name/label string optional 1444 | * 'desc' => // field description, string optional 1445 | * 'std' => // default value, string optional 1446 | * 'validate_func' => // validate function, string optional 1447 | * 'format' => // time format, default hh:mm. Optional. See more formats here: http://goo.gl/83woX 1448 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1449 | */ 1450 | public function addTime($id,$args,$repeater=false){ 1451 | $new_field = array('type' => 'time','id'=> $id,'std' => '','style' =>'','desc' => '','format'=>'hh:mm','name' => 'Time Field','multiple' => false); 1452 | $new_field = array_merge($new_field, $args); 1453 | if(false === $repeater){ 1454 | $this->_fields[] = $new_field; 1455 | }else{ 1456 | return $new_field; 1457 | } 1458 | } 1459 | 1460 | /** 1461 | * Add Color Field to meta box 1462 | * @author Ohad Raz 1463 | * @since 1.0 1464 | * @access public 1465 | * @param $id string field id, i.e. the meta key 1466 | * @param $args mixed|array 1467 | * 'name' => // field name/label string optional 1468 | * 'desc' => // field description, string optional 1469 | * 'std' => // default value, string optional 1470 | * 'validate_func' => // validate function, string optional 1471 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1472 | */ 1473 | public function addColor($id,$args,$repeater=false){ 1474 | $new_field = array('type' => 'color','id'=> $id,'std' => '','style' =>'','desc' => '','name' => 'ColorPicker Field','multiple' => false); 1475 | $new_field = array_merge($new_field, $args); 1476 | if(false === $repeater){ 1477 | $this->_fields[] = $new_field; 1478 | }else{ 1479 | return $new_field; 1480 | } 1481 | } 1482 | 1483 | /** 1484 | * Add Image Field to meta box 1485 | * @author Ohad Raz 1486 | * @since 1.0 1487 | * @access public 1488 | * @param $id string field id, i.e. the meta key 1489 | * @param $args mixed|array 1490 | * 'name' => // field name/label string optional 1491 | * 'desc' => // field description, string optional 1492 | * 'validate_func' => // validate function, string optional 1493 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1494 | */ 1495 | public function addImage($id,$args,$repeater=false){ 1496 | $new_field = array('type' => 'image','id'=> $id,'desc' => '','style' =>'','name' => 'Image Field', 'std' => '','multiple' => false); 1497 | $new_field = array_merge($new_field, $args); 1498 | if(false === $repeater){ 1499 | $this->_fields[] = $new_field; 1500 | }else{ 1501 | return $new_field; 1502 | } 1503 | } 1504 | 1505 | /** 1506 | * Add File Field to meta box 1507 | * @author Ohad Raz 1508 | * @since 1.0 1509 | * @access public 1510 | * @param $id string field id, i.e. the meta key 1511 | * @param $args mixed|array 1512 | * 'name' => // field name/label string optional 1513 | * 'desc' => // field description, string optional 1514 | * 'validate_func' => // validate function, string optional 1515 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1516 | */ 1517 | public function addFile($id,$args,$repeater=false){ 1518 | $new_field = array('type' => 'file','id'=> $id,'desc' => '','name' => 'File Field','multiple' => false); 1519 | $new_field = array_merge($new_field, $args); 1520 | if(false === $repeater){ 1521 | $this->_fields[] = $new_field; 1522 | }else{ 1523 | return $new_field; 1524 | } 1525 | } 1526 | 1527 | /** 1528 | * Add WYSIWYG Field to meta box 1529 | * @author Ohad Raz 1530 | * @since 1.0 1531 | * @access public 1532 | * @param $id string field id, i.e. the meta key 1533 | * @param $args mixed|array 1534 | * 'name' => // field name/label string optional 1535 | * 'desc' => // field description, string optional 1536 | * 'std' => // default value, string optional 1537 | * 'style' => // custom style for field, string optional Default 'width: 300px; height: 400px' 1538 | * 'validate_func' => // validate function, string optional 1539 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1540 | */ 1541 | public function addWysiwyg($id,$args,$repeater=false){ 1542 | $new_field = array('type' => 'wysiwyg','id'=> $id,'std' => '','desc' => '','style' =>'width: 300px; height: 400px','name' => 'WYSIWYG Editor Field','multiple' => false); 1543 | $new_field = array_merge($new_field, $args); 1544 | if(false === $repeater){ 1545 | $this->_fields[] = $new_field; 1546 | }else{ 1547 | return $new_field; 1548 | } 1549 | } 1550 | 1551 | /** 1552 | * Add Taxonomy Field to meta box 1553 | * @author Ohad Raz 1554 | * @since 1.0 1555 | * @access public 1556 | * @param $id string field id, i.e. the meta key 1557 | * @param $options mixed|array options of taxonomy field 1558 | * 'taxonomy' => // taxonomy name can be category,post_tag or any custom taxonomy default is category 1559 | * 'type' => // how to show taxonomy? 'select' (default) or 'checkbox_list' 1560 | * 'args' => // arguments to query taxonomy, see http://goo.gl/uAANN default ('hide_empty' => false) 1561 | * @param $args mixed|array 1562 | * 'name' => // field name/label string optional 1563 | * 'desc' => // field description, string optional 1564 | * 'std' => // default value, string optional 1565 | * 'validate_func' => // validate function, string optional 1566 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1567 | */ 1568 | public function addTaxonomy($id,$options,$args,$repeater=false){ 1569 | $q = array('hide_empty' => 0); 1570 | $tax = 'category'; 1571 | $type = 'select'; 1572 | $temp = array('taxonomy' => $tax,'type' => $type,'args' => $q); 1573 | $options = array_merge($temp,$options); 1574 | $new_field = array('type' => 'taxonomy','id'=> $id,'desc' => '','name' => 'Taxonomy Field','options'=> $options,'multiple' => false); 1575 | $new_field = array_merge($new_field, $args); 1576 | if(false === $repeater){ 1577 | $this->_fields[] = $new_field; 1578 | }else{ 1579 | return $new_field; 1580 | } 1581 | } 1582 | 1583 | /** 1584 | * Add posts Field to meta box 1585 | * @author Ohad Raz 1586 | * @since 1.0 1587 | * @access public 1588 | * @param $id string field id, i.e. the meta key 1589 | * @param $options mixed|array options of taxonomy field 1590 | * 'type' => // how to show posts? 'select' (default) or 'checkbox_list' 1591 | * 'args' => // arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1, 'post_type' => 'post') 1592 | * @param $args mixed|array 1593 | * 'name' => // field name/label string optional 1594 | * 'desc' => // field description, string optional 1595 | * 'std' => // default value, string optional 1596 | * 'validate_func' => // validate function, string optional 1597 | * @param $repeater bool is this a field inside a repeatr? true|false(default) 1598 | */ 1599 | public function addPosts($id,$options,$args,$repeater=false){ 1600 | $temp = array('type'=>'select','args'=> array('posts_per_page' => -1, 'post_type' =>'post') ); 1601 | $options = array_merge($temp,$options); 1602 | $new_field = array('type' => 'posts','id'=> $id,'desc' => '','name' => 'Posts Field','options'=> $options,'multiple' => false); 1603 | $new_field = array_merge($new_field, $args); 1604 | if(false === $repeater){ 1605 | $this->_fields[] = $new_field; 1606 | }else{ 1607 | return $new_field; 1608 | } 1609 | } 1610 | 1611 | /** 1612 | * Add repeater Field Block to meta box 1613 | * @author Ohad Raz 1614 | * @since 1.0 1615 | * @access public 1616 | * @param $id string field id, i.e. the meta key 1617 | * @param $args mixed|array 1618 | * 'name' => // field name/label string optional 1619 | * 'desc' => // field description, string optional 1620 | * 'std' => // default value, string optional 1621 | * 'style' => // custom style for field, string optional 1622 | * 'validate_func' => // validate function, string optional 1623 | * 'fields' => //fields to repeater 1624 | */ 1625 | public function addRepeaterBlock($id,$args){ 1626 | $new_field = array('type' => 'repeater','id'=> $id,'name' => 'Reapeater Field','fields' => array(),'inline'=> false); 1627 | $new_field = array_merge($new_field, $args); 1628 | $this->_fields[] = $new_field; 1629 | } 1630 | 1631 | 1632 | /** 1633 | * Finish Declaration of Meta Box 1634 | * @author Ohad Raz 1635 | * @since 1.0 1636 | * @access public 1637 | */ 1638 | public function Finish() { 1639 | $this->add_missed_values(); 1640 | } 1641 | 1642 | /** 1643 | * Helper function to check for empty arrays 1644 | * @author Ohad Raz 1645 | * @since 1.0 1646 | * @access public 1647 | * @param $args mixed|array 1648 | */ 1649 | public function is_array_empty($array){ 1650 | if (!is_array($array)) 1651 | return true; 1652 | 1653 | foreach ($array as $a){ 1654 | if (is_array($a)){ 1655 | foreach ($a as $sub_a){ 1656 | if (!empty($sub_a) && $sub_a != '') 1657 | return false; 1658 | } 1659 | }else{ 1660 | if (!empty($a) && $a != '') 1661 | return false; 1662 | } 1663 | } 1664 | return true; 1665 | } 1666 | 1667 | 1668 | //get term meta field 1669 | public function get_tax_meta($term_id,$key,$multi = false){ 1670 | $t_id = (is_object($term_id))? $term_id->term_id: $term_id; 1671 | $m = get_option( 'tax_meta_'.$t_id); 1672 | if (isset($m[$key])){ 1673 | return $m[$key]; 1674 | }else{ 1675 | return ''; 1676 | } 1677 | } 1678 | 1679 | //delete meta 1680 | public function delete_tax_meta($term_id,$key){ 1681 | $m = get_option( 'tax_meta_'.$term_id); 1682 | if (isset($m[$key])){ 1683 | unset($m[$key]); 1684 | } 1685 | update_option('tax_meta_'.$term_id,$m); 1686 | } 1687 | 1688 | //update meta 1689 | public function update_tax_meta($term_id,$key,$value){ 1690 | $m = get_option( 'tax_meta_'.$term_id); 1691 | $m[$key] = $value; 1692 | update_option('tax_meta_'.$term_id,$m); 1693 | } 1694 | 1695 | 1696 | /** 1697 | * delete_taxonomy_metadata 1698 | * 1699 | * delete meta on term deletion 1700 | * 1701 | * answers issue #16 1702 | * @author Ohad Raz 1703 | * @since 1.8.1 1704 | * @access public 1705 | * @return Void 1706 | */ 1707 | public function delete_taxonomy_metadata($term,$term_id) { 1708 | delete_option( 'tax_meta_'.$term_id ); 1709 | if ( function_exists( 'delete_term_meta') ){ 1710 | delete_term_meta( $term_id ); 1711 | } 1712 | } 1713 | 1714 | 1715 | /** 1716 | * footer_js 1717 | * fix issue #2 1718 | * @author Ohad Raz 1719 | * @since 1.7.4 1720 | * @access public 1721 | * @return Void 1722 | */ 1723 | public function footer_js(){ 1724 | ?> 1725 | 1758 | term_id: $term_id; 1772 | $m = get_option( 'tax_meta_'.$t_id); 1773 | if (isset($m[$key])){ 1774 | return $m[$key]; 1775 | }else{ 1776 | return ''; 1777 | } 1778 | } 1779 | } 1780 | 1781 | //delete meta 1782 | if (!function_exists('delete_tax_meta')){ 1783 | function delete_tax_meta($term_id,$key){ 1784 | $m = get_option( 'tax_meta_'.$term_id); 1785 | if (isset($m[$key])){ 1786 | unset($m[$key]); 1787 | } 1788 | update_option('tax_meta_'.$term_id,$m); 1789 | } 1790 | } 1791 | 1792 | //update meta 1793 | if (!function_exists('update_tax_meta')){ 1794 | function update_tax_meta($term_id,$key,$value){ 1795 | $m = get_option( 'tax_meta_'.$term_id); 1796 | $m[$key] = $value; 1797 | update_option('tax_meta_'.$term_id,$m); 1798 | } 1799 | } 1800 | 1801 | //get term meta field and strip slashes 1802 | if (!function_exists('get_tax_meta_strip')){ 1803 | function get_tax_meta_strip($term_id,$key,$multi = false){ 1804 | $t_id = (is_object($term_id))? $term_id->term_id: $term_id; 1805 | $m = get_option( 'tax_meta_'.$t_id); 1806 | if (isset($m[$key])){ 1807 | return is_array($m[$key])? $m[$key] : stripslashes($m[$key]); 1808 | }else{ 1809 | return ''; 1810 | } 1811 | } 1812 | } 1813 | //get all meta fields of a term 1814 | if (!function_exists('get_tax_meta_all')){ 1815 | function get_tax_meta_all( $term_id){ 1816 | $t_id = (is_object($term_id))? $term_id->term_id: $term_id; 1817 | return get_option( 'tax_meta_'.$t_id,array()); 1818 | } 1819 | } -------------------------------------------------------------------------------- /Tax-meta-class/css/Tax-meta-class.css: -------------------------------------------------------------------------------- 1 | /** 2 | * All Tax meta class 3 | * 4 | * JS used for the custom fields and other form items. 5 | * 6 | * Copyright 2012 Ohad Raz (admin@bainternet.info) 7 | */ 8 | 9 | /* =Common Rules for all fields. 10 | ----------------------------------------------- */ 11 | .form-table td.at-field{ border: 1px solid #DDD; padding: 10px 10px 20px; margin: 0px; font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue", Helvetica, Arial, sans-serif; } 12 | .at-label { 13 | margin: 0 0 5px 0; padding: 5px 0 0 0; 14 | font: 20px/31px "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue", Helvetica, Arial, sans-serif; 15 | text-shadow: rgba(255, 255, 255, 1) 0 1px 0; 16 | width: auto; 17 | } 18 | .at-radio-label{ padding-right: 10px; } 19 | .at-file-upload-label{ clear: both; margin: 5px 0px 5px 1px; } 20 | 21 | 22 | /* =Form Fields 23 | ----------------------------------------------- */ 24 | .form-field input, .form-field textarea {width: auto !important;} 25 | .wp-editor-wrap{width: 500px;} textarea.at-wysiwyg{width: 498px !important;} 26 | .rw-checkbox, .at-select, .at-text , .at-textarea{width: auto!important;} 27 | .postbox .at-field input, 28 | .postbox .at-field textarea { padding: 5px; line-height: 18px; } 29 | .postbox .at-field input.at-radio{} 30 | .postbox .at-field input.at-color{ border: 0px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; margin-right: 10px; min-width: 100px; } 31 | .at-field input:focus, 32 | .at-field textarea:focus { background: #fffff8; } 33 | #wpcontent select.at-select { height: 30px !important; padding: 5px; display: block; min-width: 200px; } 34 | .at-field .desc-field { color: #AAA; font-style: italic; margin: 5px 0 0 3px !important; font-size: 13px; } 35 | .at-field .wp_themeSkin table.mceLayout{ border: 1px solid #DFDFDF; } 36 | #post-body .at-field .wp_themeSkin .mceStatusbar a.mceResize{ top: -25px; } 37 | 38 | /* =Uploaded Images 39 | ----------------------------------------------- */ 40 | .at-images li { margin: 5px 10px 0px 0; float: left; width: 150px; height: 150px; text-align: center; border: 3px solid #ccc; cursor: move; position: relative; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; } 41 | .at-images img { width: 150px; height: 150px; } 42 | .at-images a { position: absolute; top: -12px; right: -12px; color: #fff; font-weight: bold; padding: 5px; } 43 | .at-images .at-delete-file img{ width: 16px; height: 16px; } 44 | 45 | /* =Upload Button 46 | ----------------------------------------------- */ 47 | .at-upload-button { float: left; clear: both; margin-top: 10px; } 48 | .at-add-file { float: left; clear: both; margin-top: 10px; } 49 | 50 | /* =Time Picker 51 | ----------------------------------------------- */ 52 | .ui-timepicker-div { font-size: 0.9em; } 53 | .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } 54 | .ui-timepicker-div dl { text-align: left; } 55 | .ui-timepicker-div dl dt { height: 25px; } 56 | .ui-timepicker-div dl dd { margin: -25px 0 10px 65px; } 57 | .ui-timepicker-div td { font-size: 90%; } 58 | 59 | /* =Repater Block 60 | ----------------------------------------------- */ 61 | /* inline */ 62 | .at-inline label{font-size: 12px !important;} 63 | .at-inline textarea{height: 130px;width: 200px;} -------------------------------------------------------------------------------- /Tax-meta-class/images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/images/add.png -------------------------------------------------------------------------------- /Tax-meta-class/images/delete-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/images/delete-16.png -------------------------------------------------------------------------------- /Tax-meta-class/images/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/images/edit.png -------------------------------------------------------------------------------- /Tax-meta-class/images/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/images/remove.png -------------------------------------------------------------------------------- /Tax-meta-class/js/tax-meta-clss.js: -------------------------------------------------------------------------------- 1 | /** 2 | * All Tax meta class 3 | * 4 | * JS used for the custom fields and other form items. 5 | * 6 | * Copyright 2012 Ohad Raz (admin@bainternet.info) 7 | * @since 1.0 8 | * 9 | * @package Tax Meta Class 10 | * 11 | */ 12 | 13 | var $ =jQuery.noConflict(); 14 | function update_repeater_fields(){ 15 | 16 | /** 17 | * WysiWyg editor 18 | * 19 | * @since 1.9.6 20 | */ 21 | $(".theEditor").each(function(){ 22 | if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) { 23 | tinyMCE.execCommand("mceAddControl", false, $(this).attr('id')); 24 | } 25 | }); 26 | 27 | /** 28 | * Datepicker Field. 29 | * 30 | * @since 1.0 31 | */ 32 | $('.at-date').each( function() { 33 | 34 | var $this = $(this), 35 | format = $this.attr('rel'); 36 | 37 | $this.datepicker( { showButtonPanel: true, dateFormat: format } ); 38 | 39 | }); 40 | 41 | /** 42 | * Timepicker Field. 43 | * 44 | * @since 1.0 45 | */ 46 | $('.at-time').each( function() { 47 | 48 | var $this = $(this), 49 | format = $this.attr('rel'); 50 | 51 | $this.timepicker( { showSecond: true, timeFormat: format } ); 52 | 53 | }); 54 | 55 | 56 | /** 57 | * Select Color Field. 58 | * 59 | * uses: wpColorPicker 60 | * 61 | * @since 2.1.1 62 | */ 63 | $('.at-color').wpColorPicker(); 64 | 65 | /** 66 | * Delete File. 67 | * 68 | * @since 1.0 69 | */ 70 | $('.at-upload').delegate( '.at-delete-file', 'click' , function() { 71 | 72 | var $this = $(this), 73 | $parent = $this.parent(), 74 | data = $this.attr('rel'); 75 | 76 | $.post( ajaxurl, { action: 'at_delete_file', data: data }, function(response) { 77 | response == '0' ? ( alert( 'File has been successfully deleted.' ), $parent.remove() ) : alert( 'You do NOT have permission to delete this file.' ); 78 | }); 79 | 80 | return false; 81 | 82 | }); 83 | 84 | /** 85 | * Reorder Images. 86 | * 87 | * @since 1.0 88 | */ 89 | $('.at-images').each( function() { 90 | 91 | var $this = $(this), order, data; 92 | 93 | $this.sortable( { 94 | placeholder: 'ui-state-highlight', 95 | update: function (){ 96 | order = $this.sortable('serialize'); 97 | data = order + '|' + $this.siblings('.at-images-data').val(); 98 | 99 | $.post(ajaxurl, {action: 'at_reorder_images', data: data}, function(response){ 100 | response == '0' ? alert( 'Order saved!' ) : alert( "You don't have permission to reorder images." ); 101 | }); 102 | } 103 | }); 104 | 105 | }); 106 | 107 | } 108 | jQuery(document).ready(function($) { 109 | 110 | /** 111 | * repater Field 112 | * @since 1.1 113 | */ 114 | /*$( ".at-repeater-item" ).live('click', function() { 115 | var $this = $(this); 116 | $this.siblings().toggle(); 117 | }); 118 | jQuery(".at-repater-block").click(function(){ 119 | jQuery(this).find('table').toggle(); 120 | }); 121 | 122 | */ 123 | //edit 124 | $(document).on('click','.at-re-toggle',function() { 125 | $(this).prev().toggle('slow'); 126 | }); 127 | 128 | 129 | /** 130 | * Datepicker Field. 131 | * 132 | * @since 1.0 133 | */ 134 | $('.at-date').each( function() { 135 | 136 | var $this = $(this), 137 | format = $this.attr('rel'); 138 | 139 | $this.datepicker( { showButtonPanel: true, dateFormat: format } ); 140 | 141 | }); 142 | 143 | /** 144 | * Timepicker Field. 145 | * 146 | * @since 1.0 147 | */ 148 | $('.at-time').each( function() { 149 | 150 | var $this = $(this), 151 | format = $this.attr('rel'); 152 | 153 | $this.timepicker( { showSecond: true, timeFormat: format } ); 154 | 155 | }); 156 | 157 | $('.at-color').wpColorPicker(); 158 | 159 | /** 160 | * Helper Function 161 | * 162 | * Get Query string value by name. 163 | * 164 | * @since 1.0 165 | */ 166 | function get_query_var( name ) { 167 | var match = RegExp('[?&]' + name + '=([^&#]*)').exec(location.href); 168 | return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); 169 | } 170 | 171 | //clear form after submit 172 | $( document ).ajaxComplete(function( event, xhr, settings ) { 173 | try{ 174 | $respo = $.parseXML(xhr.responseText); 175 | 176 | //exit on error 177 | if ($($respo).find('wp_error').length) return; 178 | 179 | $($respo).find('response').each(function(i,e){ 180 | if ($(e).attr('action').indexOf("add-tag") > -1){ 181 | var tid = $(e).find('term_id'); 182 | if (tid){ 183 | clear_form($( "form[action='edit-tags.php']" )); 184 | } 185 | } 186 | }); 187 | }catch(err) {} 188 | }); 189 | function version_compare(a,b){ 190 | var c=a.split('.'); 191 | var d=b.split('.'); 192 | for(var i=0;id[i]){ 199 | return"gt"; 200 | }else{ 201 | return"lt"; 202 | } 203 | } 204 | if(c.length!=d.length){ 205 | return"lt"; 206 | } 207 | return"eq"; 208 | } 209 | function clear_form(form){ 210 | $('input[type="text"]:visible, textarea:visible', form).val(''); 211 | //color field 212 | $('.at-color', form).attr('style',''); 213 | //image upload 214 | $('.simplePanelImagePreview img').remove(); 215 | $('simplePanelimageUploadclear').each(function(){ 216 | var $field = $(this); 217 | //clear urls 218 | $field.prev().val(''); 219 | //clear ids 220 | $field.prev().prev().val(''); 221 | simplePanelupload.getInstance().replaceImageUploadClass($field); 222 | }); 223 | //file upload 224 | $('.simplePanelfilePreview ul li').remove(); 225 | $('simplePanelfileUploadclear').each(function(){ 226 | var $field = $(this); 227 | //clear urls 228 | $field.prev().val(''); 229 | //clear ids 230 | $field.prev().prev().val(''); 231 | simplePanelupload.getInstance().replaceImageUploadClass($field); 232 | }); 233 | //repeater 234 | $(".at-repater-block").remove(); 235 | //select 236 | $('select',form).val(''); 237 | //checkboxes 238 | $( "input[type='checkbox']",form ).prop('checked',false); 239 | //radio 240 | $( "input[type='radio']",form ).prop('checked',false); 241 | } 242 | /** pre bind jquery function **/ 243 | $.fn.preBind = function (type, data, fn) { 244 | this.each(function () { 245 | var $this = $(this); 246 | 247 | $this.bind(type, data, fn); 248 | if (version_compare($.fn.jquery,'1.8') == 'lt') 249 | var currentBindings = $this.data('events')[type]; 250 | else 251 | var currentBindings = $._data(this, "events")[type]; 252 | if ($.isArray(currentBindings)) { 253 | currentBindings.unshift(currentBindings.pop()); 254 | } 255 | }); 256 | return this; 257 | }; 258 | /** fix tinymce not saving on add screen*/ 259 | $('#submit').preBind('click', function() { 260 | if(typeof tinymce !== "undefined" && $('input[name=action]').val() == 'add-tag'){ 261 | $.each(tinymce.editors,function(i,editor){ 262 | var tx = editor.targetElm; 263 | $(tx).html(editor.getContent()); 264 | }); 265 | } 266 | }); 267 | }); 268 | 269 | 270 | var simple_meta_box; 271 | jQuery(document).ready(function($){ 272 | var simplePanelupload = (function(){ 273 | var inited; 274 | var file_id; 275 | var file_url; 276 | var file_type; 277 | function init (){ 278 | return { 279 | image_frame: new Array(), 280 | file_frame: new Array(), 281 | hooks:function(){ 282 | $(document).on('click','.simplePanelimageUpload,.simplePanelfileUpload', function( event ){ 283 | event.preventDefault(); 284 | if ($(this).hasClass('simplePanelfileUpload')) 285 | inited.upload($(this),'file'); 286 | else 287 | inited.upload($(this),'image'); 288 | }); 289 | 290 | $(document).on('click','.simplePanelimageUploadclear,.simplePanelfileUploadclear', function( event ){ 291 | event.preventDefault(); 292 | inited.set_fields($(this)); 293 | $(inited.file_url).val(""); 294 | $(inited.file_id).val(""); 295 | if ($(this).hasClass('simplePanelimageUploadclear')){ 296 | inited.set_preview('image',false); 297 | inited.replaceImageUploadClass($(this)); 298 | }else{ 299 | inited.set_preview('file',false); 300 | inited.replaceFileUploadClass($(this)); 301 | } 302 | }); 303 | }, 304 | set_fields: function (el){ 305 | inited.file_url = $(el).prev(); 306 | inited.file_id = $(inited.file_url).prev(); 307 | }, 308 | upload:function(el,utype){ 309 | inited.set_fields(el) 310 | if (utype == 'image') 311 | inited.upload_Image($(el)); 312 | else 313 | inited.upload_File($(el)); 314 | }, 315 | upload_File: function(el){ 316 | // If the media frame already exists, reopen it. 317 | var mime = $(el).attr('data-mime_type') || ''; 318 | var ext = $(el).attr("data-ext") || false; 319 | var name = $(el).attr('id'); 320 | var multi = ($(el).hasClass("multiFile")? true: false); 321 | 322 | if ( typeof inited.file_frame[name] !== "undefined") { 323 | if (ext){ 324 | inited.file_frame[name].uploader.uploader.param( 'uploadeType', ext); 325 | inited.file_frame[name].uploader.uploader.param( 'uploadeTypecaller', 'my_meta_box' ); 326 | } 327 | inited.file_frame[name].open(); 328 | return; 329 | } 330 | // Create the media frame. 331 | 332 | inited.file_frame[name] = wp.media({ 333 | library: { 334 | type: mime 335 | }, 336 | title: jQuery( this ).data( 'uploader_title' ), 337 | button: { 338 | text: jQuery( this ).data( 'uploader_button_text' ), 339 | }, 340 | multiple: multi // Set to true to allow multiple files to be selected 341 | }); 342 | 343 | 344 | // When an image is selected, run a callback. 345 | inited.file_frame[name].on( 'select', function() { 346 | // We set multiple to false so only get one image from the uploader 347 | attachment = inited.file_frame[name].state().get('selection').first().toJSON(); 348 | // Do something with attachment.id and/or attachment.url here 349 | $(inited.file_id).val(attachment.id); 350 | $(inited.file_url).val(attachment.url); 351 | inited.replaceFileUploadClass(el); 352 | inited.set_preview('file',true); 353 | }); 354 | // Finally, open the modal 355 | 356 | inited.file_frame[name].open(); 357 | if (ext){ 358 | inited.file_frame[name].uploader.uploader.param( 'uploadeType', ext); 359 | inited.file_frame[name].uploader.uploader.param( 'uploadeTypecaller', 'my_meta_box' ); 360 | } 361 | }, 362 | upload_Image:function(el){ 363 | var name = $(el).attr('id'); 364 | var multi = ($(el).hasClass("multiFile")? true: false); 365 | // If the media frame already exists, reopen it. 366 | if ( typeof inited.image_frame[name] !== "undefined") { 367 | inited.image_frame[name].open(); 368 | return; 369 | } 370 | // Create the media frame. 371 | inited.image_frame[name] = wp.media({ 372 | library: { 373 | type: 'image' 374 | }, 375 | title: jQuery( this ).data( 'uploader_title' ), 376 | button: { 377 | text: jQuery( this ).data( 'uploader_button_text' ), 378 | }, 379 | multiple: multi // Set to true to allow multiple files to be selected 380 | }); 381 | //set pre selected images 382 | inited.image_frame[name].on('open',function(){ 383 | var selection = inited.image_frame[name].state().get('selection'); 384 | var att_ids = $(inited.file_id).val().split("|"); 385 | $.each(att_ids,function(i,v){ 386 | if (v.length){ 387 | attachment = wp.media.attachment(v); 388 | attachment.fetch(); 389 | selection.add( attachment ? [ attachment ] : [] ); 390 | } 391 | }); 392 | }); 393 | // When an image is selected, run a callback. 394 | inited.image_frame[name].on( 'select', function() { 395 | if (!multi){ 396 | attachment = inited.image_frame[name].state().get('selection').first().toJSON(); 397 | // Do something with attachment.id and/or attachment.url here 398 | $(inited.file_id).val(attachment.id); 399 | $(inited.file_url).val(attachment.url); 400 | inited.replaceImageUploadClass(el); 401 | inited.set_preview('image',true); 402 | }else{ 403 | var att_ids = ''; 404 | var att_urls = ''; 405 | inited.image_frame[name].state().get('selection').each(function(i){ 406 | att_ids += i.get('id') + '|'; 407 | att_urls += i.get('url') + '|'; 408 | }); 409 | att_ids = att_ids.substring(0, att_ids.length - 1); 410 | att_urls = att_urls.substring(0, att_urls.length - 1); 411 | $(inited.file_id).val(att_ids); 412 | $(inited.file_url).val(att_urls); 413 | inited.set_multiple_img_preview(true); 414 | } 415 | }); 416 | // Finally, open the modal 417 | inited.image_frame[name].open(); 418 | }, 419 | replaceImageUploadClass: function(el){ 420 | if ($(el).hasClass("simplePanelimageUpload")){ 421 | $(el).removeClass("simplePanelimageUpload").addClass('simplePanelimageUploadclear').val('Remove Image'); 422 | }else{ 423 | $(el).removeClass("simplePanelimageUploadclear").addClass('simplePanelimageUpload').val('Upload Image'); 424 | } 425 | }, 426 | replaceFileUploadClass: function(el){ 427 | if ($(el).hasClass("simplePanelfileUpload")){ 428 | $(el).removeClass("simplePanelfileUpload").addClass('simplePanelfileUploadclear').val('Remove File'); 429 | }else{ 430 | $(el).removeClass("simplePanelfileUploadclear").addClass('simplePanelfileUpload').val('Upload File'); 431 | } 432 | }, 433 | set_preview: function(stype,ShowFlag){ 434 | ShowFlag = ShowFlag || false; 435 | var fileuri = $(inited.file_url).val(); 436 | if (stype == 'image'){ 437 | if (ShowFlag) 438 | $(inited.file_id).prev().find('img').attr('src',fileuri).show(); 439 | else 440 | $(inited.file_id).prev().find('img').attr('src','').hide(); 441 | }else{ 442 | if (ShowFlag) 443 | $(inited.file_id).prev().find('ul').append('
  • '+fileuri+'
  • '); 444 | else 445 | $(inited.file_id).prev().find('ul').children().remove(); 446 | } 447 | }, 448 | set_multiple_img_preview: function(ShowFlag){ 449 | ShowFlag = ShowFlag || false; 450 | var fileuri = $(inited.file_url).val(); 451 | var fileids = $(inited.file_id).val(); 452 | if (fileuri == '') return; 453 | fileuri = fileuri.split("|"); 454 | fileids = fileids.split("|"); 455 | if (ShowFlag){ 456 | $(inited.file_id).prev().find('ul').remove(); 457 | $(inited.file_id).prev().append('') 458 | $.each(fileuri,function(i,f){ 459 | $(inited.file_id).prev().find('.imageSortable').append('
  • '); 460 | }); 461 | $( ".imageSortable" ).sortable({ 462 | placeholder: "ui-state-highlight", 463 | update: function( event, ui ) { 464 | var $ul = $(ui.item[0]).parent(); 465 | var att_ids = ''; 466 | var att_urls = ''; 467 | $ul.find('img').each(function(i,v){ 468 | att_ids += $(v).attr('data-attid') + '|'; 469 | att_urls += $(v).attr('src') + '|'; 470 | }); 471 | att_ids = att_ids.substring(0, att_ids.length - 1); 472 | att_urls = att_urls.substring(0, att_urls.length - 1); 473 | $(inited.file_id).val(att_ids); 474 | $(inited.file_url).val(att_urls); 475 | } 476 | }); 477 | }else{ 478 | $(inited.file_id).prev().find('ul').remove(); 479 | } 480 | } 481 | } 482 | } 483 | return { 484 | getInstance :function(){ 485 | if (!inited){ 486 | inited = init(); 487 | } 488 | return inited; 489 | } 490 | } 491 | })() 492 | simplePanelupload.getInstance().hooks(); 493 | }); -------------------------------------------------------------------------------- /Tax-meta-class/lang/default.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/lang/default.mo -------------------------------------------------------------------------------- /Tax-meta-class/lang/default.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Tax meta class\n" 4 | "POT-Creation-Date: 2013-04-25 09:31+0100\n" 5 | "PO-Revision-Date: 2013-04-25 09:31+0100\n" 6 | "Last-Translator: David Thomas \n" 7 | "Language-Team: David THOMAS \n" 8 | "Language: fr_FR\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.5.5\n" 13 | "X-Poedit-KeywordsList: _;__;_e;gettext;gettext_noop\n" 14 | "X-Poedit-Basepath: .\n" 15 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 16 | "X-Poedit-SearchPath-0: ../../Tax-meta-class\n" 17 | 18 | #: ../../Tax-meta-class/Tax-meta-class.php:250 19 | msgid "Delete this image" 20 | msgstr "" 21 | 22 | #: ../../Tax-meta-class/Tax-meta-class.php:250 23 | #: ../../Tax-meta-class/Tax-meta-class.php:882 24 | msgid "Delete" 25 | msgstr "" 26 | 27 | #: ../../Tax-meta-class/Tax-meta-class.php:357 28 | msgid "Cannot delete file. Something's wrong." 29 | msgstr "" 30 | 31 | #: ../../Tax-meta-class/Tax-meta-class.php:582 32 | #: ../../Tax-meta-class/Tax-meta-class.php:629 33 | msgid "Remove" 34 | msgstr "" 35 | 36 | #: ../../Tax-meta-class/Tax-meta-class.php:595 37 | msgid "Add" 38 | msgstr "" 39 | 40 | #: ../../Tax-meta-class/Tax-meta-class.php:878 41 | msgid "Uploaded files" 42 | msgstr "" 43 | 44 | #: ../../Tax-meta-class/Tax-meta-class.php:889 45 | msgid "Upload new files" 46 | msgstr "" 47 | 48 | #: ../../Tax-meta-class/Tax-meta-class.php:895 49 | msgid "Add more files" 50 | msgstr "" 51 | 52 | #: ../../Tax-meta-class/Tax-meta-class.php:947 53 | msgid "Select a color" 54 | msgstr "" 55 | -------------------------------------------------------------------------------- /Tax-meta-class/lang/fr_FR.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bainternet/Tax-Meta-Class/a8acfdb6b8fef22d1eefdbe75481e73d2c44d445/Tax-meta-class/lang/fr_FR.mo -------------------------------------------------------------------------------- /Tax-meta-class/lang/fr_FR.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Tax meta class\n" 4 | "POT-Creation-Date: 2013-04-25 09:31+0100\n" 5 | "PO-Revision-Date: 2013-04-25 09:34+0100\n" 6 | "Last-Translator: David Thomas \n" 7 | "Language-Team: David THOMAS \n" 8 | "Language: fr_FR\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.5.5\n" 13 | "X-Poedit-KeywordsList: _;__;_e;gettext;gettext_noop\n" 14 | "X-Poedit-Basepath: .\n" 15 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 16 | "X-Poedit-SearchPath-0: ../../Tax-meta-class\n" 17 | 18 | #: ../../Tax-meta-class/Tax-meta-class.php:250 19 | msgid "Delete this image" 20 | msgstr "Supprimer cette image" 21 | 22 | #: ../../Tax-meta-class/Tax-meta-class.php:250 23 | #: ../../Tax-meta-class/Tax-meta-class.php:882 24 | msgid "Delete" 25 | msgstr "Supprimer" 26 | 27 | #: ../../Tax-meta-class/Tax-meta-class.php:357 28 | msgid "Cannot delete file. Something's wrong." 29 | msgstr "Impossible de supprimer le fichier. Quelque chose cloche." 30 | 31 | #: ../../Tax-meta-class/Tax-meta-class.php:582 32 | #: ../../Tax-meta-class/Tax-meta-class.php:629 33 | msgid "Remove" 34 | msgstr "Enlever" 35 | 36 | #: ../../Tax-meta-class/Tax-meta-class.php:595 37 | msgid "Add" 38 | msgstr "Ajouter" 39 | 40 | #: ../../Tax-meta-class/Tax-meta-class.php:878 41 | msgid "Uploaded files" 42 | msgstr "Fichiers téléchargés" 43 | 44 | #: ../../Tax-meta-class/Tax-meta-class.php:889 45 | msgid "Upload new files" 46 | msgstr "Télécharger de nouveaux fichiers" 47 | 48 | #: ../../Tax-meta-class/Tax-meta-class.php:895 49 | msgid "Add more files" 50 | msgstr "Ajouter des fichiers" 51 | 52 | #: ../../Tax-meta-class/Tax-meta-class.php:947 53 | msgid "Select a color" 54 | msgstr "Sélectionner une couleur" 55 | -------------------------------------------------------------------------------- /Tax-meta-class/migration/tax_to_term_meta.php: -------------------------------------------------------------------------------- 1 | delete_options = $delete_options; 44 | $this->hooks(); 45 | } 46 | 47 | function hooks(){ 48 | add_action('init',array($this, 'migrate_data_maybe') ); 49 | if ( $this->delete_options ){ 50 | add_action('shutdown',array( $this, 'delete_options') ); 51 | } 52 | } 53 | 54 | function migrate_data_maybe(){ 55 | //needs migration? 56 | $do_migration = get_option('tax_meta_migrated', 'do_migration'); 57 | if ( 'do_migration' == $do_migration ){ 58 | $this->do_migration(); 59 | update_option( 'tax_meta_migrated', 'done' ); 60 | } 61 | } 62 | 63 | function do_migration(){ 64 | $options = $this->get_options(); 65 | foreach ($options as $option) { 66 | $term_id = $this->term_id_from_option( $option ); 67 | $meta = get_option( $option ); 68 | $this->tax_to_term( $term_id, $meta ); 69 | if( $this->delete_options ){ 70 | delete_option( $option ); 71 | } 72 | } 73 | } 74 | 75 | function tax_to_term( $term_id, $meta ){ 76 | foreach ((array)$meta as $meta_name => $meta_value) { 77 | update_term_meta( $term_id, $meta_name, $meta_value ); 78 | } 79 | } 80 | 81 | function term_id_from_option( $option ){ 82 | return str_replace('tax_meta_', '', $option ); 83 | } 84 | 85 | function get_options(){ 86 | global $wpdb; 87 | $query = "SELECT option_name 88 | FROM $wpdb->options 89 | WHERE option_name LIKE 'tax_meta_%' 90 | "; 91 | $options = $wpdb->get_col( $query ); 92 | return $options; 93 | } 94 | 95 | function delete_options(){ 96 | $options = $this->get_options(); 97 | foreach ($options as $option) { 98 | delete_option( $option ); 99 | } 100 | } 101 | } 102 | 103 | /* 104 | * meta functions for easy access using term meta api 105 | */ 106 | //get term meta field 107 | if (!function_exists('get_tax_meta')){ 108 | function get_tax_meta($term_id,$key,$multi = false){ 109 | $term_id = (is_object($term_id))? $term_id->term_id: $term_id; 110 | return get_term_meta( $term_id, $key, $multi ); 111 | } 112 | } 113 | 114 | //delete meta 115 | if (!function_exists('delete_tax_meta')){ 116 | function delete_tax_meta($term_id,$key){ 117 | $term_id = (is_object($term_id))? $term_id->term_id: $term_id; 118 | return delete_term_meta( $term_id, $key ); 119 | } 120 | } 121 | 122 | //update meta 123 | if (!function_exists('update_tax_meta')){ 124 | function update_tax_meta($term_id,$key,$value){ 125 | $term_id = (is_object($term_id))? $term_id->term_id: $term_id; 126 | return update_term_meta( $term_id, $key, $value ); 127 | } 128 | } 129 | 130 | //get term meta field and strip slashes 131 | if (!function_exists('get_tax_meta_strip')){ 132 | function get_tax_meta_strip($term_id,$key,$multi = false){ 133 | return stripslashes( get_term_meta( $term_id, $key, $multi ) ); 134 | } 135 | } 136 | //get all meta fields of a term 137 | if (!function_exists('get_tax_meta_all')){ 138 | function get_tax_meta_all( $term_id){ 139 | $term_id = (is_object($term_id))? $term_id->term_id: $term_id; 140 | return get_term_meta( $term_id ); 141 | } 142 | } -------------------------------------------------------------------------------- /class-usage-demo.php: -------------------------------------------------------------------------------- 1 | 'demo_meta_box', // meta box id, unique per meta box 24 | 'title' => 'Demo Meta Box', // meta box title 25 | 'pages' => array('category'), // taxonomy name, accept categories, post_tag and custom taxonomies 26 | 'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional 27 | 'fields' => array(), // list of meta fields (can be added by field arrays) 28 | 'local_images' => false, // Use local or hosted images (meta box images for add/remove) 29 | 'use_with_theme' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false). 30 | ); 31 | 32 | 33 | /* 34 | * Initiate your meta box 35 | */ 36 | $my_meta = new Tax_Meta_Class($config); 37 | 38 | /* 39 | * Add fields to your meta box 40 | */ 41 | 42 | //text field 43 | $my_meta->addText($prefix.'text_field_id',array('name'=> __('My Text ','tax-meta'),'desc' => 'this is a field desription')); 44 | //textarea field 45 | $my_meta->addTextarea($prefix.'textarea_field_id',array('name'=> __('My Textarea ','tax-meta'))); 46 | //checkbox field 47 | $my_meta->addCheckbox($prefix.'checkbox_field_id',array('name'=> __('My Checkbox ','tax-meta'))); 48 | //select field 49 | $my_meta->addSelect($prefix.'select_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> __('My select ','tax-meta'), 'std'=> array('selectkey2'))); 50 | //radio field 51 | $my_meta->addRadio($prefix.'radio_field_id',array('radiokey1'=>'Radio Value1','radiokey2'=>'Radio Value2'),array('name'=> __('My Radio Filed','tax-meta'), 'std'=> array('radionkey2'))); 52 | //date field 53 | $my_meta->addDate($prefix.'date_field_id',array('name'=> __('My Date ','tax-meta'))); 54 | //Time field 55 | $my_meta->addTime($prefix.'time_field_id',array('name'=> __('My Time ','tax-meta'))); 56 | //Color field 57 | $my_meta->addColor($prefix.'color_field_id',array('name'=> __('My Color ','tax-meta'))); 58 | //Image field 59 | $my_meta->addImage($prefix.'image_field_id',array('name'=> __('My Image ','tax-meta'))); 60 | //file upload field 61 | $my_meta->addFile($prefix.'file_field_id',array('name'=> __('My File ','tax-meta'))); 62 | //wysiwyg field 63 | $my_meta->addWysiwyg($prefix.'wysiwyg_field_id',array('name'=> __('My wysiwyg Editor ','tax-meta'))); 64 | //taxonomy field 65 | $my_meta->addTaxonomy($prefix.'taxonomy_field_id',array('taxonomy' => 'category'),array('name'=> __('My Taxonomy ','tax-meta'))); 66 | //posts field 67 | $my_meta->addPosts($prefix.'posts_field_id',array('args' => array('post_type' => 'page')),array('name'=> __('My Posts ','tax-meta'))); 68 | 69 | /* 70 | * To Create a reapeater Block first create an array of fields 71 | * use the same functions as above but add true as a last param 72 | */ 73 | 74 | $repeater_fields[] = $my_meta->addText($prefix.'re_text_field_id',array('name'=> __('My Text ','tax-meta')),true); 75 | $repeater_fields[] = $my_meta->addTextarea($prefix.'re_textarea_field_id',array('name'=> __('My Textarea ','tax-meta')),true); 76 | $repeater_fields[] = $my_meta->addCheckbox($prefix.'re_checkbox_field_id',array('name'=> __('My Checkbox ','tax-meta')),true); 77 | $repeater_fields[] = $my_meta->addImage($prefix.'image_field_id',array('name'=> __('My Image ','tax-meta')),true); 78 | 79 | /* 80 | * Then just add the fields to the repeater block 81 | */ 82 | //repeater block 83 | $my_meta->addRepeaterBlock($prefix.'re_',array('inline' => true, 'name' => __('This is a Repeater Block','tax-meta'),'fields' => $repeater_fields)); 84 | /* 85 | * Don't Forget to Close up the meta box decleration 86 | */ 87 | //Finish Meta Box Decleration 88 | $my_meta->Finish(); 89 | } 90 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------