diff --git a/classes/class-connectors.php b/classes/class-connectors.php index 588206f89..a748f5041 100644 --- a/classes/class-connectors.php +++ b/classes/class-connectors.php @@ -76,6 +76,7 @@ public function load_connectors() { 'edd', 'gravityforms', 'jetpack', + 'mercator', 'user-switching', 'woocommerce', 'wordpress-seo', diff --git a/connectors/class-connector-mercator.php b/connectors/class-connector-mercator.php new file mode 100644 index 000000000..ac41c29a0 --- /dev/null +++ b/connectors/class-connector-mercator.php @@ -0,0 +1,221 @@ + esc_html__( 'Make primary domain', 'stream' ), + 'created' => esc_html__( 'Created', 'stream' ), + 'deleted' => esc_html__( 'Deleted', 'stream' ), + 'updated' => esc_html__( 'Updated', 'stream' ), + ); + } + + /** + * Return translated context labels + * + * @return array + */ + public function get_context_labels() { + $labels = array(); + + if ( is_multisite() && ! wp_is_large_network() ) { + $blogs = wp_stream_get_sites(); + + foreach ( $blogs as $blog ) { + $blog_details = get_site( $blog->blog_id ); + $key = sanitize_key( $blog_details->blogname ); + $labels[ $key ] = $blog_details->blogname; + } + } + + return $labels; + } + + /** + * Add action links to Stream drop row in admin list screen + * + * @filter wp_stream_action_links_{connector} + * + * @param array $links + * @param Record $record + * + * @return array + */ + public function action_links( $links, $record ) { + $links [ esc_html__( 'Site Admin' ) ] = get_admin_url( $record->object_id ); + + if ( $record->object_id ) { + $site_admin_link = get_admin_url( $record->object_id ); + + if ( $site_admin_link ) { + $links [ esc_html__( 'Site Admin' ) ] = $site_admin_link; + } + + $site_settings_link = add_query_arg( + array( + 'id' => $record->object_id, + 'action' => 'mercator-aliases', + ), + network_admin_url( 'admin.php' ) + ); + + if ( $site_settings_link ) { + $links [ esc_html__( 'Domain mapping Settings', 'stream' ) ] = $site_settings_link; + } + } + + return $links; + } + + /** + * Log if domain is made primary. + * + * @param $mapping + */ + public function callback_mercator_mapping_made_primary( $mapping ) { + $blog_id = $mapping->get_site_id(); + $blog = get_site( $blog_id ); + + $this->log( + // translators: Placeholder refers to site name (e.g. "FooBar Blog") + _x( + '"%1$s" domain alias was make primary for "%2$s"', + '1. Domain alias 2. Site name', + 'stream' + ), + array( + 'domain' => $mapping->get_domain(), + 'site_name' => $blog->blogname, + ), + $blog_id, + sanitize_key( $blog->blogname ), + 'made_primary' + ); + } + + /** + * Log if domain alias is updated. + * + * @param $mapping + * @param $old_mapping + */ + public function callback_mercator_mapping_updated( $mapping, $old_mapping ) { + + $blog_id = $mapping->get_site_id(); + $blog = get_site( $blog_id ); + + $this->log( + // translators: Placeholder refers to site name (e.g. "FooBar Blog") + _x( + 'The domain alias "%1$s" was updated to "%2$s" for site "%3$s"', + '1. Old Domain alias 2. Domain alias 2. Site name', + 'stream' + ), + array( + 'old_domain' => $old_mapping->get_domain(), + 'domain' => $mapping->get_domain(), + 'site_name' => $blog->blogname, + ), + $blog_id, + sanitize_key( $blog->blogname ), + 'updated' + ); + + } + + /** + * Log if domain alias is deleted. + * + * @param $mapping + */ + public function callback_mercator_mapping_deleted( $mapping ) { + + $blog_id = $mapping->get_site_id(); + $blog = get_site( $blog_id ); + + $this->log( + // translators: Placeholder refers to site name (e.g. "FooBar Blog") + _x( + '"%1$s" domain alias was deleted for "%2$s"', + '1. Domain alias 2. Site name', + 'stream' + ), + array( + 'domain' => $mapping->get_domain(), + 'site_name' => $blog->blogname, + ), + $blog_id, + sanitize_key( $blog->blogname ), + 'deleted' + ); + + } + + /** + * Log if domain alias is created. + * + * @param $mapping + */ + public function callback_mercator_mapping_created( $mapping ) { + $blog_id = $mapping->get_site_id(); + $blog = get_site( $blog_id ); + + $this->log( + // translators: Placeholder refers to site name (e.g. "FooBar Blog") + _x( + '"%1$s" domain alias was created for "%2$s"', + '1. Domain alias 2. Site name', + 'stream' + ), + array( + 'domain' => $mapping->get_domain(), + 'site_name' => $blog->blogname, + ), + $blog_id, + sanitize_key( $blog->blogname ), + 'created' + ); + } +}