SiteHelper
@SiteHelper
WordPress

WordPress TinyMCE + ACF поля?

Здравствуйте!
Есть стандартный tinymce WP редактор, есть ACF PRO. Задача сделать кнопку, чтобы по клику всплывал попап, в попапе поле acf "Объект записи" (Post Object),возвращаемый формат id, после выбора нужных постов сохранялся бы набор id-шек в шоткод и вставлялся в редактор, шоткод вида [objects ids='31,31,54,87,98']. Кнопка готова, попап есть, шоткод сделан. Но никак не получается acf поле вставить в попап. Может кто-нибудь сталкивался?

function custom_button_add() {
	if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
		return;
	}
	if ( 'true' == get_user_option( 'rich_editing' ) ) {
		add_filter( 'mce_external_plugins', 'custom_button_add_script' );
		add_filter( 'mce_buttons', 'c_register_mce_button' );
	}
}
add_action('admin_head', 'custom_button_add');
function custom_button_add_script( $plugin_array ) {
	$plugin_array['c_mce_button'] = get_stylesheet_directory_uri() .'/button.js';
	return $plugin_array;
}
function c_register_mce_button( $buttons ) {
	array_push( $buttons, 'c_mce_button' );
	return $buttons;
}
function get_objects( $object_ids ) {
	$args = array(
	'post_type' => 'objects',
	'post__in'  => explode(',',$objects_ids )
	);
$objects_list = new WP_Query( $args ); ?>

<?php if ( $objects_list->have_posts() ) : while ( $objects_list->have_posts() ) : $objects_list->the_post();
?>
<?php the_title(); ?>
<?php endwhile; else: echo 'Не найдено'; endif; ?>
<?php }

function objects_shortcode( $atts ) {
	ob_start();
	$params = shortcode_atts( array(
	'ids' => '',
	), $atts );
	$objects_ids = $params['ids'];
	return get_objects( $objects_ids );
	return ob_get_clean();
}
add_shortcode ('objects', 'objects_shortcode');


(function() {
	tinymce.PluginManager.add('c_mce_button', function( editor, url ) {
		editor.addButton( 'c_mce_button', {
			text: 'Objects',
			onclick: function() {
								editor.windowManager.open( {
									title: 'Выберите посты',
									body: [										
										{
											type: 'textbox',
											name: 'ids',
											label: 'IDS',
											multiline: true,
											minWidth: 300,
											minHeight: 100
										}
									],
									onsubmit: function( e ) {
										editor.insertContent( '[objects ids="' + e.data.ids + '"]');
									}
								});					
			}
		});
	});
})();
  • Вопрос задан
  • 52 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы