From f99e1a6421b01146a005de038b8c47bdeed70412 Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:20:41 +0100 Subject: [PATCH 1/9] redeclare some methods according to wordpress warnings --- wp-content/wpalchemy/MetaBox.php | 192 +++++++++++++++---------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 27bccdb..a9d0a52 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -88,12 +88,12 @@ class WPAlchemy_MetaBox var $template; /** - * Used to set the post types that the meta box can appear in, this option + * Used to set the post types that the meta box can appear in, this option * should be used when instantiating the class. * * @since 1.0 * @access public - * @var array + * @var array */ var $types; @@ -110,7 +110,7 @@ class WPAlchemy_MetaBox * @var bool */ var $priority = 'high'; - + /** * @since 1.0 * @access public @@ -121,8 +121,8 @@ class WPAlchemy_MetaBox /** * Used to set how the class does its data storage, data will be stored as * an associative array in a single meta entry in the wp_postmeta table or - * data can be set and individual entries in the wp_postmeta table, the - * following constants should be used when setting this option, + * data can be set and individual entries in the wp_postmeta table, the + * following constants should be used when setting this option, * WPALCHEMY_MODE_ARRAY (default) and WPALCHEMY_MODE_EXTRACT, this option * should be used when instantiating the class. * @@ -229,7 +229,7 @@ class WPAlchemy_MetaBox var $include_post_id; /** - * Callback used on the WordPress "admin_init" action, the main benefit is + * Callback used on the WordPress "admin_init" action, the main benefit is * that this callback is executed only when the meta box is present, this * option should be used when instantiating the class. * @@ -344,7 +344,7 @@ class WPAlchemy_MetaBox * @var bool optional */ var $use_media_buttons = FALSE; - + /** * Used to hide the meta box title, this option should be used when * instantiating the class. @@ -357,7 +357,7 @@ class WPAlchemy_MetaBox var $hide_title = FALSE; /** - * Used to lock a meta box in place, possible values are: top, bottom, + * Used to lock a meta box in place, possible values are: top, bottom, * before_post_title, after_post_title, this option should be used when * instantiating the class. * @@ -444,11 +444,11 @@ class WPAlchemy_MetaBox * @see have_fields_and_multi(), have_fields() */ var $_loop_data; - + function WPAlchemy_MetaBox($arr) { $this->_loop_data = new stdClass; - + $this->meta = array(); $this->types = array('post', 'page'); @@ -467,7 +467,7 @@ function WPAlchemy_MetaBox($arr) if (empty($this->template)) die('Meta box template file required'); // check for nonarray values - + $exc_inc = array ( 'exclude_template', @@ -497,13 +497,13 @@ function WPAlchemy_MetaBox($arr) // convert depreciated variables if ($this->lock_on_top) $this->lock = WPALCHEMY_LOCK_TOP; elseif ($this->lock_on_bottom) $this->lock = WPALCHEMY_LOCK_BOTTOM; - + add_action('admin_init', array($this,'_init')); // uses the default wordpress-importer plugin hook add_action('import_post_meta', array($this, '_import'), 10, 3); } - else + else { die('Associative array parameters required'); } @@ -524,7 +524,7 @@ function _import($post_id, $key, $value) // using $wp_import to get access to the raw postmeta data prior to it getting passed // through "maybe_unserialize()" in "plugins/wordpress-importer/wordpress-importer.php" // the "import_post_meta" action is called after "maybe_unserialize()" - + global $wp_import; foreach ( $wp_import->posts as $post ) @@ -538,7 +538,7 @@ function _import($post_id, $key, $value) // try to fix corrupted serialized data, specifically "\r\n" being converted to "\n" during wordpress XML export (WXR) // "maybe_unserialize()" fixes a wordpress bug which double serializes already serialized data during export/import $value = maybe_unserialize( preg_replace( '!s:(\d+):"(.*?)";!es', "'s:'.strlen('$2').':\"$2\";'", stripslashes( $meta['value'] ) ) ); - + update_post_meta( $post_id, $key, $value ); } } @@ -558,7 +558,7 @@ function _init() { // must be creating or editing a post or page if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; - + if ( ! empty($this->output_filter)) { $this->add_filter('output', $this->output_filter); @@ -566,7 +566,7 @@ function _init() if ($this->can_output()) { - foreach ($this->types as $type) + foreach ($this->types as $type) { add_meta_box($this->id . '_metabox', $this->title, array($this, '_setup'), $type, $this->context, $this->priority); } @@ -626,7 +626,7 @@ function _init() /** * Used to insert STYLE or SCRIPT tags into the head, called on WordPress * admin_head action. - * + * * @since 1.3 * @access private * @see _foot() @@ -786,7 +786,7 @@ function _foot() ob_end_clean(); } - + // filter: foot if ($this->has_filter('foot')) { @@ -812,7 +812,7 @@ function _foot() function _setup() { $this->in_template = TRUE; - + // also make current post data available global $post; @@ -824,7 +824,7 @@ function _setup() // use include because users may want to use one templete for multiple meta boxes include $this->template; - + // create a nonce for verification echo ''; @@ -834,7 +834,7 @@ function _setup() /** * Used to properly prefix the filter tag, the tag is unique to the meta * box instance - * + * * @since 1.3 * @access private * @param string $tag name of the filter @@ -948,7 +948,7 @@ function has_action($tag, $function_to_check = FALSE) /** * Uses WordPress remove_action() function, see WordPress remove_action() - * + * * @since 1.3 * @access public * @link http://core.trac.wordpress.org/browser/trunk/wp-includes/plugin.php#L513 @@ -981,7 +981,7 @@ function do_action($tag, $arg = '') * @return bool * @see _is_page() */ - function _is_post() + private static function _is_post() { if ('post' == WPAlchemy_MetaBox::_is_post_or_page()) { @@ -1019,7 +1019,7 @@ function _is_page() * @return string "post" or "page" * @see _is_post(), _is_page() */ - function _is_post_or_page() + private static function _is_post_or_page() { $post_type = WPAlchemy_MetaBox::_get_current_post_type(); @@ -1046,7 +1046,7 @@ function _is_post_or_page() * @since 1.4.6 * @return string [custom_post_type], page or post */ - function _get_current_post_type() + static function _get_current_post_type() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; @@ -1102,7 +1102,7 @@ function _get_post_id() { return (integer) $post_id; } - + return null; } @@ -1118,10 +1118,10 @@ function can_output() $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); } - if + if ( - !empty($this->exclude_category) OR - !empty($this->exclude_category_id) OR + !empty($this->exclude_category) OR + !empty($this->exclude_category_id) OR !empty($this->include_category) OR !empty($this->include_category_id) ) @@ -1129,10 +1129,10 @@ function can_output() $categories = wp_get_post_categories($post_id,'fields=all'); } - if + if ( - !empty($this->exclude_tag) OR - !empty($this->exclude_tag_id) OR + !empty($this->exclude_tag) OR + !empty($this->exclude_tag_id) OR !empty($this->include_tag) OR !empty($this->include_tag_id) ) @@ -1145,25 +1145,25 @@ function can_output() $can_output = TRUE; // include all - if + if ( - !empty($this->exclude_template) OR - !empty($this->exclude_category_id) OR - !empty($this->exclude_category) OR + !empty($this->exclude_template) OR + !empty($this->exclude_category_id) OR + !empty($this->exclude_category) OR !empty($this->exclude_tag_id) OR !empty($this->exclude_tag) OR !empty($this->exclude_post_id) OR - !empty($this->include_template) OR - !empty($this->include_category_id) OR - !empty($this->include_category) OR - !empty($this->include_tag_id) OR - !empty($this->include_tag) OR + !empty($this->include_template) OR + !empty($this->include_category_id) OR + !empty($this->include_category) OR + !empty($this->include_tag_id) OR + !empty($this->include_tag) OR !empty($this->include_post_id) ) { if (!empty($this->exclude_template)) { - if (in_array($template_file,$this->exclude_template)) + if (in_array($template_file,$this->exclude_template)) { $can_output = FALSE; } @@ -1173,7 +1173,7 @@ function can_output() { foreach ($categories as $cat) { - if (in_array($cat->term_id,$this->exclude_category_id)) + if (in_array($cat->term_id,$this->exclude_category_id)) { $can_output = FALSE; break; @@ -1185,11 +1185,11 @@ function can_output() { foreach ($categories as $cat) { - if + if ( in_array($cat->slug,$this->exclude_category) OR in_array($cat->name,$this->exclude_category) - ) + ) { $can_output = FALSE; break; @@ -1201,7 +1201,7 @@ function can_output() { foreach ($tags as $tag) { - if (in_array($tag->term_id,$this->exclude_tag_id)) + if (in_array($tag->term_id,$this->exclude_tag_id)) { $can_output = FALSE; break; @@ -1213,11 +1213,11 @@ function can_output() { foreach ($tags as $tag) { - if + if ( - in_array($tag->slug,$this->exclude_tag) OR + in_array($tag->slug,$this->exclude_tag) OR in_array($tag->name,$this->exclude_tag) - ) + ) { $can_output = FALSE; break; @@ -1227,7 +1227,7 @@ function can_output() if (!empty($this->exclude_post_id)) { - if (in_array($post_id,$this->exclude_post_id)) + if (in_array($post_id,$this->exclude_post_id)) { $can_output = FALSE; } @@ -1235,13 +1235,13 @@ function can_output() // excludes are not set use "include only" mode - if + if ( - empty($this->exclude_template) AND - empty($this->exclude_category_id) AND - empty($this->exclude_category) AND - empty($this->exclude_tag_id) AND - empty($this->exclude_tag) AND + empty($this->exclude_template) AND + empty($this->exclude_category_id) AND + empty($this->exclude_category) AND + empty($this->exclude_tag_id) AND + empty($this->exclude_tag) AND empty($this->exclude_post_id) ) { @@ -1250,7 +1250,7 @@ function can_output() if (!empty($this->include_template)) { - if (in_array($template_file,$this->include_template)) + if (in_array($template_file,$this->include_template)) { $can_output = TRUE; } @@ -1260,7 +1260,7 @@ function can_output() { foreach ($categories as $cat) { - if (in_array($cat->term_id,$this->include_category_id)) + if (in_array($cat->term_id,$this->include_category_id)) { $can_output = TRUE; break; @@ -1272,7 +1272,7 @@ function can_output() { foreach ($categories as $cat) { - if + if ( in_array($cat->slug,$this->include_category) OR in_array($cat->name,$this->include_category) @@ -1288,7 +1288,7 @@ function can_output() { foreach ($tags as $tag) { - if (in_array($tag->term_id,$this->include_tag_id)) + if (in_array($tag->term_id,$this->include_tag_id)) { $can_output = TRUE; break; @@ -1300,11 +1300,11 @@ function can_output() { foreach ($tags as $tag) { - if + if ( in_array($tag->slug,$this->include_tag) OR in_array($tag->name,$this->include_tag) - ) + ) { $can_output = TRUE; break; @@ -1314,7 +1314,7 @@ function can_output() if (!empty($this->include_post_id)) { - if (in_array($post_id,$this->include_post_id)) + if (in_array($post_id,$this->include_post_id)) { $can_output = TRUE; } @@ -1361,7 +1361,7 @@ function _global_head() jQuery(function($) { $(document).click(function(e) - { + { var elem = $(e.target); if (elem.attr('class') && elem.filter('[class*=dodelete]').length) @@ -1385,9 +1385,9 @@ function _global_head() { elem.parents('.wpa_group').remove(); } - + var the_group = elem.parents('.wpa_group'); - + if(the_group && the_group.attr('class')) { the_name = the_group.attr('class').match(/wpa_group-([a-zA-Z0-9_-]*)/i); @@ -1487,7 +1487,7 @@ function checkLoopLimit(name) } } } - + /* do an initial limit check, show or hide buttons */ $('[class*=docopy-]').each(function() { @@ -1588,7 +1588,7 @@ function _meta($post_id = NULL, $internal = FALSE) if ( ! empty($fields) AND is_array($fields)) { $meta = array(); - + foreach ($fields as $field) { $field_noprefix = preg_replace('/^' . $this->prefix . '/i', '', $field); @@ -1639,7 +1639,7 @@ function the_field($n, $hint = NULL) function have_value($n = NULL) { if ($this->get_the_value($n)) return TRUE; - + return FALSE; } @@ -1763,7 +1763,7 @@ function get_the_name($n = NULL) if (!is_null($n)) $the_field = $this->id . '[' . $this->name . '][' . $this->current . '][' . $n . ']' ; - else $the_field = $this->id . '[' . $this->name . '][' . $this->current . ']' ; + else $the_field = $this->id . '[' . $this->name . '][' . $this->current . ']' ; } else { @@ -2004,7 +2004,7 @@ function get_the_group_open($t = 'div') $loop_open = NULL; $loop_open_classes = array('wpa_loop', 'wpa_loop-' . $this->name); - + $css_class = array('wpa_group', 'wpa_group-'. $this->name); if ($this->is_first()) @@ -2050,12 +2050,12 @@ function the_group_close() function get_the_group_close() { $loop_close = NULL; - + if ($this->is_last()) { $loop_close = ''; } - + return 'group_tag . '>' . $loop_close; } @@ -2069,7 +2069,7 @@ function have_fields_and_multi($n, $options = NULL) { // use as stdClass object $options = (object)$options; - + $length = @$options->length; $this->_loop_data->limit = @$options->limit; @@ -2120,13 +2120,13 @@ function _loop($n,$length=NULL,$and_one=0) { $this->in_loop = TRUE; } - + $this->name = $n; $cnt = count(!empty($this->meta[$n])?$this->meta[$n]:NULL); $length = is_null($length) ? $cnt : $length ; - + if ($this->in_loop == 'multi' AND $cnt > $length) $length = $cnt; $this->length = $length; @@ -2171,11 +2171,11 @@ function _loop($n,$length=NULL,$and_one=0) * @since 1.0 * @access private */ - function _save($post_id) + function _save($post_id) { /** - * note: the "save_post" action fires for saving revisions and post/pages, - * when saving a post this function fires twice, once for a revision save, + * note: the "save_post" action fires for saving revisions and post/pages, + * when saving a post this function fires twice, once for a revision save, * and again for the post/page save ... the $post_id is different for the * revision save, this means that "get_post_meta()" will not work if trying * to get values for a revision (as it has no post meta data) @@ -2187,28 +2187,28 @@ function _save($post_id) */ $real_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : NULL ; - + // check autosave if (defined('DOING_AUTOSAVE') AND DOING_AUTOSAVE AND !$this->autosave) return $post_id; - + // make sure data came from our meta box, verify nonce $nonce = isset($_POST[$this->id.'_nonce']) ? $_POST[$this->id.'_nonce'] : NULL ; if (!wp_verify_nonce($nonce, $this->id)) return $post_id; - + // check user permissions - if ($_POST['post_type'] == 'page') + if ($_POST['post_type'] == 'page') { if (!current_user_can('edit_page', $post_id)) return $post_id; } - else + else { if (!current_user_can('edit_post', $post_id)) return $post_id; } - + // authentication passed, save data - + $new_data = isset( $_POST[$this->id] ) ? $_POST[$this->id] : NULL ; - + WPAlchemy_MetaBox::clean($new_data); if (empty($new_data)) @@ -2242,7 +2242,7 @@ function _save($post_id) foreach ($new_data as $k => $v) { $field = $this->prefix . $k; - + array_push($new_fields,$field); $new_value = $new_data[$k]; @@ -2324,25 +2324,25 @@ function clean(&$arr) { foreach ($arr as $i => $v) { - if (is_array($arr[$i])) + if (is_array($arr[$i])) { WPAlchemy_MetaBox::clean($arr[$i]); - - if (!count($arr[$i])) + + if (!count($arr[$i])) { unset($arr[$i]); } } - else + else { - if ('' == trim($arr[$i]) OR is_null($arr[$i])) + if ('' == trim($arr[$i]) OR is_null($arr[$i])) { unset($arr[$i]); } } } - if (!count($arr)) + if (!count($arr)) { $arr = array(); } @@ -2354,7 +2354,7 @@ function clean(&$arr) foreach ($keys as $key) { - if (!is_numeric($key)) + if (!is_numeric($key)) { $is_numeric = FALSE; break; From c4700c867778abd7dd41a28b6bd7485c514308e1 Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:23:31 +0100 Subject: [PATCH 2/9] another function I forgot --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index a9d0a52..7b4b8b5 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1000,7 +1000,7 @@ private static function _is_post() * @return bool * @see _is_post() */ - function _is_page() + private static function _is_page() { if ('page' == WPAlchemy_MetaBox::_is_post_or_page()) { From b14221acaeb3b95598db3b543d1230d89cf5200f Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:24:39 +0100 Subject: [PATCH 3/9] declaration --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 7b4b8b5..9783a88 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1346,7 +1346,7 @@ function can_output() * @access private * @see _global_foot() */ - function _global_head() + private static function _global_head() { // must be creating or editing a post or page if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; From 30597cccd7945a97e5c9c857caa97804943eef9d Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:25:53 +0100 Subject: [PATCH 4/9] can't declare a method as private. Docs say I should, though. --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 9783a88..5b301c3 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1346,7 +1346,7 @@ function can_output() * @access private * @see _global_foot() */ - private static function _global_head() + static function _global_head() { // must be creating or editing a post or page if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; From 994b8ea6eb89775ad12950a1564e723c9c92d77a Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:26:32 +0100 Subject: [PATCH 5/9] another --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 5b301c3..2de2633 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1510,7 +1510,7 @@ function checkLoopLimit(name) * @access private * @see _global_head() */ - function _global_foot() + static function _global_foot() { // must be creating or editing a post or page if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; From 48378b5a73933995a757e64663637f3f8f644de3 Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 18:33:48 +0100 Subject: [PATCH 6/9] others --- wp-content/wpalchemy/MetaBox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 2de2633..2c828f3 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1086,7 +1086,7 @@ static function _get_current_post_type() * @since 1.4.8 * @return int post ID */ - function _get_post_id() + static function _get_post_id() { global $post; @@ -2209,7 +2209,7 @@ function _save($post_id) $new_data = isset( $_POST[$this->id] ) ? $_POST[$this->id] : NULL ; - WPAlchemy_MetaBox::clean($new_data); + $this->clean($new_data); if (empty($new_data)) { From fcdf343ca1a60928394114412762986a71f4bf65 Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 19:22:45 +0100 Subject: [PATCH 7/9] test --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 2c828f3..3627108 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -2209,7 +2209,7 @@ function _save($post_id) $new_data = isset( $_POST[$this->id] ) ? $_POST[$this->id] : NULL ; - $this->clean($new_data); + WPAlchemy_MetaBox::clean($new_data); if (empty($new_data)) { From 380ee0e01756d341ea0278cc2f15e9f7ec9c3b71 Mon Sep 17 00:00:00 2001 From: stratboy Date: Thu, 21 Nov 2013 19:28:25 +0100 Subject: [PATCH 8/9] clean() > static --- wp-content/wpalchemy/MetaBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 3627108..cb0a50d 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -2318,7 +2318,7 @@ function _save($post_id) * @access public * @param array the array to clean (passed by reference) */ - function clean(&$arr) + static function clean(&$arr) { if (is_array($arr)) { From 004fc7c552421e6755831aa010bbacc8677884c7 Mon Sep 17 00:00:00 2001 From: stratboy Date: Fri, 27 Jun 2014 10:04:05 +0200 Subject: [PATCH 9/9] mediaaccess: mods to use new media upload panel --- wp-content/wpalchemy/MediaAccess.php | 188 ++++++++++++++------------- 1 file changed, 97 insertions(+), 91 deletions(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 7eca1ea..47d0e44 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -43,6 +43,17 @@ class WPAlchemy_MediaAccess */ public $insert_button_label = null; + /** + * User defined label for the "Add Media" button, this + * can be set once or per field and button pair. + * + * @since 0.1 + * @access public + * @var string optional + * @see setInsertButtonLabel() + */ + public $button_label = null; + /** * Used to track the current groupname for pairing a field and button. * @@ -83,6 +94,7 @@ public function __construct(array $a = array()) define('WPALCHEMY_SEND_TO_EDITOR_ENABLED', true); } + } /** @@ -114,6 +126,13 @@ public function setInsertButtonLabel($label = 'Insert') return $this; } + public function setButtonLabel($button = 'Add Media') + { + $this->button_label = $button; + + return $this; + } + public function setTab($name) { $this->tab = $name; @@ -151,7 +170,7 @@ public function setGroupName($name) public function getField(array $attr) { $groupname = isset($attr['groupname']) ? $attr['groupname'] : $this->groupname ; - + $attr_default = array ( 'type' => 'text', @@ -200,8 +219,15 @@ public function getButtonLink($tab = null) $tab = ! empty($tab) ? $tab : $this->tab ; $tab = ! empty($tab) ? $tab : 'library' ; - - return 'media-upload.php?post_id=' . $post_ID . '&tab=' . $tab . '&TB_iframe=1'; + + $update_href = esc_url( add_query_arg( array( + 'post_id' => $post_ID, + 'tab' => $tab, + 'TB_iframe' => 1, + '_wpnonce' => wp_create_nonce('shiba_gallery_options'), + ), admin_url('upload.php') ) ); + + return $update_href; } /** @@ -218,8 +244,8 @@ public function getButtonLink($tab = null) public function getButtonClass($groupname = null) { $groupname = isset($groupname) ? $groupname : $this->groupname ; - - return $this->button_class_name . '-' . $groupname . ' thickbox'; + + return $this->button_class_name . '-' . $groupname . ' '; } /** @@ -254,17 +280,16 @@ public function getButton(array $attr = array()) $groupname = isset($attr['groupname']) ? $attr['groupname'] : $this->groupname ; $tab = isset($attr['tab']) ? $attr['tab'] : $this->tab ; - + $attr_default = array ( - 'label' => 'Add Media', - 'href' => $this->getButtonLink($tab), + 'label' => $this->button_label, 'class' => $this->getButtonClass($groupname) . ' button', ); if (isset($this->insert_button_label)) { - $attr_default['class'] .= " {label:'" . $this->insert_button_label . "'}"; + $attr_default['data-update'] = $this->insert_button_label; } ### @@ -289,9 +314,12 @@ public function getButton(array $attr = array()) array_push($elem_attr, $n . '="' . $v . '"'); } - ### + $link = $this->getButtonLink(); + - return '' . $label . ''; + ### + //return ''; + return ''.$label.''; } /** @@ -304,111 +332,89 @@ public function getButton(array $attr = array()) */ public function init() { + global $post_ID; $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; $file = basename(parse_url($uri, PHP_URL_PATH)); - if ($uri AND in_array($file, array('post.php', 'post-new.php'))) { - // include javascript for special functionality - ?> +