getWidgetId(), __( $this->getWidgetName(), 'wp_auth0_widget_domain' ), array( 'description' => __( $this->getWidgetDescription(), 'wpb_widget_domain' ) ) ); $this->options = WP_Auth0_Options::Instance(); } protected function getWidgetId() { return 'wp_auth0_social_amplification_widget'; } protected function getWidgetName() { return __( 'Auth0 Social Amplification', 'wp-auth0' ); } protected function getWidgetDescription() { return __( 'Shows Auth0 Social Amplification widget in a sidebar', 'wp-auth0' ); } /** * Build the widget settings form in the Customizer and wp-admin > Widgets page. * * @param array $instance - Current instance of this widget. */ public function form( $instance ) { $fields = array( 'amplificator_title' => __( 'Widget title', 'wp-auth0' ), 'amplificator_subtitle' => __( 'Widget subtitle', 'wp-auth0' ), 'social_twitter_message' => __( 'Twitter message', 'wp-auth0' ), ); foreach ( $fields as $field => $title ) { $field_value = isset( $instance[ $field ] ) ? $instance[ $field ] : $this->options->get( $field ); printf( '
', esc_attr( $this->get_field_id( $field ) ), sanitize_text_field( $title ), esc_attr( $this->get_field_id( $field ) ), esc_attr( $this->get_field_name( $field ) ), esc_textarea( $field_value ) ); } printf( '%s %s.
%s
%s - %s%s - %s' . sanitize_text_field( $widget_subtitle ) . '
'; } wp_enqueue_style( 'auth0-aplificator-css', WPA0_PLUGIN_CSS_URL . 'amplificator.css' ); wp_enqueue_script( 'auth0-aplificator-js', WPA0_PLUGIN_JS_URL . 'amplificator.js', array( 'jquery' ), WPA0_VERSION ); wp_localize_script( 'auth0-aplificator-js', 'auth0_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); $current_page_url = self::current_page_url(); foreach ( $supportedProviders as $provider ) { if ( in_array( $provider, $providers ) && in_array( $provider, $enabledProviders ) ) { $js_function = "Auth0Amplify(this,'$provider', '$current_page_url')"; } else { $share_url = ''; switch ( $provider ) { case 'facebook': $share_url = 'https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( $current_page_url ); break; case 'twitter': $message = ''; if ( ! empty( $instance['social_twitter_message'] ) ) { $message = str_replace( '%page_url%', $current_page_url, $instance['social_twitter_message'] ); $message = str_replace( '%site_url%', home_url(), $message ); } $share_url = sprintf( 'https://twitter.com/share?url=%s&text=%s', rawurlencode( $current_page_url ), rawurlencode( $message ) ); break; } $js_function = sprintf( "javascript: void window.open('%s', '','height=300, width=600')", $share_url ); } printf( '', esc_attr( $js_function ), esc_attr( $provider ), esc_attr( $provider ), esc_attr( $provider ) ); } echo $args['after_widget']; } } /** * @deprecated - 3.9.0, functionality removed */ protected static function current_page_url() { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); return home_url( $_SERVER['REQUEST_URI'] ); } }