-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpfp-content-filter.php
57 lines (49 loc) · 2.18 KB
/
wpfp-content-filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
Plugin Name: WP Favorite Posts: Filter Hooks
Description: By default, WPFP adds it's bookmark text to every 'single' post view, this plugin unhooks it and rehooks it checking that we're not on a product page before adding
Version: 0.1
Author: The team at PIE
Author URI: http://pie.co.de
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
/* PIE\WPFavouritePostsFilter is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version.
PIE\WPFavouritePostsFilter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with PIE\WPFavouritePostsFilter. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html */
namespace PIE\WPFavouritePostsFilter;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Re-add WP Favourite posts filter to dictate where the content shows
*/
function adjust_wpfp_filters(){
remove_filter( 'the_content', '\wpfp_content_filter' );
add_filter( 'the_content', __NAMESPACE__ . '\wpfp_content_filter' );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\adjust_wpfp_filters' );
/**
* Filter WP Favourite Posts content
*
* @param string $content
* @return string
*/
function wpfp_content_filter( $content ) {
if ( is_page() ) {
if ( strpos( $content,'{{wp-favorite-posts}}' ) !== false ) {
$content = str_replace( '{{wp-favorite-posts}}', wpfp_list_favorite_posts(), $content );
}
}
if ( strpos( $content,'[wpfp-link]' ) !== false ) {
$content = str_replace( '[wpfp-link]', wpfp_link(1), $content );
}
if ( is_single() && ! is_singular( 'product' ) ) {
if ( wpfp_get_option( 'autoshow' ) == 'before' ) {
$content = wpfp_link(1) . $content;
} else if ( wpfp_get_option( 'autoshow' ) == 'after' ) {
$content .= wpfp_link(1);
}
}
return $content;
}