From 56a9b7ba9c3606abebdd489c200ea5973faed2d1 Mon Sep 17 00:00:00 2001 From: Andrei Baicus Date: Sun, 4 Mar 2018 14:52:46 +0200 Subject: [PATCH 1/4] Fixed Analytics module issues. Better UX on module activation. --- .../helpers/class-orbit-fox-render-helper.php | 109 +++++++++++++---- obfx_modules/google-analytics/init.php | 111 ++++++++---------- 2 files changed, 133 insertions(+), 87 deletions(-) diff --git a/core/app/helpers/class-orbit-fox-render-helper.php b/core/app/helpers/class-orbit-fox-render-helper.php index a583c1d8..e2ef9286 100644 --- a/core/app/helpers/class-orbit-fox-render-helper.php +++ b/core/app/helpers/class-orbit-fox-render-helper.php @@ -23,9 +23,11 @@ class Orbit_Fox_Render_Helper { * * @since 1.0.0 * @access public + * * @param string $name The name of the partial w/o '-tpl.php'. - * @param array $args Optional. An associative array with name and value to be + * @param array $args Optional. An associative array with name and value to be * passed to the partial. + * * @return string */ public function get_partial( $name = '', $args = array() ) { @@ -39,6 +41,7 @@ public function get_partial( $name = '', $args = array() ) { if ( file_exists( $file ) ) { include $file; } + return ob_get_clean(); } @@ -47,9 +50,11 @@ public function get_partial( $name = '', $args = array() ) { * * @since 1.0.0 * @access public + * * @param string $name The name of the partial w/o '-page.php'. - * @param array $args Optional. An associative array with name and value to be + * @param array $args Optional. An associative array with name and value to be * passed to the view. + * * @return string */ public function get_view( $name = '', $args = array() ) { @@ -63,6 +68,7 @@ public function get_view( $name = '', $args = array() ) { if ( file_exists( $file ) ) { include $file; } + return ob_get_clean(); } @@ -71,7 +77,9 @@ public function get_view( $name = '', $args = array() ) { * * @since 1.0.0 * @access private - * @param array $option The specific defaults array. + * + * @param array $option The specific defaults array. + * * @return array */ private function sanitize_option( $option ) { @@ -98,7 +106,9 @@ private function sanitize_option( $option ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function set_field_value( $option = array() ) { @@ -106,6 +116,7 @@ private function set_field_value( $option = array() ) { if ( isset( $option['value'] ) && $option['value'] != '' ) { $field_value = $option['value']; } + return $field_value; } @@ -114,8 +125,10 @@ private function set_field_value( $option = array() ) { * * @since 1.0.0 * @access private + * * @param string $element_id The option id field. * @param string $title The option title field. + * * @return string */ private function get_title( $element_id, $title ) { @@ -123,6 +136,7 @@ private function get_title( $element_id, $title ) { if ( $title ) { $display_title = ''; } + return $display_title; } @@ -131,7 +145,9 @@ private function get_title( $element_id, $title ) { * * @since 1.0.0 * @access private + * * @param string $description The option description field. + * * @return string */ private function get_description( $description ) { @@ -139,6 +155,7 @@ private function get_description( $description ) { if ( $description ) { $display_description = '

' . $description . '

'; } + return $display_description; } @@ -147,8 +164,10 @@ private function get_description( $description ) { * * @since 1.0.0 * @access private - * @param array $option The option array. + * + * @param array $option The option array. * @param string $element The element we want to wrap. + * * @return string */ private function wrap_element( $option, $element ) { @@ -167,13 +186,13 @@ private function wrap_element( $option, $element ) { return ' ' . $before_wrap . ' -
- ' . $title . ' - ' . $element . ' - ' . $description . ' -
- ' . $after_wrap . ' - '; +
+ ' . $title . ' + ' . $element . ' + ' . $description . ' +
+ ' . $after_wrap . ' + '; } /** @@ -181,20 +200,22 @@ private function wrap_element( $option, $element ) { * * @since 1.0.0 * @access private + * * @param string $type The field type ( checkbox | radio ). * @param string $field_value The field value. * @param string $checked The checked flag. * @param string $label The option label. - * @param array $option The option from the module. + * @param array $option The option from the module. + * * @return string */ private function generate_check_type( $type = 'radio', $field_value, $checked, $label, $option = array() ) { return ' - - '; + + '; } /** @@ -202,8 +223,10 @@ private function generate_check_type( $type = 'radio', $field_value, $checked, $ * * @since 1.0.0 * @access private + * * @param array $option The option from the module. - * @param bool $is_email Render an email input instead of text. + * @param bool $is_email Render an email input instead of text. + * * @return mixed */ private function field_text( $option = array(), $is_email = false ) { @@ -224,7 +247,9 @@ private function field_text( $option = array(), $is_email = false ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function field_textarea( $option = array() ) { @@ -240,7 +265,9 @@ private function field_textarea( $option = array() ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function field_select( $option = array() ) { @@ -254,9 +281,9 @@ private function field_select( $option = array() ) { $select_options .= ''; } $field = ' - '; + '; $field = $this->wrap_element( $option, $field ); return $field; @@ -267,7 +294,9 @@ private function field_select( $option = array() ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function field_radio( $option = array() ) { @@ -290,7 +319,9 @@ private function field_radio( $option = array() ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function field_checkbox( $option = array() ) { @@ -310,7 +341,9 @@ private function field_checkbox( $option = array() ) { * * @since 1.0.0 * @access private + * * @param array $option The option from the module. + * * @return mixed */ private function field_toggle( $option = array() ) { @@ -320,10 +353,31 @@ private function field_toggle( $option = array() ) { $checked = 'checked'; } $field = ' - '; + '; + $field = $this->wrap_element( $option, $field ); + + return $field; + } + + /** + * Render a toggle field. + * + * @since 1.0.0 + * @access private + * + * @param array $option The option from the module. + * + * @return mixed + */ + private function field_link( $option = array() ) { + $field = ' + ' . + wp_kses_post( $option['text'] ) + . ''; + $field = $this->wrap_element( $option, $field ); return $field; @@ -334,6 +388,7 @@ private function field_toggle( $option = array() ) { * * @since 1.0.0 * @access public + * * @param array $option The option from the module.. * * @return mixed @@ -365,7 +420,9 @@ public function render_option( $option = array() ) { break; case 'custom': return apply_filters( 'obfx_custom_control_' . $option['id'], '' ); - + break; + case 'link': + return $this->field_link( $option ); break; default: return __( 'No option found for provided type', 'themeisle-companion' ); diff --git a/obfx_modules/google-analytics/init.php b/obfx_modules/google-analytics/init.php index c9f710f0..9f39ce2b 100644 --- a/obfx_modules/google-analytics/init.php +++ b/obfx_modules/google-analytics/init.php @@ -82,9 +82,6 @@ public function hooks() { $this->loader->add_action( 'rest_api_init', $this, 'register_endpoints' ); $this->loader->add_action( 'current_screen', $this, 'maybe_save_obfx_token' ); $this->loader->add_action( 'admin_enqueue_scripts', $this, 'enqueue_analytics_scripts' ); - $this->loader->add_filter( 'obfx_custom_control_google_signin', $this, 'generate_analytics_login' ); - $this->loader->add_filter( 'obfx_custom_control_analytics_accounts_refresh', $this, 'render_refresh_control' ); - $this->loader->add_filter( 'obfx_custom_control_analytics_accounts_unregister', $this, 'render_unregister_control' ); $this->loader->add_action( 'wp_head', $this, 'output_analytics_code', 0 ); } @@ -100,6 +97,11 @@ public function register_endpoints() { ) ); } + /** + * Refresh Tracking links. + * + * @return array|bool|WP_Error + */ public function refresh_tracking_links() { if ( ! current_user_can( 'manage_options' ) ) { @@ -117,6 +119,13 @@ public function refresh_tracking_links() { $this->get_tracking_codes( $obfx_token, true ); } + /** + * Unregister website. + * + * @param $obfx_token + * + * @return array|bool|WP_Error + */ public function unregister_website( $obfx_token ) { if ( ! isset( $obfx_token ) ) { return false; @@ -147,6 +156,9 @@ public function public_enqueue() { return array(); } + /** + * Enqueue JavaScript that requires localization. + */ public function enqueue_analytics_scripts() { $script_handle = $this->slug . '-script'; wp_register_script( $script_handle, plugin_dir_url( $this->get_dir() ) . $this->slug . '/js/script.js', array( 'jquery' ), $this->version ); @@ -191,11 +203,20 @@ public function admin_enqueue() { public function options() { $token = get_option( 'obfx_token', '' ); if ( empty( $token ) ) { + $url = $this->api_url . '/auth'; + $url = add_query_arg( array( + 'site_hash' => $this->get_site_hash(), + 'site_url' => home_url(), + 'site_return' => admin_url( 'admin.php?page=obfx_companion' ), + ), $url ); return array( array( - 'id' => 'google_signin', - 'name' => 'google_signin', - 'type' => 'custom', + 'id' => 'google_signin', + 'name' => 'google_signin', + 'type' => 'link', + 'url' => $url, + 'link-class' => 'btn btn-success', + 'text' => '' . __( 'Authenticate with Google', 'themeisle-companion' ), ), ); } @@ -215,7 +236,11 @@ public function options() { array( 'id' => 'analytics_accounts_refresh', 'name' => 'analytics_accounts_refresh', - 'type' => 'custom', + 'type' => 'link', + 'link-class' => 'btn btn-primary btn-sm', + 'link-id' => 'refresh-analytics-accounts', + 'text' => ' ' . __( 'Refresh Accounts', 'themeisle-companion' ), + 'url' => '' ), array( 'id' => 'analytics_accounts_select', @@ -227,33 +252,15 @@ public function options() { array( 'id' => 'analytics_accounts_unregister', 'name' => 'analytics_accounts_unregister', - 'type' => 'custom', + 'type' => 'link', + 'link-class' => 'btn btn-sm', + 'link-id' => 'unregister-analytics', + 'text' => '' . __( 'Unregister Site', 'themeisle-companion' ), + 'url' => '' ) ); } - /** - * Render the refresh button. - * - * @return string - */ - public function render_refresh_control() { - $refresh_button = '

'; - - return $refresh_button; - } - - /** - * Render the unregister button. - * - * @return string - */ - public function render_unregister_control() { - $unregister_button = '

'; - - return $unregister_button; - } - /** * Get tracking codes from server. * @@ -296,24 +303,6 @@ public function get_tracking_codes( $obfx_token = '', $forced = false ) { update_option( 'obfx_google_accounts_tracking_codes', $accounts ); } - /** - * Generates the analytics login control. - * - * @return string - */ - public function generate_analytics_login() { - $url = $this->api_url . '/auth'; - $url = add_query_arg( array( - 'site_hash' => $this->get_site_hash(), - 'site_url' => home_url(), - 'site_return' => admin_url( 'admin.php?page=obfx_companion' ), - ), $url ); - - $template = '' . __( 'Authenticate with Google', 'themeisle-companion' ) . ''; - - return $template; - } - /** * Generate a website hash. * @@ -349,21 +338,21 @@ public final function maybe_save_obfx_token() { public final function output_analytics_code() { $ua_code = $this->get_option( 'analytics_accounts_select' ); ?> - - - - + - + gtag( 'config', '' ); + + Date: Sun, 4 Mar 2018 14:53:23 +0200 Subject: [PATCH 2/4] Phpcs fixes. --- core/app/helpers/class-orbit-fox-render-helper.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/app/helpers/class-orbit-fox-render-helper.php b/core/app/helpers/class-orbit-fox-render-helper.php index e2ef9286..b9d70a75 100644 --- a/core/app/helpers/class-orbit-fox-render-helper.php +++ b/core/app/helpers/class-orbit-fox-render-helper.php @@ -25,8 +25,8 @@ class Orbit_Fox_Render_Helper { * @access public * * @param string $name The name of the partial w/o '-tpl.php'. - * @param array $args Optional. An associative array with name and value to be - * passed to the partial. + * @param array $args Optional. An associative array with name and value to be + * passed to the partial. * * @return string */ @@ -52,8 +52,8 @@ public function get_partial( $name = '', $args = array() ) { * @access public * * @param string $name The name of the partial w/o '-page.php'. - * @param array $args Optional. An associative array with name and value to be - * passed to the view. + * @param array $args Optional. An associative array with name and value to be + * passed to the view. * * @return string */ @@ -165,7 +165,7 @@ private function get_description( $description ) { * @since 1.0.0 * @access private * - * @param array $option The option array. + * @param array $option The option array. * @param string $element The element we want to wrap. * * @return string @@ -205,7 +205,7 @@ private function wrap_element( $option, $element ) { * @param string $field_value The field value. * @param string $checked The checked flag. * @param string $label The option label. - * @param array $option The option from the module. + * @param array $option The option from the module. * * @return string */ @@ -225,7 +225,7 @@ private function generate_check_type( $type = 'radio', $field_value, $checked, $ * @access private * * @param array $option The option from the module. - * @param bool $is_email Render an email input instead of text. + * @param bool $is_email Render an email input instead of text. * * @return mixed */ From 3ca5f6c3ff1f85a27f122f964a597d294c10f28a Mon Sep 17 00:00:00 2001 From: Andrei Baicus Date: Sun, 4 Mar 2018 14:53:34 +0200 Subject: [PATCH 3/4] Version bump --- core/assets/css/orbit-fox-admin.css | 2 +- core/includes/class-orbit-fox.php | 2 +- package.json | 2 +- themeisle-companion.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/assets/css/orbit-fox-admin.css b/core/assets/css/orbit-fox-admin.css index f4e6aad6..79975127 100644 --- a/core/assets/css/orbit-fox-admin.css +++ b/core/assets/css/orbit-fox-admin.css @@ -8,7 +8,7 @@ * Extends Spectre.css Library */ /* - Version: 2.4.2 + Version: 2.4.3 */ /* Document diff --git a/core/includes/class-orbit-fox.php b/core/includes/class-orbit-fox.php index b1c8e85f..b0c643a5 100644 --- a/core/includes/class-orbit-fox.php +++ b/core/includes/class-orbit-fox.php @@ -69,7 +69,7 @@ public function __construct() { $this->plugin_name = 'orbit-fox'; - $this->version = '2.4.2'; + $this->version = '2.4.3'; $this->load_dependencies(); $this->set_locale(); diff --git a/package.json b/package.json index ae153c69..79638106 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "themeisle-companion", - "version": "2.4.2", + "version": "2.4.3", "description": "Orbit Fox", "repository": { "type": "git", diff --git a/themeisle-companion.php b/themeisle-companion.php index 7ba2de76..b0729596 100644 --- a/themeisle-companion.php +++ b/themeisle-companion.php @@ -15,7 +15,7 @@ * Plugin Name: Orbit Fox Companion * Plugin URI: https://themeisle.com/plugins/orbit-fox-companion * Description: This swiss-knife plugin comes with a quality template library, menu/sharing icons modules, and newly added Elementor/BeaverBuilder page builder widgets on each release. - * Version: 2.4.2 + * Version: 2.4.3 * Author: Themeisle * Author URI: https://themeisle.com * License: GPL-2.0+ From 4c3c32d755628a05650d701aa0bfaf90a8191b0b Mon Sep 17 00:00:00 2001 From: Andrei Baicus Date: Sun, 4 Mar 2018 15:14:39 +0200 Subject: [PATCH 4/4] Requires at least 4.7 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index aa45e1a9..63cc9962 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Orbit Fox by ThemeIsle === Contributors: themeisle, codeinwp, rodicaelena, baicusandrei Tags: widget, admin, widgets, sharing, sections, themes, stock photos, custom icons, icons, menu icons, stock, templates -Requires at least: 3.0 +Requires at least: 4.7 Tested up to: 4.9 Requires PHP: 5.3 Stable tag: trunk