本文整理汇总了PHP中wpcf_pr_admin_get_has函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_pr_admin_get_has函数的具体用法?PHP wpcf_pr_admin_get_has怎么用?PHP wpcf_pr_admin_get_has使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_pr_admin_get_has函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_pr_admin_post_init_action
/**
* Init function.
*
* Enqueues styles and scripts on post edit page.
*
* @param type $post_type
* @param type $post
* @param type $groups
* @param type $wpcf_active
*/
function wpcf_pr_admin_post_init_action($post_type, $post, $groups, $wpcf_active)
{
// See if any data
$has = wpcf_pr_admin_get_has($post_type);
$belongs = wpcf_pr_admin_get_belongs($post_type);
/*
*
* Enqueue styles and scripts
*/
if (!empty($has) || !empty($belongs)) {
add_action('admin_head', 'wpcf_pr_add_field_js');
$output = wpcf_pr_admin_post_meta_box_output($post, array('post_type' => $post_type, 'has' => $has, 'belongs' => $belongs));
add_meta_box('wpcf-post-relationship', __('Fields table', 'wpcf'), 'wpcf_pr_admin_post_meta_box', $post_type, 'normal', 'default', array('output' => $output));
if (!empty($output)) {
wp_enqueue_script('wpcf-post-relationship', WPCF_EMBEDDED_RELPATH . '/resources/js/post-relationship.js', array('jquery'), WPCF_VERSION);
wp_enqueue_style('wpcf-post-relationship', WPCF_EMBEDDED_RELPATH . '/resources/css/post-relationship.css', array(), WPCF_VERSION);
if (!$wpcf_active) {
wpcf_enqueue_scripts();
wp_enqueue_style('wpcf-pr-post', WPCF_EMBEDDED_RES_RELPATH . '/css/fields-post.css', array(), WPCF_VERSION);
wp_enqueue_script('wpcf-form-validation', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/jquery.validate.min.js', array('jquery'), WPCF_VERSION);
wp_enqueue_script('wpcf-form-validation-additional', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/additional-methods.min.js', array('jquery'), WPCF_VERSION);
}
wpcf_admin_add_js_settings('wpcf_pr_del_warning', '\'' . __('Are you sure about deleting this post?', 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_pagination_warning', '\'' . __('If you continue without saving your changes, it might get lost.', 'wpcf') . '\'');
}
}
}
示例2: wpcf_relationship_is_parent
/**
* Checks if post type is parent
* @param type $parent_post_type
* @param type $child_post_type
* @return type
*/
function wpcf_relationship_is_parent($parent_post_type, $child_post_type)
{
$has = wpcf_pr_admin_get_has($parent_post_type);
return isset($has[$child_post_type]);
}
示例3: wpcf_pr_get_has
/**
* Gets all post types and data that owns.
*
* @param type $post_type
* @return type
*/
function wpcf_pr_get_has($post_type)
{
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
return wpcf_pr_admin_get_has($post_type);
}
示例4: wpcf_admin_metabox_relationship
function wpcf_admin_metabox_relationship($post_type)
{
$form = array();
$form['table-pr-open'] = wpcf_admin_metabox_begin(__('Post Relationship', 'wpcf'), 'relationship', 'wpcf-types-form-pr-table', false);
/**
* belongs/children section
*/
$has = wpcf_pr_admin_get_has($post_type['slug']);
$belongs = wpcf_pr_admin_get_belongs($post_type['slug']);
$post_types = get_post_types('', 'objects');
if (empty($has) || empty($post_type['slug'])) {
$txt_has = __("Children: None", 'wpcf');
} else {
$txt_has = array();
foreach ($has as $pr_key => $pr_data) {
$txt_has[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key;
}
$txt_has = sprintf(__("Children: %s", 'wpcf'), implode(', ', $txt_has));
}
if (!empty($belongs)) {
$txt_belongs = array();
foreach ($belongs as $pr_key => $pr_data) {
$txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key;
}
$txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs));
} else {
$txt_belongs = __("Parent: None", 'wpcf');
}
// Others belonging to
if (!empty($belongs)) {
$txt_belongs = array();
foreach ($belongs as $pr_key => $pr_data) {
$txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key;
}
$txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs));
} else {
$txt_belongs = __("Parent: None", 'wpcf');
}
$form['table-pr-belongs'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 10px 0;"><span class="wpcf-pr-belongs-summary">' . $txt_belongs . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-belongs-edit" class="button-secondary wpcf-pr-edit">' . __('Edit', 'wpcf') . '</a>');
$options = array();
/**
* build excluded post types
*/
global $wpcf;
$excluded_post_types = $wpcf->excluded_post_types;
$excluded_post_types[] = $post_type['slug'];
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) {
continue;
}
// Check if it's in has
if (isset($has[$temp_post_type_slug])) {
continue;
}
$options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][belongs][' . $temp_post_type_slug . ']';
$options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name;
$options[$temp_post_type_slug]['#default_value'] = isset($belongs[$temp_post_type_slug]);
$options[$temp_post_type_slug]['#inline'] = true;
$options[$temp_post_type_slug]['#after'] = ' ';
if (is_rtl()) {
$options[$temp_post_type_slug]['#before'] = '<div style="float:right;margin-left:10px;">';
$options[$temp_post_type_slug]['#after'] .= '</div>';
}
}
$form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-belongs-apply">' . __('Apply', 'wpcf') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-belongs-cancel">' . __('Cancel', 'wpcf') . '</a></div></div>', '#inline' => true);
$form['table-pr-has'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 5px 0;"><span class="wpcf-pr-has-summary">' . $txt_has . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-has-edit" class="button-secondary wpcf-pr-edit">' . __('Edit', 'wpcf') . '</a>');
$options = array();
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) {
continue;
}
// Check if it already belongs
if (isset($belongs[$temp_post_type_slug])) {
continue;
}
$options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][has][' . $temp_post_type_slug . ']';
$options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name;
$options[$temp_post_type_slug]['#default_value'] = isset($has[$temp_post_type_slug]);
$options[$temp_post_type_slug]['#inline'] = true;
$options[$temp_post_type_slug]['#after'] = isset($has[$temp_post_type_slug]) ? '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pt_edit_fields&child=' . $temp_post_type_slug . '&parent=' . $post_type['slug'] . '&_wpnonce=' . wp_create_nonce('pt_edit_fields') . '&KeepThis=true&TB_iframe=true') . '" class="thickbox" title="' . __('Select child fields to be displayed', 'wpcf') . '">(' . __('Edit fields', 'wpcf') . ')</a> ' : '' . '<a href="javascript:void(0);" style="color:Gray;" title="' . __('Please save the page first, before you can edit the child items', 'wpcf') . '">(' . __('Edit fields', 'wpcf') . ')</a> ';
if (is_rtl()) {
$options[$temp_post_type_slug]['#before'] = '<div style="float:right;margin-left:10px;">';
$options[$temp_post_type_slug]['#after'] .= '</div>';
}
}
$form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-has-apply">' . __('Apply', 'wpcf') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-has-cancel">' . __('Cancel', 'wpcf') . '</a></div></div>', '#inline' => true);
$form['table-pr-explanation'] = array('#type' => 'markup', '#markup' => '<p>' . __("You can choose which fields will show when editing parent pages.", 'wpcf') . '<br />' . __("Click on the 'edit' button to select them for each parent.", 'wpcf') . '<br />' . sprintf(__('Learn about %sPost Type Relationships%s', 'wpcf'), '<a href="http://wp-types.com/documentation/user-guides/creating-post-type-relationships/" target="_blank">', ' »</a>') . '</p>');
/**
* close form
*/
$form['table-pr-close'] = wpcf_admin_metabox_end();
/**
* additional settings
*/
wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt', '\'' . __("Children: None", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_has_txt', '\'' . __("Children: %s", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt', '\'' . __("Parent: None", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_belongs_txt', '\'' . __("Parent: %s", 'wpcf') . '\'');
return $form;
}
示例5: wpcf_pr_post_type_form_filter
/**
* Adds Post relationship table to form.
*
* @param type $form
* @param type $post_type
* @return string
*/
function wpcf_pr_post_type_form_filter($form, $post_type)
{
$has = wpcf_pr_admin_get_has($post_type['slug']);
$belongs = wpcf_pr_admin_get_belongs($post_type['slug']);
$post_types = get_post_types('', 'objects');
if (empty($has) || empty($post_type['slug'])) {
$txt_has = __("Children: None", 'wpcf');
// $txt_has = __("None post type belongs to this post type", 'wpcf');
} else {
$txt_has = array();
foreach ($has as $pr_key => $pr_data) {
$txt_has[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key;
}
$txt_has = sprintf(__("Children: %s", 'wpcf'), implode(', ', $txt_has));
// if (count($txt_has) < 2) {
// $txt_has = sprintf(__("%s belong to this post type", 'wpcf'),
// implode(', ', $txt_has));
// } else {
// $txt_has = sprintf(__("%s belongs to this post type", 'wpcf'),
// implode(', ', $txt_has));
// }
}
wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt', '\'' . __("Children: None", 'wpcf') . '\'');
// wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt',
// '\'' . __("None post type belongs to this post type", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_has_txt', '\'' . __("Children: %s", 'wpcf') . '\'');
// wpcf_admin_add_js_settings('wpcf_pr_has_txt',
// '\'' . __("%s belong to this post type", 'wpcf') . '\'');
// Others belonging to
if (!empty($belongs)) {
$txt_belongs = array();
foreach ($belongs as $pr_key => $pr_data) {
$txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key;
}
$txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs));
// if (count($txt_belongs) > 1) {
// $txt_belongs = sprintf(__("This post type belongs to %s", 'wpcf'),
// implode(', ', $txt_belongs));
// } else {
// $txt_belongs = sprintf(__("This post type belongs to %s", 'wpcf'),
// $txt_belongs[0]);
// }
} else {
// $txt_belongs = __("This post type belongs to none", 'wpcf');
$txt_belongs = __("Parent: None", 'wpcf');
}
// wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt',
// '\'' . __("This post type belongs to none", 'wpcf') . '\'');
// wpcf_admin_add_js_settings('wpcf_pr_belongs_txt',
// '\'' . __("This post type belongs to %s", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt', '\'' . __("Parent: None", 'wpcf') . '\'');
wpcf_admin_add_js_settings('wpcf_pr_belongs_txt', '\'' . __("Parent: %s", 'wpcf') . '\'');
$form['table-pr-open'] = array('#type' => 'markup', '#markup' => '<table id="wpcf-types-form-pr-table" class="wpcf-types-form-table widefat"><thead><tr><th>' . __('Post Relationship', 'wpcf') . '</th></tr></thead><tbody><tr><td>');
$form['table-pr-belongs'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 10px 0;"><span class="wpcf-pr-belongs-summary">' . $txt_belongs . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-belongs-edit" class="button-secondary wpcf-pr-edit">' . __('Edit') . '</a>');
$options = array();
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, array($post_type['slug'], 'revision', 'view', 'view-template', 'nav_menu_item', 'attachment', 'mediapage')) || !$temp_post_type->show_ui) {
continue;
}
// Check if it's in has
if (isset($has[$temp_post_type_slug])) {
continue;
}
$options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][belongs][' . $temp_post_type_slug . ']';
$options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name;
$options[$temp_post_type_slug]['#default_value'] = isset($belongs[$temp_post_type_slug]);
$options[$temp_post_type_slug]['#inline'] = true;
$options[$temp_post_type_slug]['#after'] = ' ';
}
$form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-belongs-apply">' . __('Apply') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-belongs-cancel">' . __('Cancel') . '</a></div></div>', '#inline' => true);
$form['table-pr-has'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 5px 0;"><span class="wpcf-pr-has-summary">' . $txt_has . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-has-edit" class="button-secondary wpcf-pr-edit">' . __('Edit') . '</a>');
$options = array();
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, array($post_type['slug'], 'revision', 'view', 'view-template', 'nav_menu_item', 'attachment', 'mediapage')) || !$temp_post_type->show_ui) {
continue;
}
// Check if it already belongs
if (isset($belongs[$temp_post_type_slug])) {
continue;
}
$options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][has][' . $temp_post_type_slug . ']';
$options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name;
$options[$temp_post_type_slug]['#default_value'] = isset($has[$temp_post_type_slug]);
$options[$temp_post_type_slug]['#inline'] = true;
$options[$temp_post_type_slug]['#after'] = isset($has[$temp_post_type_slug]) ? '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pt_edit_fields&child=' . $temp_post_type_slug . '&parent=' . $post_type['slug'] . '&_wpnonce=' . wp_create_nonce('pt_edit_fields') . '&KeepThis=true&TB_iframe=true') . '" class="thickbox">(' . __('Edit fields') . ')</a> ' : '' . '<a href="javascript:void(0);" style="color:Gray;" title="' . __('Please save the page first, before you can edit the child items', 'wpcf') . '">(' . __('Edit fields') . ')</a> ';
}
$form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-has-apply">' . __('Apply') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-has-cancel">' . __('Cancel') . '</a></div></div>', '#inline' => true);
$form['table-pr-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table>');
$form['table-pr-explanation'] = array('#type' => 'markup', '#markup' => '<div>' . __("You can choose which fields will show when editing parent pages.", 'wpcf') . '<br />' . __("Click on the 'edit' button to select them for each parent.", 'wpcf') . '<br />' . sprintf(__('Learn about %sPost Type Relationships%s', 'wpcf'), '<a href="http://wp-types.com/documentation/user-guides/creating-post-type-relationships/" target="_blank">', '</a>') . '</div>');
return $form;
}
示例6: wpcf_ajax_embedded
/**
* All AJAX calls go here.
*/
function wpcf_ajax_embedded()
{
if (!current_user_can('manage_options') || (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action']))) {
die('Verification failed');
}
switch ($_REQUEST['wpcf_action']) {
case 'editor_insert_date':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/date.php';
wpcf_fields_date_editor_form();
break;
case 'insert_skype_button':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php';
wpcf_fields_skype_meta_box_ajax();
break;
case 'editor_callback':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
$field = wpcf_admin_fields_get_field($_GET['field_id']);
if (!empty($field)) {
// TODO Remove
// $file = WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $field['type'] . '.php';
// if (file_exists($file)) {
// require_once $file;
$function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
if (function_exists($function)) {
call_user_func($function);
}
// }
}
break;
case 'dismiss_message':
if (isset($_GET['id'])) {
$messages = get_option('wpcf_dismissed_messages', array());
$messages[] = $_GET['id'];
update_option('wpcf_dismissed_messages', $messages);
}
break;
case 'pr_add_child_post':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) {
$relationships = get_option('wpcf_post_relationship', array());
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type_child'];
$parent_post_type = $_GET['post_type_parent'];
$data = $relationships[$parent_post_type][$post_type];
$output = wpcf_pr_admin_post_meta_box_has_row($post, $post_type, $data, $parent_post_type, false);
}
echo json_encode(array('output' => $output));
break;
case 'pr_save_child_post':
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = array();
if (isset($_GET['post_id']) && isset($_GET['post_type_child'])) {
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type_child'];
// $output = wpcf_pr_admin_save_child_item($post, $post_type,
// $_POST);
$output = wpcf_pr_admin_save_post_hook($_GET['post_id']);
}
echo json_encode(array('output' => $output));
break;
case 'pr_delete_child_post':
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id'])) {
$output = wpcf_pr_admin_delete_child_item($_GET['post_id']);
}
echo json_encode(array('output' => $output));
break;
case 'pr-update-belongs':
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_POST['post_id']) && isset($_POST['wpcf_pr_belongs'])) {
$output = wpcf_pr_admin_update_belongs($_POST['post_id'], $_POST['wpcf_pr_belongs']);
}
echo json_encode(array('output' => $output));
break;
case 'pr_pagination':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id']) && isset($_GET['post_type'])) {
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type'];
$has = wpcf_pr_admin_get_has($post->post_type);
$output = wpcf_pr_admin_post_meta_box_has_form($post, $post_type, $has[$post_type], $post->post_type);
}
echo json_encode(array('output' => $output));
break;
case 'pr_sort':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
//.........这里部分代码省略.........
示例7: wpcf_ajax_embedded
/**
* All AJAX calls go here.
*/
function wpcf_ajax_embedded()
{
if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action'])) {
die('Verification failed');
}
switch ($_REQUEST['wpcf_action']) {
case 'editor_insert_date':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/date.php';
wpcf_fields_date_editor_form();
break;
case 'insert_skype_button':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php';
wpcf_fields_skype_meta_box_ajax();
break;
case 'editor_callback':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
$field = wpcf_admin_fields_get_field($_GET['field_id']);
if (!empty($field)) {
$function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
if (function_exists($function)) {
call_user_func($function);
}
}
break;
case 'dismiss_message':
if (isset($_GET['id'])) {
$messages = get_option('wpcf_dismissed_messages', array());
$messages[] = $_GET['id'];
update_option('wpcf_dismissed_messages', $messages);
}
break;
case 'pr_add_child_post':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) {
$relationships = get_option('wpcf_post_relationship', array());
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type_child'];
$parent_post_type = $_GET['post_type_parent'];
$data = $relationships[$parent_post_type][$post_type];
$output = wpcf_pr_admin_post_meta_box_has_row($post, $post_type, $data, $parent_post_type, false);
}
echo json_encode(array('output' => $output));
break;
case 'pr_save_child_post':
ob_start();
// Try to catch any errors
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = array();
if (isset($_GET['post_id']) && isset($_GET['post_type_child'])) {
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type_child'];
$output = wpcf_pr_admin_save_post_hook($_GET['post_id']);
}
$errors = ob_get_clean();
echo json_encode(array('output' => $output, 'errors' => $errors));
break;
case 'pr_delete_child_post':
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id'])) {
$output = wpcf_pr_admin_delete_child_item($_GET['post_id']);
}
echo json_encode(array('output' => $output));
break;
case 'pr-update-belongs':
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_POST['post_id']) && isset($_POST['wpcf_pr_belongs'])) {
$output = wpcf_pr_admin_update_belongs($_POST['post_id'], $_POST['wpcf_pr_belongs']);
}
echo json_encode(array('output' => $output));
break;
case 'pr_pagination':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['post_id']) && isset($_GET['post_type'])) {
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type'];
$has = wpcf_pr_admin_get_has($post->post_type);
$output = wpcf_pr_admin_post_meta_box_has_form($post, $post_type, $has[$post_type], $post->post_type);
}
echo json_encode(array('output' => $output));
break;
case 'pr_sort':
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php';
$output = 'Passed wrong parameters';
if (isset($_GET['field']) && isset($_GET['sort']) && isset($_GET['post_id']) && isset($_GET['post_type'])) {
$post = get_post($_GET['post_id']);
$post_type = $_GET['post_type'];
$has = wpcf_pr_admin_get_has($post->post_type);
//.........这里部分代码省略.........
示例8: wpcf_admin_metabox_relationship
function wpcf_admin_metabox_relationship($post_type)
{
$form = array();
$form['description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', sprintf('%s <a href="%s" target="_blank">%s</a>.', __('Parent/child relationship lets you connect between posts of different types. When you edit a parent, you will see its children listed in a table and you can edit the fields of the children. When you edit a child, you can choose the parents. On the front-end, you can display a list of children or information about the parents.', 'wpcf'), Types_Helper_Url::get_url('post-relationship', true, 'parent_child_relationship', Types_Helper_Url::UTM_MEDIUM_POSTEDIT), __('Parent/child documentation', 'wpcf'))));
$custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
$is_error = false;
$error_message = '';
// Detect situations when we cannot configure post relationships yet. Render a message and finish.
$is_unsaved_post_type = !isset($_REQUEST['wpcf-post-type']) || !isset($custom_types[$_REQUEST['wpcf-post-type']]);
if ($is_unsaved_post_type) {
$is_error = true;
$error_message = __('Please save first, before you can edit the relationship.', 'wpcf');
}
$is_attachment = isset($_REQUEST['wpcf-post-type']) && 'attachment' == $_REQUEST['wpcf-post-type'];
if ($is_attachment) {
$is_error = true;
$error_message = __('Post relationships are not allowed for the Media post type.', 'wpcf');
}
if ($is_error) {
$form['alert'] = array('#type' => 'notice', '#markup' => $error_message);
$form = wpcf_form(__FUNCTION__, $form);
echo $form->renderForm();
return;
}
$post_type = $custom_types[$_REQUEST['wpcf-post-type']];
unset($custom_types);
// No problems detected, go ahead and render the options.
// belongs/children section
$has = wpcf_pr_admin_get_has($post_type['slug']);
$belongs = wpcf_pr_admin_get_belongs($post_type['slug']);
$post_types = get_post_types('', 'objects');
// parents
$form['parent-h3'] = array('#type' => 'markup', '#markup' => sprintf('<h3>%s</h3>', __('Parent Post Types:', 'wpcf')));
$form['parent-description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Select which post types will be parents of this type.', 'wpcf')));
$options = array();
// Build excluded post types
global $wpcf;
$excluded_post_types = $wpcf->excluded_post_types;
$excluded_post_types[] = $post_type['slug'];
// Explicitly exclude attachments for post relationships because there is no GUI for it
// (but we're not excluding them from all Types functionality)
$excluded_post_types[] = 'attachment';
foreach ($post_types as $post_type_option_slug => $post_type_option) {
$is_excluded = in_array($post_type_option_slug, $excluded_post_types);
$has_no_ui = !$post_type_option->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true);
if ($is_excluded || $has_no_ui) {
continue;
}
$options[$post_type_option_slug] = array('#name' => 'ct[post_relationship][belongs][' . $post_type_option_slug . ']', '#title' => $post_type_option->labels->singular_name, '#default_value' => isset($belongs[$post_type_option_slug]), '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#attributes' => array('class' => 'js-wpcf-relationship-checkbox', 'data-wpcf-type' => 'belongs', 'data-wpcf-value' => esc_attr($post_type_option_slug), 'data-wpcf-message-disabled' => esc_attr__('This post type is disabled, becouse is used as child post.', 'wpcf')));
if (isset($has[$post_type_option_slug])) {
$options[$post_type_option_slug]['#before'] = '<li class="disabled">';
$options[$post_type_option_slug]['#attributes']['disabled'] = 'disabled';
}
}
$form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#inline' => true, '#before' => '<ul>', '#after' => '</ul>');
// child posts
$form['child-h3'] = array('#type' => 'markup', '#markup' => sprintf('<hr /><h3>%s</h3>', __('Children Post Types:', 'wpcf')));
$form['child-description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Select which post types will be children of this type.', 'wpcf')));
$options = array();
foreach ($post_types as $post_type_option_slug => $post_type_option) {
if (in_array($post_type_option_slug, $excluded_post_types) || !$post_type_option->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) {
continue;
}
$nonce = sprintf('child-post-fields-%s-%s', $post_type['slug'], $post_type_option_slug);
$a = sprintf(' <span>(<a class="js-wpcf-edit-child-post-fields" href="#" data-wpcf-nonce="%s" data-wpcf-child="%s" data-wpcf-parent="%s" data-wpcf-title="%s" data-wpcf-buttons-apply="%s" data-wpcf-buttons-cancel="%s" data-wpcf-message-loading="%s" data-wpcf-save-status="%s">%s</a>)</span>', esc_attr(wp_create_nonce($nonce)), esc_attr($post_type_option_slug), esc_attr($post_type['slug']), esc_attr(sprintf(__('Select child fields from %s to be displayed in Post Relationship table', 'wpcf'), $post_type_option->labels->singular_name)), esc_attr__('Apply', 'wpcf'), esc_attr__('Cancel', 'wpcf'), esc_attr__('Please Wait, Loading…', 'wpcf'), esc_attr(isset($has[$post_type_option_slug]) ? 'saved' : 'new'), esc_attr__('Select fields', 'wpcf'));
$options[$post_type_option_slug] = array('#name' => 'ct[post_relationship][has][' . $post_type_option_slug . ']', '#title' => $post_type_option->labels->singular_name, '#inline' => true, '#before' => '<li>', '#after' => $a . '</li>', '#attributes' => array('class' => 'js-wpcf-relationship-checkbox', 'data-wpcf-type' => 'has', 'data-wpcf-value' => esc_attr($post_type_option_slug), 'data-wpcf-message-disabled' => esc_attr__('This post type is disabled, becouse is used as parent post.', 'wpcf')));
// Check if it already belongs
if (isset($belongs[$post_type_option_slug])) {
$options[$post_type_option_slug]['#before'] = '<li class="disabled">';
$options[$post_type_option_slug]['#attributes']['disabled'] = 'disabled';
} else {
if (isset($has[$post_type_option_slug])) {
$options[$post_type_option_slug]['#default_value'] = true;
$options[$post_type_option_slug]['#before'] = '<li class="active">';
}
}
}
$form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#inline' => true, '#before' => '<ul>', '#after' => '</ul>');
$form = wpcf_form(__FUNCTION__, $form);
echo $form->renderForm();
}
示例9: wpcf_admin_metabox_relationship
function wpcf_admin_metabox_relationship($post_type)
{
$form = array();
$form['description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Parent/child relationship lets you connect between posts of different types. When you edit a parent, you will see its children listed in a table and you can edit the fields of the children. When you edit a child, you can choose the parents. On the front-end, you can display a list of children or information about the parents. <a href="https://wp-types.com/documentation/user-guides/creating-post-type-relationships/?utm_source=typesplugin&utm_medium=postedit&utm_campaign=parent_child_relationship" target="_blank">Parent/child documentation</a>.', 'wpcf')));
$custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
if (!isset($_REQUEST['wpcf-post-type']) || !isset($custom_types[$_REQUEST['wpcf-post-type']])) {
$form['alert'] = array('#type' => 'notice', '#markup' => __('Please save first, before you can edit the relationship.', 'wpcf'));
$form = wpcf_form(__FUNCTION__, $form);
echo $form->renderForm();
return false;
}
$post_type = false;
$post_type = $custom_types[$_REQUEST['wpcf-post-type']];
unset($custom_types);
/**
* belongs/children section
*/
$has = wpcf_pr_admin_get_has($post_type['slug']);
$belongs = wpcf_pr_admin_get_belongs($post_type['slug']);
$post_types = get_post_types('', 'objects');
/**
* parents
*/
$form['parent-h3'] = array('#type' => 'markup', '#markup' => sprintf('<h3>%s</h3>', __('Parent Post Types:', 'wpcf')));
$form['parent-description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Select which post types will be parents of this type.', 'wpcf')));
$options = array();
/**
* build excluded post types
*/
global $wpcf;
$excluded_post_types = $wpcf->excluded_post_types;
$excluded_post_types[] = $post_type['slug'];
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) {
continue;
}
$options[$temp_post_type_slug] = array('#name' => 'ct[post_relationship][belongs][' . $temp_post_type_slug . ']', '#title' => $temp_post_type->labels->singular_name, '#default_value' => isset($belongs[$temp_post_type_slug]), '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#attributes' => array('class' => 'js-wpcf-relationship-checkbox', 'data-wpcf-type' => 'belongs', 'data-wpcf-value' => esc_attr($temp_post_type_slug), 'data-wpcf-message-disabled' => esc_attr__('This post type is disabled, becouse is used as child post.', 'wpcf')));
if (isset($has[$temp_post_type_slug])) {
$options[$temp_post_type_slug]['#before'] = '<li class="disabled">';
$options[$temp_post_type_slug]['#attributes']['disabled'] = 'disabled';
}
}
$form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#inline' => true, '#before' => '<ul>', '#after' => '</ul>');
/**
* child posts
*/
$form['child-h3'] = array('#type' => 'markup', '#markup' => sprintf('<hr /><h3>%s</h3>', __('Children Post Types:', 'wpcf')));
$form['child-description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Select which post types will be children of this type.', 'wpcf')));
$options = array();
foreach ($post_types as $temp_post_type_slug => $temp_post_type) {
if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) {
continue;
}
$nonce = sprintf('child-post-fields-%s-%s', $post_type['slug'], $temp_post_type_slug);
$a = sprintf(' <span>(<a class="js-wpcf-edit-child-post-fields" href="#" data-wpcf-nonce="%s" data-wpcf-child="%s" data-wpcf-parent="%s" data-wpcf-title="%s" data-wpcf-buttons-apply="%s" data-wpcf-buttons-cancel="%s" data-wpcf-message-loading="%s" data-wpcf-save-status="%s">%s</a>)</span>', esc_attr(wp_create_nonce($nonce)), esc_attr($temp_post_type_slug), esc_attr($post_type['slug']), esc_attr(sprintf(__('Select child fields from %s to be displayed in Post Relationship table', 'wpcf'), $temp_post_type->labels->singular_name)), esc_attr__('Apply', 'wpcf'), esc_attr__('Cancel', 'wpcf'), esc_attr__('Please Wait, Loading…', 'wpcf'), esc_attr(isset($has[$temp_post_type_slug]) ? 'saved' : 'new'), esc_attr__('Select fields', 'wpcf'));
$options[$temp_post_type_slug] = array('#name' => 'ct[post_relationship][has][' . $temp_post_type_slug . ']', '#title' => $temp_post_type->labels->singular_name, '#inline' => true, '#before' => '<li>', '#after' => $a . '</li>', '#attributes' => array('class' => 'js-wpcf-relationship-checkbox', 'data-wpcf-type' => 'has', 'data-wpcf-value' => esc_attr($temp_post_type_slug), 'data-wpcf-message-disabled' => esc_attr__('This post type is disabled, becouse is used as parent post.', 'wpcf')));
// Check if it already belongs
if (isset($belongs[$temp_post_type_slug])) {
$options[$temp_post_type_slug]['#before'] = '<li class="disabled">';
$options[$temp_post_type_slug]['#attributes']['disabled'] = 'disabled';
} else {
if (isset($has[$temp_post_type_slug])) {
$options[$temp_post_type_slug]['#default_value'] = true;
$options[$temp_post_type_slug]['#before'] = '<li class="active">';
}
}
}
$form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#inline' => true, '#before' => '<ul>', '#after' => '</ul>');
$form = wpcf_form(__FUNCTION__, $form);
echo $form->renderForm();
}