wp_mail fails.
* This function is originally used for wp_mail fallback.
* But you can use this function to send message which will be
* displayed on admin screen.
*
* @param int $user_id
* @param string $body
* @param int $from
* @param string $subject
* @return bool
*/
function gianism_message($user_id, $body, $from = 0, $subject = '' ){
/** @var \Gianism\Message $gianism */
$gianism = \Gianism\Message::get_instance();
return $gianism->send_message($user_id, $body, $from, $subject);
}
/**
* Returns Facebook ID
*
* @since 1.0
* @param int $user_id
* @return string
*/
function get_facebook_id($user_id){
/** @var \Gianism\Service\Facebook $facebook */
$facebook = \Gianism\Service\Facebook::get_instance();
return get_user_meta($user_id, $facebook->umeta_id, true);
}
/**
* Returns url to get Publish stream permission
*
* This function itself has no effect without action hook.
* See example below:
*
*
* // In some template, display button.
* get_facebook_publish_permission_link(get_permalink(), 'my_favorite_action', array('post_id' => get_the_ID()));
*
* // Then, hook action in functions.php in your theme.
* add_action('my_favorite_action', 'my_publish_action');
*
* function my_publish_action($facebook, $args){
* $post = get_post($args['post_id']);
* try{
* $facebook->api("/me/feed", "POST", array(
* "message" => "I read this article!",
* "link" => get_permalink($post->ID),
* "name" => get_the_title($post->ID),
* "description" => strip_tags($post->post_content),
* "action" => json_encode(array(
* "name" => get_bloginfo('name'),
* "link" => home_url('/')))
* ));
* }catch(FacebookApiException $e){
* // Error
* wp_die($e->getMessage());
* }
* }
*
*
* @since 1.3
* @param string $redirect_url URL where user will be redirect afeter authentication
* @param string $action Action name which will be fired after authenticaction
* @param array $args Array which will be passed to action hook
* @return string
*/
function get_facebook_publish_permission_link($redirect_url = null, $action = '', $args = array()){
/** @var \Gianism\Service\Facebook $facebook */
$facebook = \Gianism\Service\Facebook::get_instance();
return $facebook->get_publish_permission_link($redirect_url, $action, $args);
}
/**
* Returns if user is connected with particular web service.
*
* @since 1.0
* @param string $service One of facebook, mixi, yahoo, twitter or google.
* @param int $user_id If not specified, current user id will be used.
* @return boolean
*/
function is_user_connected_with($service, $user_id = 0){
/** @var \Gianism\Bootstrap $gianism */
$gianism = \Gianism\Bootstrap::get_instance();
if(!$user_id){
$user_id = get_current_user_id();
}
return ($instance = $gianism->get_service_instance($service) ) && $instance->is_connected($user_id);
}
/**
* Get user object by credencial
*
* Only facebook is supported.
*
* @todo Make other services to work.
* @global \wpdb $wpdb
* @since 1.0
* @param string $service
* @param mixed $credential
* @return \WP_User
*/
function get_user_by_service($service, $credential){
global $wpdb;
$gianism = \Gianism\Bootstrap::get_instance();
$instance = $gianism->get_instance($service);
if(!$instance){
return false;
}
switch($service){
case 'facebook':
$user_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$instance->umeta_id}' AND meta_value = %s", $credential));
if($user_id){
return new WP_User($user_id);
}else{
return null;
}
break;
default:
return null;
break;
}
}
/**
* Returns if current user liked or not.
*
* You can use this function only on Facebook fan page tab.
*
* @since 1.0
* @return boolean
*/
function is_user_like_fangate(){
/** @var \Gianism\Service\Facebook $fb */
$fb = \Gianism\Service\Facebook::get_instance();
return $fb->is_user_like_me_on_fangate();
}
/**
* Returns if current user is guest.
*
* Valid only on facebook fan gate.
*
* @since 1.0
* @return boolean
*/
function is_guest_on_fangate(){
/** @var \Gianism\Service\Facebook $fb */
$fb = \Gianism\Service\Facebook::get_instance();
return $fb->is_guest_on_fangate();
}
/**
* Returns if current user has wordpress account.
*
* You can this function only on Facebook fan page tab.
*
* @global \wpdb $wpdb
* @param string $service
* @return boolean
*/
function is_user_registered_with($service){
global $wpdb;
$gianism = \Gianism\Bootstrap::get_instance();
$instance = $gianism->get_instance($service);
switch($service){
case 'facebook':
$user_id = get_user_id_on_fangate();
$sql = <<
* $timeline = get_transient('twitter_timeline');
* if( false === $timeline){
* $timeline = twitter_get_timeline('my_screen_name');
* set_transient('twitter_timeline', $timeline, 3600);
* }
* foreach($timeline as $status){
* // Echo status
* }
*
*
* @since 1.3
* @param string $screen_name If not specified, admin user's screen name will be used.
* @param array $additional_data
* @return object JSON format object.
*/
function twitter_get_timeline($screen_name = null, array $additional_data = array()){
/** @var \Gianism\Service\Twitter $twitter */
$twitter = \Gianism\Service\Twitter::get_instance();
if(is_null($screen_name)){
$screen_name = $twitter->tw_screen_name;
}
return $twitter->call_api('statuses/user_timeline', array_merge(
array('screen_name' => $screen_name),
$additional_data
));
}
/**
* Show Login buttons
*
* Show login buttons where you want.
*
* @since 1.0
* @param string $before
* @param string $after
*/
function gianism_login($before = '', $after = ''){
/** @var \Gianism\Login $login */
$login = \Gianism\Login::get_instance();
$login->login_form($before, $after);
}
/**
* Detect if user is geek
*
* Geek means user is connected with Github.
*
* @since 2.0.0
* @param int $user_id
* @return bool
*/
function is_geek($user_id){
/** @var \Gianism\Service\Github $github */
$github = \Gianism\Service\Github::get_instance();
return (bool)get_user_meta($user_id, $github->umeta_id);
}
/**
* Detect if current user is geek
*
* @since 2.0.0
* @see is_geek
* @return bool
*/
function is_current_user_geek(){
return is_geek(get_current_user_id());
}