| 1 |
<?php |
| 2 |
namespace Imagify\ThirdParty\FormidablePro; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Compat class for Formidable Forms Pro plugin. |
| 8 |
* Each call to `new WP_Query()` made by Imagify must have a `'is_imagify' => true` argument. |
| 9 |
* |
| 10 |
* @since 1.6.13 |
| 11 |
* @author Grégory Viguier |
| 12 |
*/ |
| 13 |
class Main { |
| 14 |
use \Imagify\Traits\InstanceGetterTrait; |
| 15 |
|
| 16 |
/** |
| 17 |
* Class version. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
const VERSION = '1.1'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Set to true when the current query comes from Imagify. |
| 25 |
* |
| 26 |
* @var int |
| 27 |
*/ |
| 28 |
protected $is_imagify; |
| 29 |
|
| 30 |
/** |
| 31 |
* Launch the hooks. |
| 32 |
* |
| 33 |
* @since 1.6.13 |
| 34 |
* @author Grégory Viguier |
| 35 |
*/ |
| 36 |
public function init() { |
| 37 |
add_action( 'parse_query', array( $this, 'maybe_remove_media_library_filter' ) ); |
| 38 |
add_action( 'posts_selection', array( $this, 'maybe_put_media_library_filter_back' ) ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Fires before the 'pre_get_posts' hook. |
| 43 |
* |
| 44 |
* @since 1.6.13 |
| 45 |
* @author Grégory Viguier |
| 46 |
* |
| 47 |
* @param object $wp_query The WP_Query instance (passed by reference). |
| 48 |
*/ |
| 49 |
public function maybe_remove_media_library_filter( $wp_query ) { |
| 50 |
if ( ! empty( $wp_query->query_vars['is_imagify'] ) && class_exists( 'FrmProFileField' ) ) { |
| 51 |
$this->is_imagify = true; |
| 52 |
remove_action( 'pre_get_posts', 'FrmProFileField::filter_media_library', 99 ); |
| 53 |
} else { |
| 54 |
$this->is_imagify = false; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Fires after the 'pre_get_posts' hook. |
| 60 |
* |
| 61 |
* @since 1.6.13 |
| 62 |
* @author Grégory Viguier |
| 63 |
*/ |
| 64 |
public function maybe_put_media_library_filter_back() { |
| 65 |
if ( $this->is_imagify ) { |
| 66 |
add_action( 'pre_get_posts', 'FrmProFileField::filter_media_library', 99 ); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|