• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
    • Help
      • Online help
      • Learn Git
      • Welcome to Bitbucket
      • Keyboard shortcuts
    • Log In
    Blackrock
    1. Blackrock

    main

    Public
    Actions
    • Clone

    Learn more about cloning repositories

    You have read-only access

    Navigation
    • Source
    • Commits
    • Branches
    • All Branches Graph
    • Graphs
    • Forks
    1. Blackrock
    2. main

    Source

    main/wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-image-translate.php
    Артем ШиряевАртем Ширяев committed 554847ddcb906 Apr 2021
    Raw file
    Source viewDiff to previous
     
    1
    <?php
    2
    ​
    3
    /**
    4
     * Class WPML_Media_Image_Translate
    5
     * Allows getting translated images in a give language from an attachment
    6
     */
    7
    class WPML_Media_Image_Translate {
    8
    ​
    9
        /**
    10
         * @var SitePress
    11
         */
    12
        private $sitepress;
    13
    ​
    14
        /**
    15
         * @var WPML_Media_Attachment_By_URL_Factory
    16
         */
    17
        private $attachment_by_url_factory;
    18
    ​
    19
        /**
    20
         * WPML_Media_Image_Translate constructor.
    21
         *
    22
         * @param SitePress                            $sitepress
    23
         * @param WPML_Media_Attachment_By_URL_Factory $attachment_by_url_factory
    24
         */
    25
        public function __construct( SitePress $sitepress, WPML_Media_Attachment_By_URL_Factory $attachment_by_url_factory ) {
    26
            $this->sitepress                 = $sitepress;
    27
            $this->attachment_by_url_factory = $attachment_by_url_factory;
    28
        }
    29
    ​
    30
        /**
    31
         * @param int    $attachment_id
    32
         * @param string $language
    33
         * @param string $size
    34
         *
    35
         * @return string
    36
         */
    37
        public function get_translated_image( $attachment_id, $language, $size = null ) {
    38
            $image_url              = '';
    39
            $attachment             = new WPML_Post_Element( $attachment_id, $this->sitepress );
    40
            $attachment_translation = $attachment->get_translation( $language );
    41
    ​
    42
            if ( $attachment_translation ) {
    43
                $uploads_dir   = wp_get_upload_dir();
    44
                $attachment_id = $attachment_translation->get_id();
    45
                if ( null === $size ) {
    46
                    $image_url = $uploads_dir['baseurl'] . '/' . get_post_meta( $attachment_id, '_wp_attached_file', true );
    47
                } else {
    48
                    $image_url = $this->get_sized_image_url( $attachment_id, $size, $uploads_dir );
    49
                }
    50
            }
    51
    ​
    52
            return $image_url;
    53
        }
    54
    ​
    55
        /**
    56
         * @param string $img_src
    57
         * @param string $source_language
    58
         * @param string $target_language
    59
         *
    60
         * @return string|bool
    61
         */
    62
        public function get_translated_image_by_url( $img_src, $source_language, $target_language ) {
    63
    ​
    • Git repository management for enterprise teams powered by Atlassian Bitbucket
    • Atlassian Bitbucket v5.10.1
    • Documentation
    • Contact Support
    • Request a feature
    • About
    • Contact Atlassian
    Atlassian

    Everything looks good. Well let you know here if theres anything you should know about.