maybe_disable_jp_carousel() )
return;
$this->in_jetpack = ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'enable_module_configurable' ) ) ? true : false;
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 );
add_filter( 'post_gallery', array( $this, 'enqueue_assets' ), 1000, 2 ); // load later than other callbacks hooked it
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->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 fase.
*/
return apply_filters( 'jp_carousel_maybe_disable', 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 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' ) );
// 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' );
if ( $this->first_run ) {
wp_enqueue_script( 'jetpack-carousel', plugins_url( 'jetpack-carousel.js', __FILE__ ), array( 'jquery.spin' ), $this->asset_version( '20160325' ), 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( get_option( 'carousel_display_exif' ), true ),
'display_geo' => $this->test_1or0_option( get_option( 'carousel_display_geo' ), true ),
'background_color' => $this->carousel_background_color_sanitize( get_option( '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' ),
'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() ) ),
);
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'] = '