maybe_disable_jp_carousel() )
return;
$this->in_jetpack = ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'enable_module_configurable' ) ) ? true : false;
$this->single_image_gallery_enabled = !$this->maybe_disable_jp_carousel_single_images();
$this->single_image_gallery_enabled_media_file = $this->maybe_enable_jp_carousel_single_images_media_file();
if ( is_admin() ) {
// Register the Carousel-related related settings
add_action( 'admin_init', array( $this, 'register_settings' ), 5 );
if ( ! $this->in_jetpack ) {
if ( 0 == $this->test_1or0_option( get_option( 'carousel_enable_it' ), true ) )
return; // Carousel disabled, abort early, but still register setting so user can switch it back on
}
// If in admin, register the ajax endpoints.
add_action( 'wp_ajax_get_attachment_comments', array( $this, 'get_attachment_comments' ) );
add_action( 'wp_ajax_nopriv_get_attachment_comments', array( $this, 'get_attachment_comments' ) );
add_action( 'wp_ajax_post_attachment_comment', array( $this, 'post_attachment_comment' ) );
add_action( 'wp_ajax_nopriv_post_attachment_comment', array( $this, 'post_attachment_comment' ) );
} else {
if ( ! $this->in_jetpack ) {
if ( 0 == $this->test_1or0_option( get_option( 'carousel_enable_it' ), true ) )
return; // Carousel disabled, abort early
}
// If on front-end, do the Carousel thang.
/**
* Filter the array of default prebuilt widths used in Carousel.
*
* @module carousel
*
* @since 1.6.0
*
* @param array $this->prebuilt_widths Array of default widths.
*/
$this->prebuilt_widths = apply_filters( 'jp_carousel_widths', $this->prebuilt_widths );
// below: load later than other callbacks hooked it (e.g. 3rd party plugins handling gallery shortcode)
add_filter( 'post_gallery', array( $this, 'check_if_shortcode_processed_and_enqueue_assets' ), 1000, 2 );
add_filter( 'post_gallery', array( $this, 'set_in_gallery' ), -1000 );
add_filter( 'gallery_style', array( $this, 'add_data_to_container' ) );
add_filter( 'wp_get_attachment_image_attributes', array( $this, 'add_data_to_images' ), 10, 2 );
if ( $this->single_image_gallery_enabled ) {
add_filter( 'the_content', array( $this, 'add_data_img_tags_and_enqueue_assets' ) );
}
}
if ( $this->in_jetpack && method_exists( 'Jetpack', 'module_configuration_load' ) ) {
Jetpack::enable_module_configurable( dirname( dirname( __FILE__ ) ) . '/carousel.php' );
Jetpack::module_configuration_load( dirname( dirname( __FILE__ ) ) . '/carousel.php', array( $this, 'jetpack_configuration_load' ) );
}
}
function maybe_disable_jp_carousel() {
/**
* Allow third-party plugins or themes to disable Carousel.
*
* @module carousel
*
* @since 1.6.0
*
* @param bool false Should Carousel be disabled? Default to false.
*/
return apply_filters( 'jp_carousel_maybe_disable', false );
}
function maybe_disable_jp_carousel_single_images() {
/**
* Allow third-party plugins or themes to disable Carousel for single images.
*
* @module carousel
*
* @since 4.5.0
*
* @param bool false Should Carousel be disabled for single images? Default to false.
*/
return apply_filters( 'jp_carousel_maybe_disable_single_images', false );
}
function maybe_enable_jp_carousel_single_images_media_file() {
/**
* Allow third-party plugins or themes to enable Carousel
* for single images linking to 'Media File' (full size image).
*
* @module carousel
*
* @since 4.5.0
*
* @param bool false Should Carousel be enabled for single images linking to 'Media File'? Default to false.
*/
return apply_filters( 'jp_carousel_load_for_images_linked_to_file', false );
}
function jetpack_configuration_load() {
wp_safe_redirect( admin_url( 'options-media.php#carousel_background_color' ) );
exit;
}
function asset_version( $version ) {
/**
* Filter the version string used when enqueuing Carousel assets.
*
* @module carousel
*
* @since 1.6.0
*
* @param string $version Asset version.
*/
return apply_filters( 'jp_carousel_asset_version', $version );
}
function display_bail_message( $output= '' ) {
// Displays a message on top of gallery if carousel has bailed
$message = '
';
$message .= __( 'Jetpack\'s Carousel has been disabled, because another plugin or your theme is overriding the [gallery] shortcode.', 'jetpack' );
$message .= '
';
// put before gallery output
$output = $message . $output;
return $output;
}
function check_if_shortcode_processed_and_enqueue_assets( $output ) {
if (
! empty( $output ) &&
/**
* Allow third-party plugins or themes to force-enable Carousel.
*
* @module carousel
*
* @since 1.9.0
*
* @param bool false Should we force enable Carousel? Default to false.
*/
! apply_filters( 'jp_carousel_force_enable', false )
) {
// Bail because someone is overriding the [gallery] shortcode.
remove_filter( 'gallery_style', array( $this, 'add_data_to_container' ) );
remove_filter( 'wp_get_attachment_image_attributes', array( $this, 'add_data_to_images' ) );
remove_filter( 'the_content', array( $this, 'add_data_img_tags_and_enqueue_assets' ) );
// Display message that carousel has bailed, if user is super_admin, and if we're not on WordPress.com.
if (
is_super_admin() &&
! ( defined( 'IS_WPCOM' ) && IS_WPCOM )
) {
add_filter( 'post_gallery', array( $this, 'display_bail_message' ) );
}
return $output;
}
/**
* Fires when thumbnails are shown in Carousel.
*
* @module carousel
*
* @since 1.6.0
**/
do_action( 'jp_carousel_thumbnails_shown' );
$this->enqueue_assets();
return $output;
}
function enqueue_assets() {
if ( $this->first_run ) {
wp_enqueue_script(
'jetpack-carousel',
Jetpack::get_file_url_for_environment(
'_inc/build/carousel/jetpack-carousel.min.js',
'modules/carousel/jetpack-carousel.js'
),
array( 'jquery.spin' ),
$this->asset_version( '20170209' ),
true
);
// Note: using home_url() instead of admin_url() for ajaxurl to be sure to get same domain on wpcom when using mapped domains (also works on self-hosted)
// Also: not hardcoding path since there is no guarantee site is running on site root in self-hosted context.
$is_logged_in = is_user_logged_in();
$current_user = wp_get_current_user();
$comment_registration = intval( get_option( 'comment_registration' ) );
$require_name_email = intval( get_option( 'require_name_email' ) );
$localize_strings = array(
'widths' => $this->prebuilt_widths,
'is_logged_in' => $is_logged_in,
'lang' => strtolower( substr( get_locale(), 0, 2 ) ),
'ajaxurl' => set_url_scheme( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'carousel_nonce' ),
'display_exif' => $this->test_1or0_option( Jetpack_Options::get_option_and_ensure_autoload( 'carousel_display_exif', true ) ),
'display_geo' => $this->test_1or0_option( Jetpack_Options::get_option_and_ensure_autoload( 'carousel_display_geo', true ) ),
'single_image_gallery' => $this->single_image_gallery_enabled,
'single_image_gallery_media_file' => $this->single_image_gallery_enabled_media_file,
'background_color' => $this->carousel_background_color_sanitize( Jetpack_Options::get_option_and_ensure_autoload( 'carousel_background_color', '' ) ),
'comment' => __( 'Comment', 'jetpack' ),
'post_comment' => __( 'Post Comment', 'jetpack' ),
'write_comment' => __( 'Write a Comment...', 'jetpack' ),
'loading_comments' => __( 'Loading Comments...', 'jetpack' ),
'download_original' => sprintf( __( 'View full size %1$s×%2$s', 'jetpack' ), '{0}', '{1}' ),
'no_comment_text' => __( 'Please be sure to submit some text with your comment.', 'jetpack' ),
'no_comment_email' => __( 'Please provide an email address to comment.', 'jetpack' ),
'no_comment_author' => __( 'Please provide your name to comment.', 'jetpack' ),
'comment_post_error' => __( 'Sorry, but there was an error posting your comment. Please try again later.', 'jetpack' ),
'comment_approved' => __( 'Your comment was approved.', 'jetpack' ),
'comment_unapproved' => __( 'Your comment is in moderation.', 'jetpack' ),
'camera' => __( 'Camera', 'jetpack' ),
'aperture' => __( 'Aperture', 'jetpack' ),
'shutter_speed' => __( 'Shutter Speed', 'jetpack' ),
'focal_length' => __( 'Focal Length', 'jetpack' ),
'copyright' => __( 'Copyright', 'jetpack' ),
'comment_registration' => $comment_registration,
'require_name_email' => $require_name_email,
/** This action is documented in core/src/wp-includes/link-template.php */
'login_url' => wp_login_url( apply_filters( 'the_permalink', get_permalink() ) ),
'blog_id' => (int) get_current_blog_id(),
'meta_data' => array( 'camera', 'aperture', 'shutter_speed', 'focal_length', 'copyright' )
);
if ( ! isset( $localize_strings['jetpack_comments_iframe_src'] ) || empty( $localize_strings['jetpack_comments_iframe_src'] ) ) {
// We're not using Comments after all, so fallback to standard local comments.
if ( $is_logged_in ) {
$localize_strings['local_comments_commenting_as'] = '