0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/page/?([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_category=$matches[1]&paged=$matches[2]', 'top' ); add_rewrite_rule( "$link/([^/]+)/?$", 'index.php?page_id='.$id.'&acadp_category=$matches[1]', 'top' ); } // Single Location Page $id = $page_settings['location']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/page/?([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_location=$matches[1]&paged=$matches[2]', 'top' ); add_rewrite_rule( "$link/([^/]+)/?$", 'index.php?page_id='.$id.'&acadp_location=$matches[1]', 'top' ); } // User Listings Page $id = $page_settings['user_listings']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/page/?([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_user=$matches[1]&paged=$matches[2]', 'top' ); add_rewrite_rule( "$link/([^/]+)/?$", 'index.php?page_id='.$id.'&acadp_user=$matches[1]', 'top' ); } // Listings Edit, Delete (or) Renew Pages $id = $page_settings['listing_form']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_action=$matches[1]&acadp_listing=$matches[2]', 'top' ); } // Remove from Favourites Page $id = $page_settings['favourite_listings']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_action=$matches[1]&acadp_listing=$matches[2]', 'top' ); } // Checkout page $id = $page_settings['checkout']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([^/]+)/([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_action=$matches[1]&acadp_order=$matches[2]', 'top' ); add_rewrite_rule( "$link/([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_listing=$matches[1]', 'top' ); } // Payment success page $id = $page_settings['payment_receipt']; if( $id > 0 ) { $link = str_replace( $url, '', get_permalink( $id ) ); $link = trim( $link, '/' ); add_rewrite_rule( "$link/([0-9]{1,})/?$", 'index.php?page_id='.$id.'&acadp_order=$matches[1]', 'top' ); } // Rewrite tags add_rewrite_tag( '%acadp_category%', '([^/]+)' ); add_rewrite_tag( '%acadp_location%', '([^/]+)' ); add_rewrite_tag( '%acadp_user%', '([^/]+)' ); add_rewrite_tag( '%acadp_listing%', '([0-9]{1,})' ); add_rewrite_tag( '%acadp_action%', '([^/]+)' ); add_rewrite_tag( '%acadp_order%', '([0-9]{1,})' ); } /** * Flush rewrite rules when it's necessary. * * @since 1.0.0 * @access public */ public function maybe_flush_rules() { $rewrite_rules = get_option( 'rewrite_rules' ); if( $rewrite_rules ) { global $wp_rewrite; foreach( $rewrite_rules as $rule => $rewrite ) { $rewrite_rules_array[$rule]['rewrite'] = $rewrite; } $rewrite_rules_array = array_reverse( $rewrite_rules_array, true ); $maybe_missing = $wp_rewrite->rewrite_rules(); $missing_rules = false; foreach( $maybe_missing as $rule => $rewrite ) { if( ! array_key_exists( $rule, $rewrite_rules_array ) ) { $missing_rules = true; break; } } if( true === $missing_rules ) { flush_rewrite_rules(); } } } /** * Registers and enqueues the stylesheets for the public-facing side of the site. * * @since 1.0.0 * @access public */ public function register_enqueue_styles() { $general_settings = get_option( 'acadp_general_settings' ); $deps = array(); if( isset( $general_settings['load_bootstrap'] ) && in_array( 'css' , $general_settings['load_bootstrap'] ) ) { wp_register_style( ACADP_PLUGIN_NAME.'-bootstrap', ACADP_PLUGIN_URL . 'includes/libraries/bootstrap/acadp-bootstrap.css', array(), '3.3.5', 'all' ); $deps[] = ACADP_PLUGIN_NAME.'-bootstrap'; } wp_register_style( ACADP_PLUGIN_NAME, ACADP_PLUGIN_URL . 'public/css/acadp-public.css', $deps, ACADP_VERSION_NUM, 'all' ); // Enqueue style dependencies if( is_singular('acadp_listings') ) { wp_enqueue_style( ACADP_PLUGIN_NAME ); } } /** * Registers and enqueues javascript for the public-facing side of the site. * * @since 1.0.0 * @access public */ public function register_enqueue_scripts() { $general_settings = get_option( 'acadp_general_settings' ); $recaptcha_settings = get_option( 'acadp_recaptcha_settings' ); if( isset( $general_settings['load_bootstrap'] ) && in_array( 'javascript' , $general_settings['load_bootstrap'] ) ) { wp_register_script( ACADP_PLUGIN_NAME.'-bootstrap', ACADP_PLUGIN_URL.'includes/libraries/bootstrap/bootstrap.min.js', array( 'jquery' ), '3.3.5', false ); } wp_register_script( ACADP_PLUGIN_NAME.'-validator', ACADP_PLUGIN_URL.'includes/libraries/bootstrap/validator.min.js', array( 'jquery' ), '0.9.0', false ); wp_register_script( ACADP_PLUGIN_NAME, ACADP_PLUGIN_URL.'public/js/acadp-public.js', array( 'jquery' ), ACADP_VERSION_NUM, false ); if( ! empty( $recaptcha_settings['site_key'] ) && ! empty( $recaptcha_settings['forms'] ) ) { $recaptcha_site_key = $recaptcha_settings['site_key']; $recaptcha_listing = in_array( 'listing', $recaptcha_settings['forms'] ) ? 1 : 0; $recaptcha_contact = ! empty( $general_settings['has_contact_form'] ) && in_array( 'contact', $recaptcha_settings['forms'] ) ? 1 : 0; $recaptcha_report_abuse = ! empty( $general_settings['has_report_abuse'] ) && in_array( 'report_abuse', $recaptcha_settings['forms'] ) ? 1 : 0; } else { $recaptcha_site_key = ''; $recaptcha_listing = 0; $recaptcha_contact = 0; $recaptcha_report_abuse = 0; } wp_localize_script( ACADP_PLUGIN_NAME, 'acadp', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'maximum_images_per_listing' => $general_settings['maximum_images_per_listing'], 'recaptcha_site_key' => $recaptcha_site_key, 'recaptcha_listing' => $recaptcha_listing, 'recaptcha_contact' => $recaptcha_contact, 'recaptcha_report_abuse' => $recaptcha_report_abuse, 'recaptchas' => array( 'listing' => 0, 'contact' => 0, 'report_abuse' => 0 ), 'recaptcha_invalid_message' => __( "You can't leave Captcha Code empty", 'advanced-classifieds-and-directory-pro' ), 'user_login_alert_message' => __( 'Sorry, you need to login first.', 'advanced-classifieds-and-directory-pro' ) ) ); wp_register_script( ACADP_PLUGIN_NAME.'-google-map', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array( ACADP_PLUGIN_NAME ), '', false ); wp_register_script( ACADP_PLUGIN_NAME."-recaptcha", "https://www.google.com/recaptcha/api.js?onload=acadp_on_recaptcha_load&render=explicit", array( ACADP_PLUGIN_NAME ), '', false ); // Enqueue script dependencies if( is_singular('acadp_listings') ) { if( wp_script_is( ACADP_PLUGIN_NAME.'-bootstrap', 'registered' ) ) { wp_enqueue_script( ACADP_PLUGIN_NAME.'-bootstrap' ); } wp_enqueue_script( ACADP_PLUGIN_NAME.'-validator' ); wp_enqueue_script( ACADP_PLUGIN_NAME ); wp_enqueue_script( ACADP_PLUGIN_NAME.'-google-map' ); if( isset( $recaptcha_settings['forms'] ) && in_array( 'listing', $recaptcha_settings['forms'] ) ) { wp_enqueue_script( ACADP_PLUGIN_NAME . "-recaptcha" ); } } } /** * Adds the Facebook OG tags and Twitter Cards. * * @since 1.0.0 * @access public */ public function og_metatags() { global $post; if( is_page() ) { $page_settings = get_option( 'acadp_page_settings' ); $socialshare_settings = get_option( 'acadp_socialshare_settings' ); $page = ''; if( is_singular('acadp_listings') ) { $page = 'listing'; } else { if( $page_settings['categories'] == $post->ID ) { $page = 'categories'; } if( $page_settings['locations'] == $post->ID ) { $page = 'locations'; } if( in_array( $post->ID, array( $page_settings['listings'], $page_settings['user_listings'], $page_settings['category'], $page_settings['location'], $page_settings['search'] ) ) ) { $page = 'listings'; } } if( isset( $socialshare_settings['pages'] ) && in_array( $page, $socialshare_settings['pages'] ) ) { echo ''; echo ''; echo ''; if( 'listing' == $page ) { echo ''; $images = get_post_meta( $post->ID, 'images', true ); if( isset( $images ) ) { $thumbnail = wp_get_attachment_image_src( $images[0], 'full' ); echo ''; } } echo ''; echo ''; } } } /** * Force Specific Pages to load with the SSL Certificate. * * @since 1.0.0 * @access public * * @params boolean $force_ssl Whether to force SSL in current page. * @params int $post_id Page ID. * @return boolean True to force SSL, false if not. */ public function force_ssl_https( $force_ssl, $post_id ) { $page_settings = get_option( 'acadp_page_settings' ); if ( $post_id == ( int ) $page_settings['checkout'] ) { $gateway_settings = get_option( 'acadp_gateway_settings' ); if( ! empty( $gateway_settings['use_https'] ) ) { return true; } } return $force_ssl; } /** * Change the current page title if applicable. * * @since 1.0.0 * @access public * * @params string $title Current page title. * @return string $title Modified page title. */ public function the_title( $title ) { global $id, $post; if( $id && $post ) return $title; if( is_singular('acadp_listings') && 'acadp_listings' == $post->post_type ) return $title; if( is_page() && in_the_loop() ) { $page_settings = get_option( 'acadp_page_settings' ); // Change Category page title if( $id == $page_settings['category'] ) { if( $slug = get_query_var( 'acadp_category' ) ) { $term = get_term_by( 'slug', $slug, 'acadp_categories' ); $title = $term->name; } } // Change Location page title if( $id == $page_settings['location'] ) { if( $slug = get_query_var( 'acadp_location' ) ) { $term = get_term_by( 'slug', $slug, 'acadp_locations' ); $title = $term->name; } } // Change User Listings page title if( $id == $page_settings['user_listings'] ) { if( $slug = get_query_var( 'acadp_user' ) ) { $user = get_user_by( 'slug', $slug ); $title = $user->display_name; } } } return $title; } /** * Set the email content type. * * @since 1.0.0 * @access public * * @params string $content_type Default content type. */ public function set_content_type( $content_type ) { return 'text/html'; } }