abilities
3 days ago
admin
3 days ago
compatibility
3 days ago
extensions
3 days ago
foopluginbase
3 days ago
public
3 days ago
thumbs
3 days ago
asset-manifest.php
3 days ago
class-attachment-filters.php
3 days ago
class-command-palette.php
3 days ago
class-foogallery-animated-gif-support.php
3 days ago
class-foogallery-attachment-custom-class.php
3 days ago
class-foogallery-attachment-filename.php
3 days ago
class-foogallery-attachment-type.php
3 days ago
class-foogallery-attachment.php
3 days ago
class-foogallery-cache.php
3 days ago
class-foogallery-common-fields.php
3 days ago
class-foogallery-crop-position.php
3 days ago
class-foogallery-datasource-media_library.php
3 days ago
class-foogallery-debug.php
3 days ago
class-foogallery-delayed-runtime-loader.php
3 days ago
class-foogallery-extensions-compatibility.php
3 days ago
class-foogallery-force-https.php
3 days ago
class-foogallery-lazyload.php
3 days ago
class-foogallery-license-constant-handler.php
3 days ago
class-foogallery-lightbox.php
3 days ago
class-foogallery-no-javascript-fallback.php
3 days ago
class-foogallery-paging.php
3 days ago
class-foogallery-password-protect.php
3 days ago
class-foogallery-sitemaps.php
3 days ago
class-foogallery-widget.php
3 days ago
class-foogallery.php
3 days ago
class-gallery-advanced-settings.php
3 days ago
class-il8n.php
3 days ago
class-override-thumbnail.php
3 days ago
class-posttypes.php
3 days ago
class-previews.php
3 days ago
class-retina.php
3 days ago
class-thumbnail-dimensions.php
3 days ago
class-thumbnails.php
3 days ago
class-version-check.php
3 days ago
constants.php
3 days ago
functions.php
3 days ago
gallery-management-functions.php
3 days ago
includes.php
3 days ago
index.php
3 days ago
render-functions.php
3 days ago
class-foogallery-attachment-custom-class.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class used to add custom classes to gallery links |
| 9 | * Date: 04/06/2017 |
| 10 | */ |
| 11 | if ( ! class_exists( 'FooGallery_Attachment_Custom_Class' ) ) { |
| 12 | |
| 13 | class FooGallery_Attachment_Custom_Class { |
| 14 | |
| 15 | function __construct() { |
| 16 | add_filter( 'foogallery_attachment_custom_fields', array( $this, 'add_custom_class_field' ) ); |
| 17 | add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'alter_class_attributes' ), 99, 3 ); |
| 18 | add_action( 'foogallery_attachment_instance_after_load', array( $this, 'load_custom_class_meta' ), 10, 2 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Adds a custom class field to the attachments |
| 23 | * |
| 24 | * @param $fields array |
| 25 | * |
| 26 | * @return array |
| 27 | */ |
| 28 | function add_custom_class_field( $fields ) { |
| 29 | $fields['foogallery_custom_class'] = array( |
| 30 | 'label' => __( 'Custom Class', 'foogallery' ), |
| 31 | 'input' => 'text', |
| 32 | 'helps' => __( 'Add extra classes to the attachment', 'foogallery' ), |
| 33 | 'exclusions' => array( 'audio', 'video' ), |
| 34 | ); |
| 35 | |
| 36 | return $fields; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Alters the actual link output to include the custom class added |
| 41 | * |
| 42 | * @uses "foogallery_attachment_html_link_attributes" filter |
| 43 | * |
| 44 | * @param $attr |
| 45 | * @param $args |
| 46 | * @param object|FooGalleryAttachment $object |
| 47 | * |
| 48 | * @return array |
| 49 | */ |
| 50 | function alter_class_attributes( $attr, $args, $object ) { |
| 51 | //if the object is a FooGalleryAttachment and has a custom class, add it to the custom class |
| 52 | if ( $object instanceof FooGalleryAttachment && !empty( $object->custom_class ) ) { |
| 53 | if ( !isset( $attr[ 'class' ] ) ) { |
| 54 | $attr[ 'class' ] = $object->custom_class; |
| 55 | }else{ |
| 56 | $attr[ 'class' ] .= ' ' . $object->custom_class; |
| 57 | } |
| 58 | |
| 59 | //check for any special class names and do some magic! |
| 60 | if ( 'nolink' === $object->custom_class ) { |
| 61 | unset( $attr['href'] ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return $attr; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Loads any extra custom class data for an attachment. |
| 70 | * |
| 71 | * @param $foogallery_attachment |
| 72 | * @param $post |
| 73 | */ |
| 74 | public function load_custom_class_meta( $foogallery_attachment, $post ) { |
| 75 | $custom_class = get_post_meta( $post->ID, '_foogallery_custom_class', true ); |
| 76 | if ( !empty( $custom_class ) ) { |
| 77 | $foogallery_attachment->custom_class = foogallery_sanitize_javascript( $custom_class ); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 |