wpalchemy
wpalchemy copied to clipboard
MediaAccess.php with latest Wordpress 5.5 issues
Hi there.
With latest Wordpress 5.5 MediaAccess.php break Wordpress Editor giving errors in console:
Uncaught TypeError: d(...).live is not a function
In post pages and custom post types.
I have found it is caused by
Query(function(d){var a="";var c=null;var e;var b=0;d("[class*=<?php echo $this->button_class_name;?>]").live("click",function(f){f.preventDefault();if(g){g.open();return} ......
But i have been unable to solve this issue.
This is the code I used till now:
`class WPAlchemy_MediaAccess { public $button_class_name = 'mediabutton'; public $field_class_name = 'mediafield'; public $insert_button_label = null; public $button_label = null; private $groupname = null; private $tab = null; public function __construct(array $a = array()) { foreach ($a as $n => $v) { $this->$n = $v; } if (!defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) { add_action('admin_footer', array( $this, 'init' )); define('WPALCHEMY_SEND_TO_EDITOR_ENABLED', true); } } private function getName() { return substr(md5(microtime() . rand()) , rand(0, 25) , 6); } public function setInsertButtonLabel($label = 'Insert') { $this->insert_button_label = $label; return $this; } public function setButtonLabel($button = 'Add Media') { $this->button_label = $button; return $this; } public function setTab($name) { $this->tab = $name; $this; } public function setGroupName($name) { $this->groupname = $name; return $this; } public function getField(array $attr) { $groupname = isset($attr['groupname']) ? $attr['groupname'] : $this->groupname; $attr_default = array( 'type' => 'text', 'class' => $this->field_class_name . '-' . $groupname, ); if (isset($attr['class'])) { $attr['class'] = $attr_default['class'] . ' ' . trim($attr['class']); } $attr = array_merge($attr_default, $attr); $elem_attr = array(); foreach ($attr as $n => $v) { array_push($elem_attr, $n . '="' . $v . '"'); } return '<input ' . implode(' ', $elem_attr) . '/>'; } public function getButtonLink($tab = null) { global $post_ID; $tab = !empty($tab) ? $tab : $this->tab; $tab = !empty($tab) ? $tab : 'library'; $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; } public function getButtonClass($groupname = null) { $groupname = isset($groupname) ? $groupname : $this->groupname; return $this->button_class_name . '-' . $groupname . ' '; } public function getFieldClass($groupname = null) { $groupname = isset($groupname) ? $groupname : $this->groupname; return $this->field_class_name . '-' . $groupname; } 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' => $this->button_label, 'class' => $this->getButtonClass($groupname) . ' button', ); if (isset($this->insert_button_label)) { $attr_default['data-update'] = $this->insert_button_label; } if (isset($attr['class'])) { $attr['class'] = $attr_default['class'] . ' ' . trim($attr['class']); } $attr = array_merge($attr_default, $attr); $label = $attr['label']; unset($attr['label']); $elem_attr = array(); foreach ($attr as $n => $v) { array_push($elem_attr, $n . '="' . $v . '"'); } $link = $this->getButtonLink(); return '<a href="' . $link . '" ' . implode(' ', $elem_attr) . '>' . $label . ''; } 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' ))) { $post = get_post($post_ID); if (!post_type_supports($post->post_type, 'thumbnail') && function_exists('wp_enqueue_media')) { if (!wp_script_is('custom-header')) { wp_enqueue_script('custom-header'); } wp_enqueue_media(); } ?>
While I have not used this code for sometime now ... try using the current "MediaAccess.php" (get the latest here on github) .. it is likely you have an older version .. "live" was removed sometime ago.
Many thanks Dimas for help us in such a genious framework you once created... The thing is the current "MediaAccess.php" file dont use the new "modern" media manager instead of an Iframe. That's why I used the "modified" version till now, i started using again the current "MediaAccess.php" file i found here on github.
Thanks again.