true, // Afrikaans 'ar_AR' => true, // Arabic 'az_AZ' => true, // Azerbaijani 'be_BY' => true, // Belarusian 'bg_BG' => true, // Bulgarian 'bn_IN' => true, // Bengali 'bs_BA' => true, // Bosnian 'ca_ES' => true, // Catalan 'cs_CZ' => true, // Czech 'cy_GB' => true, // Welsh 'da_DK' => true, // Danish 'de_DE' => true, // German 'el_GR' => true, // Greek 'en_US' => true, // English (US) 'en_GB' => true, // English (UK) 'eo_EO' => true, // Esperanto 'es_LA' => true, // Spanish 'es_ES' => true, // Spanish (Spain) 'et_EE' => true, // Estonian 'eu_ES' => true, // Basque 'fa_IR' => true, // Persian 'fi_FI' => true, // Finnish 'fo_FO' => true, // Faroese 'fr_FR' => true, // French (France) 'fr_CA' => true, // French (Canada) 'fy_NL' => true, // Frisian 'ga_IE' => true, // Irish 'gl_ES' => true, // Galician 'he_IL' => true, // Hebrew 'hi_IN' => true, // Hindi 'hr_HR' => true, // Croatian 'hu_HU' => true, // Hungarian 'hy_AM' => true, // Armenian 'id_ID' => true, // Indonesian 'is_IS' => true, // Icelandic 'it_IT' => true, // Italian 'ja_JP' => true, // Japanese 'ka_GE' => true, // Georgian 'km_KH' => true, // Khmer 'ko_KR' => true, // Korean 'ku_TR' => true, // Kurdish 'la_VA' => true, // Latin 'lt_LT' => true, // Lithuanian 'lv_LV' => true, // Latvian 'mk_MK' => true, // Macedonian 'ml_IN' => true, // Malayalam 'ms_MY' => true, // Malay 'nb_NO' => true, // Norwegian (bokmal) 'ne_NP' => true, // Nepali 'nl_NL' => true, // Dutch 'nn_NO' => true, // Norwegian (nynorsk) 'pa_IN' => true, // Punjabi 'pl_PL' => true, // Polish 'ps_AF' => true, // Pashto 'pt_BR' => true, // Portuguese (Brazil) 'pt_PT' => true, // Portuguese (Portugal) 'ro_RO' => true, // Romanian 'ru_RU' => true, // Russian 'sk_SK' => true, // Slovak 'sl_SI' => true, // Slovenian 'sq_AL' => true, // Albanian 'sr_RS' => true, // Serbian 'sv_SE' => true, // Swedish 'sw_KE' => true, // Swahili 'ta_IN' => true, // Tamil 'te_IN' => true, // Telugu 'th_TH' => true, // Thai 'tl_PH' => true, // Filipino 'tr_TR' => true, // Turkish 'uk_UA' => true, // Ukrainian 'vi_VN' => true, // Vietnamese 'zh_CN' => true, // Simplified Chinese (China) 'zh_HK' => true, // Traditional Chinese (Hong Kong) 'zh_TW' => true // Traditional Chinese (Taiwan) ); /** * Configures the plugin and future actions. * * @since 1.1 */ public function __construct() { // load plugin files relative to this directory $this->plugin_directory = dirname(__FILE__) . '/'; // set the Facebook locale based on the WordPress site's locale. Used to load the appropriate version of the Facebook SDK for JavaScript. $this->set_locale(); // Load the textdomain for translations load_plugin_textdomain( 'facebook', false, $this->plugin_directory . 'languages/' ); // load Facebook application data $credentials = get_option( 'facebook_application' ); if ( ! is_array( $credentials ) ) $credentials = array(); $this->credentials = $credentials; unset( $credentials ); $this->kid_directed = (bool) get_option( 'facebook_kid_directed_site' ); if ( $this->app_access_token_exists() ) { // Facebook Social Publisher functionality if ( ! class_exists( 'Facebook_Social_Publisher' ) ) require_once( $this->plugin_directory . 'admin/social-publisher/social-publisher.php' ); add_action( 'init', array( 'Facebook_Social_Publisher', 'init' ) ); } // Include Facebook widgets add_action( 'widgets_init', array( &$this, 'widgets_init' ) ); // load shortcodes if ( ! class_exists( 'Facebook_Shortcodes' ) ) require_once( $this->plugin_directory . 'social-plugins/shortcodes.php' ); Facebook_Shortcodes::init(); if ( is_user_logged_in() ) { // admin bar may show on public-facing site as well as administrative section add_action( 'add_admin_bar_menus', array( &$this, 'admin_bar' ) ); } if ( is_admin() ) { add_action( 'admin_enqueue_scripts', array( &$this, 'register_js_sdk' ), 1 ); $this->admin_init(); } else { add_action( 'wp_enqueue_scripts', array( &$this, 'register_js_sdk' ), 1 ); // split initialization functions into early (init) and regular (wp) action groups add_action( 'init', array( &$this, 'public_early_init' ), 1, 0 ); add_action( 'wp', array( &$this, 'public_init' ) ); } } /** * Add Facebook functionality to the WordPress admin bar. * * Add a link to the Facebook Comments Box moderation tool if Facebook Comments Box enabled. Replaces a link to WordPress comments moderation. * * @since 1.1 * * @return void */ public function admin_bar() { if ( isset( $this->credentials ) && isset( $this->credentials['app_id'] ) ) { if ( get_option( 'facebook_comments_enabled' ) ) { if ( ! class_exists( 'Facebook_Comments' ) ) require_once( $this->plugin_directory . 'social-plugins/class-facebook-comments.php' ); Facebook_Comments::admin_bar_menu(); } } } /** * Register the Facebook JavaScript SDK for later enqueueing * * @since 1.1 * * @uses wp_register_script * @global WP_Scripts $wp_scripts add extra JavaScript to the registered script handle * @return void */ public function register_js_sdk() { global $wp_scripts; $handle = 'facebook-jssdk'; // match the Facebook async snippet ID to avoid double load wp_register_script( $handle, ( is_ssl() ? 'https' : 'http' ) . '://connect.facebook.net/' . $this->locale . '/' . ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? 'all/debug.js' : 'all.js' ), array(), null, true ); // register the script but take it back with an async load add_filter( 'script_loader_src', array( 'Facebook_Loader', 'async_script_loader_src' ), 1, 2 ); $args = array( 'xfbml' => true ); if ( is_admin() ) { $args['status'] = true; $args['cookie'] = true; } else if ( $this->kid_directed ) { $args['kidDirectedSite'] = true; } // appId optional if ( ! empty( $this->credentials['app_id'] ) ) $args['appId'] = $this->credentials['app_id']; /** * Override options passed to the FB.init function to initialize the Facebook SDK for JavaScript. * * @since 1.1 * * @link https://developers.facebook.com/docs/reference/javascript/FB.init/ Facebook SDK for JavaScript FB.init * @param array $args Facebook SDK for JavaScript initialization options */ $args = apply_filters( 'facebook_jssdk_init_options', $args ); // allow the publisher to short circuit the init through the filter if ( ! empty( $args ) && isset( $wp_scripts ) ) { $wp_scripts->add_data( $handle, 'data', 'var FB_WP=FB_WP||{};FB_WP.queue={_methods:[],flushed:false,add:function(fn){FB_WP.queue.flushed?fn():FB_WP.queue._methods.push(fn)},flush:function(){for(var fn;fn=FB_WP.queue._methods.shift();){fn()}FB_WP.queue.flushed=true}};window.fbAsyncInit=function(){FB.init(' . json_encode( $args ) . ');if(FB_WP && FB_WP.queue && FB_WP.queue.flush){FB_WP.queue.flush()}' . apply_filters( 'facebook_jssdk_init_extras', '', isset( $this->credentials['app_id'] ) ? $this->credentials['app_id'] : '' ) . '}' ); } } /** * Proactively resolve Facebook JavaScript SDK domain name asynchronously before later use. * * @since 1.1.9 * * @link http://dev.chromium.org/developers/design-documents/dns-prefetching Chromium prefetch behavior * @link https://developer.mozilla.org/en-US/docs/Controlling_DNS_prefetching Firefox prefetch behavior * @return void */ public static function dns_prefetch_js_sdk() { echo '' . "\n"; } /** * Enqueue the JavaScript SDK * * @since 1.1 * * @uses wp_enqueue_script() */ public static function enqueue_js_sdk() { wp_enqueue_script( 'facebook-jssdk', false, array(), false, true ); } /** * Load Facebook SDK for JavaScript using an asynchronous loader. * * Called from script_loader_src filter. * * @since 1.1 * * @param string $src script URL * @param string $handle WordPress registered script handle * @global WP_Scripts $wp_scripts match concatenation preferences * @return string empty string if Facebook JavaScript SDK, else give back the src variable */ public static function async_script_loader_src( $src, $handle ) { global $wp_scripts; if ( $handle !== 'facebook-jssdk' ) return $src; // @link https://developers.facebook.com/docs/javascript/gettingstarted/#loading $html = '' . "\n"; if ( isset( $wp_scripts ) && $wp_scripts->do_concat ) $wp_scripts->print_html .= $html; else echo $html; // place after wp_print_footer_scripts at priority 20 add_action( 'wp_footer', array( 'Facebook_Loader', 'js_sdk_root_div' ), 21 ); // empty out the src response to avoid extra