class-columns.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /* |
| 8 | * FooGallery Admin Columns class |
| 9 | */ |
| 10 | |
| 11 | if ( ! class_exists( 'FooGallery_Albums_Admin_Columns' ) ) { |
| 12 | |
| 13 | class FooGallery_Albums_Admin_Columns { |
| 14 | |
| 15 | private $include_clipboard_script = false; |
| 16 | |
| 17 | function __construct() { |
| 18 | add_filter( 'manage_edit-' . FOOGALLERY_CPT_ALBUM . '_columns', array( $this, 'album_custom_columns' ) ); |
| 19 | add_action( 'manage_posts_custom_column', array( $this, 'album_custom_column_content' ) ); |
| 20 | add_action( 'admin_footer', array( $this, 'include_clipboard_script' ) ); |
| 21 | } |
| 22 | |
| 23 | function album_custom_columns( $columns ) { |
| 24 | $columns[FOOGALLERY_CPT_ALBUM . '_template'] = __( 'Template', 'foogallery' ); |
| 25 | $columns[FOOGALLERY_CPT_ALBUM . '_galleries'] = __( 'Galleries', 'foogallery' ); |
| 26 | $columns[FOOGALLERY_CPT_ALBUM . '_shortcode'] = __( 'Shortcode', 'foogallery' ); |
| 27 | |
| 28 | return $columns; |
| 29 | } |
| 30 | |
| 31 | function album_custom_column_content( $column ) { |
| 32 | global $post; |
| 33 | |
| 34 | switch ( $column ) { |
| 35 | case FOOGALLERY_CPT_ALBUM . '_template': |
| 36 | $album = FooGalleryAlbum::get( $post ); |
| 37 | $template = $album->album_template_details(); |
| 38 | if ( false !== $template ) { |
| 39 | echo esc_html( $template['name'] ); |
| 40 | } |
| 41 | break; |
| 42 | case FOOGALLERY_CPT_ALBUM . '_galleries': |
| 43 | $album = FooGalleryAlbum::get( $post ); |
| 44 | echo absint( $album->gallery_count() ); |
| 45 | break; |
| 46 | case FOOGALLERY_CPT_ALBUM . '_shortcode': |
| 47 | $album = FooGalleryAlbum::get( $post ); |
| 48 | $shortcode = $album->shortcode(); |
| 49 | echo '<input type="text" readonly="readonly" size="' . absint( strlen( $shortcode ) ) . '" value="' . esc_attr( $shortcode ) . '" class="foogallery-shortcode" />'; |
| 50 | $this->include_clipboard_script = true; |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | function include_clipboard_script() { |
| 56 | if ( $this->include_clipboard_script ) { ?> |
| 57 | <script> |
| 58 | jQuery(function($) { |
| 59 | $('.foogallery-shortcode').on('click', function () { |
| 60 | try { |
| 61 | //select the contents |
| 62 | this.select(); |
| 63 | //copy the selection |
| 64 | document.execCommand('copy'); |
| 65 | //show the copied message |
| 66 | $('.foogallery-shortcode-message').remove(); |
| 67 | $(this).after('<p class="foogallery-shortcode-message"><?php esc_html_e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
| 68 | } catch(err) { |
| 69 | console.log('Oops, unable to copy!'); |
| 70 | } |
| 71 | }); |
| 72 | }); |
| 73 | </script> |
| 74 | <?php |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |