slug}.php"; break; } } // Check for archive pages if ( adqs_is_listing_archive() ) { $file = "archive-{$this->slug}.php"; } // Check for author pages - only load directory template for directory requests if ( is_author() && adqs_is_author_listing_archive() ) { $file = "archive-{$this->slug}.php"; } // There is a file, create a new template path if ( $file ) { // Check in Theme for folder adirectory/templates/ and the file inside $template = locate_template( "adirectory/{$file}" ); // There is no template in the theme if ( ! $template ) { // Get from Plugin's folder 'templates' $template = adqs_templates_location() . "/{$file}"; } } return $template; } // end /** * Author listing Page rewrite rules * * @param object $wpr * @return object */ public function author_page_rewrite_rules( $wpr ) { // Create rewrite rule for author archive with "directory" slug $key = '^author/([a-zA-Z0-9\-_]+)/directory(?:/page/([0-9]+))?/?$'; $rewrite = 'index.php?author_name=$matches[1]&paged=$matches[2]'; $newRules = [ $key => $rewrite ]; $wpr->rules = $newRules + $wpr->rules; // Also handle the case where someone visits /author/username/ directly $key2 = '^author/([a-zA-Z0-9\-_]+)/?$'; $rewrite2 = 'index.php?author_name=$matches[1]'; $newRules2 = [ $key2 => $rewrite2 ]; $wpr->rules = $newRules2 + $wpr->rules; return $wpr; } // end /** * template include for overwrite * filter hook for single listing page * * @param string $template * @return string */ public function comment_review_template_loader( $template ) { global $post; if ( ! adqs_is_directory_post_type( $post->post_type ) ) { return $template; } $theme_dir = get_stylesheet_directory() . '/adirectory'; $template_name = 'single-listing-reviews.php'; if ( file_exists( $theme_dir . '/' . $template_name ) ) { $template = $theme_dir . '/' . $template_name; } elseif ( file_exists( adqs_templates_location() . $template_name ) ) { $template = adqs_templates_location() . $template_name; } return $template; } // end /** * Ensure admin bar works on single listing pages */ public function ensure_admin_bar_works() { if ( is_user_logged_in() && is_singular() && adqs_is_directory_post_type( get_post_type() ) ) { // Ensure user has admin bar enabled $user_id = get_current_user_id(); $admin_bar_pref = get_user_option( 'show_admin_bar_front', $user_id ); if ( $admin_bar_pref !== 'true' ) { update_user_option( $user_id, 'show_admin_bar_front', 'true' ); } } } /** * Add edit link to admin bar for single listing pages */ public function add_edit_link_to_admin_bar( $wp_admin_bar ) { if ( is_singular() && adqs_is_directory_post_type( get_post_type() ) ) { $post_id = get_queried_object_id(); // Check if user can edit this post if ( current_user_can( 'edit_post', $post_id ) ) { $edit_link = get_edit_post_link( $post_id ); if ( $edit_link ) { $args = [ 'id' => 'edit', 'title' => __( 'Edit Listing', 'adirectory' ), 'href' => $edit_link, 'meta' => [ 'class' => 'ab-item', ], ]; $wp_admin_bar->add_node( $args ); } } } } }