Coder Social home page Coder Social logo

bainternet / my-meta-box Goto Github PK

View Code? Open in Web Editor NEW
223.0 32.0 89.0 239 KB

A class for creating custom meta boxes for WordPress

Home Page: http://en.bainternet.info/2012/how-i-add-a-wordpress-metabox

License: GNU General Public License v3.0

PHP 29.96% CSS 3.44% JavaScript 66.59%

my-meta-box's Introduction

My Wordpress Meta box Class
=======================
Contributors: bainternet
Requires at least: 3.1
Tested up to: 3.7.1

Description
-----------
The Meta Box Class is used by including it in your plugin files and using its methods to 
create custom meta boxes for custom post types. It is meant to be very simple and 
straightforward. For name spacing purposes, All Types metabox ( meaning you can do anything with it )
is used. 

This class is derived from Meta Box script by Rilwis<[email protected]> version 3.2. which later was forked 
by Cory Crowley (email: [email protected]) The purpose of this class is not to rewrite the script but to 
modify and change small things and adding a few field types that i needed to my personal preference. 
The original author did a great job in writing this class, so all props goes to him.

Usage
--------
Take a look at the `class-usage-demo.php` file which can also be tested as a WordPress Plugin. 
Other options are available for each field which can be see in the 'my-meta-box-class.php' file, 


Known Issues and Limitations
-------------
Reapater field can't handle Posts and Taxonomy for now (and maybe even others).


Changelog
---------
= 3.1.1 =

* Fixed  #94.
* Fixed #92.
* Fixed #93. added an option to show an empty select option to posts field using `emptylabel` in the field config array.
* Fixed #88.

= 3.1.0 = 

* All uploads hadled by wordpress and not by the class
* Removed media upload functions
* Replaced Image field to new media uploader
* Replaced file field to new media uploader and added a type limiter.
* Dropped supprot for farbtastic. and probbably wp < 3.5
* Repeater field label is a counter if first field is an image or file field.
* Fixed typo in css class name for post select field.
* Deprecated  save_field_file_repeater method.
* Fixed posts filed query args
* Added WYSIWYG editor settings option.
* Removed all refreance object calls (for php 5.4 prep).
* Removed support for hosted icons.
* Refreshed repeater block icons.
* Cleaned repeater block.
* Repeater block sortable now has an icon for sorting.
* Added Repeater block sortable drop place holder.
* Updated plugin version 
* Added file field width type limitation.

= 3.0.6 = 
Fixed issue #74.

= 3.0.5 = 
Fixed issue #64

= 3.0.4 =  
Fixed #52

= 3.0.3 =  
Added html5 Number Field

= 3.0.2 =
Fixed #48.
Cleaned up Javascript file.
Added Swedish translations thanks to #lolitaloco :)

= 3.0.1 = 
Better add_meta_box logic

= 3.0.0 =
fixed issues #45 #42

= 2.9.9 =
Cleaned up some comments in the code.
Added a conditional fields block #37 ,as can be seen in demo plugin.


= 2.9.8 =
Fixed field groupping #32
Added Select2 #31
Added WordPress 3.5 color picker support.
better field type checking algo.

= 2.9.7 =
Added class attribute to most fields. #33
Added Style attribute to most fields. #33
fixed Language Mo issue.
improved has_filed logic for better performance.


= 2.9.6 = 
Fixed file upload issue #22

= 2.9.5 = 
Typo.

= 2.9.4 = 
Added localization support.

= 2.9.3 =
Fixed issue #27
moved all external file calls to local


= 2.9.2 =
Fixed issue #25

= 2.9.1 =
Fixed Typo in line 1812, issue #24

= 2.9 =
Fixed "array" when repater field has something other then text field :).
has_field() now checks repeater fields as well.

= 2.8 =
Fixed issue #10 by moving ajax hook to constructor.
split demo meta box to 2 meta boxes.

= 2.7 =
Fixed Load js on edit pages only.

= 2.6 =
Fixed issue #13.
Fixed issue #14.

= 2.5 = 
Fixed Issue #11.
Added Sortable option to repeater field.

= 2.4 =
Fixed WP_DEBUG errors, and taxonomy field args notice.

= 2.3 = 
* added AMPM param to addTime to show time field with am/pm option

= 2.2 = 
* Fixed use with theme on custom path

= 2.1 = 
* Added Code Editor with syntax highlighting (php,css,html,javascript) using CodeMirror.

= 2.0 =
* Fixed Insert To Post bug

= 1.9 = 
* Fixed Image field functions in repeater block.

= 1.8 =
* fixed multiple image upload issue.
* cleaned js file from unused function.


= 1.7 =
* Fixed demo plugi file with new function names.
* Fixed Wysiwyg for version 3.3 once more, (which should work now).
* Fixed image upload field.

= 1.6 =
* Added an option to set path for themes.
* Fixed repeater dynamic editing

= 1.5 =
* Fixed Wysiwyg for version 3.3


= 1.2 =
* Fixed repeater block JS code.
* Offloaded images with an option to use local images.
* Added inline for repater block.
* Added genric addFiled function.

= 1.1 =
* Reapater Implemented and removed debug leftover var_dump

= 1.0 =
* First Release
[![Analytics](https://ga-beacon.appspot.com/UA-50573135-4/My-Meta-Box/main)](https://github.com/bainternet/My-Meta-Box)

my-meta-box's People

Contributors

anou avatar bainternet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

my-meta-box's Issues

how to put my option panel to custom menu?

i create a setting menu on admin menu because i don't want option panel under wordpress setting menu, i try to create a new menu on admin menu call Website Setting, how to put option panel to that menu?

can anyone tell me please!

Is there any way I can group content???

Hi,
I was looking at code and found no way of grouping elements like,

I want to show single title and then added two or more text boxes e.g.
Date
input field type date which is start date & input field type date which is ending date???

and also I want to group visually other elements as well

Like I would like to have a grouping of fields.

Lets say I have single meta box but I want to group its fields like
let say I have departments and I show

Depart one
its fields, text, textarea, date etc etc
Depart two
its fields, text, textarea, date etc etc
Depart three
its fields, text, textarea, date etc etc

etc etc, my point is I don't want to show multiple meta boxes for each I just want to group them visually by showing main Heading and then fields and their titles, descriptions etc.?????

Thanks,
Syed

Strange addColor behaviour

I''ve read through the issues with JS, installed 3.0.1. It's working within a plugin and everything's ok except addColor. The field shows up as a normal text box (saves & retrieves ok), no picker. I've checked Firebug for JS errors or otherwise, none show up. I've also added a Date field to the same box to test JS and curiously it works as it should (i.e. a calendar popup shows up, as expected). Thanks for the lib.

addFile Errors

After selecting a file to upload and saving the post the page errors out with the following:

Notice: Undefined index: _file_field_id in /meta-box-class/my-meta-box-class.php on line 1275

Warning: Cannot modify header information - headers already sent by (output started at /meta-box-class/my-meta-box-class.php:1275) in /wp/wp-includes/pluggable.php on line 876

The file is uploaded and the record created though.

No custom styles applying????

Hi,
I want to apply custom style inline and / or classes as well. I don't see any code line apply the present argument named style for fields, and would you be implementing class support, I would like to apply my custom classes to fields. or even their containers if possible???

Thanks,
Syed

Can I have description field???

Hi Bainternet,
I was wondering if I could have an option of adding description to the field??

I have a sample screenshot of my custom meta boxe created manually, may be that helps what I want.

Video Meta Box Edit Post My Local Site WordPress 2012-12-18 14-48-27

Let me know what you think.

Syed

Can you add helper function for inline javascript????

Hi Raz,
First of all thanks for the last updates you did, as per, select2, grouping of items.

Now I was working on some customizations and I felt there should be some helper function which allow me to add my own javascript based on my customizations.

Here is how I did it,
[code]

/**
* @var string
*/
private $_inline_js = '';

add_action('admin_footer', array($this, 'output_inline_js'), 25);

   function output_inline_js() {
        //only load styles and js when needed
        /*
         * since 1.8
         */
        global $typenow;
        if (in_array($typenow, $this->_meta_box['pages']) && $this->is_edit_page()) {
            echo "<!-- my meta box JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";

            // Sanitize
            $this->_inline_js = wp_check_invalid_utf8($this->_inline_js);
            $this->_inline_js = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", $this->_inline_js);
            $this->_inline_js = str_replace("\r", '', $this->_inline_js);

            // Output
            echo $this->_inline_js;

            echo "});\n</script>\n";

            $this->_inline_js = '';
        }
    }

/**
* Add some JavaScript inline to be output in the footer.
*
* @access public
* @param string $code
* @return void
*/
public function add_inline_js($code) {
$this->_inline_js .= "\n" . $code . "\n";
}
[/code]

Can you please add it in your plugin core???? I get the code from @woocommerce and its v. useful.

Let me know what you think???

File Upload fields won't save the attachments

Hi Man,

The class is working great so far, and BIG thanks for maintaining and developing it.
I have a small or not so small problem though...
I created a products custom post type where You can attach documents like pdf, doc, docs etc to a product.

I used the meta-box-class to create the fields:

$config4 = array(
'id' => 'ua_attachments',
'title' => 'Attach Your files',
'pages' => array('termek','post'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(),
'local_images' => false,
'use_with_theme' => true // I am using it as theme function not as a plugin
);

  $my_meta4 =  new AT_Meta_Box($config4);

  $my_meta4->addFile($prefix.'attach_mp3',array('name'=> 'MP3 attachment '));
  $my_meta4->addFile($prefix.'attach_zip',array('name'=> 'ZIP attachment '));
  $my_meta4->addFile($prefix.'attach_docx',array('name'=> 'DOCX attachment '));
  $my_meta4->addFile($prefix.'attach_xsl',array('name'=> 'XSL attachment '));
  $my_meta4->addFile($prefix.'attach_doc',array('name'=> 'DOC attachment '));

  $my_meta4->Finish();

The problem occurs when I try to publish, or update the post because they will disappear instantly.
I am developing using MAMP and the newest WP version (3.4.2). I checked the upload folder, and I can see the product images (I used metabox class for them too), but I cannot see the files which I attached to the product.

I looked into the Wiki, but I couldn't find the file upload field description in the Fields Options and API section.

Would You be so kind to help me out with this issue?

Thanks in advance, and please let me know if You need additional info to solve this bug!

Best Wishes,
Matt

datepicker depends on select-field

My problem: without a Select-field the date and time picker do not show up. I slimmed down the demo file to the first box and added a date-field. No picker until I add a Select-field, too. I hope it´s my fault or just a little jQuery thing.
Anyway: Thanks.

WYSIWYG Error on Repeating Blocks

When trying to add a WYSIWYG Field to a Repeater Block, It doesn't work and I get the following error from Google Chrome Dev Tools:

Uncaught SyntaxError: Unexpected token <

and it references this line of code as the issue:

HTML

It looks like this is some jQuery output by WordPress as I couldn't find it anywhere in the class files.

Any ideas on this?

Any plans on an "hide-options-after-this" Checkbox?

So far the class is great! we have build an images-only radio-field (will do a pull-request after we cleaned up the code, its a parent-class, atm), thanks!

It would be great to have a checkbox that enables a block of options that come after it. Like a repeater-box but as a one-time-thing. Any ideas how to implement that without reinventing-the-wheel?

Screenshot_02_01_2013_18_16

Any plans on an image select field?

Do you have any plans to add an image-select field? An example would be an array like this:

array(
    'id' => '13',
    'type' => 'radio_img',
    'title' => __('Radio Image Option', Redux_TEXT_DOMAIN), 
    'sub_desc' => __('No validation can be done on this field type', Redux_TEXT_DOMAIN),
    'desc' => __('This is the description field, again good for additional info.', Redux_TEXT_DOMAIN),
    'options' => array(
        '1' => array('title' => 'Opt 1', 'img' => 'images/align-none.png'),
        '2' => array('title' => 'Opt 2', 'img' => 'images/align-left.png'),
        '3' => array('title' => 'Opt 3', 'img' => 'images/align-center.png'),
        '4' => array('title' => 'Opt 4', 'img' => 'images/align-right.png')
    ), // Must provide key => value(array:title|img) pairs for radio options
    'std' => '2'
),

(used here)

If not we might have a go at it, just don't want to step on any toes.

add date meta box

I am trying to get the date picker to work. I have the meta box showing in my post area. The field shows but when I click in it to add the date, the date picker does not show.

if (is_admin()){

require_once("inc/meta-box-class/amaranthe_meta_box_class.php");
$prefix = '_ba_';

$config = array(
    'id' => 'showdates',             // meta box id, unique per meta box
    'title' => 'Tour Dates',      // meta box title
    'pages' => array('post'),    // post types, accept custom post types as well, default is array('post'); optional
    'context' => 'side',               // where the meta box appear: normal (default), advanced, side; optional
    'priority' => 'low',                // order of meta box: high (default), low; optional
    'fields' => array(),                 // list of meta fields (can be added by field arrays) or using the class's functions
    'local_images' => false,             // Use local or hosted images (meta box images for add/remove)
    'use_with_theme' => get_template_directory_uri() .'/inc/meta-box-class/amaranthe_meta_box_class.php'            //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);

$amaranthe_meta = new AT_Meta_Box($config);

$amaranthe_meta->addDate($prefix.'showdates',array('name'=> 'Show Date '));
$amaranthe_meta->Finish();

}

Repeater field not displaying on front end

Hi thanks for this great plugin, I am using it for repeater fields in my custom post type. But i am not able get any output of the values in my template files. I read the wiki too. But $saved_data is just empty i think. Can you help me on this? when i open the post for editing, I am able to see all the data inside fields but can't display it on front end. Please help

Including in a theme?

I like this fork a lot.

How easy is it to include in a theme rather than a plugin?

Translate meta-box title and other input label, desc...

Hello,
I'm trying to make my custom meta-boxes multilingual this way with the __() WP function. For example:

$config = array(
    'id' => 'upload_img_slider',             // meta box id, unique per meta box
    'title' => __('Slider images','iftheme'),      // meta box title
    'pages' => array('if_slider'),    // post types, accept custom post types as well, default is array('post'); optional
    'context' => 'normal',               // where the meta box appear: normal (default), advanced, side; optional
    'priority' => 'high',                // order of meta box: high (default), low; optional
    'fields' => array(),                 // list of meta fields (can be added by field arrays) or using the class's functions
    'local_images' => true,             // Use local or hosted images (meta box images for add/remove)
    'use_with_theme' => true            //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
$slider = new AT_Meta_Box($config); 
global $current_user;
if($current_user->ID == 1) { $slider->addCheckbox('is_country',array('name'=> __('Country slider','iftheme'), 'desc'=>__("Check this box if this slider is for Country homepage",'iftheme'))); }

$repeater_fields[] = $slider->addText('slide_title',array('name'=> __('Title / Description', 'iftheme')),true);
$repeater_fields[] = $slider->addText('url_img_slide',array('name'=> __('URL link for the image', 'iftheme')),true);
$repeater_fields[] = $slider->addImage('image_slide',array('name'=> __('Image', 'iftheme')),true);

...ETC...

I get all the strings in my .PO but seems like they are printed by WP before parsing thru my PO file and on the create/edit page of my content they still in English.

Surely I'm doing something wrong ?

Thanks for you're help.

Checkbox inside a conditional block has the wrong size (15 instead of 83)

When a heckbox is placed inside a conditional block it has the wrong size.

Code (just added a checkbox to the conditional block in the demo:

/**
   * To Create a Conditional Block first create an array of fields (just like a repeater block
   * use the same functions as above but add true as a last param
   */
  $Conditinal_fields[] = $options_panel->addText('con_text_field_id',array('name'=> __('My Text ','apc')),true);
  $Conditinal_fields[] = $options_panel->addTextarea('con_textarea_field_id',array('name'=> __('My Textarea ','apc')),true);
  $Conditinal_fields[] = $options_panel->addImage('con_image_field_id',array('name'=> __('My Image ','apc')),true);
  $Conditinal_fields[] = $options_panel->addCheckbox('checkbox_field_id',array('name'=> __('My Checkbox ','apc'), 'std' => true),true );

  /**
   * Then just add the fields to the repeater block
   */
  //conditinal block
  $options_panel->addCondition('conditinal_fields',
      array(
        'name'=> __('Enable conditinal fields? ','apc'),
        'desc' => __('<small>Turn ON if you want to enable the <strong>conditinal fields</strong>.</small>','apc'),
        'fields' => $Conditinal_fields,
        'std' => false
      ));

Adding a "Save" button

I want to add a save button directly in the widget box.

I just wanted to ask if someone has done this before and is able to share the solution and/or a few pointers? That'd be greatly appreciated.

My plan is to use an Ajax call that's posting to my own function that'll save the custom fields. I'll investigate if I can hook into the functionality of "my meta box" to do that in the same way a post save/update would work.

Thoughts? Ideas?

Thanks!!

Javascript errors????

Hi Raz,
a) I saw error when I didn't used color picker on my meta box.
[code]
$('.at-color-iris').wpColorPicker();
[/code]
b)
b) I saw error when I didn't used any select but strangely I saw error even when I used select but in the form of addPosts, so it was treated as 'posts' type so select2 wasn't loaded and this code thrown error
[code]
$(this).select2();
[/code]

My suggestion: Could you use wp_localize_script, so we can better handle javascrip properly, like
you detect if select2 or color picker or similar script is loaded or not, so add global variables so you can detect those variables values in javascript and act accordingly.

Like in case of select2, execute its relevant code only if global variable says its loaded.

And you know better how to use wp_localize_script.

It will be good to have better code handling to avoid errors like above.

Syed

Full utilization of select2????

Hi Raz,
Thanks for adding select2 plugin, I really liked using it :). I have some suggestions I hope you will like them.
a) You should modify the default code for select2 implementation.
[code]
$("select").each(function (){
if(! $(this).hasClass('no-fancy'))
$(this).select2();
});
[/code]

its making every select on page select2 able, thats not necessary or good idea I think. Why not make it conditional like

[code]
$(".select2").each(function (){
if(! $(this).hasClass('no-fancy'))
$(this).select2();
});
[/code]
this means, we should make it optional, like if we attach class to any element, it should become select2 'able, that will make more customizeable.

Also I would like to see some codes so we can use select2 more easily like
I would like to see support for
select, or the local or tags,

by utilizing classes for basic functionality,

this is how I tried to achieve it.
[code]
$("[class*=select2_]").each(function (){
if($(this).hasClass("select2_tags")){
var tagSeperator = " ";
if($(this).hasClass("tokenSeparators_comma")){
tagSeperator = ",";
}
$(this).select2({
tags:[],
tokenSeparators: [tagSeperator] //, " "
});
}
});
[/code]
I hope that code is self explanatory, so could you please make class more select2 friendly so I can utilize it.

Syed

css not working in custom theme

Hi, I tried to add the reapeater field in functions file. But I can't see the add and remove button in admin. Else working fine. Plz suggest what should be done.
Add New Page autoX WordPress 2013-01-28 12-26-12

addCheckBoxList

Hi,

Firstly, I'd like to thank you for doing such a great job on this meta box class. It has saved me a heap of work on a client's site. And I will definitely be using this code again in the future.

I was implementing a checkbox list, when I noticed that the checkboxes were not rendering to the dashboard page. I looked in the code and changed line 1527 of my-meta-box-class.php to the following:

    $new_field = array('type' => 'checkbox_list','id'=> $id,'std' => array(),'desc' => '','style' =>'','name' => 'Checkbox List Field','multiple' => true,'options' => $options);

i.e. I copied and modified the addSelect $new_field array elements:
'multiple' => true,
'options' => $options

This fixes the checkbox list issue.

Happy coding

Ajax

Error when image is the first element in a repeater field

I am getting an error " Array to string conversion in /Volumes/Disk 1/MAMP/wpdev/wp-content/plugins/slideshow/inc/meta-box-class/my-meta-box-class.php on line 518" when an image is the first item in a repeater field. Personally I think a small 50x50 thumbnail would be a great label here. I will try to work on it and submit a patch.

Image Uploader

So, the image uploader previously wasn't working for the image fields, but now that it's working, I can no longer upload images and insert them in WYSIWYG fields. . .

Image Uploader doesn't work. class-usage-demo.php doesn't work.

Hey,
I noticed a few issues with your class.

  1. The wysiwyg editor doesn't work for me (WP3.3).

  2. The image uploader doesn't work too. The upload window opens, I can select one or more images but everytime I update/save the post all images disappear. I assume that they're not saved correctly. (WP3.3)

  3. The class-usage-demo.php demo causes fatal errors. I think the reason is that you renamed all "addXYField" functions to "addXY".

Wordpress 3.5 - Date field issue

Hi,

It seems that there`s a little bug with the class related to this new WordPress 3.5 update

The date field issue is breaking the WordPress dashboard.

$date_field->addDate($prefix.'field_date_id',array('name'=> 'Date '));

The error is a javascript one and sounds like this :"Cannot read property 'length' of undefined ".

I guess is related to the jQuery update to 1.8.3 WordPress made.

Thank you!

addPosts() not using custom post type when set outside of args

Noticed this issue when adding a custom post type to an addPosts() field. The function as documented at https://github.com/bainternet/My-Meta-Box/wiki/Posts-Field lets you pass a custom post type seperately from the args array, but then does not use it.

I am not sure if this is intentional and the wiki is incorrect, or if the wiki simply describes intended functionality that does not work.

I recommend either clarifying in the wiki that post_type must be added to the args array explicitly and removing the reference to post_type outside of args, or adding something similar to the below at line 998 in the class, before the get_posts() call:

if (!isset($options['args']['post_type'])){
    $options['args']['post_type'] = $options['post_type'];
}

select2 and it ajax utlization???

Hi Raz,
I tried to utilize the select2 ajax capabilities and was successful partially, this is what I tried to achieve,
I want to make addPosts to be select2 ajax friendly, so instead of loading all the posts in the field, we should allow user to search the posts and select one from the founds posts in result. I am able to successfully achieve it, and its being saved to database as well, but only issue that arises is when page loads, it doesn't populate the field properly. It only stores the post id, where as when searching it shows post titles in dropdown and their ids as values.

Here is my code
[code]

function postFormatResult(post) {
var markup = "<table class='movie-result'>";
if (post.thumbnail !== undefined && post.posters.thumbnail !== undefined) {
markup += "<td class='movie-image'><img src='" + post.posters.thumbnail + "'/>";
}
markup += "<td class='movie-info'><div class='movie-title'>" + post.title + "";
markup += ""
return markup;
}

function postFormatSelection(post) {
return post.title;
}
$(".select_2_search").select2({
placeholder: "Search...",
minimumInputLength: 3,
ajax: {
url: "' . admin_url('admin-ajax.php', 'relative') . '",
dataType: "json",
quietMillis: 100,
data: function (term, page) {
return {
term: term, //search term
action: "custom_json_search_posts" //wordpress action
};
},
results: function (data, page) {
return {
results: data.posts
};
}
},
formatResult: postFormatResult,
formatSelection: postFormatSelection,
dropdownCssClass: "bigdrop" // apply css that makes the dropdown taller
});
[/code]

and wordpress backend code
[code]
add_action('wp_ajax_custom_json_search_posts', 'custom_json_search_posts');
function custom_json_search_posts($x = '', $post_types = array('post')) {
//global $post;
//check_ajax_referer('search-posts', 'security');

$term = (string) urldecode(stripslashes(strip_tags($_GET['term'])));

if (empty($term))
    die();

    $args = array(
        'post_type' => $post_types,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        's' => $term,
        'fields' => 'ids'
    );

$posts = get_posts($args);

$found_posts = array();
$counter = 0;
if ($posts) {
    foreach ($posts as $post) {
        $found_posts[$counter]['id'] = $post;
        $found_posts[$counter]['title'] = get_the_title($post) . ' &ndash; #' . $post; 
        $found_posts[$counter]['posters']['thumbnail'] = 'thumbnail.png'; 
        $counter++;
    }
}
wp_reset_postdata();
$response_found_posts['total'] = 10;
$response_found_posts['posts'] = $found_posts;
echo json_encode($response_found_posts);

die();

}

[/code]

Hope that helps, I saw the similar feature inside woocommerce which utilizes chosen, and ajaxChosen, and works fine, so it will be great to have similar code working inside your class.

Thanks,
Syed

repeater posts_field & taxonomy_field

When including addPosts or addTaxonomy to a repeater I see an 'unterminated string literal' message from firebug. I am able to use any other field type without problems.

Also, no matter what I choose for the post type for the posts_field, it displays the ('post_type' => 'post') titles in the dropdown in the admin.

Would be considering implement multisite support????

Hi,
I was wondering would you be able to implement multisite support?? I mean like post or page restrictions for meta box showing I would like to restrict my meta boxes to certain blogs in multisite network, like
I want to show it on blog with id lets say 1, 3 and 5, but doesn't want my meta box to be shown on 2 & 4 blogs (by their ID's).
I am doing hacky way, but its not stable,
on metabox creation I am passing.
[code]
'show_in_blog' => array(1,3,5), //blog id(s) on which it will be shown
OR
'hide_in_blog' => array(2, 4), //blog id(s) on which it will not be shown
[/code]
and on class I changed
public function add() ;

and added this check in start of function
[code]
global $blog_id;
if (isset($this->_meta_box['show_in_blog'])
&& !empty($this->_meta_box['show_in_blog'])) {
if (!in_array($blog_id, $this->_meta_box['show_in_blog'])) {
return;
}
} else if (isset($this->_meta_box['hide_in_blog'])
&& !empty($this->_meta_box['hide_in_blog'])) {
if (in_array($blog_id, $this->_meta_box['hide_in_blog'])) {
return;
}
}
[/code]
and also changed
public function add_missed_values();
and added extra parameters
[code]
// Default values for meta box
$this->_meta_box = array_merge(array('context' => 'normal', 'priority' => 'high', 'pages' => array('post'), 'show_in_blog' => array(), 'hide_in_blog' => array()), (array) $this->_meta_box);
[/code]
Please have a look at tell me if you can do it??? and implement better logic. I would appreciate if you look into this as this way I will be able to get benefits from your updates.
Thanks,
Syed

Add Posts not working.

I tried demo on multisite and its stopped processing my script further after this line

$my_meta->addPosts($prefix . 'posts_field_id', array('post_type' => 'post'), array('name' => 'My Posts '));

I am using it in theme and set the 'use_with_theme' => true.

Also I was wondering if you could provide a config option for blog_id, I mean like showing it on post I also want to have a control over my multisite blogs, to show only on predefined blogs not on all.

Like

'pages' => array('post'),

this controls where to show I want similar option.

'blogs' => array(1,2,3),

Note: I am debugging my development environment and I no see any error logged after that point :(.

Let me know what you think.

Thanks,
Syed

Dropdown User

It would be great if there would be a drop down field like "post list dropdown' but for Users.

Repeater field "Illegal offset"

I use repeater field for one field only - addPosts. Those "posts" are actually custom post type o7_application which I wanna add to a custom post type "character" since every character has 0 or many applications.

$config = array(
    'id' => 'character_applications',   // meta box id, unique per meta box
    'title' => 'Character Applications',    // meta box title
    'pages' => array('character'),  // post types, accept custom post types as well, default is array('post'); optional
    'context' => 'side',                // where the meta box appear: normal (default), advanced, side; optional
    'priority' => 'low',                // order of meta box: high (default), low; optional
    'fields' => array(),                // list of meta fields (can be added by field arrays)
    'local_images' => true,         // Use local or hosted images (meta box images for add/remove)
    'use_with_theme' => true            //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
$my_meta =  new AT_Meta_Box($config);
$repeater_fields[] = $my_meta->addPosts($prefix.'application', array('post_type' => 'o7_application'), array('name'=> 'Application '), true);
$my_meta->addRepeaterBlock($prefix.'applications', array('name' => 'Applications', 'fields' => $repeater_fields));
$my_meta->Finish();

The error I'm getting is: Warning: Illegal offset type in .../meta-box-class/my-meta-box-class.php on line 517

I don't know what is supposed to happen on line 517 but for me I solved it like this: $mmm = ($me[$field['fields'][0]['id']]) ? get_the_title($me[$field['fields'][0]['id']]) : "";

You should look into that ;)

Image Uploader

Adding more than 1 image field doesn't work. Only the first image upload field will work with the Thickbox.

But even using just one image uploader isn't working for me. When I upload the image and click insert selected image, I just get a white screen in the thickbox and nothing is inserted.

Are you using any jquery plugins for multiselect and / or select????

Hi,
I tried to find any jquery plugin which enhances my long select / multiple select or even grouped one's into autocomplete and better looking. I mean by this is

I have implemented this

https://github.com/harvesthq/chosen/

into your class and I liked it, this is how it done it

I added this extra check inside
public function load_scripts_styles();
[code]
//check for select, multiselect field
$this->check_field_select();
[/code]

and added
this function
[code]
public function check_field_select() {

        if ($this->has_field('select') && $this->is_edit_page()) {
            $plugin_path = $this->SelfPath;
            // Enqueu JQuery chosen library, use proper version.
            wp_enqueue_style('at-multiselect-chosen-css', $plugin_path . '/js/jquery-ui/chosen.css', array(), null);

            wp_enqueue_script('at-multiselect-chosen-js', $plugin_path . '/js/jquery-ui/chosen.jquery.min.js', array('jquery'), false, true);
        }
    }

[/code]

and also added this javascript code inside "meta-box.js"

in line
[code]
var Ed_array = Array;
jQuery(document).ready(function($) {
//added bellow code for chosen
$(".at-select").chosen();
[/code]

Hoping that you will look into this and implement it officially.

Thanks,
Syed

Fix select2 if condition

Hi,
There is an bug with if condition related select2.

"meta-box-class/js/meta-box.js"
line 308:
if($.select2)

should be
if (window.Select2 !== undefined)

I tried to send pull request but failed :), as I am not familiar with system properly. So opening issue.

Note: I have given a thought to what you said about merging this to admin page class, I believe its not necessary, instead what I found you should look into is building common class for input elements, like for text, textarea, etc etc. So you can utilize it on all plugins (my meta box and etc). And that way you will have to only fix once or add new feature once and will not have to redo for all plugins. Its just an idea that popped into my mind :).

Thanks,
Syd

Date & Timepicker Issue

First off, very big THANK YOU for all the work you've put into this. It's an awesome script and a HUGE time saver!

Anyway, when I try to use the datepicker and timepicker fields, I get js errors that also cause the image uploaders not to work.

The error shows:

meta-box.js:223Uncaught TypeError: Object [object Object] has no method 'datepicker'

If I remove the date field, then I get a timepicker error:

Uncaught TypeError: Object [object Object] has no method 'timepicker'

If I remove both the date and time fields from my meta box, all other meta boxes work just fine.

Any ideas? Perhaps it's a user error on my part?

This is the code I've used to create the meta boxes. . .

$my_meta->addDate($prefix.'date_field_id',array('name'=> 'Date '));
$my_meta->addTime($prefix.'time_field_id',array('name'=> 'Time '));

Insert to Post missing?

So, now that the Image uploader is working for the WYSIWYG Field, I noticed that it only works for uploading NEW content form the desktop.

If you try to insert previously uploaded content, there is no "Insert to Post" option.

Any ideas?

Repeater Blocks

So, I have created a repeater block to use on one custom post type, with 2 select boxes in the repeater block. It works perfect.

However, I created another meta box to use on another custom post type, and added a repeater block with an input and a select.

Now, when I click the + to add a new repeater block, both repeater blocks get added, instead of just the one intended for that post type.

Hopefully this makes sense.

I can send screenshots if that helps.

Thanks,

Jason

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.