uninstall_plugin( __FILE__ ); } } if ( APB_HAS_PRO ) { require_once( APB_PATH . 'inc/fs-init.php' ); } require_once APB_PATH . '/inc/block.php'; require_once APB_PATH . '/inc/functions.php'; require_once APB_PATH . '/inc/free.php'; require_once APB_PATH . '/inc/custom-post.php'; 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(); } } // 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']); if( !apbIsPremium() ){ add_action( 'admin_bar_menu', [$this, 'adminBarMenu'], 500 ); add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] ); } 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']; 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 adminBarMenu ( \WP_Admin_Bar $admin_bar ) { if ( ! current_user_can( 'manage_options' ) ) { return; } $admin_bar->add_menu( array( 'id' => 'apb_offer_menu', 'parent' => 'top-secondary', 'group' => null, 'title' => '40% Off Black Friday!', //you can use img tag with image link. it will show the image icon Instead of the title. 'href' => admin_url('edit.php?post_type=apb&page=apb-upgrade'), 'meta' => [ 'title' => __( '40% Off Black Friday!', 'advanced-post-block' ), //This title will show on hover ] ) ); } function adminEnqueueScripts() { wp_enqueue_style( 'apb-admin-style', APB_DIR . 'dist/admin.css', [], APB_VERSION ); wp_enqueue_script( 'apb-admin-script', APB_DIR . 'dist/admin.js', [], APB_VERSION ); wp_set_script_translations( 'apb-admin-script', 'advanced-post-block', APB_PATH . 'languages' ); } function blockCategories( $categories ){ return array_merge( [ [ 'slug' => 'APBlock', 'title' => 'Advanced Post Block' ] ], $categories ); } function query( $attributes ){ extract( $attributes ); $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( apbIsPremium() ) { $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;