私はセクション ソーター プラグインに取り組んでいます。そのため、Redux を使用して、ソーター フィールドのみのシンプルなオプション ページを設定しました。問題は、有効な値をプログラムで設定できないことです。いくつかの方法を試しましたが、何も機能していないようです。
ホームページのすべてのセクション タグの ID を取得するために AJAX を使用しています。次に、セクションの ID をオプション ファイル (Redux オプション ファイル、sample-config.php、または私の場合は sorting-sections-options) の関数に送信します。 .php 、次のように:
これは私の JS/JQ/AJAX コードです:
jQuery(document).ready(function($){
var sections_ids = {action: 'save_sections_ids'};
$.get(window.location.protocol + "//" + window.location.host + "/futbol-americano", function(data) {
var sections_elements = $(data).find("section");
sections_elements.each(function(){
var section_id = $(this).attr("id");
sections_ids[section_id] = section_id;
console.log(section_id);
});
pass_ids_to_server(sections_ids);
});
function pass_ids_to_server(sections_ids){
$.ajax({
url : sorting_sections.ajax_url,
type : 'post',
data : sections_ids,
success : function( response ) {
alert(response);
}
});
}
});
これは、ajax からデータを受け取る関数です。
これは現在の形式ですが、$_POST 変数をループして配列を返して 'enabled' => $array 内に配置するなど、いくつかの方法を試しました。関数の前にデータをユーザーメタに保存することにしました。
add_action( 'wp_ajax_save_sections_ids', 'save_sections_ids_sorting_sections' );
function save_sections_ids_sorting_sections() {
$user_id = get_current_user_id();
update_user_meta($user_id, "set-sections", $_POST);
}
AJAX 呼び出しが機能し、データを受信する関数も機能します。データはデータベースの user_meta テーブルに保存されます。しかし、私がこれを行うとき:
$user_id = get_current_user_id();
$get_sections_array = get_user_meta($user_id, "set-sections", true);
//Returns false but if var_dumped inside the save_sections_ids_sorting_sections() function, it shows the array correctly in an alert box (from succes on ajax call).
$sorter_field = array(
'section_id' => 'basic',
'id' => 'opt-homepage-layout-3',
'type' => 'sorter',
'title' => 'Este es el titulo',
'desc' => 'this is the description',
'compiler' => 'true',
'options' => array(
'disabled' => array(
),
'enabled' => $get_sections_array;
));
Redux::setField($opt_name, $sorter_field );
//The Redux::setField($opt_name, $sorter_field ); works if I define $sorter_field manually before the instance.
オプション ページに次のエラー メッセージが表示されます。
警告: array_merge(): 引数 #2 は C:\xampp\htdocs\futbol-americano\wp-content\plugins\sorting-sections\ReduxFramework\ReduxCore\inc\fields\sorter\field_sorter.php の配列ではありません。 81
警告: 103 行目の C:\xampp\htdocs\futbol-americano\wp-content\plugins\sorting-sections\ReduxFramework\ReduxCore\inc\fields\sorter\field_sorter.php の foreach() に無効な引数が指定されました
誰かがこれを手伝ってくれることを願っています。
前もって感謝します。