Takip et butonu oluşturmak istiyorum hazır oluşturulmuş buton var ama takip butonuna bastığım zaman fonksiyon farklı işliyor.
function gp_follow_items() {
if (isset($_REQUEST['wpfpaction'])) {
global $ajax_mode;
$ajax_mode = isset($_REQUEST['ajax']) ? $_REQUEST['ajax'] : false;
if ($_REQUEST['wpfpaction'] == 'add') {
gp_follow();
} else if ($_REQUEST['wpfpaction'] == 'remove') {
gp_unfollow();
} else if ($_REQUEST['wpfpaction'] == 'clear') {
if ( gp_clear_followed() ) {
gp_die_or_go( '' . __( 'All items removed', 'gp_lang' ) . '' );
} else {
gp_die_or_go( 'Error' );
}
}
}
}
add_action('wp_loaded', 'gp_follow_items');
function gp_follow( $post_id = '' ) {
global $gp;
if ( empty( $post_id ) ) $post_id = $_REQUEST['postid'];
if ( $gp['hub_following_items'] == 'members' && ! is_user_logged_in() ) {
gp_die_or_go( __( 'Only registered users can follow items.', 'gp_lang' ) );
return false;
}
if ( gp_do_add_to_list($post_id) ) {
do_action('gp_after_add', $post_id);
gp_update_post_meta( $post_id, 1 );
$str = gp_follow_button( 1, "remove", 0, array( 'post_id' => $post_id ) );
gp_die_or_go( $str );
}
}
function gp_do_add_to_list($post_id) {
if (gp_check_followed($post_id))
return false;
if (is_user_logged_in()) {
return gp_add_to_usermeta($post_id);
} else {
return gp_set_cookie($post_id, "added");
}
}
function gp_unfollow($post_id = "") {
global $gp;
if (empty($post_id)) $post_id = $_REQUEST['postid'];
if (gp_do_unfollow($post_id)) {
do_action('gp_after_remove', $post_id);
gp_update_post_meta($post_id, -1);
if ( isset($_REQUEST['page']) && $_REQUEST['page'] == 1 ) {
$str = '';
} else {
$str = gp_follow_button(1, "add", 0, array( 'post_id' => $post_id ) );
}
gp_die_or_go($str);
}
else return false;
}
function gp_die_or_go( $str ) {
global $ajax_mode;
if ( $ajax_mode ) {
die( $str );
} else {
wp_redirect( $_SERVER['HTTP_REFERER'] );
}
}
function gp_add_to_usermeta($post_id) {
$gp_followed = gp_get_user_meta();
$gp_followed[] = $post_id;
gp_update_user_meta($gp_followed);
return true;
}
function gp_check_followed($cid) {
if (is_user_logged_in()) {
$following_page_ids = gp_get_user_meta();
if ($following_page_ids)
foreach ($following_page_ids as $fpost_id)
if ($fpost_id == $cid) return true;
} else {
if (gp_get_cookie()):
foreach (gp_get_cookie() as $fpost_id => $val)
if ($fpost_id == $cid) return true;
endif;
}
return false;
}
function gp_follow_button( $return = 0, $action = "", $show_span = 1, $args = array() ) {
$post_id = $GLOBALS['gp_post_id'];
extract($args);
$str = '';
if ($action == "remove"):
$str .= gp_follow_button_html($post_id, __( 'Unfollow', 'gp_lang' ), "remove");
elseif ($action == "add"):
$str .= gp_follow_button_html($post_id, __( 'Follow', 'gp_lang' ), "add");
elseif (gp_check_followed($post_id)):
$str .= gp_follow_button_html($post_id, __( 'Unfollow', 'gp_lang' ), "remove");
else:
$str .= gp_follow_button_html($post_id, __( 'Follow', 'gp_lang' ), "add");
endif;
$str .= '';
if ( $return ) {
return $str;
} else {
echo html_entity_decode( $str );
}
}
function gp_follow_button_html($post_id, $opt, $action) {
$link = "" . gp_loader() . $opt . "";
$link = apply_filters( 'gp_follow_button_html', $link );
return $link;
}
function gp_get_users_following($user = "") {
$following_page_ids = array();
if (!empty($user)):
return gp_get_user_meta($user);
endif;
# collect favorites from cookie and if user is logged in from database.
if (is_user_logged_in()):
$following_page_ids = gp_get_user_meta();
else:
if (gp_get_cookie()):
foreach (gp_get_cookie() as $post_id => $post_title) {
array_push($following_page_ids, $post_id);
}
endif;
endif;
return $following_page_ids;
}
function gp_list_follow_items( $args = array() ) {
$user = isset($_REQUEST['user']) ? $_REQUEST['user'] : "";
extract($args);
global $following_page_ids;
if ( !empty($user) ) {
if ( gp_is_user_favlist_public($user) )
$following_page_ids = gp_get_users_following($user);
} else {
$following_page_ids = gp_get_users_following();
}
}