PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / addon-api / fields / media.php
wp-all-export / addon-api / fields Last commit date
checkbox.php 3 weeks ago date.php 3 weeks ago datetime.php 3 weeks ago field.php 3 weeks ago gallery.php 3 weeks ago media.php 3 weeks ago number.php 3 weeks ago post.php 3 weeks ago radio.php 3 weeks ago repeater.php 3 weeks ago select.php 3 weeks ago switcher.php 3 weeks ago text.php 3 weeks ago time.php 3 weeks ago toggle.php 3 weeks ago user.php 3 weeks ago
media.php
83 lines
1 <?php
2
3 namespace Wpae\AddonAPI;
4
5 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 class PMXE_Addon_Media_Field extends PMXE_Addon_Field {
8
9 public function getMediaId( $value ) {
10 if ( is_numeric( $value ) ) {
11 return $value;
12 } elseif ( is_array( $value ) ) {
13 if ( isset( $value['id'] ) ) {
14 return $value['id'];
15 }
16 if ( isset( $value['ID'] ) ) {
17 return $value['ID'];
18 }
19
20 return '';
21 } elseif ( is_string( $value ) ) {
22 $id = attachment_url_to_postid( $value );
23
24 return $id > 0 ? $id : '';
25 }
26
27 return '';
28 }
29
30 public function getMediaUrl( $value ) {
31 return wp_get_attachment_url( $this->getMediaId( $value ) );
32 }
33
34 public function getFileName( $value ) {
35 $url = $this->getMediaUrl( $value );
36 if ( empty( $url ) ) {
37 return '';
38 }
39 $path = wp_parse_url( $url, PHP_URL_PATH );
40
41 return basename( $path );
42 }
43
44 public function toString() {
45 $format = $this->settings['value_format'] ?? 'url';
46
47 switch ( $format ) {
48 case 'id':
49 return $this->getMediaId( $this->value );
50 case 'filename':
51 return $this->getFileName( $this->value );
52 default:
53 return $this->getMediaUrl( $this->value );
54 }
55 }
56
57 public function exportCustomXml( $article, $value, $write = true ) {
58
59 $this->local_value = $value;
60
61 $formatted_values = $this->toString();
62
63 $exported_value = $this->runPhpFunction( $formatted_values );
64
65 // By default we write the values to $article and return it.
66 // But if !$write we return the list of subfields we built instead.
67 if ( $write ) {
68 wp_all_export_write_article( $article, $this->elName, $exported_value );
69
70 return $article;
71 } else {
72 return $exported_value;
73 }
74 }
75
76 public static function getImportTemplate( $field, $name, $field_tpl_key, $implode_delimiter, $is_xml_template ) {
77 return [
78 'search_in_media' => 1,
79 'url' => '{' . $field_tpl_key . '}'
80 ];
81 }
82 }
83