plugin_locale = 'drawattention-fi'; $this->plugin_options_slug = 'drag-drop-featured-image'; $this->plugin_dirname = dirname(plugin_basename(__FILE__)); $this->plugin_directory = DrawAttention::get_plugin_url().'/public/includes/lib/drag-drop-featured-image/'; $this->selected_post_types = $this->get_option_post_types(); $this->selected_file_types = $this->get_option_file_types(); $this->selected_page_reload = $this->get_option_page_reload(); // Set WordPress version: $this->wordpress_version = substr(str_replace('.', '', $wp_version), 0, 2); } /** * Get selected post types. * @return array */ public function get_option_post_types(){ return array( 'da_image' ); } /** * Get selected file types. * @return array */ public function get_option_file_types(){ return array('jpg', 'jpeg', 'png', 'gif', 'webp'); } /** * Get page reload status. * @return boolean */ public function get_option_page_reload(){ return 0; } /** * Load plugin textdomain. */ public function load_textdomain(){ load_plugin_textdomain('drawattention-fi', false, dirname(plugin_basename(__FILE__)).'/languages/'); } /** * Print current post ID in header. */ public function print_header_post_id(){ global $post, $current_screen; if ($current_screen->base === 'post'){ echo ' '; } } /** * Toggle the metaboxes. */ public function toggle_meta_box_functionality(){ global $wp_meta_boxes; // Fetch selected post types: $selected = $this->get_option_post_types(); // Add theme support: add_theme_support('post-thumbnails', $selected); // Remove default meta box: foreach ($selected as $post_type){ add_post_type_support($post_type, 'thumbnail'); remove_meta_box('postimagediv', $post_type, 'side'); // needed for reported conflict with plugin: conditionally-display-featured-image-on-singular-pages if ( isset( $wp_meta_boxes[ $post_type ]['side']['low']['postimagediv'] ) && false === $wp_meta_boxes[ $post_type ]['side']['low']['postimagediv'] ) { unset ( $wp_meta_boxes[ $post_type ]['side']['low']['postimagediv'] ); } remove_meta_box('postimagediv', $post_type, 'normal'); remove_meta_box('postimagediv', $post_type, 'advanced'); } // Add the enhanced meta box: foreach ($selected as $post_type){ add_meta_box('drag_to_upload', __('Image'), array(&$this, 'updated_upload_meta_box'), $post_type, 'side', 'default'); } } /** * Handle script loading. * @param $hook */ public function handle_plugin_script_loading($hook){ // Globalize: global $post; // Get current post type: if (!is_null($post)){ $current_post_type = get_post_type($post->ID); } // Post edit screen: if ($hook == 'post.php' || $hook == 'post-new.php'){ if (in_array($current_post_type, $this->selected_post_types)){ // Stylesheets: wp_register_style('dgd_uploaderStyle', $this->plugin_directory.'assets/style/drag-drop-uploader.css', false); wp_enqueue_style('dgd_uploaderStyle'); // Scripts: wp_enqueue_script('plupload-all'); wp_register_script('dgd_uploaderScript', $this->plugin_directory.'assets/scripts/drag-drop-uploader.js', 'jquery'); wp_enqueue_script('dgd_uploaderScript'); // Localize JavaScript: wp_localize_script('dgd_uploaderScript', 'dgd_strings', array( 'panel' => array( 'title' => __('Set featured image'), 'button' => __('Set featured image') ) )); } } // Plugin options screen: if ($hook === 'settings_page_'.$this->plugin_options_slug){ // Stylesheets: wp_register_style('itoggle_style', $this->plugin_directory.'assets/style/engage.itoggle.css', false); wp_register_style('dgd_panelStyle', $this->plugin_directory.'assets/style/drag-to-feature.css', false); wp_enqueue_style('itoggle_style'); wp_enqueue_style('dgd_panelStyle'); // Scripts: wp_register_script('itoggle_script', $this->plugin_directory.'assets/scripts/engage.itoggle.1.7.min.js', 'jquery'); wp_register_script('dgd_panelScript', $this->plugin_directory.'assets/scripts/drag-to-feature.js', 'jquery'); wp_enqueue_script('itoggle_script'); wp_enqueue_script('dgd_panelScript'); } } /** * Render options page. */ public function render_options_page(){ require_once('assets/views/options.php'); } /** * Byte formatting function: * @param $bytes * @param int $precision * @return float */ public function format_bytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, $precision); } /** * Uploading functionality trigger. * (Most of the code comes from media.php and handlers.js) */ function updated_upload_meta_box(){ ?>