Source
<?php
use WPML\FP\Str;
/**
* WPML_Attachment_Action class file.
*
* @package WPML
*/
/**
* Class WPML_Attachment_Action
*/
class WPML_Attachment_Action implements IWPML_Action {
/**
* SitePress instance.
*
* @var SitePress
*/
private $sitepress;
/**
* Wpdb instance.
*
* @var wpdb
*/
private $wpdb;
/**
* WPML_Attachment_Action constructor.
*
* @param SitePress $sitepress SitePress instance.
* @param wpdb $wpdb wpdb instance.
*/
public function __construct( SitePress $sitepress, wpdb $wpdb ) {
$this->sitepress = $sitepress;
$this->wpdb = $wpdb;
}
/**
* Add hooks.
*/
public function add_hooks() {
if ( $this->is_admin_or_xmlrpc() && ! $this->is_uploading_plugin_or_theme() ) {
$active_languages = $this->sitepress->get_active_languages();
if ( count( $active_languages ) > 1 ) {
add_filter( 'views_upload', array( $this, 'views_upload_actions' ) );
}
}
add_filter( 'attachment_link', array( $this->sitepress, 'convert_url' ), 10, 1 );
add_filter( 'wp_delete_file', array( $this, 'delete_file_filter' ) );
}
/**
* Check if we are in site console or xmlrpc request is active.
*
* @return bool
*/
private function is_admin_or_xmlrpc() {