* add_filter('crop_thumbnails_activat_on_adminpages', function($oldValue) { * global $pagenow; * return $oldValue || $pagenow==='term.php';//for adding taxonomy edit-page to the list of pages where crop-thumbnails work * }); * */ protected function shouldCropThumbnailsBeActive() { global $pagenow; $result = ($pagenow == 'post.php' || $pagenow == 'post-new.php' || $pagenow == 'page.php' || $pagenow == 'page-new.php' || $pagenow == 'upload.php'); $result = apply_filters('crop_thumbnails_activat_on_adminpages',$result); return $result; } /** * For adding the styles in the backend */ public function adminHeaderCSS() { global $pagenow; if ($this->shouldCropThumbnailsBeActive()) { wp_enqueue_style('jcrop'); wp_enqueue_style('crop-thumbnails-options-style', plugins_url('app/app.css', dirname(__FILE__)), array('jcrop'), CROP_THUMBNAILS_VERSION); } } /** * For adding the "crop-thumbnail"-link on posts, pages and the mediathek */ function adminHeaderJS() { global $pagenow; if ($this->shouldCropThumbnailsBeActive()) { wp_enqueue_script( 'jcrop' ); wp_enqueue_script( 'cpt_vue', plugins_url('app/vendor/vue.min.js', dirname(__FILE__)), array(), CROP_THUMBNAILS_VERSION); wp_enqueue_script( 'cpt_crop_editor', plugins_url('app/app.js', dirname(__FILE__)), array('jquery','cpt_vue','imagesloaded','json2','jcrop'), CROP_THUMBNAILS_VERSION); add_action('admin_footer',array($this,'addLinksToAdmin')); } } /** * Add an field to the attachment edit dialog * @see http://code.tutsplus.com/tutorials/creating-custom-fields-for-attachments-in-wordpress--net-13076 * @see https://make.wordpress.org/core/2012/12/12/attachment-editing-now-with-full-post-edit-ui/ * @param array $form_fields * @param object $post */ public function add_button_to_attachment_edit_view( $form_fields, $post ) { if(in_array($post->post_mime_type,$this->allowedMime)) { $html = ''; $html.= 'ID.',"viewmode":"single"}\' title="'.esc_attr__('Crop Featured Image','crop-thumbnails').'">'; $html.= ' '.esc_html__('Crop Featured Image','crop-thumbnails'); $html.= ''; $form_fields['cropthumbnails'] = array( 'label' => ' ', 'input' => 'html', 'html' => $html ); } return $form_fields; } /** * Check if on the current admin page (posttype) the crop-button should be visible in the featured image Box. */ protected static function showCropButtonOnThisAdminPage() { $screenData = get_current_screen(); $settings = $GLOBALS['CROP_THUMBNAILS_HELPER']->getOptions(); $showFeaturedImageCropButton = false; if(empty($settings['hide_post_type'][ $screenData->post_type ])) { $showFeaturedImageCropButton = true; } return $showFeaturedImageCropButton; } /** * adds the links into post-types and the media-library */ function addLinksToAdmin() { ?>