uninstall_plugin( __FILE__ ); } require_once APB_PATH . '/inc/block.php'; require_once APB_PATH . '/inc/functions.php'; // Advanced Post Block class APBPlugin{ function __construct(){ add_action( 'wp_ajax_apbPosts', [$this, 'apbPosts'] ); add_action( 'wp_ajax_nopriv_apbPosts', [$this, 'apbPosts'] ); register_activation_hook( __FILE__, [$this, 'onPluginActivate'] ); add_filter( 'block_categories_all', [$this, 'blockCategories'] ); } function onPluginActivate(){ if ( is_plugin_active( 'advanced-post-block-pro/plugin.php' ) ){ deactivate_plugins( 'advanced-post-block-pro/plugin.php' ); } } function blockCategories( $categories ){ return array_merge( [ [ 'slug' => 'APBlock', 'title' => 'Advanced Post Block' ] ], $categories ); } function query( $attributes ){ extract( $attributes ); global $apb_bs; $termsQuery = ['relation' => 'AND']; foreach ( $selectedTaxonomies as $taxonomy => $terms ){ if( count( $terms ) ){ $termsQuery[] = [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $terms, ]; } } $defaultPostQuery = 'post' === $postType ? [ 'category__in' => $selectedCategories, 'tag__in' => $selectedTags ?? [] ] : []; $postsInclude = APB\Inc\Functions::filterNaN( $postsInclude ?? [] ); $post__in = !empty( $postsInclude ) ? [ 'post__in' => $postsInclude ] : []; $postsExclude = APB\Inc\Functions::filterNaN( $postsExclude ?? [] ); $query = array_merge( [ 'post_type' => $postType, 'posts_per_page' => $isPostsPerPageAll ? -1 : $postsPerPage, 'orderby' => $postsOrderBy, 'order' => $postsOrder, 'tax_query' => $termsQuery, 'offset' => $isPostsPerPageAll ? 0 : $postsOffset, 'post__not_in' => $isExcludeCurrent ? array_merge( [ get_the_ID() ], $postsExclude ) : $postsExclude ], $post__in, $defaultPostQuery ); if( $apb_bs->can_use_premium_feature() ) { $query = apply_filters( 'apb_query', $query ); } return $query; } function apbPosts(){ $attributes = $_POST['queryAttr']; $pageNumber = (int)$_POST['pageNumber']; extract( $attributes ); $attributes['isPostsPerPageAll'] = 'true' === $isPostsPerPageAll; $attributes['isExcludeCurrent'] = 'true' === $isExcludeCurrent; $newArgs = wp_parse_args( [ 'offset' => ( $postsPerPage * ( $pageNumber - 1 ) ) + $postsOffset ], $this->query( $attributes ) ); $posts = APB\Inc\Functions::arrangedPosts( get_posts( $newArgs ), $postType, $fImgSize, $metaDateFormat ); wp_send_json_success( $posts ); } } new APBPlugin; // Require Files global $apb_bs; if( $apb_bs->can_use_premium_feature() ) { require_once APB_PATH . '/inc/custom-post.php'; }