- made external integrations class;

This commit is contained in:
nikitozzzzzzz
2017-12-19 14:44:06 +02:00
parent 45498f16dc
commit f861de65a8
7 changed files with 157 additions and 73 deletions
+2 -2
View File
@@ -2183,8 +2183,8 @@ Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ?
*
* @return array
*/
function um_admin_settings_email_section_fields( $section_fields, $email_key ){
if( um_is_wpml_active() ){
function um_admin_settings_email_section_fields( $section_fields, $email_key ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$default_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() );
@@ -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' => '<input type="checkbox" />' ), $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 '<a class="button um-email-configure" href="' . add_query_arg( array( 'email' => $item['key'] ) ) . '"><span class="dashicons dashicons-admin-generic"></span></a>';
}
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 '';
}
+14
View File
@@ -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
*
@@ -0,0 +1,91 @@
<?php
namespace um\core;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'External_Integrations' ) ) {
class External_Integrations {
/**
* Access constructor.
*/
function __construct() {
add_filter( 'um_get_core_page_filter', array( &$this, 'get_core_page_url' ), 10, 3 );
//check the site's accessible more priority have Individual Post/Term Restriction settings
add_action( 'template_redirect', array( &$this, 'template_redirect' ), 1000 );
}
/**
* Check if WPML is active
*
* @return bool|mixed
*/
function is_wpml_active() {
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
global $sitepress;
return $sitepress->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;
}
}
}
+1 -1
View File
@@ -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() );
+28
View File
@@ -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;
}
+14 -65
View File
@@ -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 );
}
/***