0 ) {
$link = str_replace( $url, '', get_permalink( $id ) );
$link = trim( $link, '/' );
add_rewrite_rule( "$link/([^/]+)/page/?([0-9]{1,})/?$", 'index.php?page_id=' . $id . '&aiovg_category=$matches[1]&paged=$matches[2]', 'top' );
add_rewrite_rule( "$link/([^/]+)/?$", 'index.php?page_id=' . $id . '&aiovg_category=$matches[1]', 'top' );
}
// User videos page
$id = $page_settings['user_videos'];
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 . '&aiovg_user=$matches[1]&paged=$matches[2]', 'top' );
add_rewrite_rule( "$link/([^/]+)/?$", 'index.php?page_id=' . $id . '&aiovg_user=$matches[1]', 'top' );
}
// Player page
$id = $page_settings['player'];
if ( $id > 0 ) {
$link = str_replace( $url, '', get_permalink( $id ) );
$link = trim( $link, '/' );
add_rewrite_rule( "$link/id/([^/]+)/?$", 'index.php?page_id=' . $id . '&aiovg_type=id&aiovg_video=$matches[1]', 'top' );
}
// Rewrite tags
add_rewrite_tag( '%aiovg_category%', '([^/]+)' );
add_rewrite_tag( '%aiovg_user%', '([^/]+)' );
add_rewrite_tag( '%aiovg_type%', '([^/]+)' );
add_rewrite_tag( '%aiovg_video%', '([^/]+)' );
}
/**
* Flush rewrite rules when it's necessary.
*
* @since 1.0.0
*/
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();
}
}
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
$general_settings = get_option( 'aiovg_general_settings' );
$deps = array();
if ( isset( $general_settings['bootstrap']['css'] ) ) {
wp_register_style( AIOVG_PLUGIN_SLUG . '-bootstrap', AIOVG_PLUGIN_URL . 'public/assets/css/bootstrap.css', array(), '3.3.7', 'all' );
$deps[] = AIOVG_PLUGIN_SLUG . '-bootstrap';
}
if ( ! empty( $general_settings['fontawesome'] ) ) {
wp_register_style( AIOVG_PLUGIN_SLUG . '-fontawesome', AIOVG_PLUGIN_URL . 'public/assets/css/font-awesome.min.css', array(), '4.7.0', 'all' );
$deps[] = AIOVG_PLUGIN_SLUG . '-fontawesome';
}
wp_register_style( AIOVG_PLUGIN_SLUG . '-magnific-popup', AIOVG_PLUGIN_URL . 'public/assets/css/magnific-popup.css', array(), '1.1.0', 'all' );
wp_register_style( AIOVG_PLUGIN_SLUG, AIOVG_PLUGIN_URL . 'public/assets/css/aiovg-public.css', $deps, AIOVG_PLUGIN_VERSION, 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
wp_register_script( AIOVG_PLUGIN_SLUG . '-magnific-popup', AIOVG_PLUGIN_URL . 'public/assets/js/magnific-popup.min.js', array( 'jquery' ), '1.1.0', false );
wp_register_script( AIOVG_PLUGIN_SLUG, AIOVG_PLUGIN_URL . 'public/assets/js/aiovg-public.js', array( 'jquery' ), AIOVG_PLUGIN_VERSION, false );
}
/**
* Override the default page/post title.
*
* @since 1.0.0
* @param string $title The document title.
* @param string $sep Title separator.
* @param string $seplocation Location of the separator (left or right).
* @return string The filtered title.
*/
public function wp_title( $title, $sep, $seplocation ) {
global $post;
if ( ! isset( $post ) ) return $title;
$page_settings = get_option( 'aiovg_page_settings' );
$site_name = get_bloginfo( 'name' );
$custom_title = '';
// Get category page title
if ( $post->ID == $page_settings['category'] ) {
if ( $slug = get_query_var( 'aiovg_category' ) ) {
$term = get_term_by( 'slug', $slug, 'aiovg_categories' );
$custom_title = $term->name;
}
}
// Get user videos page title
if ( $post->ID == $page_settings['user_videos'] ) {
if ( $slug = get_query_var( 'aiovg_user' ) ) {
$user = get_user_by( 'slug', $slug );
$custom_title = $user->display_name;
}
}
// ...
if ( ! empty( $custom_title ) ) {
$title = ( 'left' == $seplocation ) ? "$site_name $sep $custom_title" : "$custom_title $sep $site_name";
}
return $title;
}
/**
* Fix conflict with the YOAST plugin when updating the page/post title.
*
* @since 1.0.0
* @param array $title The document title.
* @return Filtered title.
*/
public function pre_get_document_title( $title ) {
global $post;
if ( ! isset( $post ) ) return $title;
$page_settings = get_option( 'aiovg_page_settings' );
if ( in_array( $post->ID, array( $page_settings['category'], $page_settings['user_videos'] ) ) ) {
$title = '';
}
return $title;
}
/**
* Override the default post/page title depending on the AIOVG view.
*
* @since 1.0.0
* @param array $title The document title parts.
* @return Filtered title parts.
*/
public function document_title_parts( $title ) {
global $post;
if ( ! isset( $post ) ) return $title;
$page_settings = get_option( 'aiovg_page_settings' );
// Get category page title
if ( $post->ID == $page_settings['category'] ) {
if ( $slug = get_query_var( 'aiovg_category' ) ) {
$term = get_term_by( 'slug', $slug, 'aiovg_categories' );
$title['title'] = $term->name;
}
}
// Get user videos page title
if ( $post->ID == $page_settings['user_videos'] ) {
if ( $slug = get_query_var( 'aiovg_user' ) ) {
$user = get_user_by( 'slug', $slug );
$title['title'] = $user->display_name;
}
}
// Return
return $title;
}
/**
* Adds the Facebook OG tags and Twitter Cards.
*
* @since 1.0.0
*/
public function og_metatags() {
global $post;
if ( isset( $post ) && is_singular( 'aiovg_videos' ) ) {
printf( '', get_permalink() );
echo '';
printf( '', get_the_title() );
if ( ! empty( $post->post_content ) ) printf( '', aiovg_get_excerpt() );
$image = get_post_meta( $post->ID, 'image', true );
$image_id = get_post_meta( $post->ID, 'image_id', true );
$image = aiovg_get_image_url( $image_id, 'large', $image, 'player' );
if ( ! empty( $image ) ) printf( '', $image );
printf( '', get_bloginfo( 'name' ) );
echo '';
}
}
/**
* Change the current page title if applicable.
*
* @since 1.0.0
* @param string $title Current page title.
* @return string $title Modified page title.
*/
public function the_title( $title ) {
if ( ! in_the_loop() || ! is_main_query() ) {
return $title;
}
global $post;
$page_settings = get_option( 'aiovg_page_settings' );
// Change category page title
if ( $post->ID == $page_settings['category'] ) {
if ( $slug = get_query_var( 'aiovg_category' ) ) {
$term = get_term_by( 'slug', $slug, 'aiovg_categories' );
$title = $term->name;
}
}
// Change search page title
if ( $post->ID == $page_settings['search'] ) {
$queries = array();
if ( ! empty( $_GET['vi'] ) ) {
$queries[] = sanitize_text_field( $_GET['vi'] );
}
if ( ! empty( $_GET['ca'] ) ) {
$term = get_term_by( 'id', (int) $_GET['ca'], 'aiovg_categories' );
$queries[] = $term->name;
}
if ( ! empty( $queries ) ) {
$title = sprintf( __( 'Showing results for "%s"', 'all-in-one-video-gallery' ), implode( ', ', $queries ) );
}
}
// Change user videos page title
if ( $post->ID == $page_settings['user_videos'] ) {
if ( $slug = get_query_var( 'aiovg_user' ) ) {
$user = get_user_by( 'slug', $slug );
$title = $user->display_name;
}
}
return $title;
}
/**
* Always use our custom page for AIOVG categories.
*
* @since 1.0.0
* @param string $url The term URL.
* @param object $term The term object.
* @param string $taxonomy The taxonomy slug.
* @return string $url Filtered term URL.
*/
public function term_link( $url, $term, $taxonomy ) {
if ( 'aiovg_categories' == $taxonomy ) {
$url = aiovg_get_category_page_url( $term );
}
return $url;
}
}