From f861de65a8ad850876417956d29acba279e2802a Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 19 Dec 2017 14:44:06 +0200 Subject: [PATCH] - made external integrations class; --- includes/admin/core/class-admin-settings.php | 4 +- .../core/list-tables/emails-list-table.php | 12 ++- includes/class-init.php | 14 +++ includes/core/class-external-integrations.php | 91 +++++++++++++++++++ includes/core/class-mail.php | 2 +- includes/um-deprecated-functions.php | 28 ++++++ includes/um-short-functions.php | 79 +++------------- 7 files changed, 157 insertions(+), 73 deletions(-) create mode 100644 includes/core/class-external-integrations.php diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 36308157..8ddbd1fc 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -2183,8 +2183,8 @@ Use Only Cookies: external_integrations()->is_wpml_active() ) { global $sitepress; $default_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() ); diff --git a/includes/admin/core/list-tables/emails-list-table.php b/includes/admin/core/list-tables/emails-list-table.php index 73a9bb1d..b1dff113 100644 --- a/includes/admin/core/list-tables/emails-list-table.php +++ b/includes/admin/core/list-tables/emails-list-table.php @@ -188,13 +188,13 @@ class UM_Emails_List_Table extends WP_List_Table { } function set_columns( $args = array() ) { - if( count( $this->bulk_actions ) ) { + if ( count( $this->bulk_actions ) ) { $args = array_merge( array( 'cb' => '' ), $args ); } $this->columns = $args; - if( um_is_wpml_active() ){ - $this->columns = UM_WPML_Column_Extends::add_management_column($this->columns); + if ( UM()->external_integrations()->is_wpml_active() ) { + $this->columns = UM_WPML_Column_Extends::add_management_column( $this->columns ); } return $this; } @@ -240,10 +240,12 @@ class UM_Emails_List_Table extends WP_List_Table { return ''; } - function column_icl_translations( $item ){ - if( um_is_wpml_active() ){ + function column_icl_translations( $item ) { + if ( UM()->external_integrations()->is_wpml_active() ) { return UM_WPML_Column_Extends::add_content_for_management_column( $item ); } + + return ''; } diff --git a/includes/class-init.php b/includes/class-init.php index a4034c7a..a382578e 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -317,6 +317,7 @@ if ( ! class_exists( 'UM' ) ) { $this->cron(); $this->tracking(); $this->mobile(); + $this->external_integrations(); } @@ -333,6 +334,19 @@ if ( ! class_exists( 'UM' ) ) { } + /** + * @since 2.0 + * + * @return um\core\External_Integrations() + */ + function external_integrations() { + if ( empty( $this->classes['external_integrations'] ) ) { + $this->classes['external_integrations'] = new um\core\External_Integrations(); + } + return $this->classes['external_integrations']; + } + + /** * @since 2.0 * diff --git a/includes/core/class-external-integrations.php b/includes/core/class-external-integrations.php new file mode 100644 index 00000000..450d2730 --- /dev/null +++ b/includes/core/class-external-integrations.php @@ -0,0 +1,91 @@ +get_setting( 'setup_complete' ); + } + + return false; + } + + + /** + * Get a translated core page URL + * + * @param $post_id + * @param $language + * @return bool|false|string + */ + function get_url_for_language( $post_id, $language ) { + if ( ! $this->is_wpml_active() ) + return ''; + + $lang_post_id = icl_object_id( $post_id, 'page', true, $language ); + + if ( $lang_post_id != 0 ) { + $url = get_permalink( $lang_post_id ); + } else { + // No page found, it's most likely the homepage + global $sitepress; + $url = $sitepress->language_url( $language ); + } + + return $url; + } + + + /** + * @param $url + * @param $slug + * @param $updated + * + * @return bool|false|string + */ + function get_core_page_url( $url, $slug, $updated ) { + + if ( ! $this->is_wpml_active() ) + return $url; + + if ( function_exists( 'icl_get_current_language' ) && icl_get_current_language() != icl_get_default_language() ) { + $url = $this->get_url_for_language( UM()->config()->permalinks[ $slug ], icl_get_current_language() ); + + if ( get_post_meta( get_the_ID(), '_um_wpml_account', true ) == 1 ) { + $url = get_permalink( get_the_ID() ); + } + if ( get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) { + $url = $this->get_url_for_language( UM()->config()->permalinks[ $slug ], icl_get_current_language() ); + } + } + + return $url; + } + + + } +} \ No newline at end of file diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index 1efea292..a020daa4 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -331,7 +331,7 @@ if ( ! class_exists( 'Mail' ) ) { * @return string */ function um_email_send_subject( $subject, $template ){ - if( um_is_wpml_active() ){ + if ( UM()->external_integrations()->is_wpml_active() ) { global $sitepress; $default_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() ); diff --git a/includes/um-deprecated-functions.php b/includes/um-deprecated-functions.php index 7a5ffeb5..40425244 100644 --- a/includes/um-deprecated-functions.php +++ b/includes/um-deprecated-functions.php @@ -72,4 +72,32 @@ function um_update_option( $option_id, $value ) { function um_remove_option( $option_id ) { //um_deprecated_function( 'um_remove_option', '2.0', 'UM()->options()->remove' ); UM()->options()->remove( $option_id ); +} + + +/** + * Get a translated core page URL + * + * @deprecated 2.0.1 + * + * @param $post_id + * @param $language + * @return bool|false|string + */ +function um_get_url_for_language( $post_id, $language ) { + //um_deprecated_function( 'um_get_url_for_language', '2.0', 'UM()->external_integrations()->get_url_for_language' ); + if ( ! UM()->external_integrations()->is_wpml_active() ) + return ''; + + $lang_post_id = icl_object_id( $post_id, 'page', true, $language ); + + if ( $lang_post_id != 0 ) { + $url = get_permalink( $lang_post_id ); + } else { + // No page found, it's most likely the homepage + global $sitepress; + $url = $sitepress->language_url( $language ); + } + + return $url; } \ No newline at end of file diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index d1bb2e5d..7f2db63a 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -589,46 +589,6 @@ } - /** - * Get a translated core page URL - * - * @param $post_id - * @param $language - * @return bool|false|string - */ - function um_get_url_for_language( $post_id, $language ) { - if ( ! um_is_wpml_active() ) - return ''; - - $lang_post_id = icl_object_id( $post_id, 'page', true, $language ); - - if ( $lang_post_id != 0 ) { - $url = get_permalink( $lang_post_id ); - } else { - // No page found, it's most likely the homepage - global $sitepress; - $url = $sitepress->language_url( $language ); - } - - return $url; - } - - - /** - * Check if WPML is active - * - * @return bool|mixed - */ - function um_is_wpml_active() { - if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { - global $sitepress; - - return $sitepress->get_setting( 'setup_complete' ); - } - - return false; - } - /*** *** @Get core page url ***/ @@ -672,37 +632,26 @@ return $value; } - /*** - *** @Get core page url - ***/ + + /** + * Get core page url + * + * + * @param $slug + * @param bool $updated + * + * @return bool|false|mixed|string|void + */ function um_get_core_page( $slug, $updated = false ) { $url = ''; - if (isset( UM()->config()->permalinks[$slug] )) { - $url = get_permalink( UM()->config()->permalinks[$slug] ); - if ($updated) + if ( isset( UM()->config()->permalinks[ $slug ] ) ) { + $url = get_permalink( UM()->config()->permalinks[ $slug ] ); + if ( $updated ) $url = add_query_arg( 'updated', esc_attr( $updated ), $url ); } - if (function_exists( 'icl_get_current_language' ) && icl_get_current_language() != icl_get_default_language()) { - - $url = um_get_url_for_language( UM()->config()->permalinks[$slug], icl_get_current_language() ); - - if (get_post_meta( get_the_ID(), '_um_wpml_account', true ) == 1) { - $url = get_permalink( get_the_ID() ); - } - if (get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1) { - $url = um_get_url_for_language( UM()->config()->permalinks[$slug], icl_get_current_language() ); - } - } - - if ($url) { - $url = apply_filters( 'um_get_core_page_filter', $url, $slug, $updated ); - - return $url; - } - - return ''; + return apply_filters( 'um_get_core_page_filter', $url, $slug, $updated ); } /***