PluginProbe
Gianism / 4.0.0
Gianism v4.0.0
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / functions.php

functions.php in Gianism 4.0.0, at functions.php

120 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Global functions for Gianism.
4 *
5 * @package Gianism
6 * @since 1.0
7 * @author Takahashi Fumiki
8 */
9
10
11
12
13
14 /**
15 * Returns if user is connected with particular web service.
16 *
17 * @package Gianism
18 * @since 3.0.0
19 *
20 * @param string $service One of facebook, mixi, yahoo, twitter or google.
21 * @param int $user_id If not specified, current user id will be used.
22 *
23 * @return boolean
24 */
25 function gianism_is_user_connected_with( $service, $user_id = 0 ) {
26 /** @var \Gianism\Bootstrap $gianism */
27 $gianism = \Gianism\Bootstrap::get_instance();
28 if ( ! $user_id ) {
29 $user_id = get_current_user_id();
30 }
31
32 return ( $instance = $gianism->service->get( $service ) ) && $instance->is_connected( $user_id );
33 }
34
35
36 /**
37 * Get user object by credential
38 *
39 * Only facebook is supported.
40 *
41 * @todo Make other services to work.
42 * @package Gianism
43 * @since 3.0.0
44 * @global \wpdb $wpdb
45 * @param string $service
46 * @param mixed $credential
47 *
48 * @return \WP_User
49 */
50 function gianism_get_user_by_service( $service, $credential ) {
51 global $wpdb;
52 $gianism = \Gianism\Bootstrap::get_instance();
53 $instance = $gianism->service->get( $service );
54 if ( ! $instance ) {
55 return false;
56 }
57 switch ( $service ) {
58 case 'facebook':
59 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$instance->umeta_id}' AND meta_value = %s", $credential ) );
60 if ( $user_id ) {
61 return new WP_User( $user_id );
62 } else {
63 return null;
64 }
65 break;
66 default:
67 return null;
68 break;
69 }
70 }
71
72 /**
73 * Show Login buttons
74 *
75 * Show login buttons where you want.
76 *
77 * @package Gianism
78 * @since 1.0
79 *
80 * @param string $before
81 * @param string $after
82 * @param string $redirect_to
83 */
84 function gianism_login( $before = '', $after = '', $redirect_to = '' ) {
85 /** @var \Gianism\Controller\Login $login */
86 $login = \Gianism\Controller\Login::get_instance();
87 $login->login_form( $before, $after, false, $redirect_to );
88 }
89
90 /**
91 * Add UTM campaign link to WordPress admin
92 *
93 * @package Gianism
94 * @since 3.0.0
95 * @internal
96 * @param string $url
97 * @param array $args
98 *
99 * @return string
100 */
101 function gianism_utm_link( $url, $args = [] ) {
102 $args = wp_parse_args( $args, [
103 'utm_source' => 'wp-admin',
104 'utm_medium' => 'link',
105 'utm_campaign' => 'Plugin User',
106 ] );
107 return add_query_arg( $args, $url );
108 }
109
110 /**
111 * Detect if WooCommerce is activated
112 *
113 * @package Gianism
114 * @since 3.0.5
115 * @return bool
116 */
117 function gianism_woocommerce_detected() {
118 return class_exists( 'WooCommerce' );
119 }
120