ACTUS_XF_VERSION,
'fieldsets' => $_SESSION['AXF_fieldsets'],
);
$matched_fieldsets = AXF_target_match();
// SCREEN CONTROL
if ( $matched_fieldsets != "" ) {
foreach( $matched_fieldsets as $current ) {
if ( isset( $axf_options['fieldsets'][$current]['options'] ) ) {
foreach( $axf_options['fieldsets'][$current]['options']['hide'] as $hide ) {
if ( $hide == 'permalink' ) {
echo "";
} else if ( $hide == 'slug' ) {
echo "";
} else if ( $hide == 'categories' ) {
echo "";
} else if ( $hide == 'tags' ) {
echo "";
} else {
remove_post_type_support('post', $hide);
remove_post_type_support('page', $hide);
if ( $hide == 'comments' ) {
echo "";
}
}
}
}
}
}
//if ( $axf_options['fieldsets'] )
// remove_post_type_support('page', 'editor');
// DEFINE $AXFields
function AXF_wp_loaded(){
global $post, $AXFields;
$AXFieldsLoaded = json_decode( stripslashes(get_post_meta( $post->ID, 'actus_xfields', true )), true );
$AXGlobalsLoaded = json_decode( stripslashes( get_option( 'AXF_globals' ) ), true );
$AXFields = array();
$AXGlobals = array();
// string values
if ( $AXGlobalsLoaded )
$AXGlobals = $AXGlobalsLoaded;
if ( $AXFieldsLoaded )
foreach ($AXFieldsLoaded as $key => $field) {
$AXFields[ $key ] = $field;
}
}
add_action( 'wp', 'AXF_wp_loaded' );
function create_AXF_metabox() {
global $post, $matched_fieldsets;
$actus_black = ACTUS_XF_URL . 'img/actus_black_20.png';
$metabox_title = "";
$metabox_title .= esc_html__( 'ACTUS extra fields', 'actus-xfields' );
// Can only be used on a single post type (ie. page or post or a custom post type).
// Must be repeated for each post type you want the metabox to appear on.
add_meta_box(
'actus_fields', // Metabox ID
$metabox_title, // Title to display
'AXF_render_metabox', // Function to call that contains the metabox content
'page', // Post type to display metabox on
'normal', // Where to put it (normal = main colum, side = sidebar, etc.)
'default' // Priority relative to other metaboxes
);
add_meta_box(
'actus_fields',
'ACTUS extra fields',
'AXF_render_metabox',
'post',
'normal',
'default'
);
$current_user = wp_get_current_user();
if($current_user->roles[0] === 'administrator') {
add_meta_box( 'axf_meta', __( 'Meta Box Title', 'actus-xfields' ), 'prfx_meta_callback', 'dashboard' );
}
}
add_action( 'add_meta_boxes', 'create_AXF_metabox' );
function dbg( $data, $label="" ){
echo '';
}
add_action( 'current_screen', 'AXF_admin_screens' );
function AXF_admin_screens() {
global $post, $axf_options, $admin_matched, $matched_fieldsets, $menu, $submenu, $hook_suffix;
$current_screen = get_current_screen();
if ( $current_screen->id != 'page' && $current_screen->id != 'post' ) {
$matched_fieldsets = array();
foreach( $admin_matched as $key => $fieldset_ids ) {
foreach( $fieldset_ids as $fieldset_id ) {
if( strpos( $key, $current_screen->id ) !== false ||
strpos( $current_screen->id, $key ) !== false ||
$current_screen->id == $key ||
$hook_suffix == $key ) {
$match = $key;
if ( ! in_array($fieldset_id, $matched_fieldsets) )
$matched_fieldsets[] = $fieldset_id;
$hook = $match;
if ( $hook == 'actus-xfields' )
$hook = 'actus_page_actus-xfields';
$hook = 'admin_head';
$hook = 'admin_footer';
$hook = 'admin_head-'.$hook_suffix;
$hook = 'admin_footer-'.$hook_suffix;
add_action($hook, 'AXF_render_metabox_admin');
}
}
}
}
}
function AXF_render_metabox_admin() {
global $post, $axf_options, $admin_matched, $matched_fieldsets, $menu, $submenu;
echo '
"); $value = str_replace($remove, '', $value); $value = str_replace('\"', "\'", $value); } if ( is_array( $_POST[ $xfield['id'] ] ) ) $value = $_POST[ $xfield['id'] ]; $actus_xfields_save[ $xfield['name'] ] = $value; } // MULTI if ( substr($xfield['parent_group'],0,5) === 'multi' && $xfield['type'] != 'multi' ) { $multiName = $fieldset['xfields'][ $xfield['parent_group'] ]['name']; if ( ! isset( $actus_xfields_save[ $multiName ] ) ) $actus_xfields_save[ $multiName ] = array(); if ( $xfield['type'] == 'textarea' || $xfield['type'] == 'texteditor' ) { $count = intval( $_POST[ $xfield['parent_group'] ] ); $value = array(); $value[0] = ""; for ( $n=1;$n<=$count;$n++) { $value[$n] = wp_filter_post_kses( wp_unslash( $_POST[ $xfield['parent_group'].'_'.$xfield['id'] . '_' . $n ] )); $remove = array("\r\n", "\n", "\r", "rn", "rnrn", "
"); $value[$n] = str_replace($remove, '', $value[$n]); } } else { $value = $_POST[ $xfield['parent_group'].'_'.$xfield['id'] ]; foreach( $value as $n => $v ) { $v = wp_filter_post_kses( wp_unslash($v) ); $value[ $n ] = $v; } } $actus_xfields_save[ $multiName ][ $xfield['name'] ] = $value; } //} } } } $actus_xfields_save_str = json_encode( $actus_xfields_save, JSON_UNESCAPED_UNICODE ); update_post_meta( $post->ID, 'actus_xfields', $actus_xfields_save_str ); //update_post_meta( $post->ID, 'actus_xfields_post', json_encode($_POST) ); } add_action( 'save_post', 'actus_extra_fields_save', 1, 2 );