やるきなし

2017/08/12 11:52 / WordPress Multisite Post Duplicator Plugin 1.7.1

以下のように wp-cli (以下の wp command)を使って WordPress の自動 update を行っているのだが,

#!/bin/sh

wp core update
wp core update-db --network
wp plugin update --all
wp theme update --all
wp core language update

cron から以下のようなエラーメールが届く.

PHP Parse error:  syntax error, unexpected '[' in /somewhere/public_html/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php on line 418
Parse error: syntax error, unexpected '[' in /somewhere/public_html/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php on line 418
PHP Parse error:  syntax error, unexpected '[' in /somewhere/public_html/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php on line 418
Parse error: syntax error, unexpected '[' in /somewhere/public_html/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php on line 418

Update 後 Multisite Post Duplicator (v1.7.1) (https://wordpress.org/plugins/multisite-post-duplicator/) が正常動作せず,うまく表示がされなくなる.

サーバの PHP のバージョンは以下のとおりで,

% php -v
PHP 5.3.3 (cli) (built: Jan  5 2016 08:52:51)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

http://php.net/manual/en/language.types.array.php にある PHP 5.4 形式の配列(array in PHP = ordered map)定義を使っているのが原因.ということで,以下パッチ.

--- a/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php
+++ b/wp-content/plugins/multisite-post-duplicator/inc/mpd-functions.php
@@ -415,10 +415,10 @@ function mpd_get_images_from_the_content($post_id){
             $image_obj = get_post($matches[0]);
             //Push this object into an array.
             // Save all elements needed to the duplication process
-            $images_objects_from_post[ $matches[0] ] = [
+            $images_objects_from_post[ $matches[0] ] = array(
                 'attached_file_path' => get_attached_file( $matches[0] ),
                 'object'             => $image_obj
-             ];
+            );
 
         }
         //Deliver the array of attachment objects to the core