uninstall_plugin( __FILE__ ); } } if ( APB_HAS_PRO ) { require_once APB_DIR_PATH . 'inc/fs-init.php'; if( function_exists( 'apb_fs' ) ){ apb_fs()->set_basename( false, __FILE__ ); } } function apbIsPremium(){ if( APB_HAS_FREE ){ global $apb_bs; return $apb_bs->can_use_premium_feature(); } if ( APB_HAS_PRO ) { return apb_fs()->can_use_premium_code(); } } if( APB_HAS_FREE ){ // disable update for old gumroad pro users add_filter('site_transient_update_plugins', 'apb_remove_update_notification_1234'); function apb_remove_update_notification_1234( $value ) { // replace is_gumroad_pro_user with proper pro user checker method if( apbIsPremium() || get_option('apb_user_type') === 'pro'){ update_option('apb_user_type', 'pro'); unset( $value->response[ plugin_basename(__FILE__) ] ); // plugin_basename(__FILE__) should be slug/main_file.php if the code is not used in the main file return $value; } return $value; } } // Advanced Post Block class APBPlugin{ function __construct(){ add_action( 'wp_ajax_apbPipeChecker', [$this, 'apbPipeChecker'] ); add_action( 'wp_ajax_nopriv_apbPipeChecker', [$this, 'apbPipeChecker'] ); add_action( 'admin_init', [$this, 'registerSettings'] ); add_action( 'rest_api_init', [$this, 'registerSettings']); add_action( 'wp_ajax_apbPosts', [$this, 'apbPosts'] ); add_action( 'wp_ajax_nopriv_apbPosts', [$this, 'apbPosts'] ); add_filter( 'block_categories_all', [$this, 'blockCategories'] ); } function apbPipeChecker(){ $nonce = $_POST['_wpnonce'] ?? null; if( !wp_verify_nonce( $nonce, 'wp_ajax' )){ wp_send_json_error( 'Invalid Request' ); } wp_send_json_success( [ 'isPipe' => apbIsPremium() ] ); } function registerSettings(){ register_setting( 'apbUtils', 'apbUtils', [ 'show_in_rest' => [ 'name' => 'apbUtils', 'schema' => [ 'type' => 'string' ] ], 'type' => 'string', 'default' => wp_json_encode( [ 'nonce' => wp_create_nonce( 'wp_ajax' ) ] ), 'sanitize_callback' => 'sanitize_text_field' ] ); } function blockCategories( $categories ){ return array_merge( [ [ 'slug' => 'APBlock', 'title' => 'Advanced Post Block' ] ], $categories ); } function query( $attributes ){ extract( $attributes ); $selectedTaxonomies = $selectedTaxonomies ?? []; $selectedCategories = $selectedCategories ?? []; $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 ?? [] ); $passFilter = $passFilter ?? null; $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, 'has_password' => $passFilter === 'true' && current_user_can( 'read' ) ? true : ( current_user_can( 'read' ) && $passFilter === 'null' ? null : false) ], $post__in, $defaultPostQuery ); if( apbIsPremium() ) { $query = apply_filters( 'apb_query', $query ); } return $query; } function getPosts( $attributes, $pageNumber = 1 ){ 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 ); return $posts; } function apbPosts(){ $nonce = $_POST['_wpnonce'] ?? null; $attributes = $_POST['queryAttr']; $pageNumber = (int)$_POST['pageNumber']; extract( $attributes ); if( !wp_verify_nonce( $nonce, 'wp_ajax' )){ wp_send_json_error( 'Invalid Request' ); } $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_once APB_DIR_PATH . '/inc/block.php'; require_once APB_DIR_PATH . '/inc/functions.php'; require_once APB_DIR_PATH . '/inc/CustomPost.php'; require_once APB_DIR_PATH . '/inc/HelpPage.php'; if( APB_HAS_FREE ){ require_once APB_DIR_PATH . '/inc/UpgradePage.php'; } }