} } public function atp_check_pro_albums( $available, $display_type ) { if ( ! defined( 'NGG_PRO_ALBUMS' ) ) { return $available; } if ( in_array( $display_type->name, [ NGG_PRO_LIST_ALBUM, NGG_PRO_GRID_ALBUM ] ) && in_array( 'C_Component_Registry', get_declared_classes(), true ) && \C_Component_Registry::get_instance()->is_module_loaded( NGG_PRO_ALBUMS ) ) { $available = true; } return $available; } public function no_debug_bar() { if ( ATPManager::is_atp_url() ) { \wp_dequeue_script( 'debug-bar-console' ); } } // A lot of routing issues start occuring with WordPress SEO when the routing system is // initialized by the excerpt, and then again from the post content. public function disable_galleries_in_excerpts( $excerpt ) { if ( in_array( 'WPSEO_OpenGraph', get_declared_classes(), true ) ) { ATPManager::$substitute_placeholders = false; } return $excerpt; } public function enable_galleries_in_excerpts( $excerpt ) { if ( in_array( 'WPSEO_OpenGraph', get_declared_classes(), true ) ) { ATPManager::$substitute_placeholders = true; } return $excerpt; } public function fix_wpml_canonical_redirect() { Router::$use_canonical_redirect = false; Router::$use_old_slugs = false; } /** * NGG automatically purges unused terms when managing a gallery, but this also ensnares WPML translations * * @param $term_id * @return bool */ public function dont_auto_purge_wpml_terms( $term_id ) { $args = [ 'element_id' => $term_id, 'element_type' => 'ngg_tag', ]; $term_language_code = \apply_filters( 'wpml_element_language_code', null, $args ); if ( ! empty( $term_language_code ) ) { return false; } else { return $term_id; } } /** * Prevent WPML's parse_query() from conflicting with NGG's pagination & router module controlled endpoints * * @param string $redirect What WPML is send to wp_safe_redirect() * @param int $post_id * @param \WP_Query $q * @return bool|string FALSE prevents a redirect from occurring */ public function wpml_is_redirected( $redirect, $post_id, $q ) { $router = Router::get_instance(); if ( ! $router->serve_request() && $router->has_parameter_segments() ) { return false; } else { return $redirect; } } /** * CKEditor features a custom NextGEN shortcode generator that unfortunately relies on parts of the NextGEN * 1.9x API that has been deprecated in NextGEN 2.0 * * @param $plugins * @return mixed */ public function ckeditor_plugins( $plugins ) { if ( ! in_array( 'add_ckeditor_button', get_declared_classes(), true ) ) { return $plugins; } if ( ! empty( $plugins['nextgen'] ) ) { unset( $plugins['nextgen'] ); } return $plugins; } public function check_for_jquery_lightbox() { // Fix for jQuery Lightbox: http://wordpress.org/plugins/wp-jquery-lightbox/ // jQuery Lightbox tries to modify the content of a post, but it does so before we modify // the content, and therefore it's modifications have no effect on our galleries. if ( function_exists( 'jqlb_autoexpand_rel_wlightbox' ) ) { $settings = Settings::get_instance(); // First, we make it appear that NGG has no lightbox effect enabled. That way we don't any lightbox resources. $settings->delete( 'thumbEffect' ); // We would normally just let the third-party plugin do it's thing, but it's regex doesn't // seem to work on our tags (perhaps because they span multiple of lines or have data attributes) // So instead, we just do what the third-party plugin wants - add the rel attribute. $settings->set( 'thumbCode', "rel='lightbox[%POST_ID%]'" ); } } /** * Weaver II's 'weaver_show_posts' shortcode creates a new wp-query, causing a second round of 'the_content' * filters to apply. This checks for WeaverII and enables all NextGEN shortcodes that would otherwise be left * disabled by our shortcode manager. See https://core.trac.wordpress.org/ticket/17817 for more. * * @param string $content * @return string $content */ public function check_weaverii( $content ) { if ( function_exists( 'weaverii_show_posts_shortcode' ) ) { Shortcodes::get_instance()->activate_all(); } return $content; } /** * WPML assigns an action to 'init' that *may* enqueue some admin-side JS. This JS relies on some inline JS * to be injected that isn't present in ATP so for ATP requests ONLY we disable their action that enqueues * their JS files. */ public function wpml() { if ( ! in_array( 'SitePress', get_declared_classes(), true ) ) { return; } if ( ! ATPManager::is_atp_url() ) { return; } global $wp_filter; if ( empty( $wp_filter['init'][2] ) && empty( $wp_filter['after_setup_theme'][1] ) ) { return; } foreach ( $wp_filter['init'][2] as $id => $filter ) { if ( ! strpos( $id, 'js_load' ) ) { continue; } $object = $filter['function'][0]; if ( is_object( $object ) && get_class( $object ) != 'SitePress' ) { continue; } \remove_action( 'init', [ $object, 'js_load' ], 2 ); } foreach ( $wp_filter['after_setup_theme'][1] as $id => $filter ) { if ( $id !== 'wpml_installer_instance_delegator' ) { continue; } \remove_action( 'after_setup_theme', 'wpml_installer_instance_delegator', 1 ); } } /** * WPML Translation Management has a similar problem to plain ol' WPML */ public function wpml_translation_management() { if ( ! in_array( 'WPML_Translation_Management', get_declared_classes(), true ) ) { return; } if ( ! ATPManager::is_atp_url() ) { return; } global $wp_filter; if ( empty( $wp_filter['init'][10] ) ) { return; } foreach ( $wp_filter['init'][10] as $id => $filter ) { if ( ! strpos( $id, 'init' ) ) { continue; } $object = $filter['function'][0]; if ( is_object( $object ) && get_class( $object ) != 'WPML_Translation_Management' ) { continue; } \remove_action( 'init', [ $object, 'init' ], 10 ); } } /** * Headway themes offer gzip compression, but it causes problems with NextGEN output. Disable that feature while * NextGEN is active. * * @param $option * @return bool */ public function headway_gzip( $option ) { if ( ! in_array( 'HeadwayOption', get_declared_classes(), true ) ) { return $option; } return false; } /** * Colorbox fires a filter (pri=100) to add class attributes to images via a the_content filter. We fire our * shortcodes at PHP_INT_MAX-1 to avoid encoding issues with some themes. Here we move the Colorbox filters * priority to PHP_INT_MAX so that they run after our shortcode text has been replaced with rendered galleries. */ public function colorbox() { if ( ! in_array( 'JQueryColorboxFrontend', get_declared_classes(), true ) ) { return; } global $wp_filter; if ( empty( $wp_filter['the_content'][100] ) ) { return; } foreach ( $wp_filter['the_content'][100] as $id => $filter ) { if ( ! strpos( $id, 'addColorboxGroupIdToImages' ) ) { continue; } $object = $filter['function'][0]; if ( is_object( $object ) && get_class( $object ) != 'JQueryColorboxFrontend' ) { continue; } \remove_filter( 'the_content', [ $object, 'addColorboxGroupIdToImages' ], 100 ); \remove_filter( 'the_excerpt', [ $object, 'addColorboxGroupIdToImages' ], 100 ); \add_filter( 'the_content', [ $object, 'addColorboxGroupIdToImages' ], PHP_INT_MAX ); \add_filter( 'the_excerpt', [ $object, 'addColorboxGroupIdToImages' ], PHP_INT_MAX ); break; } } /** * Flattr fires a filter (pri=32767) on "the_content" that recurses. This causes problems, * see https://core.trac.wordpress.org/ticket/17817 for more information. Moving their filter to PHP_INT_MAX * is enough for us though */ public function flattr() { if ( ! in_array( 'Flattr', get_declared_classes(), true ) ) { return; } global $wp_filter; $level = 32767; if ( empty( $wp_filter['the_content'][ $level ] ) ) { return; } foreach ( $wp_filter['the_content'][ $level ] as $id => $filter ) { if ( ! strpos( $id, 'injectIntoTheContent' ) ) { continue; } $object = $filter['function'][0]; if ( is_object( $object ) && get_class( $object ) != 'Flattr' ) { continue; } \remove_filter( 'the_content', [ $object, 'injectIntoTheContent' ], $level ); \add_filter( 'the_content', [ $object, 'injectIntoTheContent' ], PHP_INT_MAX ); break; } } /** * For the same reasons as Colorbox we move BJ-Lazy-load's filter() method to a later priority so it can access * our rendered galleries. */ public function bjlazyload() { if ( ! in_array( 'BJLL', get_declared_classes(), true ) ) { return; } global $wp_filter; if ( empty( $wp_filter['the_content'][200] ) ) { return; } foreach ( $wp_filter['the_content'][200] as $id => $filter ) { if ( ! strpos( $id, 'filter' ) ) { continue; } $object = $filter['function'][0]; if ( is_object( $object ) && get_class( $object ) != 'BJLL' ) { continue; } \remove_filter( 'the_content', [ $object, 'filter' ], 200 ); \add_filter( 'the_content', [ $object, 'filter' ], PHP_INT_MAX ); break; } \add_filter( 'the_content', [ $this, 'bjlazyload_filter' ], PHP_INT_MAX - 1 ); } /** * BJ-Lazy-load's regex is lazy and doesn't handle multiline search or instances where