Version Description
- Fix: For the
[mla_gallery]
shortcode, a defect (introduced in v3.02) in expanding template values has been corrected.
Download this release
Release Info
Developer | dglingren |
Plugin | Media Library Assistant |
Version | 3.03 |
Comparing to | |
See all releases |
Code changes from version 3.01 to 3.03
- examples/plugins/mla-csv-data-source-example/mla-csv-data-source-example.php +5 -3
- examples/plugins/mla-list-table-hooks-example.php +22 -2
- examples/plugins/mla-wfu-data-source/admin-settings-page.tpl +350 -0
- examples/plugins/mla-wfu-data-source/class-mla-example-plugin-settings-101.php +569 -0
- examples/plugins/mla-wfu-data-source/mla-wfu-data-source.php +555 -0
- includes/class-mla-ajax.php +1 -0
- includes/class-mla-core.php +1 -1
- includes/class-mla-data.php +8 -2
- includes/class-mla-edit-media.php +13 -6
- includes/class-mla-main.php +12 -2
- includes/class-mla-objects.php +1 -1
- includes/class-mla-options.php +5 -0
- includes/class-mla-polylang-support.php +35 -19
- includes/class-mla-wpml-support.php +114 -33
- includes/mla-main-search-box-template.php +1 -1
- index.php +2 -2
- readme.txt +25 -28
- tpls/documentation-settings-tab.tpl +8 -0
examples/plugins/mla-csv-data-source-example/mla-csv-data-source-example.php
CHANGED
@@ -59,7 +59,7 @@
|
|
59 |
* https://wordpress.org/support/topic/import-export-to-csv-for-bulk-edit/
|
60 |
*
|
61 |
* @package MLA CSV Data Source Example
|
62 |
-
* @version 1.
|
63 |
*/
|
64 |
|
65 |
/*
|
@@ -67,7 +67,7 @@ Plugin Name: MLA CSV Data Source Example
|
|
67 |
Plugin URI: http://davidlingren.com/
|
68 |
Description: Populates one or more data sources from a CSV file
|
69 |
Author: David Lingren
|
70 |
-
Version: 1.
|
71 |
Author URI: http://davidlingren.com/
|
72 |
|
73 |
Copyright 2020 David Lingren
|
@@ -103,7 +103,7 @@ class MLACSVDataSourceExample {
|
|
103 |
*
|
104 |
* @var string
|
105 |
*/
|
106 |
-
const PLUGIN_VERSION = '1.
|
107 |
|
108 |
/**
|
109 |
* Slug prefix for registering and enqueueing submenu pages, style sheets, scripts and settings
|
@@ -139,6 +139,7 @@ class MLACSVDataSourceExample {
|
|
139 |
'general_tab_values' => array(), // additional page_values for 'page-level-options' template
|
140 |
'documentation_tab_values' => array(
|
141 |
'plugin_title' => 'MLA CSV Data Source Example',
|
|
|
142 |
), // page_values for 'documentation-tab' template
|
143 |
);
|
144 |
|
@@ -173,6 +174,7 @@ class MLACSVDataSourceExample {
|
|
173 |
|
174 |
// Add the run-time values to the arguments
|
175 |
self::$settings_arguments['template_file'] = dirname( __FILE__ ) . self::$settings_arguments['template_file'];
|
|
|
176 |
|
177 |
// Create our own settings object
|
178 |
self::$plugin_settings = new MLAExamplePluginSettings101( self::$settings_arguments );
|
59 |
* https://wordpress.org/support/topic/import-export-to-csv-for-bulk-edit/
|
60 |
*
|
61 |
* @package MLA CSV Data Source Example
|
62 |
+
* @version 1.03
|
63 |
*/
|
64 |
|
65 |
/*
|
67 |
Plugin URI: http://davidlingren.com/
|
68 |
Description: Populates one or more data sources from a CSV file
|
69 |
Author: David Lingren
|
70 |
+
Version: 1.03
|
71 |
Author URI: http://davidlingren.com/
|
72 |
|
73 |
Copyright 2020 David Lingren
|
103 |
*
|
104 |
* @var string
|
105 |
*/
|
106 |
+
const PLUGIN_VERSION = '1.03';
|
107 |
|
108 |
/**
|
109 |
* Slug prefix for registering and enqueueing submenu pages, style sheets, scripts and settings
|
139 |
'general_tab_values' => array(), // additional page_values for 'page-level-options' template
|
140 |
'documentation_tab_values' => array(
|
141 |
'plugin_title' => 'MLA CSV Data Source Example',
|
142 |
+
'settingsURL' => '', // Set at runtime in initialize()
|
143 |
), // page_values for 'documentation-tab' template
|
144 |
);
|
145 |
|
174 |
|
175 |
// Add the run-time values to the arguments
|
176 |
self::$settings_arguments['template_file'] = dirname( __FILE__ ) . self::$settings_arguments['template_file'];
|
177 |
+
self::$settings_arguments['documentation_tab_values']['settingsURL'] = admin_url('options-general.php');
|
178 |
|
179 |
// Create our own settings object
|
180 |
self::$plugin_settings = new MLAExamplePluginSettings101( self::$settings_arguments );
|
examples/plugins/mla-list-table-hooks-example.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Provides an example of hooking all actions and filters provided for the Media/Assistant Submenu Screen
|
4 |
*
|
5 |
* @package MLA List Table Hooks Example
|
6 |
-
* @version 1.
|
7 |
*/
|
8 |
|
9 |
/*
|
@@ -11,7 +11,7 @@ Plugin Name: MLA List Table Hooks Example
|
|
11 |
Plugin URI: http://davidlingren.com/
|
12 |
Description: Provides an example of hooking all actions and filters provided for the Media/Assistant Submenu Screen
|
13 |
Author: David Lingren
|
14 |
-
Version: 1.
|
15 |
Author URI: http://davidlingren.com/
|
16 |
|
17 |
Copyright 2014 - 2022 David Lingren
|
@@ -140,6 +140,8 @@ class MLAListTableHooksExample {
|
|
140 |
add_filter( 'views_upload', 'MLAListTableHooksExample::views_upload', 10, 1 );
|
141 |
|
142 |
// Defined in /media-library-assistant/includes/class-mla-edit-media.php
|
|
|
|
|
143 |
add_filter( 'mla_upload_bulk_edit_form_values', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_values', 10, 1 );
|
144 |
add_filter( 'mla_upload_bulk_edit_form_template', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_template', 10, 1 );
|
145 |
add_filter( 'mla_upload_bulk_edit_form_parse', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse', 10, 3 );
|
@@ -1175,6 +1177,24 @@ class MLAListTableHooksExample {
|
|
1175 |
return $views;
|
1176 |
} // views_upload
|
1177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1178 |
/**
|
1179 |
* MLAEdit bulk edit on upload item values
|
1180 |
*
|
3 |
* Provides an example of hooking all actions and filters provided for the Media/Assistant Submenu Screen
|
4 |
*
|
5 |
* @package MLA List Table Hooks Example
|
6 |
+
* @version 1.13
|
7 |
*/
|
8 |
|
9 |
/*
|
11 |
Plugin URI: http://davidlingren.com/
|
12 |
Description: Provides an example of hooking all actions and filters provided for the Media/Assistant Submenu Screen
|
13 |
Author: David Lingren
|
14 |
+
Version: 1.13
|
15 |
Author URI: http://davidlingren.com/
|
16 |
|
17 |
Copyright 2014 - 2022 David Lingren
|
140 |
add_filter( 'views_upload', 'MLAListTableHooksExample::views_upload', 10, 1 );
|
141 |
|
142 |
// Defined in /media-library-assistant/includes/class-mla-edit-media.php
|
143 |
+
add_filter( 'mla_get_bulk_edit_form_presets', 'MLAListTableHooksExample::mla_get_bulk_edit_form_presets', 10, 3 );
|
144 |
+
|
145 |
add_filter( 'mla_upload_bulk_edit_form_values', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_values', 10, 1 );
|
146 |
add_filter( 'mla_upload_bulk_edit_form_template', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_template', 10, 1 );
|
147 |
add_filter( 'mla_upload_bulk_edit_form_parse', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse', 10, 3 );
|
1177 |
return $views;
|
1178 |
} // views_upload
|
1179 |
|
1180 |
+
/**
|
1181 |
+
* MLA_List_Table item bulk edit form preset values
|
1182 |
+
*
|
1183 |
+
* This filter gives you a chance to modify or extend the presets used to populate
|
1184 |
+
* the Media/Assistant Bulk Edit and Bulk Edit on Upload forms.
|
1185 |
+
*
|
1186 |
+
* @since 1.13
|
1187 |
+
*
|
1188 |
+
* @param array $option_value data values to populate the form presets
|
1189 |
+
* @param string $option 'mla_bulk_edit_presets' or 'mla_bulk_edit_presets_per_user'
|
1190 |
+
* @param boolean $get_default True to ignore current setting and return default values
|
1191 |
+
*/
|
1192 |
+
public static function mla_get_bulk_edit_form_presets( $option_value, $option, $get_default ) {
|
1193 |
+
//error_log( __LINE__ . " MLAListTableHooksExample::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) \$option_value = " . var_export( $option_value, true ), 0 );
|
1194 |
+
|
1195 |
+
return $option_value;
|
1196 |
+
} // mla_get_bulk_edit_form_presets
|
1197 |
+
|
1198 |
/**
|
1199 |
* MLAEdit bulk edit on upload item values
|
1200 |
*
|
examples/plugins/mla-wfu-data-source/admin-settings-page.tpl
ADDED
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- template="page" -->
|
2 |
+
<a name="backtotop"></a>
|
3 |
+
|
4 |
+
<div class="wrap">
|
5 |
+
<h1 class="wp-heading-inline">[+plugin_title+] [+version+] Settings</h1>
|
6 |
+
[+messages+]
|
7 |
+
[+tablist+]
|
8 |
+
[+tab_content+]
|
9 |
+
</div><!-- wrap -->
|
10 |
+
|
11 |
+
<!-- template="tablist" -->
|
12 |
+
<h2 class="nav-tab-wrapper">
|
13 |
+
[+tablist+]
|
14 |
+
</h2>
|
15 |
+
<!-- template="tablist-item" -->
|
16 |
+
<a data-tab-id="[+data-tab-id+]" class="nav-tab [+nav-tab-active+]" href="?page=[+settings-page+]&mla_tab=[+data-tab-id+]">[+title+]</a>
|
17 |
+
|
18 |
+
<!-- template="messages" -->
|
19 |
+
<div class="[+mla_messages_class+]">
|
20 |
+
<p>
|
21 |
+
[+messages+]
|
22 |
+
</p>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<!-- template="select-option" -->
|
26 |
+
<option [+selected+] value="[+value+]">[+text+]</option>
|
27 |
+
|
28 |
+
<!-- template="page-level-options" -->
|
29 |
+
<tr valign="top">
|
30 |
+
<td class="textright">
|
31 |
+
<strong>Conversion Rules</strong>
|
32 |
+
</td>
|
33 |
+
<td>
|
34 |
+
<textarea name="[+slug_prefix+]_options[conversion_rules]" id="[+slug_prefix+]_options_conversion_rules" rows="10" cols="80" >[+conversion_rules+]</textarea>
|
35 |
+
<div class="mla-settings-help"> Enter your conversion rules; one entry per line.<br /> See Documentation tab for details.</div>
|
36 |
+
</td>
|
37 |
+
</tr>
|
38 |
+
|
39 |
+
<!-- template="general-tab" -->
|
40 |
+
<style type='text/css'>
|
41 |
+
.mla-settings-help {
|
42 |
+
font-size: 8pt;
|
43 |
+
padding-bottom: 5px
|
44 |
+
}
|
45 |
+
|
46 |
+
.mla-page-level-options-form {
|
47 |
+
margin-left: 0px;
|
48 |
+
margin-top: 10px;
|
49 |
+
padding-bottom: 10px;
|
50 |
+
border-bottom:thin solid #888888;
|
51 |
+
}
|
52 |
+
|
53 |
+
span.submit.mla-settings-submit,
|
54 |
+
p.submit.mla-settings-submit {
|
55 |
+
padding-bottom: 0px
|
56 |
+
}
|
57 |
+
|
58 |
+
ul.mla_settings {
|
59 |
+
list-style-type: disc;
|
60 |
+
list-style-position: outside;
|
61 |
+
}
|
62 |
+
|
63 |
+
ul.mla_settings li {
|
64 |
+
margin-left: 2em;
|
65 |
+
}
|
66 |
+
</style>
|
67 |
+
<h2>Plugin Options</h2>
|
68 |
+
<p>In this tab you can define the conversion rules you want to derive more useful representations of the WFU additional data fields.</p>
|
69 |
+
<p>You can find more information about using the features of this plugin in the Documentation tab on this screen.</p>
|
70 |
+
<div class="mla-page-level-options-form">
|
71 |
+
<form action="[+form_url+]" method="post" class="mla-display-settings-page" id="mla-display-settings-path-mapping-tab">
|
72 |
+
<table class="optiontable">
|
73 |
+
<tbody>
|
74 |
+
[+options_list+]
|
75 |
+
</tbody>
|
76 |
+
</table>
|
77 |
+
<span class="submit mla-settings-submit">
|
78 |
+
<input name="[+slug_prefix+]_options_save" class="button-primary" id="[+slug_prefix+]_options_save" type="submit" value="Save Changes" />
|
79 |
+
<input name="[+slug_prefix+]_options_reset" class="button-primary alignright" id="[+slug_prefix+]_options_reset" type="submit" value="Delete Settings, Restore Defaults" />
|
80 |
+
</span>
|
81 |
+
[+_wpnonce+]
|
82 |
+
</form>
|
83 |
+
</div>
|
84 |
+
|
85 |
+
<!-- template="documentation-tab" -->
|
86 |
+
<style type='text/css'>
|
87 |
+
.mla-doc-toc-list {
|
88 |
+
list-style-position:inside;
|
89 |
+
list-style:disc;
|
90 |
+
line-height: 15px;
|
91 |
+
padding-left: 20px
|
92 |
+
}
|
93 |
+
|
94 |
+
.mla-doc-hook-label {
|
95 |
+
text-align: right;
|
96 |
+
padding: 0 1em 2em 0;
|
97 |
+
vertical-align: top;
|
98 |
+
font-weight:bold
|
99 |
+
}
|
100 |
+
|
101 |
+
.mla-doc-hook-definition {
|
102 |
+
vertical-align: top;
|
103 |
+
}
|
104 |
+
|
105 |
+
.mla-doc-table-label {
|
106 |
+
text-align: right;
|
107 |
+
padding-right: 10px;
|
108 |
+
vertical-align: top;
|
109 |
+
font-weight:bold
|
110 |
+
}
|
111 |
+
|
112 |
+
.mla-doc-table-sublabel {
|
113 |
+
padding-right: 10px;
|
114 |
+
vertical-align: top
|
115 |
+
}
|
116 |
+
|
117 |
+
.mla-doc-table-reverse {
|
118 |
+
text-align: right;
|
119 |
+
padding-right: 10px;
|
120 |
+
vertical-align:top
|
121 |
+
}
|
122 |
+
|
123 |
+
.mla-doc-table-definition {
|
124 |
+
vertical-align: top;
|
125 |
+
}
|
126 |
+
|
127 |
+
.mla-doc-bold-link {
|
128 |
+
font-size:14px;
|
129 |
+
font-weight:bold
|
130 |
+
}
|
131 |
+
|
132 |
+
ul.mla_settings {
|
133 |
+
list-style-type: disc;
|
134 |
+
list-style-position: outside;
|
135 |
+
}
|
136 |
+
|
137 |
+
ul.mla_settings li {
|
138 |
+
margin-left: 2em;
|
139 |
+
}
|
140 |
+
</style>
|
141 |
+
<h2>Plugin Documentation. In this tab, jump to:</h2>
|
142 |
+
<div class="mla-display-settings-page" id="mla-display-settings-documentation-tab" style="width:700px">
|
143 |
+
<ul class="mla-doc-toc-list">
|
144 |
+
<li><a href="#introduction"><strong>Introduction</strong></a></li>
|
145 |
+
<li><a href="#processing"><strong>How the Plugin Works</strong></a></li>
|
146 |
+
<li><a href="#general-options"><strong>General Plugin Options</strong></a></li>
|
147 |
+
<li><a href="#boolean-rule"><strong>The Boolean Rule</strong></a></li>
|
148 |
+
<li><a href="#list-rule"><strong>The Element and List Rules</strong></a></li>
|
149 |
+
<li><a href="#equal-rule"><strong>The Equal Rule</strong></a></li>
|
150 |
+
<!-- <li><a href="#examples"><strong>Examples</strong></a></li> -->
|
151 |
+
<li><a href="#debugging"><strong>Debugging and Troubleshooting</strong></a></li>
|
152 |
+
</ul>
|
153 |
+
<p>
|
154 |
+
|
155 |
+
<a name="introduction"></a>
|
156 |
+
</p>
|
157 |
+
<p>
|
158 |
+
<a href="#backtotop">Go to Top</a>
|
159 |
+
</p>
|
160 |
+
<h3>Introduction</h3>
|
161 |
+
<p>
|
162 |
+
<!-- Refer to the Settings/Media Library Assistant Documentation tab like this: <a href="[+settingsURL+]?page=mla-settings-menu-documentation&mla_tab=documentation#mla_variable_parameters" target="_blank">Field-level substitution parameters</a>. -->
|
163 |
+
The <a href="https://wordpress.org/plugins/wp-file-upload/" title="WFU Repository page" target="_blank">WordPress File Upload plugin, by Nickolas Bossinas</a> (WFU), is a popular solution for uploading files from the WordPress front end and has an option to create Media Library items for the uploaded files. It supports additional form fields (like checkboxes, text fields, email fields, dropdown lists etc), which are copied into the item's Attachment Metadata "WFU User Data" array as an array of text values keyed by the form field labels.
|
164 |
+
</p>
|
165 |
+
<p>
|
166 |
+
This example plugin lets you access WFU form fields as MLA custom data sources in a more convenient way. For example, instead of coding <code>[+meta:WFU User Data.Description+]</code> you can code <code>[+wfu:Description+]</code>. This plugin also lets you define rules that derive additional data sources to transform WFU field values into a more useful form. Rule definitions and examples can be found in the sections below.
|
167 |
+
<a name="processing"></a>
|
168 |
+
</p>
|
169 |
+
<p>
|
170 |
+
<a href="#backtotop">Go to Top</a>
|
171 |
+
</p>
|
172 |
+
<h3>How the Plugin Works</h3>
|
173 |
+
<p>
|
174 |
+
This plugin makes use of a hook MLA provides ('mla_expand_custom_prefix') to extend its <a href="[+settingsURL+]?page=mla-settings-menu-documentation&mla_tab=documentation#mla_variable_parameters" target="_blank">Field-level substitution parameters</a>. A new <code>wfu:</code> prefix is handled by the code in this plugin to return WFU additional form field values as well as derived field values that represent WFU values in a more useful way. The field name is either the WFU label or a data source name defined in one of this plugin's Conversion Rules. You can add any of MLA's option/format values after the field name to further modify the value, e.g., <code>[+wfu:Date Created,date('j F, Y')+]</code>.
|
175 |
+
</p>
|
176 |
+
<p>
|
177 |
+
|
178 |
+
<a name="general-options"></a>
|
179 |
+
</p>
|
180 |
+
<p>
|
181 |
+
<a href="#backtotop">Go to Top</a>
|
182 |
+
</p>
|
183 |
+
<h3>General Plugin Options</h3>
|
184 |
+
<p>
|
185 |
+
This version of the plugin contains one setting on the General tab, "Conversion Rules". It is a text area in which you enter your conversion rules, one rule per line. Each rule has three parts:
|
186 |
+
</p>
|
187 |
+
<ul class="mla_settings">
|
188 |
+
<li><strong>Data Source</strong> - The data source/substitution parameter name by which you access the rule value, ending with a comma. Names are case-sensitive and, like WordPress custom field names, can contain spaces. If your data source name is the same as a WFU additional field label, only the converted value will be available using the <code>wfu:</code> prefix.</li>
|
189 |
+
<li><strong>Rule Type</strong> - one of "boolean", "element", "list" or "equal". Each rule type is described in the sections following this one.</li>
|
190 |
+
<li><strong>Rule Argument(s)</strong> - rule-specific values, separaated by commas and enclosed in parentheses. Arguments for each rule type are documented in the sections below.</li>
|
191 |
+
</ul>
|
192 |
+
<p>
|
193 |
+
Here are some example rules:<br />
|
194 |
+
<br />
|
195 |
+
<em>Member Status,boolean(Active Member,active,inactive)<br />
|
196 |
+
Color Values,element(Red,Red,' ')<br />
|
197 |
+
Color Values,element(Green,Green,' ')<br />
|
198 |
+
Color Values,element(Blue,Blue,' ')<br />
|
199 |
+
Color Values,list<br />
|
200 |
+
drivetrain,equal(Transmission,"stick shift",manual,automatic)</em><br />
|
201 |
+
<br />
|
202 |
+
The next three sections below explain each of the rules in more detail.
|
203 |
+
<a name="boolean-rule"></a>
|
204 |
+
</p>
|
205 |
+
<p>
|
206 |
+
<a href="#backtotop">Go to Top</a>
|
207 |
+
</p>
|
208 |
+
<h3>The Boolean Rule</h3>
|
209 |
+
<p>
|
210 |
+
The boolean rule tests a WFU field and returns one of two values depending on whether the WFU field is "true" or "false". A field is considered "true" if it exists, is not empty and contains any value other than "false". A field is considered "false" if it does not exist, does exist but is empty or does exist and contains the value "false". The boolean rule has three arguments:
|
211 |
+
</p>
|
212 |
+
<ul class="mla_settings">
|
213 |
+
<li><strong>WFU Field</strong> - The label of the field as defined in WFU "Additional Fields". Names are case-sensitive and, like WordPress custom field names, can contain spaces.</li>
|
214 |
+
<li><strong>True Value</strong> - the value that will be returned if the field is considered "true".</li>
|
215 |
+
<li><strong>False Value</strong> - the value that will be returned if the field is considered "false". This argument is optional; an empty value will be returned if the argument is omitted.</li>
|
216 |
+
</ul>
|
217 |
+
<p>
|
218 |
+
The boolean rule type can be applied to any WFU field but is particularly useful for checkboxes. WFU "checkbox" fields contain one of two text values; "true" if the box is checked or "false" if not. The boolean rule type lets you convert this to a more useful result. For example, you can return a value if the box is checked or an "empty value" when the box is unchecked:<br />
|
219 |
+
<br />
|
220 |
+
<em>spicy,boolean(Add Peppers,Yes,' ')</em><br />
|
221 |
+
<br />
|
222 |
+
When you code <code>[+wfu:spicy+]</code> this plugin will test the WFU "Add Peppers" field and return "Yes" if the field is "true". Note how a single space is used to represent an empty value; this is the same as omitting the last argument.
|
223 |
+
<a name="list-rule"></a>
|
224 |
+
</p>
|
225 |
+
<p>
|
226 |
+
<a href="#backtotop">Go to Top</a>
|
227 |
+
</p>
|
228 |
+
<h3>The Element and List Rules</h3>
|
229 |
+
<p>
|
230 |
+
The element and list rules work together to combine multiple WFU fields into a single result. The result will be a list of all the non-empty elements. All of the element rules and the list rule must have the same data source name. Each element rule determines if/how one WFU field is added to the list. The optional list rule specifies the "glue" added between list elements. The element rule has three arguments:
|
231 |
+
</p>
|
232 |
+
<ul class="mla_settings">
|
233 |
+
<li><strong>WFU Field</strong> - The label of the field as defined in WFU "Additional Fields". Names are case-sensitive and, like WordPress custom field names, can contain spaces.</li>
|
234 |
+
<li><strong>True Value</strong> - the value that will be returned if the field is considered "true".</li>
|
235 |
+
<li><strong>False Value</strong> - the value that will be returned if the field is considered "false". This argument is optional; an empty value will be returned if the argument is omitted.</li>
|
236 |
+
</ul>
|
237 |
+
<p>
|
238 |
+
True and false values are determined as defined in the boolean rule type above.
|
239 |
+
</p>
|
240 |
+
<p>
|
241 |
+
The list rule is optional; you can create a list just by defining a number of element rules with a common data source name. The list rule has just one optional argument:
|
242 |
+
</p>
|
243 |
+
<ul class="mla_settings">
|
244 |
+
<li><strong>Glue</strong> - The character or characters that separate elements of the list. The default glue is a single comma character</li>
|
245 |
+
</ul>
|
246 |
+
<p>
|
247 |
+
The list rule type can be applied to any WFU field but is particularly useful for building a list of taxonomy term assignments. For example:<br />
|
248 |
+
<br />
|
249 |
+
<em>Condiments,element(Ketchup,Tomato Ketchup)<br />
|
250 |
+
Condiments,element(Mustard,Brown Mustard)<br />
|
251 |
+
Condiments,element(Relish,Pickle Relish)<br />
|
252 |
+
Condiments,list(';')</em><br />
|
253 |
+
<br />
|
254 |
+
When you code <code>[+wfu:Condiments+]</code> this plugin will test each of the elements and build a list of the "true" elements, e.g., "Tomato Ketchup;Brown Mustard;Pickle Relish" if all three elements are "true". theNote how the element rules return an empty "false" value by omitting the last argument. Note also that the taxonomy term <strong>name</strong> is returned, not the term slug.
|
255 |
+
<a name="equal-rule"></a>
|
256 |
+
</p>
|
257 |
+
<p>
|
258 |
+
<a href="#backtotop">Go to Top</a>
|
259 |
+
</p>
|
260 |
+
<h3>The Equal Rule</h3>
|
261 |
+
<p>
|
262 |
+
The equal rule tests a WFU field and returns one of two values depending on whether the WFU field is equal or not equal to a specified value. A field is considered equal if it exists, is not empty and contains the specified value. A field is considered not equal if it does not exist, does exist but is empty or does exist but contains a value different from the specified value. The equal rule has four arguments:
|
263 |
+
</p>
|
264 |
+
<ul class="mla_settings">
|
265 |
+
<li><strong>WFU Field</strong> - The label of the field as defined in WFU "Additional Fields". Names are case-sensitive and, like WordPress custom field names, can contain spaces. If you have multiple equal rules for the same data source name you can use different WFU fields in them, if that makes sense for your applicaion.</li>
|
266 |
+
<li><strong>Specified Value</strong> - the WFU field value that will matched against.</li>
|
267 |
+
<li><strong>Equal Value</strong> - the value that will be returned if the field matches the specified value.</li>
|
268 |
+
<li><strong>Not Equal Value</strong> - the value that will be returned if the field does not match the specified value. This argument is optional; an empty value will be returned if the argument is omitted.</li>
|
269 |
+
</ul>
|
270 |
+
<p>
|
271 |
+
The equal rule type can be applied to any WFU field. For example, you can return a value if a simple text box matches a specific value:<br />
|
272 |
+
<br />
|
273 |
+
<em>drivetrain,equal(Transmission,"stick shift",manual,automatic)</em>
|
274 |
+
</p>
|
275 |
+
<p>
|
276 |
+
You can also enter multiple equal rules for the same data source name to test for more than one value:<br />
|
277 |
+
<br />
|
278 |
+
<em>Majority Status,equal(Person Type,"Man",adult)<br />
|
279 |
+
Majority Status,equal(Person Type,"Woman",adult)<br />
|
280 |
+
Majority Status,equal(Person Type,"Teenager",minor)<br />
|
281 |
+
Majority Status,equal(Person Type,"Child",minor,unknown)</em>
|
282 |
+
</p>
|
283 |
+
<p>
|
284 |
+
When you code <code>[+wfu:Majority Status+]</code> this plugin will test the WFU "Person Type" field and return "adult" if the field value is "Man" or "Woman". It will return "minor" if the value is "Teenager" or "Child", and it will return "unknown" if the field contains anything else. Note in this example that the first non-empty "not matched" value (e.g., "unknown") will be returned when the WFU field does not match any of the specified values.
|
285 |
+
<!-- <a name="examples"></a>
|
286 |
+
</p>
|
287 |
+
<p>
|
288 |
+
<a href="#backtotop">Go to Top</a>
|
289 |
+
</p>
|
290 |
+
<h3>Examples</h3>
|
291 |
+
<p>
|
292 |
+
Provide some examples.
|
293 |
+
</p>
|
294 |
+
<p>
|
295 |
+
-->
|
296 |
+
<a name="debugging"></a>
|
297 |
+
</p>
|
298 |
+
<p>
|
299 |
+
<a href="#backtotop">Go to Top</a>
|
300 |
+
</p>
|
301 |
+
<h3>Debugging and Troubleshooting</h3>
|
302 |
+
<p>
|
303 |
+
If you are not getting the results you expect from the plugin carefully inspecting the results of parsing the rules and generating the data source values can be a valuable exercise. For this shortcode plugin adding “0x8000” to the MLA Reporting value will generate useful information.
|
304 |
+
</p>
|
305 |
+
<p>
|
306 |
+
To activate MLA’s debug logging:
|
307 |
+
</p>
|
308 |
+
<ol>
|
309 |
+
<li>Navigate to the Settings/Media Library Assistant Debug tab.</li>
|
310 |
+
<li>Scroll down to the “MLA Reporting” text box and enter “0x8001”. This will turn on MLA debug logging for messages specific to this example plugin.</li>
|
311 |
+
<li>Click the Save Changes button to record your new setting.</li>
|
312 |
+
<li>Optionally, scroll to the bottom of the screen and click “Reset” to clear the error log. You may not want to do this depending on how you manage your error log.</li>
|
313 |
+
</ol>
|
314 |
+
<p>
|
315 |
+
Once that’s done you can run a test. The debug log can be very detailed, so restricting the test as best you can will be very helpful. When you’ve finished testing, go back to the Debug screen and:
|
316 |
+
</p>
|
317 |
+
<ol>
|
318 |
+
<li>Enter “0” in the MLA Reporting text box to turn debug logging off.</li>
|
319 |
+
<li>Click the Save Changes button to record your new setting.</li>
|
320 |
+
<li>Scroll to the bottom and click “Download” to get the log content in a text file.</li>
|
321 |
+
<li>Optionally, scroll to the bottom of the screen and click “Reset” to clear the error log.</li>
|
322 |
+
</ol>
|
323 |
+
<p>
|
324 |
+
There may be a lot of messages written to the log, so limit the amount of activity during the logging period. You should see messages in the log like these:
|
325 |
+
</p>
|
326 |
+
<blockquote>
|
327 |
+
[28-Dec-2020 05:38:55 UTC] 610 MLACore::mla_plugins_loaded_action() MLA 2.96 mla_debug_level 0x8001<br />
|
328 |
+
[28-Dec-2020 05:38:55 UTC] 623 <strong>mla_debug REQUEST</strong> = array (
|
329 |
+
'tax_input' =>
|
330 |
+
array (
|
331 |
+
'attachment_category' =>
|
332 |
+
array (
|
333 |
+
0 => 'def',
|
334 |
+
),
|
335 |
+
),
|
336 |
+
)
|
337 |
+
[28-Dec-2020 05:38:55 UTC] 635 <strong>mla_debug attributes</strong> = array (
|
338 |
+
'post_mime_type' => 'image/j*',
|
339 |
+
'numberposts' => '3',
|
340 |
+
'columns' => '2',
|
341 |
+
'size' => 'large',
|
342 |
+
'mla_debug' => 'log',
|
343 |
+
'mla_page_parameter' => 'mla_paginate_current',
|
344 |
+
)
|
345 |
+
|
346 |
+
</blockquote>
|
347 |
+
<p>
|
348 |
+
Of course, the details will be different. If you discover a defect in the plugin (or in MLA) you can <a href="http://wordpress.org/support/plugin/media-library-assistant" target="_blank">open a support topic</a> or <a href="http://davidlingren.com/#two" target="_blank">contact me at my web site</a> so it can be investigated further. I may ask for a copy of the log file from your tests.
|
349 |
+
</p>
|
350 |
+
</div>
|
examples/plugins/mla-wfu-data-source/class-mla-example-plugin-settings-101.php
ADDED
@@ -0,0 +1,569 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Provides option management and Settings/ General and Documentation submenu pages
|
4 |
+
*
|
5 |
+
* This file might be shared among multiple example plugins, so load it with:
|
6 |
+
*
|
7 |
+
* if ( ! class_exists( 'MLAExamplePluginSettings101' ) ) {
|
8 |
+
* require_once( pathinfo( __FILE__, PATHINFO_DIRNAME ) . '/class-mla-example-plugin-settings-101.php' );
|
9 |
+
* }
|
10 |
+
*
|
11 |
+
* @package Media Library Assistant
|
12 |
+
* @version 1.01
|
13 |
+
*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class MLA Example Settings Menu adds Settings/ General and Documentation submenu pages to an example plugin
|
17 |
+
*
|
18 |
+
* @package MLA Example Settings Menu
|
19 |
+
* @since 1.00
|
20 |
+
*/
|
21 |
+
class MLAExamplePluginSettings101 {
|
22 |
+
/**
|
23 |
+
* Default values for the __construct function
|
24 |
+
*
|
25 |
+
* @since 1.00
|
26 |
+
*
|
27 |
+
* @var array
|
28 |
+
*/
|
29 |
+
private static $default_arguments = array(
|
30 |
+
'slug_prefix' => 'example-plugin',
|
31 |
+
'plugin_title' => 'The Example Plugin',
|
32 |
+
'menu_title' => 'Example Plugin',
|
33 |
+
'plugin_file_name_only' => 'the-example-plugin',
|
34 |
+
'plugin_version' => '1.00',
|
35 |
+
'template_file' => 'absolute path to the template file', // e.g., dirname( __FILE__ ) . '/admin-settings-page.tpl'
|
36 |
+
'options' => array( 'slug' => array( 'type' => 'text|checkbox', 'default' => 'text|boolean' ) ),
|
37 |
+
'general_tab_values' => array(), // additional page_values for 'page-level-options' template
|
38 |
+
'documentation_tab_values' => array(), // page_values for 'documentation-tab' template
|
39 |
+
);
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Current values for this object instance
|
43 |
+
*
|
44 |
+
* @since 1.00
|
45 |
+
*
|
46 |
+
* @var array
|
47 |
+
*/
|
48 |
+
private $current_arguments = array();
|
49 |
+
|
50 |
+
/**
|
51 |
+
* This function sets option definitions and installs filters.
|
52 |
+
*
|
53 |
+
* @since 1.00
|
54 |
+
*
|
55 |
+
* @param array $attr Option definitions and settings
|
56 |
+
*/
|
57 |
+
public function __construct( $attr ) {
|
58 |
+
//error_log( __LINE__ . " MLAExamplePluginSettings101::__construct() _REQUEST = " . var_export( $_REQUEST, true ), 0 );
|
59 |
+
// Make sure $attr is an array, even if it's empty
|
60 |
+
if ( empty( $attr ) ) {
|
61 |
+
$attr = array();
|
62 |
+
} elseif ( is_string( $attr ) ) {
|
63 |
+
$attr = shortcode_parse_atts( $attr );
|
64 |
+
}
|
65 |
+
|
66 |
+
// Accept only the attributes we need and supply defaults
|
67 |
+
$this->current_arguments = shortcode_atts( self::$default_arguments, $attr );
|
68 |
+
|
69 |
+
// Compile the default settings
|
70 |
+
foreach ( $this->current_arguments['options'] as $slug => $option ) {
|
71 |
+
$this->default_settings[ $slug ] = $option['default'];
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( is_admin() ) {
|
75 |
+
// Record new settings if they're being updated
|
76 |
+
$this->request_settings = array();
|
77 |
+
if ( !empty( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options_save'] ) ) {
|
78 |
+
if ( isset( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options' ] ) ) {
|
79 |
+
$this->request_settings = wp_unslash( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options' ] );
|
80 |
+
}
|
81 |
+
} elseif ( !empty( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options_reset'] ) ) {
|
82 |
+
$this->request_settings = $this->default_settings;
|
83 |
+
}
|
84 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::__construct request_settings = ' . var_export( $this->request_settings, true ), 0 );
|
85 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::__construct mla_hex_dump( exports ) = ' . var_export( MLAData::mla_hex_dump( $this->request_settings['exports'] ), true ), 0 );
|
86 |
+
// Add submenu page in the "Settings" section
|
87 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Add submenu page in the "Settings" section
|
93 |
+
*
|
94 |
+
* @since 1.00
|
95 |
+
*/
|
96 |
+
public function admin_menu() {
|
97 |
+
/*
|
98 |
+
* We need a tab-specific page ID to manage the screen options on the General tab.
|
99 |
+
* Use the URL suffix, if present. If the URL doesn't have a tab suffix, use '-general'.
|
100 |
+
* This hack is required to pass the WordPress "referer" validation.
|
101 |
+
*/
|
102 |
+
if ( isset( $_REQUEST['page'] ) && is_string( $_REQUEST['page'] ) && ( $this->current_arguments['slug_prefix'] . '-settings-' == substr( $_REQUEST['page'], 0, strlen( $this->current_arguments['slug_prefix'] . '-settings-' ) ) ) ) {
|
103 |
+
$tab = substr( $_REQUEST['page'], strlen( $this->current_arguments['slug_prefix'] . '-settings-' ) );
|
104 |
+
} else {
|
105 |
+
$tab = 'general';
|
106 |
+
}
|
107 |
+
|
108 |
+
$tab = $this->_get_options_tablist( $tab ) ? '-' . $tab : '-general';
|
109 |
+
add_submenu_page( 'options-general.php', $this->current_arguments['plugin_title'], $this->current_arguments['menu_title'], 'manage_options', $this->current_arguments['slug_prefix'] . '-settings' . $tab, array( $this, 'add_submenu_page' ) );
|
110 |
+
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Add the "Settings" and "Guide" links to the Plugins section entry
|
115 |
+
*
|
116 |
+
* @since 1.00
|
117 |
+
*
|
118 |
+
* @param array array of links for the Plugin, e.g., "Activate"
|
119 |
+
* @param string Directory and name of the plugin Index file
|
120 |
+
*
|
121 |
+
* @return array Updated array of links for the Plugin
|
122 |
+
*/
|
123 |
+
public function plugin_action_links( $links, $file ) {
|
124 |
+
if ( $file == $this->current_arguments['plugin_file_name_only'] . '/' . $this->current_arguments['plugin_file_name_only'] . '.php' ) {
|
125 |
+
$settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . $this->current_arguments['slug_prefix'] . '-settings-documentation&mla_tab=documentation' ), 'Guide' );
|
126 |
+
array_unshift( $links, $settings_link );
|
127 |
+
$settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . $this->current_arguments['slug_prefix'] . '-settings-general' ), 'Settings' );
|
128 |
+
array_unshift( $links, $settings_link );
|
129 |
+
}
|
130 |
+
|
131 |
+
return $links;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Render (echo) the example plugin's submenu in the Settings section
|
136 |
+
*
|
137 |
+
* @since 1.00
|
138 |
+
*
|
139 |
+
* @return void Echoes HTML markup for the submenu page
|
140 |
+
*/
|
141 |
+
public function add_submenu_page() {
|
142 |
+
if ( !current_user_can( 'manage_options' ) ) {
|
143 |
+
echo '<h2>' . $this->current_arguments['plugin_title'] . " - Error</h2>\n";
|
144 |
+
wp_die( 'You do not have permission to manage plugin settings.' );
|
145 |
+
}
|
146 |
+
|
147 |
+
// Load template array and initialize page-level values.
|
148 |
+
$this->page_template_array = MLACore::mla_load_template( $this->current_arguments['template_file'], 'path' );
|
149 |
+
$current_tab_slug = isset( $_REQUEST['mla_tab'] ) ? $_REQUEST['mla_tab']: 'general';
|
150 |
+
$current_tab = $this->_get_options_tablist( $current_tab_slug );
|
151 |
+
$page_values = array(
|
152 |
+
'plugin_title' => $this->current_arguments['plugin_title'],
|
153 |
+
'version' => 'v' . $this->current_arguments['plugin_version'],
|
154 |
+
'messages' => '',
|
155 |
+
'tablist' => $this->_compose_settings_tabs( $current_tab_slug ),
|
156 |
+
'tab_content' => '',
|
157 |
+
);
|
158 |
+
|
159 |
+
// Compose tab content
|
160 |
+
if ( $current_tab ) {
|
161 |
+
if ( isset( $current_tab['render'] ) ) {
|
162 |
+
$handler = $current_tab['render'];
|
163 |
+
$page_content = call_user_func( array( $this, $handler ) );
|
164 |
+
} else {
|
165 |
+
$page_content = array( 'message' => "ERROR: Cannot render content tab {$current_tab_slug}", 'body' => '' );
|
166 |
+
}
|
167 |
+
} else {
|
168 |
+
$page_content = array( 'message' => "ERROR: Unknown content tab {$current_tab_slug}", 'body' => '' );
|
169 |
+
}
|
170 |
+
|
171 |
+
if ( ! empty( $page_content['message'] ) ) {
|
172 |
+
if ( false !== strpos( $page_content['message'], 'ERROR' ) ) {
|
173 |
+
$messages_class = 'updated error';
|
174 |
+
} else {
|
175 |
+
$messages_class = 'updated notice is-dismissible';
|
176 |
+
}
|
177 |
+
|
178 |
+
$page_values['messages'] = MLAData::mla_parse_template( $this->page_template_array['messages'], array(
|
179 |
+
'mla_messages_class' => $messages_class ,
|
180 |
+
'messages' => $page_content['message'],
|
181 |
+
) );
|
182 |
+
}
|
183 |
+
|
184 |
+
$page_values['tab_content'] = $page_content['body'];
|
185 |
+
|
186 |
+
echo MLAData::mla_parse_template( $this->page_template_array['page'], $page_values );
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Template file for the Settings page(s) and parts
|
191 |
+
*
|
192 |
+
* This array contains all of the template parts for the Settings page(s). The array is built once
|
193 |
+
* each page load and cached for subsequent use.
|
194 |
+
*
|
195 |
+
* @since 1.00
|
196 |
+
*
|
197 |
+
* @var array
|
198 |
+
*/
|
199 |
+
private $page_template_array = NULL;
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Definitions for Settings page tab ids, titles and handlers
|
203 |
+
* Each tab is defined by an array with the following elements:
|
204 |
+
*
|
205 |
+
* array key => HTML id/name attribute and option database key (OMIT MLA_OPTION_PREFIX)
|
206 |
+
*
|
207 |
+
* title => tab label / heading text
|
208 |
+
* render => rendering function for tab messages and content. Usage:
|
209 |
+
* $tab_content = ['render']();
|
210 |
+
*
|
211 |
+
* @since 1.00
|
212 |
+
*
|
213 |
+
* @var array
|
214 |
+
*/
|
215 |
+
private $mla_tablist = array(
|
216 |
+
'general' => array( 'title' => 'General', 'render' => '_compose_general_tab' ),
|
217 |
+
'documentation' => array( 'title' => 'Documentation', 'render' => '_compose_documentation_tab' ),
|
218 |
+
);
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Retrieve the list of options tabs or a specific tab value
|
222 |
+
*
|
223 |
+
* @since 1.00
|
224 |
+
*
|
225 |
+
* @param string Tab slug, to retrieve a single entry
|
226 |
+
*
|
227 |
+
* @return array|false The entire tablist ( $tab = NULL ), a single tab entry or false if not found/not allowed
|
228 |
+
*/
|
229 |
+
private function _get_options_tablist( $tab = NULL ) {
|
230 |
+
if ( is_string( $tab ) ) {
|
231 |
+
if ( isset( $this->mla_tablist[ $tab ] ) ) {
|
232 |
+
$results = $this->mla_tablist[ $tab ];
|
233 |
+
} else {
|
234 |
+
$results = false;
|
235 |
+
}
|
236 |
+
} else {
|
237 |
+
$results = $this->mla_tablist;
|
238 |
+
}
|
239 |
+
|
240 |
+
return $results;
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Compose the navigation tabs for the Settings subpage
|
245 |
+
*
|
246 |
+
* @since 1.00
|
247 |
+
* @uses $page_template_array contains tablist and tablist-item templates
|
248 |
+
*
|
249 |
+
* @param string Optional data-tab-id value for the active tab, default 'general'
|
250 |
+
*
|
251 |
+
* @return string HTML markup for the Settings subpage navigation tabs
|
252 |
+
*/
|
253 |
+
private function _compose_settings_tabs( $active_tab = 'general' ) {
|
254 |
+
$tablist_item = $this->page_template_array['tablist-item'];
|
255 |
+
$tabs = '';
|
256 |
+
foreach ( $this->_get_options_tablist() as $key => $item ) {
|
257 |
+
$item_values = array(
|
258 |
+
'data-tab-id' => $key,
|
259 |
+
'nav-tab-active' => ( $active_tab == $key ) ? 'nav-tab-active' : '',
|
260 |
+
'settings-page' => $this->current_arguments['slug_prefix'] . '-settings-' . $key,
|
261 |
+
'title' => $item['title']
|
262 |
+
);
|
263 |
+
|
264 |
+
$tabs .= MLAData::mla_parse_template( $tablist_item, $item_values );
|
265 |
+
} // foreach $item
|
266 |
+
|
267 |
+
$tablist_values = array( 'tablist' => $tabs );
|
268 |
+
return MLAData::mla_parse_template( $this->page_template_array['tablist'], $tablist_values );
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Compose the General tab content for the Settings subpage
|
273 |
+
*
|
274 |
+
* @since 1.00
|
275 |
+
* @uses $page_template_array contains tab content template(s)
|
276 |
+
*
|
277 |
+
* @return array 'message' => status/error messages, 'body' => tab content
|
278 |
+
*/
|
279 |
+
private function _compose_general_tab() {
|
280 |
+
$page_content = array( 'message' => '', 'body' => '' );
|
281 |
+
|
282 |
+
// Check for page-level Save Changes, Restore Defaults
|
283 |
+
if ( !empty( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options_save'] ) ) {
|
284 |
+
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
|
285 |
+
$page_content = $this->_save_setting_changes();
|
286 |
+
} elseif ( !empty( $_REQUEST[ $this->current_arguments['slug_prefix'] . '_options_reset'] ) ) {
|
287 |
+
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
|
288 |
+
$page_content = $this->_restore_setting_defaults();
|
289 |
+
}
|
290 |
+
|
291 |
+
if ( !empty( $page_content['body'] ) ) {
|
292 |
+
return $page_content;
|
293 |
+
}
|
294 |
+
|
295 |
+
// Display the General tab
|
296 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array(
|
297 |
+
$this->current_arguments['slug_prefix'] . '_options',
|
298 |
+
'_wpnonce',
|
299 |
+
'_wp_http_referer',
|
300 |
+
$this->current_arguments['slug_prefix'] . '_options_save',
|
301 |
+
$this->current_arguments['slug_prefix'] . '_options_reset',
|
302 |
+
), $_SERVER['REQUEST_URI'] );
|
303 |
+
|
304 |
+
// Compose page-level options
|
305 |
+
$page_values = $this->current_arguments['general_tab_values'];
|
306 |
+
|
307 |
+
foreach ( $this->current_arguments['options'] as $slug => $option ) {
|
308 |
+
if ( 'checkbox' === $option['type'] ) {
|
309 |
+
$page_values[ $slug . '_checked' ] = $this->get_plugin_option( $slug ) ? 'checked="checked" ' : '';
|
310 |
+
} else {
|
311 |
+
$page_values[ $slug ] = esc_attr( $this->get_plugin_option( $slug ) );
|
312 |
+
}
|
313 |
+
}
|
314 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::_compose_general_tab page_values = ' . var_export( $page_values, true ), 0 );
|
315 |
+
|
316 |
+
$options_list = MLAData::mla_parse_template( $this->page_template_array['page-level-options'], $page_values );
|
317 |
+
|
318 |
+
$form_arguments = '?page=' . $this->current_arguments['slug_prefix'] . '-settings-general&mla_tab=general';
|
319 |
+
|
320 |
+
$page_values = array(
|
321 |
+
'form_url' => admin_url( 'options-general.php' ) . $form_arguments,
|
322 |
+
'_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
|
323 |
+
'options_list' => $options_list,
|
324 |
+
'slug_prefix' => $this->current_arguments['slug_prefix'],
|
325 |
+
);
|
326 |
+
|
327 |
+
$page_content['body'] .= MLAData::mla_parse_template( $this->page_template_array['general-tab'], $page_values );
|
328 |
+
|
329 |
+
return $page_content;
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Compose the Documentation tab content for the Settings subpage
|
334 |
+
*
|
335 |
+
* @since 1.00
|
336 |
+
* @uses $page_template_array contains tab content template(s)
|
337 |
+
*
|
338 |
+
* @return array 'message' => status/error messages, 'body' => tab content
|
339 |
+
*/
|
340 |
+
private function _compose_documentation_tab() {
|
341 |
+
$page_content = array( 'message' => '', 'body' => '' );
|
342 |
+
$page_values = array(
|
343 |
+
);
|
344 |
+
|
345 |
+
$page_content['body'] = MLAData::mla_parse_template( $this->page_template_array['documentation-tab'], $this->current_arguments['documentation_tab_values'] );
|
346 |
+
return $page_content;
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Save settings as a WordPress wp_options entry
|
351 |
+
*
|
352 |
+
* @since 1.00
|
353 |
+
*
|
354 |
+
* @return array 'message' => status/error messages, 'body' => tab content
|
355 |
+
*/
|
356 |
+
private function _save_setting_changes() {
|
357 |
+
$page_content = array( 'message' => 'Settings unchanged.', 'body' => '' );
|
358 |
+
|
359 |
+
$changed = false;
|
360 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::_save_setting_changes current_arguments[options] = ' . var_export( $this->current_arguments['options'], true ), 0 );
|
361 |
+
foreach ( $this->current_arguments['options'] as $slug => $option ) {
|
362 |
+
if ( 'checkbox' === $option['type'] ) {
|
363 |
+
$changed |= $this->_update_plugin_option( $slug, isset( $this->request_settings[ $slug ] ) );
|
364 |
+
} else {
|
365 |
+
if ( isset( $this->request_settings[ $slug ] ) ) {
|
366 |
+
$changed |= $this->_update_plugin_option( $slug, $this->request_settings[ $slug ] );
|
367 |
+
} else {
|
368 |
+
$changed |= $this->_update_plugin_option( $slug, $option['default'] );
|
369 |
+
}
|
370 |
+
}
|
371 |
+
} // foreach option
|
372 |
+
$this->request_settings = array();
|
373 |
+
//error_log( __LINE__ . " MLAExamplePluginSettings101::_save_setting_changes( {$changed} ) final current_settings = " . var_export( $this->current_settings, true ), 0 );
|
374 |
+
|
375 |
+
if ( $changed ) {
|
376 |
+
// No reason to save defaults in the database
|
377 |
+
if ( $this->current_settings === $this->default_settings ) {
|
378 |
+
delete_option( $this->current_arguments['slug_prefix'] . '-settings' );
|
379 |
+
} else {
|
380 |
+
$changed = update_option( $this->current_arguments['slug_prefix'] . '-settings', $this->current_settings, false );
|
381 |
+
}
|
382 |
+
|
383 |
+
if ( $changed ) {
|
384 |
+
$page_content['message'] = "Settings have been updated.";
|
385 |
+
} else {
|
386 |
+
$page_content['message'] = "Settings updated failed.";
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
return $page_content;
|
391 |
+
} // _save_setting_changes
|
392 |
+
|
393 |
+
/**
|
394 |
+
* Delete the plugin's WordPress wp_options entry, restoring the default settings
|
395 |
+
*
|
396 |
+
* @since 1.00
|
397 |
+
*
|
398 |
+
* @return array 'message' => status/error messages, 'body' => tab content
|
399 |
+
*/
|
400 |
+
private function _restore_setting_defaults() {
|
401 |
+
$page_content = array( 'message' => 'Settings unchanged.', 'body' => '' );
|
402 |
+
$this->current_settings = $this->default_settings;
|
403 |
+
$changed = delete_option( $this->current_arguments['slug_prefix'] . '-settings' );
|
404 |
+
|
405 |
+
if ( $changed ) {
|
406 |
+
$page_content['message'] = "Settings have been updated.";
|
407 |
+
}
|
408 |
+
|
409 |
+
return $page_content;
|
410 |
+
} // _restore_setting_defaults
|
411 |
+
|
412 |
+
/**
|
413 |
+
* Assemble the in-memory representation of the plugin settings
|
414 |
+
*
|
415 |
+
* @since 1.00
|
416 |
+
*
|
417 |
+
* @param boolean $force_refresh Optional. Force a reload of rules. Default false.
|
418 |
+
*
|
419 |
+
* @return boolean Success (true) or failure (false) of the operation
|
420 |
+
*/
|
421 |
+
private function _get_plugin_settings( $force_refresh = false ) {
|
422 |
+
if ( false == $force_refresh && NULL != $this->current_settings ) {
|
423 |
+
return true;
|
424 |
+
}
|
425 |
+
|
426 |
+
// Update the plugin options from the wp_options table or set defaults
|
427 |
+
$this->current_settings = get_option( $this->current_arguments['slug_prefix'] . '-settings' );
|
428 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::_get_plugin_settings stored current_settings = ' . var_export( $this->current_settings, true ), 0 );
|
429 |
+
if ( !is_array( $this->current_settings ) ) {
|
430 |
+
$this->current_settings = $this->default_settings;
|
431 |
+
}
|
432 |
+
|
433 |
+
// Initialize any new setting(s) from the default settings
|
434 |
+
foreach ( $this->current_arguments['options'] as $slug => $option ) {
|
435 |
+
if ( !isset( $this->current_settings[ $slug ] ) ) {
|
436 |
+
$this->current_settings[ $slug ] = $option['default'];
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
//error_log( __LINE__ . ' MLAExamplePluginSettings101::_get_plugin_settings final current_settings = ' . var_export( $this->current_settings, true ), 0 );
|
441 |
+
return true;
|
442 |
+
}
|
443 |
+
|
444 |
+
/**
|
445 |
+
* Updated option settings from the $_REQUEST array
|
446 |
+
*
|
447 |
+
* @since 1.01
|
448 |
+
*
|
449 |
+
* @var array
|
450 |
+
*/
|
451 |
+
private $request_settings = array();
|
452 |
+
|
453 |
+
/**
|
454 |
+
* In-memory representation of the option settings
|
455 |
+
*
|
456 |
+
* @since 1.00
|
457 |
+
*
|
458 |
+
* @var array
|
459 |
+
*/
|
460 |
+
private $current_settings = NULL;
|
461 |
+
|
462 |
+
/**
|
463 |
+
* Default processing options
|
464 |
+
*
|
465 |
+
* @since 1.00
|
466 |
+
*
|
467 |
+
* @var array
|
468 |
+
*/
|
469 |
+
private $default_settings = array();
|
470 |
+
|
471 |
+
/**
|
472 |
+
* Update a plugin option setting
|
473 |
+
*
|
474 |
+
* @since 1.00
|
475 |
+
*
|
476 |
+
* @param string $name Option name
|
477 |
+
* @param mixed $new_value Option value
|
478 |
+
*
|
479 |
+
* @return mixed True if option value changed, false if value unchanged, NULL if failure
|
480 |
+
*/
|
481 |
+
private function _update_plugin_option( $name, $new_value ) {
|
482 |
+
if ( !$this->_get_plugin_settings() ) {
|
483 |
+
return NULL;
|
484 |
+
}
|
485 |
+
|
486 |
+
$old_value = isset( $this->current_settings[ $name ] ) ? $this->current_settings[ $name ] : NULL;
|
487 |
+
|
488 |
+
if ( $new_value === $old_value ) {
|
489 |
+
return false;
|
490 |
+
}
|
491 |
+
|
492 |
+
$this->current_settings[ $name ] = $new_value;
|
493 |
+
return true;
|
494 |
+
}
|
495 |
+
|
496 |
+
/**
|
497 |
+
* Get a plugin option setting
|
498 |
+
*
|
499 |
+
* @since 1.00
|
500 |
+
*
|
501 |
+
* @param string $name Option name
|
502 |
+
*
|
503 |
+
* @return mixed Option value, if it exists else NULL
|
504 |
+
*/
|
505 |
+
public function get_plugin_option( $name ) {
|
506 |
+
if ( !$this->_get_plugin_settings() ) {
|
507 |
+
return NULL;
|
508 |
+
}
|
509 |
+
|
510 |
+
// See if the setting is being updated
|
511 |
+
if ( isset( $this->request_settings[ $name ] ) ) {
|
512 |
+
return $this->request_settings[ $name ];
|
513 |
+
}
|
514 |
+
|
515 |
+
if ( isset( $this->current_settings[ $name ] ) ) {
|
516 |
+
return $this->current_settings[ $name ];
|
517 |
+
}
|
518 |
+
|
519 |
+
// Special names for debug logging
|
520 |
+
switch ( $name ) {
|
521 |
+
case 'request_settings':
|
522 |
+
return $this->request_settings;
|
523 |
+
case 'current_settings':
|
524 |
+
return $this->current_settings;
|
525 |
+
case 'default_settings':
|
526 |
+
return $this->default_settings;
|
527 |
+
}
|
528 |
+
|
529 |
+
return NULL;
|
530 |
+
}
|
531 |
+
|
532 |
+
/**
|
533 |
+
* Get a plugin argument setting
|
534 |
+
*
|
535 |
+
* @since 1.01
|
536 |
+
*
|
537 |
+
* @param string $name Argument name
|
538 |
+
*
|
539 |
+
* @return mixed Argument value, if it exists else NULL
|
540 |
+
*/
|
541 |
+
public function get_plugin_argument( $name ) {
|
542 |
+
if ( !isset( $this->current_arguments[ $name ] ) ) {
|
543 |
+
return NULL;
|
544 |
+
}
|
545 |
+
|
546 |
+
return $this->current_arguments[ $name ];
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* Update a plugin argument setting
|
551 |
+
*
|
552 |
+
* @since 1.01
|
553 |
+
*
|
554 |
+
* @param string $name Argument name
|
555 |
+
*
|
556 |
+
* @return boolean True if argument value changed, false if value unchanged
|
557 |
+
*/
|
558 |
+
public function update_plugin_argument( $name, $new_value ) {
|
559 |
+
$old_value = isset( $this->current_arguments[ $name ] ) ? $this->current_arguments[ $name ] : NULL;
|
560 |
+
|
561 |
+
if ( $new_value === $old_value ) {
|
562 |
+
return false;
|
563 |
+
}
|
564 |
+
|
565 |
+
$this->current_arguments[ $name ] = $new_value;
|
566 |
+
return true;
|
567 |
+
}
|
568 |
+
} // Class MLAExamplePluginSettings101
|
569 |
+
?>
|
examples/plugins/mla-wfu-data-source/mla-wfu-data-source.php
ADDED
@@ -0,0 +1,555 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Enhanced MLA data sources for Windows File Uploads additional data fields
|
4 |
+
*
|
5 |
+
* Much more information is in the Settings/MLA CSV Data "Documentation" tab.
|
6 |
+
*
|
7 |
+
* Created for support topic "Custom fields – Checkbox to tags"
|
8 |
+
* opened on 6/29/2022 by "johnsteed".
|
9 |
+
* https://wordpress.org/support/topic/custom-fields-checkbox-to-tags/
|
10 |
+
*
|
11 |
+
* Enhanced (updates) for support topic ""
|
12 |
+
* opened on MM/DD/YYYY by "".
|
13 |
+
* https://wordpress.org/support/topic/
|
14 |
+
*
|
15 |
+
* @package MLA WFU Data Source
|
16 |
+
* @version 1.00
|
17 |
+
*/
|
18 |
+
|
19 |
+
/*
|
20 |
+
Plugin Name: MLA WFU Data Source
|
21 |
+
Plugin URI: http://davidlingren.com/
|
22 |
+
Description: Enhanced MLA data sources for Windows File Uploads additional data fields
|
23 |
+
Author: David Lingren
|
24 |
+
Version: 1.00
|
25 |
+
Author URI: http://davidlingren.com/
|
26 |
+
|
27 |
+
Copyright 2022 David Lingren
|
28 |
+
|
29 |
+
This program is free software; you can redistribute it and/or modify
|
30 |
+
it under the terms of the GNU General Public License as published by
|
31 |
+
the Free Software Foundation; either version 2 of the License, or
|
32 |
+
(at your option) any later version.
|
33 |
+
|
34 |
+
This program is distributed in the hope that it will be useful,
|
35 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
36 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
37 |
+
GNU General Public License for more details.
|
38 |
+
|
39 |
+
You can get a copy of the GNU General Public License by writing to the
|
40 |
+
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
|
41 |
+
*/
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Class MLA WFU Data Source implements an empty Settings screen
|
45 |
+
*
|
46 |
+
* Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
|
47 |
+
* else inside a class means this is the only name you have to worry about.
|
48 |
+
*
|
49 |
+
* @package MLA WFU Data Source
|
50 |
+
* @since 1.00
|
51 |
+
*/
|
52 |
+
class MLAWFUDataSource {
|
53 |
+
/**
|
54 |
+
* Current version number
|
55 |
+
*
|
56 |
+
* @since 1.00
|
57 |
+
*
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
+
const PLUGIN_VERSION = '1.00';
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Slug prefix for registering and enqueueing submenu pages, style sheets, scripts and settings
|
64 |
+
*
|
65 |
+
* @since 1.00
|
66 |
+
*
|
67 |
+
* @var string
|
68 |
+
*/
|
69 |
+
const SLUG_PREFIX = 'mlawfudatasource';
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Constant to log this plugin's debug activity
|
73 |
+
*
|
74 |
+
* @since 1.00
|
75 |
+
*
|
76 |
+
* @var integer
|
77 |
+
*/
|
78 |
+
const MLA_DEBUG_CATEGORY = 0x00008000;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Settings Management object
|
82 |
+
*
|
83 |
+
* @since 1.02
|
84 |
+
*
|
85 |
+
* @var array
|
86 |
+
*/
|
87 |
+
private static $plugin_settings = NULL;
|
88 |
+
|
89 |
+
/**
|
90 |
+
* In-memory representation of the option settings
|
91 |
+
*
|
92 |
+
* @since 1.00
|
93 |
+
*
|
94 |
+
* @var array $_settings {
|
95 |
+
* @type boolean $assign_parents Assign all terms in path, not just the last (leaf) term
|
96 |
+
* @type boolean $assign_rule_parent Assign the Rule Parent (if any) in addition to terms in path
|
97 |
+
* @type string $path_delimiter The delimiter that separates path components
|
98 |
+
* }
|
99 |
+
*/
|
100 |
+
private static $_settings = NULL;
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Configuration values for the Settings Management object
|
104 |
+
*
|
105 |
+
* @since 1.02
|
106 |
+
*
|
107 |
+
* @var array
|
108 |
+
*/
|
109 |
+
private static $settings_arguments = array(
|
110 |
+
'slug_prefix' => self::SLUG_PREFIX,
|
111 |
+
'plugin_title' => 'MLA WFU Data Source',
|
112 |
+
'menu_title' => 'MLA WFU Data',
|
113 |
+
'plugin_file_name_only' => 'mla-wfu-data-source',
|
114 |
+
'plugin_version' => self::PLUGIN_VERSION,
|
115 |
+
'template_file' => '/admin-settings-page.tpl', // Add the path at runtime, in initialize()
|
116 |
+
'options' => array(
|
117 |
+
// 'slug' => array( 'type' => 'checkbox|text|select|textarea', 'default' => 'text|boolean(0|1)' )
|
118 |
+
// See the default values in $_default_settings below
|
119 |
+
'conversion_rules' => array( 'type' => 'textarea', 'default' => '' ),
|
120 |
+
),
|
121 |
+
'general_tab_values' => array(), // additional page_values for 'page-level-options' template
|
122 |
+
'documentation_tab_values' => array(
|
123 |
+
'plugin_title' => 'MLA WFU Data Source',
|
124 |
+
'settingsURL' => '', // Set at runtime in initialize()
|
125 |
+
), // page_values for 'documentation-tab' template
|
126 |
+
);
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Default processing options
|
130 |
+
*
|
131 |
+
* @since 1.00
|
132 |
+
*
|
133 |
+
* @var array
|
134 |
+
*/
|
135 |
+
private static $_default_settings = array (
|
136 |
+
'conversion_rules' => '',
|
137 |
+
);
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Template file for the Settings page(s) and parts
|
141 |
+
*
|
142 |
+
* This array contains all of the template parts for the Settings page(s). The array is built once
|
143 |
+
* each page load and cached for subsequent use.
|
144 |
+
*
|
145 |
+
* @since 1.00
|
146 |
+
*
|
147 |
+
* @var array
|
148 |
+
*/
|
149 |
+
public static $page_template_array = NULL;
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Definitions for Settings page tab ids, titles and handlers
|
153 |
+
* Each tab is defined by an array with the following elements:
|
154 |
+
*
|
155 |
+
* array key => HTML id/name attribute and option database key (OMIT MLA_OPTION_PREFIX)
|
156 |
+
*
|
157 |
+
* title => tab label / heading text
|
158 |
+
* render => rendering function for tab messages and content. Usage:
|
159 |
+
* $tab_content = ['render']( );
|
160 |
+
*
|
161 |
+
* @since 1.00
|
162 |
+
*
|
163 |
+
* @var array
|
164 |
+
*/
|
165 |
+
private static $mla_tablist = array(
|
166 |
+
'general' => array( 'title' => 'General', 'render' => array( 'MLAWFUDataSource', '_compose_general_tab' ) ),
|
167 |
+
'documentation' => array( 'title' => 'Documentation', 'render' => array( 'MLAWFUDataSource', '_compose_documentation_tab' ) ),
|
168 |
+
);
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Initialization function, similar to __construct()
|
172 |
+
*
|
173 |
+
* Installs filters and actions that handle the MLA hooks for uploading and mapping.
|
174 |
+
*
|
175 |
+
* @since 1.00
|
176 |
+
*
|
177 |
+
* @return void
|
178 |
+
*/
|
179 |
+
public static function initialize() {
|
180 |
+
// This plugin requires MLA
|
181 |
+
if ( ! class_exists( 'MLACore', false ) ) {
|
182 |
+
return;
|
183 |
+
}
|
184 |
+
|
185 |
+
// The plugin settings class is shared with other MLA example plugins
|
186 |
+
if ( ! class_exists( 'MLAExamplePluginSettings101' ) ) {
|
187 |
+
require_once( pathinfo( __FILE__, PATHINFO_DIRNAME ) . '/class-mla-example-plugin-settings-101.php' );
|
188 |
+
}
|
189 |
+
|
190 |
+
// Add the run-time values to the arguments
|
191 |
+
self::$settings_arguments['template_file'] = dirname( __FILE__ ) . self::$settings_arguments['template_file'];
|
192 |
+
self::$settings_arguments['documentation_tab_values']['settingsURL'] = admin_url('options-general.php');
|
193 |
+
|
194 |
+
// Create our own settings object
|
195 |
+
self::$plugin_settings = new MLAExamplePluginSettings101( self::$settings_arguments );
|
196 |
+
|
197 |
+
// Defined in /media-library-assistant/includes/class-mla-data.php
|
198 |
+
add_filter( 'mla_expand_custom_prefix', 'MLAWFUDataSource::mla_expand_custom_prefix', 10, 8 );
|
199 |
+
// Defined in /media-library-assistant/includes/class-mla-options.php
|
200 |
+
add_filter( 'mla_update_attachment_metadata_prefilter', 'MLAWFUDataSource::mla_update_attachment_metadata_prefilter', 10, 3 );
|
201 |
+
|
202 |
+
// The remaining filters are only useful in the admin section; exit if in the "front-end" posts/pages.
|
203 |
+
if ( ! is_admin() ) {
|
204 |
+
return;
|
205 |
+
}
|
206 |
+
|
207 |
+
// Load template array and initialize page-level values.
|
208 |
+
self::$page_template_array = MLACore::mla_load_template( self::$settings_arguments['template_file'], 'path' );
|
209 |
+
|
210 |
+
// Add the run-time values to the settings
|
211 |
+
// $general_tab_values = self::$plugin_settings->get_plugin_argument('general_tab_values');
|
212 |
+
// $general_tab_values['option_one_selected'] = 'one' === self::$plugin_settings->get_plugin_option('static_select_slug') ? 'selected=selected' : '';
|
213 |
+
// self::$plugin_settings->update_plugin_argument('general_tab_values', $general_tab_values );
|
214 |
+
} // initialize
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Internal form of Conversion Rules
|
218 |
+
*
|
219 |
+
* @since 1.00
|
220 |
+
*
|
221 |
+
* @var array
|
222 |
+
*/
|
223 |
+
private static $_conversion_rules = NULL;
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Parse Conversion Rules, building self::$_conversion_rules
|
227 |
+
*
|
228 |
+
* @since 1.00
|
229 |
+
*
|
230 |
+
* @return array Error messages, if any, or empty for success.
|
231 |
+
*/
|
232 |
+
private static function _load_conversion_rules() {
|
233 |
+
$messages = array ();
|
234 |
+
|
235 |
+
if ( NULL !== self::$_conversion_rules ) {
|
236 |
+
return $messages;
|
237 |
+
}
|
238 |
+
|
239 |
+
$conversion_rules = self::$plugin_settings->get_plugin_option('conversion_rules');
|
240 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::_load_conversion_rules() \$conversion_rules = " . var_export( $conversion_rules, true ), self::MLA_DEBUG_CATEGORY );
|
241 |
+
$conversion_rules = explode( "\n", str_replace( "\r", "\n", str_replace( "\r\n", "\n", $conversion_rules ) ) );
|
242 |
+
//MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::_load_conversion_rules() \$conversion_rules = " . var_export( $conversion_rules, true ), self::MLA_DEBUG_CATEGORY );
|
243 |
+
|
244 |
+
foreach ( $conversion_rules as $conversion_rule ) {
|
245 |
+
$rule = MLAData::mla_parse_substitution_parameter( $conversion_rule );
|
246 |
+
//MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::_load_conversion_rules( {$conversion_rule} ) \$rule = " . var_export( $rule, true ), self::MLA_DEBUG_CATEGORY );
|
247 |
+
|
248 |
+
$arguments = array();
|
249 |
+
if ( !empty( trim( $rule['value'] ) ) ) {
|
250 |
+
$data_source = trim( $rule['value'] );
|
251 |
+
} else {
|
252 |
+
$messages[] = "Invalid or missing data source name in '{$rule}'";
|
253 |
+
continue;
|
254 |
+
}
|
255 |
+
|
256 |
+
if ( !empty( trim( $rule['format'] ) ) ) {
|
257 |
+
$arguments['rule_type'] = trim( $rule['format'] );
|
258 |
+
} else {
|
259 |
+
$messages[] = "Missing rule type in '{$rule}'";
|
260 |
+
continue;
|
261 |
+
}
|
262 |
+
|
263 |
+
switch ( $rule['format'] ) {
|
264 |
+
case 'boolean':
|
265 |
+
if ( isset( $rule['args'][0] ) && !empty( trim( $rule['args'][0] ) ) ) {
|
266 |
+
$arguments['wfu_field'] = trim( $rule['args'][0] );
|
267 |
+
} else {
|
268 |
+
$messages[] = "Invalid or missing WFU Field Name in '{$rule}'";
|
269 |
+
break;
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( isset( $rule['args'][1] ) && !empty( trim( $rule['args'][1] ) ) ) {
|
273 |
+
$arguments['true_value'] = trim( $rule['args'][1] );
|
274 |
+
} else {
|
275 |
+
$arguments['true_value'] = ' ';
|
276 |
+
}
|
277 |
+
|
278 |
+
if ( isset( $rule['args'][2] ) && !empty( trim( $rule['args'][2] ) ) ) {
|
279 |
+
$arguments['false_value'] = trim( $rule['args'][2] );
|
280 |
+
} else {
|
281 |
+
$arguments['false_value'] = ' ';
|
282 |
+
}
|
283 |
+
|
284 |
+
self::$_conversion_rules[ $data_source ] = $arguments;
|
285 |
+
break;
|
286 |
+
case 'element':
|
287 |
+
$element = array();
|
288 |
+
if ( isset( $rule['args'][0] ) && !empty( trim( $rule['args'][0] ) ) ) {
|
289 |
+
$element['wfu_field'] = trim( $rule['args'][0] );
|
290 |
+
} else {
|
291 |
+
$messages[] = "Invalid or missing WFU Field Name in '{$rule}'";
|
292 |
+
break;
|
293 |
+
}
|
294 |
+
|
295 |
+
if ( isset( $rule['args'][1] ) && !empty( trim( $rule['args'][1] ) ) ) {
|
296 |
+
$element['true_value'] = trim( $rule['args'][1] );
|
297 |
+
} else {
|
298 |
+
$element['true_value'] = ' ';
|
299 |
+
}
|
300 |
+
|
301 |
+
if ( isset( $rule['args'][2] ) && !empty( trim( $rule['args'][2] ) ) ) {
|
302 |
+
$element['false_value'] = trim( $rule['args'][2] );
|
303 |
+
} else {
|
304 |
+
$element['false_value'] = ' ';
|
305 |
+
}
|
306 |
+
|
307 |
+
if ( isset( self::$_conversion_rules[ $data_source ] ) ) {
|
308 |
+
$arguments = self::$_conversion_rules[ $data_source ];
|
309 |
+
} else {
|
310 |
+
$arguments = array( 'rule_type' => 'list', 'elements' => array(), 'delimiter' => ',' );
|
311 |
+
}
|
312 |
+
|
313 |
+
$arguments['elements'][] = $element;
|
314 |
+
self::$_conversion_rules[ $data_source ] = $arguments;
|
315 |
+
break;
|
316 |
+
case 'list':
|
317 |
+
if ( isset( self::$_conversion_rules[ $data_source ] ) ) {
|
318 |
+
$arguments = self::$_conversion_rules[ $data_source ];
|
319 |
+
} else {
|
320 |
+
$arguments = array( 'rule_type' => 'list', 'elements' => array(), 'delimiter' => ',' );
|
321 |
+
}
|
322 |
+
|
323 |
+
if ( isset( $rule['args'][0] ) && !empty( trim( $rule['args'][0] ) ) ) {
|
324 |
+
$arguments['delimiter'] = trim( $rule['args'][0] );
|
325 |
+
}
|
326 |
+
|
327 |
+
self::$_conversion_rules[ $data_source ] = $arguments;
|
328 |
+
break;
|
329 |
+
case 'equal':
|
330 |
+
$element = array();
|
331 |
+
if ( isset( $rule['args'][0] ) && !empty( trim( $rule['args'][0] ) ) ) {
|
332 |
+
$element['wfu_field'] = trim( $rule['args'][0] );
|
333 |
+
} else {
|
334 |
+
$messages[] = "Invalid or missing WFU Field Name in '{$rule}'";
|
335 |
+
break;
|
336 |
+
}
|
337 |
+
|
338 |
+
if ( isset( $rule['args'][1] ) && !empty( trim( $rule['args'][1] ) ) ) {
|
339 |
+
$element['specified_value'] = trim( $rule['args'][1] );
|
340 |
+
} else {
|
341 |
+
$element['specified_value'] = '';
|
342 |
+
}
|
343 |
+
|
344 |
+
if ( isset( $rule['args'][2] ) && !empty( trim( $rule['args'][2] ) ) ) {
|
345 |
+
$element['true_value'] = trim( $rule['args'][2] );
|
346 |
+
} else {
|
347 |
+
$element['true_value'] = ' ';
|
348 |
+
}
|
349 |
+
|
350 |
+
if ( isset( $rule['args'][3] ) && !empty( trim( $rule['args'][3] ) ) ) {
|
351 |
+
$element['false_value'] = trim( $rule['args'][3] );
|
352 |
+
} else {
|
353 |
+
$element['false_value'] = ' ';
|
354 |
+
}
|
355 |
+
|
356 |
+
if ( isset( self::$_conversion_rules[ $data_source ] ) ) {
|
357 |
+
$arguments = self::$_conversion_rules[ $data_source ];
|
358 |
+
} else {
|
359 |
+
$arguments = array( 'rule_type' => 'equal', 'elements' => array() );
|
360 |
+
}
|
361 |
+
|
362 |
+
$arguments['elements'][] = $element;
|
363 |
+
self::$_conversion_rules[ $data_source ] = $arguments;
|
364 |
+
break;
|
365 |
+
default:
|
366 |
+
$messages[] = "Unknown rule type in '{$rule}'";
|
367 |
+
} // $rule['format']
|
368 |
+
} // foreach $conversion_rule
|
369 |
+
|
370 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::_load_conversion_rules() \$_conversion_rules = " . var_export( self::$_conversion_rules, true ), self::MLA_DEBUG_CATEGORY );
|
371 |
+
//MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::_load_conversion_rules() \$messages = " . var_export( $messages, true ), self::MLA_DEBUG_CATEGORY );
|
372 |
+
return $messages;
|
373 |
+
}
|
374 |
+
|
375 |
+
|
376 |
+
/**
|
377 |
+
* MLA Expand Custom Prefix Filter
|
378 |
+
*
|
379 |
+
* Gives you an opportunity to generate your custom data value when a parameter's prefix value is not recognized.
|
380 |
+
*
|
381 |
+
* @since 1.00
|
382 |
+
*
|
383 |
+
* @param string NULL, indicating that by default, no custom value is available
|
384 |
+
* @param string the data-source name
|
385 |
+
* @param array data-source components; prefix (empty), value, option, format and args (if present)
|
386 |
+
* @param array values from the query, if any, e.g. shortcode parameters
|
387 |
+
* @param array item-level markup template values, if any
|
388 |
+
* @param integer attachment ID for attachment-specific values
|
389 |
+
* @param boolean for option 'multi', retain existing values
|
390 |
+
* @param string default option value
|
391 |
+
*/
|
392 |
+
public static function mla_expand_custom_prefix( $custom_value, $key, $value, $query, $markup_values, $post_id, $keep_existing, $default_option ) {
|
393 |
+
if ( 'wfu' !== strtolower( $value['prefix'] ) ) {
|
394 |
+
return $custom_value;
|
395 |
+
}
|
396 |
+
|
397 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix( {$key}, {$post_id}, {$keep_existing}, {$default_option} ) \$value = " . var_export( $value, true ), self::MLA_DEBUG_CATEGORY );
|
398 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix() \$query = " . var_export( $query, true ), self::MLA_DEBUG_CATEGORY );
|
399 |
+
|
400 |
+
$messages = self::_load_conversion_rules();
|
401 |
+
if ( !empty( $messages ) ) {
|
402 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix( {$post_id} ) \$messages = " . var_export( $messages, true ), self::MLA_DEBUG_CATEGORY );
|
403 |
+
}
|
404 |
+
|
405 |
+
if ( isset( self::$_wfu_user_data_cache[ $post_id ] ) ) {
|
406 |
+
$post_meta = self::$_wfu_user_data_cache[ $post_id ];
|
407 |
+
} else {
|
408 |
+
$post_meta = get_metadata( 'post', $post_id, '_wp_attachment_metadata', true );
|
409 |
+
//MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix( {$post_id} ) \$post_meta = " . var_export( $post_meta, true ), self::MLA_DEBUG_CATEGORY );
|
410 |
+
if ( empty( $post_meta ) ) {
|
411 |
+
$post_meta = array();
|
412 |
+
}
|
413 |
+
|
414 |
+
if ( empty( $post_meta['WFU User Data'] ) ) {
|
415 |
+
$post_meta = array();
|
416 |
+
} else {
|
417 |
+
$post_meta = $post_meta['WFU User Data'];
|
418 |
+
}
|
419 |
+
|
420 |
+
self::$_wfu_user_data_cache[ $post_id ] = $post_meta;
|
421 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix( {$post_id} ) \$post_meta = " . var_export( $post_meta, true ), self::MLA_DEBUG_CATEGORY );
|
422 |
+
}
|
423 |
+
|
424 |
+
// Match against derived fields first, then WFU additional fields
|
425 |
+
$data_source = $value['value'];
|
426 |
+
if ( array_key_exists( $data_source, self::$_conversion_rules ) ) {
|
427 |
+
$rule = self::$_conversion_rules[ $data_source ];
|
428 |
+
|
429 |
+
$wfu_value = '';
|
430 |
+
if ( isset( $rule['wfu_field'] ) ) {
|
431 |
+
if ( isset( $post_meta[ $rule['wfu_field'] ] ) ) {
|
432 |
+
$wfu_value = trim( $post_meta[ $rule['wfu_field'] ] );
|
433 |
+
if ( 'false' === strtolower( $wfu_value ) ) {
|
434 |
+
$wfu_value = '';
|
435 |
+
}
|
436 |
+
}
|
437 |
+
}
|
438 |
+
|
439 |
+
switch ( $rule['rule_type'] ) {
|
440 |
+
case 'boolean':
|
441 |
+
if ( empty( $wfu_value ) ) {
|
442 |
+
$custom_value = $rule['false_value'];
|
443 |
+
} else {
|
444 |
+
$custom_value = $rule['true_value'];
|
445 |
+
}
|
446 |
+
break;
|
447 |
+
case 'list':
|
448 |
+
$custom_value = array();
|
449 |
+
|
450 |
+
foreach ( $rule['elements'] as $element ) {
|
451 |
+
$wfu_value = '';
|
452 |
+
if ( isset( $element['wfu_field'] ) ) {
|
453 |
+
if ( isset( $post_meta[ $element['wfu_field'] ] ) ) {
|
454 |
+
$wfu_value = trim( $post_meta[ $element['wfu_field'] ] );
|
455 |
+
if ( 'false' === strtolower( $wfu_value ) ) {
|
456 |
+
$wfu_value = '';
|
457 |
+
}
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
if ( empty( $wfu_value ) ) {
|
462 |
+
$element_value = $element['false_value'];
|
463 |
+
} else {
|
464 |
+
$element_value = $element['true_value'];
|
465 |
+
}
|
466 |
+
|
467 |
+
if ( ' ' !== $element_value ) {
|
468 |
+
$custom_value[] = $element_value;
|
469 |
+
}
|
470 |
+
} // foreach $element
|
471 |
+
|
472 |
+
if ( 'array' !== $value['option'] ) {
|
473 |
+
$custom_value = implode( $rule['delimiter'], $custom_value );
|
474 |
+
if ( empty( $custom_value ) ) {
|
475 |
+
$custom_value = ' ';
|
476 |
+
}
|
477 |
+
}
|
478 |
+
|
479 |
+
break;
|
480 |
+
case 'equal':
|
481 |
+
$false_value = '';
|
482 |
+
foreach ( $rule['elements'] as $element ) {
|
483 |
+
$wfu_value = '';
|
484 |
+
|
485 |
+
if ( isset( $element['wfu_field'] ) ) {
|
486 |
+
if ( isset( $post_meta[ $element['wfu_field'] ] ) ) {
|
487 |
+
$wfu_value = trim( $post_meta[ $element['wfu_field'] ] );
|
488 |
+
if ( 'false' === strtolower( $wfu_value ) ) {
|
489 |
+
$wfu_value = '';
|
490 |
+
}
|
491 |
+
}
|
492 |
+
}
|
493 |
+
|
494 |
+
if ( $wfu_value === $element['specified_value'] ) {
|
495 |
+
$custom_value = $element['true_value'];
|
496 |
+
break;
|
497 |
+
}
|
498 |
+
|
499 |
+
if ( empty( $false_value ) && ( ' ' !== $element['false_value'] ) ) {
|
500 |
+
$false_value = $element['false_value'];
|
501 |
+
}
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( ( NULL === $custom_value ) && !empty( $false_value ) ) {
|
505 |
+
$custom_value = $false_value;
|
506 |
+
}
|
507 |
+
|
508 |
+
break;
|
509 |
+
default:
|
510 |
+
$custom_value = NULL;
|
511 |
+
} // $rule_type
|
512 |
+
}
|
513 |
+
|
514 |
+
if ( ( NULL === $custom_value ) && array_key_exists( $data_source, $post_meta ) ) {
|
515 |
+
$custom_value = $post_meta[ $data_source ];
|
516 |
+
}
|
517 |
+
|
518 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_expand_custom_prefix( {$post_id}, {$key} ) \$custom_value = " . var_export( $custom_value, true ), self::MLA_DEBUG_CATEGORY );
|
519 |
+
return $custom_value;
|
520 |
+
} // mla_expand_custom_prefix
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Cache of WFU User Data values, required to avoid WP bug during uploads
|
524 |
+
*
|
525 |
+
* @since 1.00
|
526 |
+
*
|
527 |
+
* @var array
|
528 |
+
*/
|
529 |
+
private static $_wfu_user_data_cache = array();
|
530 |
+
|
531 |
+
/**
|
532 |
+
* Capture WFU User Data during file uploads
|
533 |
+
*
|
534 |
+
* @since 1.00
|
535 |
+
*
|
536 |
+
* @param array Attachment metadata for just-inserted attachment
|
537 |
+
* @param integer ID of just-inserted attachment
|
538 |
+
* @param array MLA mapping option settings
|
539 |
+
*/
|
540 |
+
|
541 |
+
public static function mla_update_attachment_metadata_prefilter( $data, $post_id, $options ) {
|
542 |
+
MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_update_attachment_metadata_prefilter( {$post_id} ) \$data = " . var_export( $data, true ), self::MLA_DEBUG_CATEGORY );
|
543 |
+
//MLACore::mla_debug_add( __LINE__ . " MLAWFUDataSource::mla_update_attachment_metadata_prefilter( {$post_id} ) \$options = " . var_export( $options, true ), self::MLA_DEBUG_CATEGORY );
|
544 |
+
|
545 |
+
if ( isset( $data['WFU User Data'] ) ) {
|
546 |
+
self::$_wfu_user_data_cache[ $post_id ] = $data['WFU User Data'];
|
547 |
+
}
|
548 |
+
|
549 |
+
return $data;
|
550 |
+
} // mla_update_attachment_metadata_prefilter
|
551 |
+
} // MLAWFUDataSource
|
552 |
+
|
553 |
+
// Install the filters at an early opportunity
|
554 |
+
add_action('init', 'MLAWFUDataSource::initialize');
|
555 |
+
?>
|
includes/class-mla-ajax.php
CHANGED
@@ -378,6 +378,7 @@ class MLA_Ajax {
|
|
378 |
|
379 |
// Get a "blank" presets array we can fill in with current settings
|
380 |
$presets = MLAEdit::mla_get_bulk_edit_form_presets( $_REQUEST['mla_preset_option'], true );
|
|
|
381 |
|
382 |
foreach ( $presets as $key => $value ) {
|
383 |
if ( !empty( $args[ $key ] ) ) {
|
378 |
|
379 |
// Get a "blank" presets array we can fill in with current settings
|
380 |
$presets = MLAEdit::mla_get_bulk_edit_form_presets( $_REQUEST['mla_preset_option'], true );
|
381 |
+
//error_log( __LINE__ . ' MLA_Ajax::mla_bulk_edit_form_presets_action presets = ' . var_export( $presets, true ), 0 );
|
382 |
|
383 |
foreach ( $presets as $key => $value ) {
|
384 |
if ( !empty( $args[ $key ] ) ) {
|
includes/class-mla-core.php
CHANGED
@@ -21,7 +21,7 @@ class MLACore {
|
|
21 |
*
|
22 |
* @var string
|
23 |
*/
|
24 |
-
const CURRENT_MLA_VERSION = '3.
|
25 |
|
26 |
/**
|
27 |
* Current date for Development Versions, empty for production versions
|
21 |
*
|
22 |
* @var string
|
23 |
*/
|
24 |
+
const CURRENT_MLA_VERSION = '3.03';
|
25 |
|
26 |
/**
|
27 |
* Current date for Development Versions, empty for production versions
|
includes/class-mla-data.php
CHANGED
@@ -1332,7 +1332,7 @@ class MLAData {
|
|
1332 |
* @param string A formatting string containing [+placeholders+]
|
1333 |
* @param array Optional: an array of values from the query, if any, e.g. shortcode parameters
|
1334 |
* @param array Optional: an array of values to add to the returned array
|
1335 |
-
* @param integer Optional: attachment ID for attachment-specific placeholders
|
1336 |
* @param boolean Optional: for option 'multi', retain existing values
|
1337 |
* @param string Optional: default option value
|
1338 |
* @param array Optional: attachment_metadata, required during item uploads
|
@@ -1342,12 +1342,18 @@ class MLAData {
|
|
1342 |
public static function mla_expand_field_level_parameters( $tpl, $query = NULL, $markup_values = array(), $post_id = 0, $keep_existing = false, $default_option = 'text', $upload_metadata = NULL ) {
|
1343 |
static $cached_post_id = 0, $item_metadata = NULL, $attachment_metadata = NULL, $id3_metadata = NULL;
|
1344 |
|
1345 |
-
if ( $cached_post_id
|
|
|
1346 |
$item_metadata = NULL;
|
1347 |
$attachment_metadata = NULL;
|
1348 |
$id3_metadata = NULL;
|
1349 |
MLAData::mla_reset_regex_matches( $post_id );
|
1350 |
$cached_post_id = $post_id;
|
|
|
|
|
|
|
|
|
|
|
1351 |
}
|
1352 |
|
1353 |
$template_count = 0;
|
1332 |
* @param string A formatting string containing [+placeholders+]
|
1333 |
* @param array Optional: an array of values from the query, if any, e.g. shortcode parameters
|
1334 |
* @param array Optional: an array of values to add to the returned array
|
1335 |
+
* @param integer Optional: attachment ID for attachment-specific placeholders; use -1 to flush the cache
|
1336 |
* @param boolean Optional: for option 'multi', retain existing values
|
1337 |
* @param string Optional: default option value
|
1338 |
* @param array Optional: attachment_metadata, required during item uploads
|
1342 |
public static function mla_expand_field_level_parameters( $tpl, $query = NULL, $markup_values = array(), $post_id = 0, $keep_existing = false, $default_option = 'text', $upload_metadata = NULL ) {
|
1343 |
static $cached_post_id = 0, $item_metadata = NULL, $attachment_metadata = NULL, $id3_metadata = NULL;
|
1344 |
|
1345 |
+
if ( $cached_post_id !== $post_id ) {
|
1346 |
+
|
1347 |
$item_metadata = NULL;
|
1348 |
$attachment_metadata = NULL;
|
1349 |
$id3_metadata = NULL;
|
1350 |
MLAData::mla_reset_regex_matches( $post_id );
|
1351 |
$cached_post_id = $post_id;
|
1352 |
+
|
1353 |
+
if ( -1 === $post_id ) {
|
1354 |
+
$cached_post_id = 0;
|
1355 |
+
return array();
|
1356 |
+
}
|
1357 |
}
|
1358 |
|
1359 |
$template_count = 0;
|
includes/class-mla-edit-media.php
CHANGED
@@ -321,17 +321,19 @@ class MLAEdit {
|
|
321 |
public static function mla_get_bulk_edit_form_presets( $option, $get_default = false ) {
|
322 |
//error_log( __LINE__ . " MLAEdit::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) _per_user = " . var_export( MLACore::mla_get_option( $option . '_per_user' ), true ), 0 );
|
323 |
if ( $get_default || ( 'checked' !== MLACore::mla_get_option( $option . '_per_user' ) ) ) {
|
324 |
-
|
|
|
|
|
|
|
325 |
}
|
326 |
-
|
327 |
-
// Handle per-user option
|
328 |
-
$option_value = get_user_meta( get_current_user_id(), $option, true );
|
329 |
-
//error_log( __LINE__ . ' MLAEdit::mla_get_bulk_edit_form_presets option_value = ' . var_export( $option_value, true ), 0 );
|
330 |
|
331 |
if ( empty( $option_value ) ) {
|
332 |
-
|
333 |
}
|
|
|
334 |
|
|
|
335 |
return $option_value;
|
336 |
}
|
337 |
|
@@ -710,6 +712,11 @@ class MLAEdit {
|
|
710 |
'label' => esc_attr( $details['name'] ),
|
711 |
'value' => '',
|
712 |
);
|
|
|
|
|
|
|
|
|
|
|
713 |
$custom_fields .= MLAData::mla_parse_template( self::$fieldset_template_array['custom_field'], $element_values );
|
714 |
}
|
715 |
|
321 |
public static function mla_get_bulk_edit_form_presets( $option, $get_default = false ) {
|
322 |
//error_log( __LINE__ . " MLAEdit::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) _per_user = " . var_export( MLACore::mla_get_option( $option . '_per_user' ), true ), 0 );
|
323 |
if ( $get_default || ( 'checked' !== MLACore::mla_get_option( $option . '_per_user' ) ) ) {
|
324 |
+
$option_value = MLACore::mla_get_option( $option, $get_default );
|
325 |
+
} else {
|
326 |
+
// Handle per-user option
|
327 |
+
$option_value = get_user_meta( get_current_user_id(), $option, true );
|
328 |
}
|
329 |
+
//error_log( __LINE__ . " MLAEdit::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) option_value = " . var_export( $option_value, true ), 0 );
|
|
|
|
|
|
|
330 |
|
331 |
if ( empty( $option_value ) ) {
|
332 |
+
$option_value = MLACore::mla_get_option( $option, true );
|
333 |
}
|
334 |
+
$option_value = apply_filters( 'mla_get_bulk_edit_form_presets', $option_value, $option, $get_default );
|
335 |
|
336 |
+
//error_log( __LINE__ . " MLAEdit::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) option_value = " . var_export( $option_value, true ), 0 );
|
337 |
return $option_value;
|
338 |
}
|
339 |
|
712 |
'label' => esc_attr( $details['name'] ),
|
713 |
'value' => '',
|
714 |
);
|
715 |
+
|
716 |
+
if ( !empty( $fieldset_values['custom_fields'][ $details['name'] ] ) ) {
|
717 |
+
$element_values['value'] = $fieldset_values['custom_fields'][ $details['name'] ];
|
718 |
+
}
|
719 |
+
|
720 |
$custom_fields .= MLAData::mla_parse_template( self::$fieldset_template_array['custom_field'], $element_values );
|
721 |
}
|
722 |
|
includes/class-mla-main.php
CHANGED
@@ -1058,7 +1058,17 @@ class MLA {
|
|
1058 |
$tz = get_option( 'timezone_string' );
|
1059 |
if ( !$tz ) {
|
1060 |
$tz = get_option( 'gmt_offset' );
|
1061 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1062 |
$tz = 'UTC';
|
1063 |
}
|
1064 |
}
|
@@ -1734,7 +1744,7 @@ class MLA {
|
|
1734 |
// Display Attachments list
|
1735 |
if ( !empty( $_REQUEST['heading_suffix'] ) ) {
|
1736 |
echo ' - ' . esc_html( urldecode( wp_kses( wp_unslash( $_REQUEST['heading_suffix'] ), 'post' ) ) ) . wp_kses( $heading_tail, 'post' );
|
1737 |
-
} elseif ( !empty( $_REQUEST['mla_terms_search'] ) ) {
|
1738 |
echo ' - ' . esc_html__( 'term search results for', 'media-library-assistant' ) . ' "' . esc_html( trim( sanitize_text_field( wp_unslash( $_REQUEST['mla_terms_search']['phrases'] ), 'post' ) ) ). "\"" . wp_kses( $heading_tail, 'post' );
|
1739 |
} elseif ( !empty( $_REQUEST['s'] ) ) {
|
1740 |
if ( empty( $_REQUEST['mla_search_fields'] ) ) {
|
1058 |
$tz = get_option( 'timezone_string' );
|
1059 |
if ( !$tz ) {
|
1060 |
$tz = get_option( 'gmt_offset' );
|
1061 |
+
if ( $tz ) {
|
1062 |
+
// Adapted from /wp-includes/functions.php wp_timezone_string() added in WP 5.3.0
|
1063 |
+
$offset = (float) $tz;
|
1064 |
+
$hours = (int) $offset;
|
1065 |
+
$minutes = ( $offset - $hours );
|
1066 |
+
|
1067 |
+
$sign = ( $offset < 0 ) ? '-' : '+';
|
1068 |
+
$abs_hour = abs( $hours );
|
1069 |
+
$abs_mins = abs( $minutes * 60 );
|
1070 |
+
$tz = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
|
1071 |
+
} else {
|
1072 |
$tz = 'UTC';
|
1073 |
}
|
1074 |
}
|
1744 |
// Display Attachments list
|
1745 |
if ( !empty( $_REQUEST['heading_suffix'] ) ) {
|
1746 |
echo ' - ' . esc_html( urldecode( wp_kses( wp_unslash( $_REQUEST['heading_suffix'] ), 'post' ) ) ) . wp_kses( $heading_tail, 'post' );
|
1747 |
+
} elseif ( !empty( $_REQUEST['mla_terms_search'] ) && is_array( $_REQUEST['mla_terms_search'] ) ) {
|
1748 |
echo ' - ' . esc_html__( 'term search results for', 'media-library-assistant' ) . ' "' . esc_html( trim( sanitize_text_field( wp_unslash( $_REQUEST['mla_terms_search']['phrases'] ), 'post' ) ) ). "\"" . wp_kses( $heading_tail, 'post' );
|
1749 |
} elseif ( !empty( $_REQUEST['s'] ) ) {
|
1750 |
if ( empty( $_REQUEST['mla_search_fields'] ) ) {
|
includes/class-mla-objects.php
CHANGED
@@ -369,7 +369,7 @@ class MLATextWidget extends WP_Widget {
|
|
369 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php echo esc_html__( 'Title', 'media-library-assistant' ) . ':'; ?></label>
|
370 |
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
|
371 |
|
372 |
-
<textarea class="widefat" rows="16" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"><?php echo
|
373 |
|
374 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox" <?php checked( isset( $instance['filter'] ) ? $instance['filter'] : 0 ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php esc_html_e( 'Automatically add paragraphs', 'media-library-assistant' ); ?></label></p>
|
375 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'textwidget_div' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'textwidget_div' ) ); ?>" type="checkbox" <?php checked( isset( $instance['textwidget_div'] ) ? $instance['textwidget_div'] : 1 ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'textwidget_div' ) ); ?>"><?php esc_html_e( 'Add .textwidget div tags', 'media-library-assistant' ); ?></label></p>
|
369 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php echo esc_html__( 'Title', 'media-library-assistant' ) . ':'; ?></label>
|
370 |
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
|
371 |
|
372 |
+
<textarea class="widefat" rows="16" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"><?php echo $text; // phpcs:ignore ?></textarea>
|
373 |
|
374 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox" <?php checked( isset( $instance['filter'] ) ? $instance['filter'] : 0 ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php esc_html_e( 'Automatically add paragraphs', 'media-library-assistant' ); ?></label></p>
|
375 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'textwidget_div' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'textwidget_div' ) ); ?>" type="checkbox" <?php checked( isset( $instance['textwidget_div'] ) ? $instance['textwidget_div'] : 1 ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'textwidget_div' ) ); ?>"><?php esc_html_e( 'Add .textwidget div tags', 'media-library-assistant' ); ?></label></p>
|
includes/class-mla-options.php
CHANGED
@@ -801,6 +801,11 @@ class MLAOptions {
|
|
801 |
do_action( 'mla_end_mapping' );
|
802 |
}
|
803 |
} else {
|
|
|
|
|
|
|
|
|
|
|
804 |
if ( $options['enable_iptc_exif_update'] || $options['enable_custom_field_update'] ) {
|
805 |
do_action( 'mla_begin_mapping', 'update_metadata', $post_id );
|
806 |
}
|
801 |
do_action( 'mla_end_mapping' );
|
802 |
}
|
803 |
} else {
|
804 |
+
// WPLR sync invokes this filter multiple times, changing file data in between; flush the cache
|
805 |
+
if ( isset( $_SERVER['REQUEST_URI'] ) && false !== strpos( $_SERVER['REQUEST_URI'], '/?wplr-sync-api' ) ) { // phpcs:ignore
|
806 |
+
mla_expand_field_level_parameters( '', NULL, array(), -1 );
|
807 |
+
}
|
808 |
+
|
809 |
if ( $options['enable_iptc_exif_update'] || $options['enable_custom_field_update'] ) {
|
810 |
do_action( 'mla_begin_mapping', 'update_metadata', $post_id );
|
811 |
}
|
includes/class-mla-polylang-support.php
CHANGED
@@ -296,10 +296,15 @@ class MLA_Polylang {
|
|
296 |
}
|
297 |
|
298 |
if ( ! array_key_exists( $inline_lang_choice, $translations ) ) {
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
|
305 |
// Record new language for Term Assignment and Synchronization
|
@@ -1732,10 +1737,15 @@ class MLA_Polylang {
|
|
1732 |
|
1733 |
$inline_lang_choice = sanitize_text_field( wp_unslash( $_REQUEST['inline_lang_choice'] ) );
|
1734 |
if ( ! array_key_exists( $inline_lang_choice, $translations ) ) {
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
|
|
|
|
|
|
|
|
|
|
1739 |
|
1740 |
// Record new language for Term Assignment and Synchronization
|
1741 |
if ( ( ! empty( $_REQUEST['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
|
@@ -1852,12 +1862,17 @@ class MLA_Polylang {
|
|
1852 |
|
1853 |
// Language dropdown in Bulk Edit area
|
1854 |
if ( isset( $_POST['inline_lang_choice'] ) && ( '-1' != $_POST['inline_lang_choice'] ) ) {
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
|
|
|
|
|
|
|
|
|
|
1861 |
|
1862 |
if ( isset( $_REQUEST['inline_lang_choice'] ) &&( $_REQUEST['inline_lang_choice'] != -1 ) ) {
|
1863 |
$item_content = array( 'message' => "Item {$post_id}, language updated." );
|
@@ -2072,9 +2087,7 @@ class MLA_Polylang {
|
|
2072 |
public static function mla_list_table_inline_parse( $html_markup, $item_template, $item_values ) {
|
2073 |
global $polylang, $post_ID;
|
2074 |
|
2075 |
-
|
2076 |
-
* Add the Quick and Bulk Translate Markup
|
2077 |
-
*/
|
2078 |
$page_template_array = MLACore::mla_load_template( 'mla-polylang-support.tpl' );
|
2079 |
if ( ! is_array( $page_template_array ) ) {
|
2080 |
MLACore::mla_debug_add( 'ERROR: mla-polylang-support.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-polylang-support.tpl', true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
|
@@ -2164,9 +2177,12 @@ class MLA_Polylang {
|
|
2164 |
MLA_Polylang::$language_columns = array();
|
2165 |
|
2166 |
if ( isset( $_REQUEST['quick_current_language'] ) ) {
|
2167 |
-
$current_language =
|
|
|
|
|
|
|
2168 |
} else {
|
2169 |
-
$current_language =
|
2170 |
}
|
2171 |
|
2172 |
if ( $show_language && empty( $current_language ) ) {
|
296 |
}
|
297 |
|
298 |
if ( ! array_key_exists( $inline_lang_choice, $translations ) ) {
|
299 |
+
if ( self::$polylang_1dot8_plus ) {
|
300 |
+
$lang = PLL()->model->get_language( $inline_lang_choice );
|
301 |
+
PLL()->model->post->update_language( $post_id, $lang );
|
302 |
+
} else {
|
303 |
+
$post = get_post( $post_id );
|
304 |
+
// save_post() does a check_admin_referer() security test
|
305 |
+
$_REQUEST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' );
|
306 |
+
$polylang->filters_post->save_post( $post_id, $post, true );
|
307 |
+
}
|
308 |
|
309 |
if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
|
310 |
// Record new language for Term Assignment and Synchronization
|
1737 |
|
1738 |
$inline_lang_choice = sanitize_text_field( wp_unslash( $_REQUEST['inline_lang_choice'] ) );
|
1739 |
if ( ! array_key_exists( $inline_lang_choice, $translations ) ) {
|
1740 |
+
if ( self::$polylang_1dot8_plus ) {
|
1741 |
+
$lang = PLL()->model->get_language( $inline_lang_choice );
|
1742 |
+
PLL()->model->post->update_language( $post_id, $lang );
|
1743 |
+
} else {
|
1744 |
+
$post = get_post( $post_id );
|
1745 |
+
// save_post() does a check_admin_referer() security test
|
1746 |
+
$_REQUEST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' );
|
1747 |
+
$polylang->filters_post->save_post( $post_id, $post, true );
|
1748 |
+
}
|
1749 |
|
1750 |
// Record new language for Term Assignment and Synchronization
|
1751 |
if ( ( ! empty( $_REQUEST['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
|
1862 |
|
1863 |
// Language dropdown in Bulk Edit area
|
1864 |
if ( isset( $_POST['inline_lang_choice'] ) && ( '-1' != $_POST['inline_lang_choice'] ) ) {
|
1865 |
+
if ( self::$polylang_1dot8_plus ) {
|
1866 |
+
$lang = PLL()->model->get_language( $_POST['inline_lang_choice'] );
|
1867 |
+
PLL()->model->post->update_language( $post_id, $lang );
|
1868 |
+
} else {
|
1869 |
+
$post = get_post( $post_id );
|
1870 |
+
// save_post() does a check_admin_referer() security test
|
1871 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'bulk-posts' );
|
1872 |
+
// save_post() looks for $_GET['bulk_edit']
|
1873 |
+
$_REQUEST['bulk_edit'] = $_GET['bulk_edit'] ='Update';
|
1874 |
+
$polylang->filters_post->save_post( $post_id, $post, true );
|
1875 |
+
}
|
1876 |
|
1877 |
if ( isset( $_REQUEST['inline_lang_choice'] ) &&( $_REQUEST['inline_lang_choice'] != -1 ) ) {
|
1878 |
$item_content = array( 'message' => "Item {$post_id}, language updated." );
|
2087 |
public static function mla_list_table_inline_parse( $html_markup, $item_template, $item_values ) {
|
2088 |
global $polylang, $post_ID;
|
2089 |
|
2090 |
+
// Add the Quick and Bulk Translate Markup
|
|
|
|
|
2091 |
$page_template_array = MLACore::mla_load_template( 'mla-polylang-support.tpl' );
|
2092 |
if ( ! is_array( $page_template_array ) ) {
|
2093 |
MLACore::mla_debug_add( 'ERROR: mla-polylang-support.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-polylang-support.tpl', true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
|
2177 |
MLA_Polylang::$language_columns = array();
|
2178 |
|
2179 |
if ( isset( $_REQUEST['quick_current_language'] ) ) {
|
2180 |
+
$current_language = sanitize_text_field( wp_unslash( $_REQUEST['quick_current_language'] ) );
|
2181 |
+
if ( !empty( $current_language ) ) {
|
2182 |
+
$current_language = (object) array( 'slug' => $current_language );
|
2183 |
+
}
|
2184 |
} else {
|
2185 |
+
$current_language = $polylang->curlang;
|
2186 |
}
|
2187 |
|
2188 |
if ( $show_language && empty( $current_language ) ) {
|
includes/class-mla-wpml-support.php
CHANGED
@@ -47,7 +47,15 @@ class MLA_WPML {
|
|
47 |
add_action( 'mla_updated_single_item', 'MLA_WPML::mla_updated_single_item', 10, 2 );
|
48 |
|
49 |
// Defined in /media-library-assistant/includes/class-mla-edit-media.php
|
50 |
-
add_filter( '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
// Defined in /media-library-assistant/includes/class-mla-media-modal.php
|
53 |
add_action( 'mla_media_modal_begin_update_compat_fields', 'MLA_WPML::mla_media_modal_begin_update_compat_fields', 10, 1 );
|
@@ -368,9 +376,7 @@ class MLA_WPML {
|
|
368 |
public static function mla_list_table_bulk_action_item_request( $request, $bulk_action, $post_id, $custom_field_map ) {
|
369 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::mla_list_table_bulk_action_item_request( {$post_id} ) request = " . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
370 |
|
371 |
-
|
372 |
-
* Note that $request may be modified by previous items, so we must return to the initial vlues
|
373 |
-
*/
|
374 |
if ( 'edit' == $bulk_action && ( ! empty( self::$bulk_edit_request['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_WPML::$mla_language_option_definitions ) ) ) {
|
375 |
self::_build_existing_terms( $post_id );
|
376 |
self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], self::$bulk_edit_request['tax_action'], true );
|
@@ -863,9 +869,7 @@ class MLA_WPML {
|
|
863 |
$taxonomies = $sitepress->get_translatable_taxonomies( true, 'attachment' );
|
864 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_build_existing_terms( {$post_id} ) \$sitepress->get_translatable_taxonomies() = " . var_export( $taxonomies, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
865 |
|
866 |
-
|
867 |
-
* Find all assigned terms and build term_master array
|
868 |
-
*/
|
869 |
$current_language = $sitepress->get_current_language();
|
870 |
foreach ( $translations as $language_code => $translation ) {
|
871 |
$sitepress->switch_lang( $language_code, true );
|
@@ -881,9 +885,7 @@ class MLA_WPML {
|
|
881 |
} // taxonomy
|
882 |
} // translation
|
883 |
|
884 |
-
|
885 |
-
* Add missing translated terms to the term_master array
|
886 |
-
*/
|
887 |
foreach ( self::$relevant_terms as $term ) {
|
888 |
foreach ( $term['translations'] as $translation ) {
|
889 |
if ( array_key_exists( $translation->element_id, self::$relevant_terms ) ) {
|
@@ -1009,6 +1011,8 @@ class MLA_WPML {
|
|
1009 |
return;
|
1010 |
}
|
1011 |
|
|
|
|
|
1012 |
self::$tax_input = array( 'tax_input_post_id' => $post_id );
|
1013 |
$active_languages = $sitepress->get_active_languages();
|
1014 |
|
@@ -1095,9 +1099,7 @@ class MLA_WPML {
|
|
1095 |
} // flat taxonomy
|
1096 |
|
1097 |
foreach( $active_languages as $language => $language_details ) {
|
1098 |
-
|
1099 |
-
* Apply the tax_action to the terms_before to find the terms_after
|
1100 |
-
*/
|
1101 |
$term_changes = isset( $input_terms[ $language ] ) ? $input_terms[ $language ] : array();
|
1102 |
if ( 'replace' == $tax_action ) {
|
1103 |
$terms_after = $term_changes;
|
@@ -1113,9 +1115,7 @@ class MLA_WPML {
|
|
1113 |
} // input_term
|
1114 |
}
|
1115 |
|
1116 |
-
|
1117 |
-
* Convert terms_after to tax_input format
|
1118 |
-
*/
|
1119 |
$term_changes = array();
|
1120 |
foreach( $terms_after as $input_term ) {
|
1121 |
$term_changes[] = $input_term->term_id;
|
@@ -1290,9 +1290,9 @@ class MLA_WPML {
|
|
1290 |
$terms_before = self::_update_existing_terms( $post_id );
|
1291 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_apply_term_synchronization( {$post_id} ) terms_before = " . var_export( $terms_before, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1292 |
|
1293 |
-
// $tax_input is a convenient source of language codes; ignore $tax_inputs
|
1294 |
$current_language = $sitepress->get_current_language();
|
1295 |
-
|
|
|
1296 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_apply_term_synchronization( {$post_id}, {$language} ) tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1297 |
// Skip the language we've already updated
|
1298 |
if ( ( ! isset( self::$existing_terms[ $language ] ) ) || ( self::$existing_terms[ 'language_code' ] == $language ) ) {
|
@@ -1323,6 +1323,11 @@ class MLA_WPML {
|
|
1323 |
public static function mla_updated_single_item( $post_id, $result ) {
|
1324 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::mla_updated_single_item( {$post_id}, {$result} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1325 |
|
|
|
|
|
|
|
|
|
|
|
1326 |
if ( self::$existing_terms['element_id'] == $post_id ) {
|
1327 |
// Synchronize the changes to all other translations
|
1328 |
self::_apply_term_synchronization( $post_id );
|
@@ -1560,24 +1565,101 @@ class MLA_WPML {
|
|
1560 |
} // edit_attachment
|
1561 |
|
1562 |
/**
|
1563 |
-
*
|
1564 |
*
|
1565 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1566 |
*
|
1567 |
-
* @
|
1568 |
*/
|
1569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1570 |
/*
|
1571 |
-
*
|
|
|
|
|
|
|
1572 |
*/
|
|
|
|
|
|
|
1573 |
if ( class_exists( 'WPML_Media' ) ) {
|
1574 |
-
|
1575 |
-
if ( isset( $content_defaults['always_translate_media'] ) && $content_defaults['always_translate_media'] ) {
|
1576 |
-
$true_selected = 'selected="selected"';
|
1577 |
-
$false_selected = '';
|
1578 |
-
} else {
|
1579 |
$true_selected = '';
|
1580 |
$false_selected = 'selected="selected"';
|
|
|
|
|
|
|
1581 |
}
|
1582 |
|
1583 |
$page_values['custom_fields'] .= ' <label class="inline-edit-c_0 clear"><span class="title">WPML</span><span class="input-text-wrap">' . "\n";
|
@@ -1588,8 +1670,9 @@ class MLA_WPML {
|
|
1588 |
$page_values['custom_fields'] .= ' </span></label>' . "\n";
|
1589 |
}
|
1590 |
|
1591 |
-
|
1592 |
-
|
|
|
1593 |
|
1594 |
/**
|
1595 |
* Adds the "Language" tab to the Settings/Media Library Assistant list
|
@@ -1718,9 +1801,7 @@ class MLA_WPML {
|
|
1718 |
return $page_content;
|
1719 |
}
|
1720 |
|
1721 |
-
|
1722 |
-
* Find WPML Media plugin status
|
1723 |
-
*/
|
1724 |
$installed = false;
|
1725 |
$active = false;
|
1726 |
$wpml_media = SitePress::get_installed_plugins();
|
47 |
add_action( 'mla_updated_single_item', 'MLA_WPML::mla_updated_single_item', 10, 2 );
|
48 |
|
49 |
// Defined in /media-library-assistant/includes/class-mla-edit-media.php
|
50 |
+
add_filter( 'mla_get_bulk_edit_form_presets', 'MLA_WPML::mla_get_bulk_edit_form_presets', 10, 3 );
|
51 |
+
|
52 |
+
add_filter( 'mla_upload_bulk_edit_form_blank_fieldset_values', 'MLA_WPML::mla_upload_bulk_edit_fieldset_values', 10, 2 );
|
53 |
+
add_filter( 'mla_upload_bulk_edit_form_initial_fieldset_values', 'MLA_WPML::mla_upload_bulk_edit_fieldset_values', 10, 2 );
|
54 |
+
add_filter( 'mla_upload_bulk_edit_form_preset_fieldset_values', 'MLA_WPML::mla_upload_bulk_edit_fieldset_values', 10, 2 );
|
55 |
+
|
56 |
+
add_filter( 'mla_upload_bulk_edit_form_blank_values', 'MLA_WPML::mla_upload_bulk_edit_values', 10, 1 );
|
57 |
+
add_filter( 'mla_upload_bulk_edit_form_initial_values', 'MLA_WPML::mla_upload_bulk_edit_values', 10, 1 );
|
58 |
+
add_filter( 'mla_upload_bulk_edit_form_preset_values', 'MLA_WPML::mla_upload_bulk_edit_values', 10, 1 );
|
59 |
|
60 |
// Defined in /media-library-assistant/includes/class-mla-media-modal.php
|
61 |
add_action( 'mla_media_modal_begin_update_compat_fields', 'MLA_WPML::mla_media_modal_begin_update_compat_fields', 10, 1 );
|
376 |
public static function mla_list_table_bulk_action_item_request( $request, $bulk_action, $post_id, $custom_field_map ) {
|
377 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::mla_list_table_bulk_action_item_request( {$post_id} ) request = " . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
378 |
|
379 |
+
// Note that $request may be modified by previous items, so we must return to the initial vlues
|
|
|
|
|
380 |
if ( 'edit' == $bulk_action && ( ! empty( self::$bulk_edit_request['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_WPML::$mla_language_option_definitions ) ) ) {
|
381 |
self::_build_existing_terms( $post_id );
|
382 |
self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], self::$bulk_edit_request['tax_action'], true );
|
869 |
$taxonomies = $sitepress->get_translatable_taxonomies( true, 'attachment' );
|
870 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_build_existing_terms( {$post_id} ) \$sitepress->get_translatable_taxonomies() = " . var_export( $taxonomies, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
871 |
|
872 |
+
// Find all assigned terms and build term_master array
|
|
|
|
|
873 |
$current_language = $sitepress->get_current_language();
|
874 |
foreach ( $translations as $language_code => $translation ) {
|
875 |
$sitepress->switch_lang( $language_code, true );
|
885 |
} // taxonomy
|
886 |
} // translation
|
887 |
|
888 |
+
// Add missing translated terms to the term_master array
|
|
|
|
|
889 |
foreach ( self::$relevant_terms as $term ) {
|
890 |
foreach ( $term['translations'] as $translation ) {
|
891 |
if ( array_key_exists( $translation->element_id, self::$relevant_terms ) ) {
|
1011 |
return;
|
1012 |
}
|
1013 |
|
1014 |
+
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_build_tax_input( {$post_id} ) \$tax_actions = " . var_export( $tax_actions, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1015 |
+
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_build_tax_input( {$post_id} ) \$tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1016 |
self::$tax_input = array( 'tax_input_post_id' => $post_id );
|
1017 |
$active_languages = $sitepress->get_active_languages();
|
1018 |
|
1099 |
} // flat taxonomy
|
1100 |
|
1101 |
foreach( $active_languages as $language => $language_details ) {
|
1102 |
+
// Apply the tax_action to the terms_before to find the terms_after
|
|
|
|
|
1103 |
$term_changes = isset( $input_terms[ $language ] ) ? $input_terms[ $language ] : array();
|
1104 |
if ( 'replace' == $tax_action ) {
|
1105 |
$terms_after = $term_changes;
|
1115 |
} // input_term
|
1116 |
}
|
1117 |
|
1118 |
+
// Convert terms_after to tax_input format
|
|
|
|
|
1119 |
$term_changes = array();
|
1120 |
foreach( $terms_after as $input_term ) {
|
1121 |
$term_changes[] = $input_term->term_id;
|
1290 |
$terms_before = self::_update_existing_terms( $post_id );
|
1291 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_apply_term_synchronization( {$post_id} ) terms_before = " . var_export( $terms_before, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1292 |
|
|
|
1293 |
$current_language = $sitepress->get_current_language();
|
1294 |
+
$active_languages = $sitepress->get_active_languages();
|
1295 |
+
foreach( $active_languages as $language => $tax_inputs ) {
|
1296 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::_apply_term_synchronization( {$post_id}, {$language} ) tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1297 |
// Skip the language we've already updated
|
1298 |
if ( ( ! isset( self::$existing_terms[ $language ] ) ) || ( self::$existing_terms[ 'language_code' ] == $language ) ) {
|
1323 |
public static function mla_updated_single_item( $post_id, $result ) {
|
1324 |
MLACore::mla_debug_add( __LINE__ . " MLA_WPML::mla_updated_single_item( {$post_id}, {$result} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
|
1325 |
|
1326 |
+
// Existing terms might have changed, e.g., during uploads
|
1327 |
+
if ( self::$existing_terms['element_id'] == 0 ) {
|
1328 |
+
self::_build_existing_terms( $post_id );
|
1329 |
+
}
|
1330 |
+
|
1331 |
if ( self::$existing_terms['element_id'] == $post_id ) {
|
1332 |
// Synchronize the changes to all other translations
|
1333 |
self::_apply_term_synchronization( $post_id );
|
1565 |
} // edit_attachment
|
1566 |
|
1567 |
/**
|
1568 |
+
* MLA_List_Table item bulk edit form preset values
|
1569 |
*
|
1570 |
+
* This filter gives you a chance to modify or extend the presets used to populate
|
1571 |
+
* the Bulk Edit on Upload form.
|
1572 |
+
*
|
1573 |
+
* @since 3.02
|
1574 |
+
*
|
1575 |
+
* @param array $option_value data values to populate the form presets
|
1576 |
+
* @param string $option 'mla_bulk_edit_presets' or 'mla_bulk_edit_presets_per_user'
|
1577 |
+
* @param boolean $get_default True to ignore current setting and return default values
|
1578 |
+
*/
|
1579 |
+
public static function mla_get_bulk_edit_form_presets( $option_value, $option, $get_default ) {
|
1580 |
+
//error_log( __LINE__ . " MLA_WPML::mla_get_bulk_edit_form_presets( {$option}, {$get_default} ) \$option_value = " . var_export( $option_value, true ), 0 );
|
1581 |
+
|
1582 |
+
if ( class_exists( 'WPML_Media', false ) ) {
|
1583 |
+
if ( $get_default || empty( $option_value['mla_always_translate_media'] ) ) {
|
1584 |
+
$content_defaults = WPML_Media::get_setting( 'new_content_settings' );
|
1585 |
+
if ( isset( $content_defaults['always_translate_media'] ) && $content_defaults['always_translate_media'] ) {
|
1586 |
+
$option_value['mla_always_translate_media'] = 'true';
|
1587 |
+
} else {
|
1588 |
+
$option_value['mla_always_translate_media'] = 'false';
|
1589 |
+
}
|
1590 |
+
}
|
1591 |
+
} else {
|
1592 |
+
unset( $option_value['mla_always_translate_media'] );
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
return $option_value;
|
1596 |
+
} // mla_get_bulk_edit_form_presets
|
1597 |
+
|
1598 |
+
/**
|
1599 |
+
* MLA_List_Table item bulk edit fieldset values
|
1600 |
+
*
|
1601 |
+
* This filter gives you a chance to modify the data values that populate the Bulk Edit form.
|
1602 |
+
*
|
1603 |
+
* @since 3.02
|
1604 |
+
*
|
1605 |
+
* @param array $fieldset_values data values to populate the form
|
1606 |
+
* @param string $filter_root identify the blank, initial and preset fieldsets
|
1607 |
+
*/
|
1608 |
+
public static function mla_upload_bulk_edit_fieldset_values( $fieldset_values, $filter_root ) {
|
1609 |
+
/*
|
1610 |
+
* You can use the 'filter_root' argument to distinguish among :
|
1611 |
+
* mla_upload_bulk_edit_form_blank,
|
1612 |
+
* mla_upload_bulk_edit_form_initial,
|
1613 |
+
* mla_upload_bulk_edit_form_preset
|
1614 |
+
*/
|
1615 |
+
//error_log( __LINE__ . " MLA_WPML::mla_upload_bulk_edit_fieldset_values( {$filter_root} ) \$fieldset_values = " . var_export( $fieldset_values, true ), 0 );
|
1616 |
+
|
1617 |
+
if ( empty( $fieldset_values['mla_always_translate_media'] ) ) {
|
1618 |
+
$fieldset_values['mla_always_translate_media'] = 'true';
|
1619 |
+
}
|
1620 |
+
|
1621 |
+
//error_log( __LINE__ . " MLA_WPML::mla_upload_bulk_edit_fieldset_values( {$filter_root} ) \$fieldset_values = " . var_export( $fieldset_values, true ), 0 );
|
1622 |
+
self::$_upload_bulk_edit_fieldset_values = $fieldset_values;
|
1623 |
+
|
1624 |
+
return $fieldset_values;
|
1625 |
+
} // mla_upload_bulk_edit_fieldset_values
|
1626 |
+
|
1627 |
+
/**
|
1628 |
+
* Share fieldset values between mla_upload_bulk_edit_fieldset_values() and mla_upload_bulk_edit_values()
|
1629 |
+
*
|
1630 |
+
* @since 3.02
|
1631 |
*
|
1632 |
+
* @var array fieldset values
|
1633 |
*/
|
1634 |
+
private static $_upload_bulk_edit_fieldset_values = array( 'mla_always_translate_media' => 'true' );
|
1635 |
+
|
1636 |
+
/**
|
1637 |
+
* MLA_List_Table item bulk edit values
|
1638 |
+
*
|
1639 |
+
* This filter gives you a chance to modify the substitution parameters used to populate
|
1640 |
+
* the Bulk Edit on Upload form.
|
1641 |
+
*
|
1642 |
+
* @since 3.02
|
1643 |
+
*
|
1644 |
+
* @param array $page_values subsitiution parameter values to populate the form
|
1645 |
+
*/
|
1646 |
+
public static function mla_upload_bulk_edit_values( $page_values ) {
|
1647 |
/*
|
1648 |
+
* You can use the 'filter_root' argument to distinguish among :
|
1649 |
+
* mla_upload_bulk_edit_form_blank,
|
1650 |
+
* mla_upload_bulk_edit_form_initial,
|
1651 |
+
* mla_upload_bulk_edit_form_preset
|
1652 |
*/
|
1653 |
+
//error_log( __LINE__ . " MLA_WPML::mla_upload_bulk_edit_values() \$page_values = " . var_export( $page_values, true ), 0 );
|
1654 |
+
|
1655 |
+
// Add markup to the $fieldset_values ['custom_fields'] element for the "Always translate" checkbox
|
1656 |
if ( class_exists( 'WPML_Media' ) ) {
|
1657 |
+
if ( isset( self::$_upload_bulk_edit_fieldset_values['mla_always_translate_media'] ) && ( 'false' === self::$_upload_bulk_edit_fieldset_values['mla_always_translate_media'] ) ) {
|
|
|
|
|
|
|
|
|
1658 |
$true_selected = '';
|
1659 |
$false_selected = 'selected="selected"';
|
1660 |
+
} else {
|
1661 |
+
$true_selected = 'selected="selected"';
|
1662 |
+
$false_selected = '';
|
1663 |
}
|
1664 |
|
1665 |
$page_values['custom_fields'] .= ' <label class="inline-edit-c_0 clear"><span class="title">WPML</span><span class="input-text-wrap">' . "\n";
|
1670 |
$page_values['custom_fields'] .= ' </span></label>' . "\n";
|
1671 |
}
|
1672 |
|
1673 |
+
//error_log( __LINE__ . " MLA_WPML::mla_upload_bulk_edit_values() \$page_values = " . var_export( $page_values, true ), 0 );
|
1674 |
+
return $page_values;
|
1675 |
+
} // mla_upload_bulk_edit_values
|
1676 |
|
1677 |
/**
|
1678 |
* Adds the "Language" tab to the Settings/Media Library Assistant list
|
1801 |
return $page_content;
|
1802 |
}
|
1803 |
|
1804 |
+
// Find WPML Media plugin status
|
|
|
|
|
1805 |
$installed = false;
|
1806 |
$active = false;
|
1807 |
$wpml_media = SitePress::get_installed_plugins();
|
includes/mla-main-search-box-template.php
CHANGED
@@ -40,7 +40,7 @@ if ( empty( $supported_taxonomies ) ) {
|
|
40 |
?>
|
41 |
<p class="search-box">
|
42 |
<label class="screen-reader-text" for="mla-media-search-input"><?php esc_html_e( 'Search Media', 'media-library-assistant' ); ?></label>
|
43 |
-
<input name="s" id="mla-media-search-input" type="
|
44 |
<input name="mla-search-submit" class="button" id="search-submit" type="submit" value="<?php esc_attr_e( 'Search Media', 'media-library-assistant' ); ?>" /><br />
|
45 |
<span <?php echo wp_kses( $controls_style, 'post' ) ?>>
|
46 |
<span id="search-title-span">
|
40 |
?>
|
41 |
<p class="search-box">
|
42 |
<label class="screen-reader-text" for="mla-media-search-input"><?php esc_html_e( 'Search Media', 'media-library-assistant' ); ?></label>
|
43 |
+
<input name="s" id="mla-media-search-input" type="search" size="45" value="<?php echo esc_attr( $search_value ) ?>" />
|
44 |
<input name="mla-search-submit" class="button" id="search-submit" type="submit" value="<?php esc_attr_e( 'Search Media', 'media-library-assistant' ); ?>" /><br />
|
45 |
<span <?php echo wp_kses( $controls_style, 'post' ) ?>>
|
46 |
<span id="search-title-span">
|
index.php
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
* will the rest of the plugin be loaded and run.
|
7 |
*
|
8 |
* @package Media Library Assistant
|
9 |
-
* @version 3.
|
10 |
*/
|
11 |
|
12 |
/*
|
@@ -16,7 +16,7 @@ Description: Enhances the Media Library; powerful [mla_gallery] [mla_tag_cloud]
|
|
16 |
Author: David Lingren
|
17 |
Text Domain: media-library-assistant
|
18 |
Domain Path: /languages
|
19 |
-
Version: 3.
|
20 |
Author URI: http://davidlingren.com/
|
21 |
|
22 |
Copyright 2011-2022 David Lingren
|
6 |
* will the rest of the plugin be loaded and run.
|
7 |
*
|
8 |
* @package Media Library Assistant
|
9 |
+
* @version 3.03
|
10 |
*/
|
11 |
|
12 |
/*
|
16 |
Author: David Lingren
|
17 |
Text Domain: media-library-assistant
|
18 |
Domain Path: /languages
|
19 |
+
Version: 3.03
|
20 |
Author URI: http://davidlingren.com/
|
21 |
|
22 |
Copyright 2011-2022 David Lingren
|
readme.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
=== Media Library Assistant ===
|
2 |
Contributors: dglingren
|
3 |
Donate link: http://davidlingren.com/#donate
|
4 |
-
Tags:
|
5 |
Requires at least: 3.5.0
|
6 |
-
Tested up to: 6.0
|
7 |
Requires PHP: 5.3
|
8 |
-
Stable tag: 3.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -187,6 +187,24 @@ All of the MLA source code has been annotated with "DocBlocks", a special type o
|
|
187 |
|
188 |
== Changelog ==
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
= 3.01 =
|
191 |
|
192 |
* Fix: For the Media/Assistant Bulk Edit feature, AJAX errors have been corrected.
|
@@ -218,29 +236,8 @@ All of the MLA source code has been annotated with "DocBlocks", a special type o
|
|
218 |
* Fix: For the Media/Assistant Bulk Edit Area, failure to update a field to a value of '0' has been corrected.
|
219 |
* Fix: For the "MLA Simple Mapping Hooks Example" plugin, the plugin is now active when media item inserts are performed in Gutenberg blocks.
|
220 |
|
221 |
-
= 2.99 =
|
222 |
-
|
223 |
-
* New: On the Media/Add New (Upload New Media) and Media/Assistant screens, **MLA Bulk Edit Area values can be saved and recalled for future/repeated use.**
|
224 |
-
* New: Current date and time values are available as field-level data sources, `current_timestamp`, `current_datetime` and `current_getdate`.
|
225 |
-
* New: Library Views based on a custom field query can now include MIME type filters in addition to the custom field query.
|
226 |
-
* New: The "MLA Advanced Custom Fields Example" and "MLA Image Source Control Example" plugins have been updated to support the new Bulk Edit Area features.
|
227 |
-
* Fix: For the `terms:` substitution prefix, operation of the field qualifier, e.g., `terms:attachment_tag(slug)`, has been restored.
|
228 |
-
* Fix: For the Polylang plugin, some defects in the display of the Media/Assistent country/flags column have been corrected.
|
229 |
-
* Fix: To reduce security risks, taxonomy, date and meta queries no longer use the "eval" function to convert parameter values to array variables.
|
230 |
-
* Fix: For some forms of the Media Manager Modal (popup) Window, taxonomy "click to toggle" functions have been restored.
|
231 |
-
* Fix: For `[mla_gallery]`, `mla_nolink_text` handling for `paginate_links` has been restored.
|
232 |
-
* Fix: For `[mla_gallery]` with Real Media Library Pro, the `orderby=` parameter has been restored.
|
233 |
-
* Fix: Version numbers for CSS and JavaScript files now include Development Version date to prevent "stale" stylesheet and script problems.
|
234 |
-
* Fix: For the "Smart Media Categories" example plugin, syncing child and parent terms during attachment uploads has been restored.
|
235 |
-
* Fix: For the "Smart Media Categories" example plugin, synch status coloring in the Posts/All Posts "Children" table column has been corrected.
|
236 |
-
* Fix: For the Settings/Media Library Assistant Views tab, a PHP warning message when canceling an Edit View action has been eliminated.
|
237 |
-
* Fix: For the Media/Add New Bulk Edit area and the Media/Assistant Bulk and Quick Edit areas, the taxonomy "Add New Term" function has been repaired.
|
238 |
-
* Fix: For `[mla_term_list]`, `include_tree` and `exclude_tree` are now evaluated before `child_of` to improve the results.
|
239 |
-
* Fix: For `[mla_term_list]`, named control values are removed from the `$_REQUEST` array if the value is not present in the current term list.
|
240 |
-
* Fix: For `[mla_term_list]`, `current_item_class` assignments for term_id values have been restored.
|
241 |
-
* Fix: For the "MLA Advanced Custom Fields Example" plugin, a PHP warning message during Media/Assistant bulk actions has been eliminated.
|
242 |
-
|
243 |
-
= 2.90 - 2.98 =
|
244 |
* 2.98 - New "Attachment File Metadata" meta box on the Media/Edit Media screen. Enhanced "MLA Advanced Custom Fields Example" and new "MLA Filename Issues Example" plugins. Five enhancements in all, eleven fixes.
|
245 |
* 2.97 - IMPORTANT: [mla_gallery] PHP "Warning: array_key_exists()..." messages have been eliminated. WP 5.8, cropping of MMMW top row image thubmnails fixed. Description element added to mapping rules. Four enhancements in all, four fixes.
|
246 |
* 2.96 - WordPress 5.8 support! New [muie_archive_list] shortcode. CSV export item values. Support for Enhanced Media Library plugin. Donation links are back. Thirteen enhancements in all, fourteen fixes.
|
@@ -361,8 +358,8 @@ All of the MLA source code has been annotated with "DocBlocks", a special type o
|
|
361 |
|
362 |
== Upgrade Notice ==
|
363 |
|
364 |
-
= 3.
|
365 |
-
IMPORTANT: For the
|
366 |
|
367 |
== Other Notes ==
|
368 |
|
1 |
=== Media Library Assistant ===
|
2 |
Contributors: dglingren
|
3 |
Donate link: http://davidlingren.com/#donate
|
4 |
+
Tags: categories, gallery, images, media, media library, tags
|
5 |
Requires at least: 3.5.0
|
6 |
+
Tested up to: 6.0.2
|
7 |
Requires PHP: 5.3
|
8 |
+
Stable tag: 3.03
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
187 |
|
188 |
== Changelog ==
|
189 |
|
190 |
+
= 3.03 =
|
191 |
+
* Fix: For the `[mla_gallery]` shortcode, a defect (introduced in v3.02) in expanding template values has been corrected.
|
192 |
+
|
193 |
+
= 3.02 =
|
194 |
+
|
195 |
+
* New: The new "MLA WFU Data Source" example plugin provides enhanced access to the "additional fields" created by the WordPress File Upload plugin. The Settings/MLA WFU Data Documentation tab has details.
|
196 |
+
* New: For the Media/Assistant Bulk Edit area and the Bulk Edit on Upload area, the new "mla_get_bulk_edit_form_presets" filter lets you customize preset fields and content.
|
197 |
+
* Fix: When Polyang is active, a defect with the "Language" dropdown for Quick Translate, Quick Edit and Bulk Edit has been corrected.
|
198 |
+
* Fix: When Photo Engine (WP/LR Sync) is active, a defect with mapping rules during "sync" operations has been corrected.
|
199 |
+
* Fix: For the Media/Assistant Search Media function, the enter key now triggers a search when the text box is not empty.
|
200 |
+
* Fix: When WPML is active, the "Make media available in all languages" dropdown control has been restored to the Bulk Edit on Upload area.
|
201 |
+
* Fix: When WPML is active, term synchronization has been restored when new items are uploaded.
|
202 |
+
* Fix: For the Media/Assistant Bulk Edit area and the Bulk Edit on Upload area, custom field values are now retained as presets for the export/import actions.
|
203 |
+
* Fix: For the Media/Assistant admin submenu, Fatal PHP errors when Bulk Editing the Uploaded on values on a site with a positive UTC offset Timezone have been avoided.
|
204 |
+
* Fix: For the "MLA CSV Data Source Example" plugin, links to the Settings/Media Library Assistant Documentation tab have been restored.
|
205 |
+
* Fix: HTML markup is preserved when editing the source of an "MLA Text" widget, subject to a `current_user_can('unfiltered_html')` check.
|
206 |
+
* Fix: For the Media/Assistant admin submenu, Fatal PHP errors when pressing the "Terms Search" button before the page load is finished have been avoided.
|
207 |
+
|
208 |
= 3.01 =
|
209 |
|
210 |
* Fix: For the Media/Assistant Bulk Edit feature, AJAX errors have been corrected.
|
236 |
* Fix: For the Media/Assistant Bulk Edit Area, failure to update a field to a value of '0' has been corrected.
|
237 |
* Fix: For the "MLA Simple Mapping Hooks Example" plugin, the plugin is now active when media item inserts are performed in Gutenberg blocks.
|
238 |
|
239 |
+
= 2.90 - 2.99 =
|
240 |
+
* 2.99 - WordPress 5.9 support. Bulk Edit values save/restore, current date/time data sources, custom field Library views filtered by MIME type. Four enhancements in all, fifteen fixes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
* 2.98 - New "Attachment File Metadata" meta box on the Media/Edit Media screen. Enhanced "MLA Advanced Custom Fields Example" and new "MLA Filename Issues Example" plugins. Five enhancements in all, eleven fixes.
|
242 |
* 2.97 - IMPORTANT: [mla_gallery] PHP "Warning: array_key_exists()..." messages have been eliminated. WP 5.8, cropping of MMMW top row image thubmnails fixed. Description element added to mapping rules. Four enhancements in all, four fixes.
|
243 |
* 2.96 - WordPress 5.8 support! New [muie_archive_list] shortcode. CSV export item values. Support for Enhanced Media Library plugin. Donation links are back. Thirteen enhancements in all, fourteen fixes.
|
358 |
|
359 |
== Upgrade Notice ==
|
360 |
|
361 |
+
= 3.03 =
|
362 |
+
IMPORTANT: For the [mla_gallery] shortcode, a defect (introduced in v3.02) in expanding template values has been corrected.
|
363 |
|
364 |
== Other Notes ==
|
365 |
|
tpls/documentation-settings-tab.tpl
CHANGED
@@ -6138,6 +6138,10 @@ The Media/Assistant Bulk Edit area has three copies of field-level values. The "
|
|
6138 |
</p>
|
6139 |
<table>
|
6140 |
<tr>
|
|
|
|
|
|
|
|
|
6141 |
<td class="mla-doc-hook-label">mla_list_table_inline_blank_fieldset_values,<br />
|
6142 |
mla_list_table_inline_initial_fieldset_values,<br />
|
6143 |
mla_list_table_inline_preset_fieldset_values
|
@@ -6246,6 +6250,10 @@ The Media/Add New (Upload New Media) Bulk Edit area has three copies of field-le
|
|
6246 |
</p>
|
6247 |
<table>
|
6248 |
<tr>
|
|
|
|
|
|
|
|
|
6249 |
<td class="mla-doc-hook-label">mla_upload_bulk_edit_form_blank_fieldset_values,<br />
|
6250 |
mla_upload_bulk_edit_form_initial_fieldset_values,<br />
|
6251 |
mla_upload_bulk_edit_form_preset_fieldset_values
|
6138 |
</p>
|
6139 |
<table>
|
6140 |
<tr>
|
6141 |
+
<td class="mla-doc-hook-label">mla_get_bulk_edit_form_presets</td>
|
6142 |
+
<td class="mla-doc-hook-definition">Gives you a chance to modify or extend the presets used to populate the Media/Assistant Bulk Edit and Bulk Edit on Upload forms.</td>
|
6143 |
+
</tr>
|
6144 |
+
<tr>
|
6145 |
<td class="mla-doc-hook-label">mla_list_table_inline_blank_fieldset_values,<br />
|
6146 |
mla_list_table_inline_initial_fieldset_values,<br />
|
6147 |
mla_list_table_inline_preset_fieldset_values
|
6250 |
</p>
|
6251 |
<table>
|
6252 |
<tr>
|
6253 |
+
<td class="mla-doc-hook-label">mla_get_bulk_edit_form_presets</td>
|
6254 |
+
<td class="mla-doc-hook-definition">Gives you a chance to modify or extend the presets used to populate the Media/Assistant Bulk Edit and Bulk Edit on Upload forms.</td>
|
6255 |
+
</tr>
|
6256 |
+
<tr>
|
6257 |
<td class="mla-doc-hook-label">mla_upload_bulk_edit_form_blank_fieldset_values,<br />
|
6258 |
mla_upload_bulk_edit_form_initial_fieldset_values,<br />
|
6259 |
mla_upload_bulk_edit_form_preset_fieldset_values
|