id == "actus_page_actus-xfields" ) {
if ( ! isset( $_SESSION[ 'axf_post_types' ] ) )
$_SESSION[ 'axf_post_types' ] = get_post_types();
//if ( ! isset( $_SESSION[ 'axf_page_templates' ] ) )
$_SESSION[ 'axf_page_templates' ] = get_page_templates();
//$_SESSION[ 'axf_post_templates' ] = wp_get_theme()->get_post_templates();
$_SESSION[ 'axf_post_templates' ] = get_page_templates(null,'post');
//if ( ! isset( $_SESSION[ 'axf_post_categories' ] ) )
$_SESSION[ 'axf_admin_pages' ] = $menu;
$_SESSION[ 'axf_admin_subpages' ] = $submenu;
$_SESSION[ 'axf_post_categories' ] = get_categories();
//if ( ! isset( $_SESSION[ 'axf_post_tags' ] ) )
$_SESSION[ 'axf_post_tags' ] = get_tags(array(
'hide_empty' => false
));
$axf_options['wp_data'] = array(
'post_types' => $_SESSION[ 'axf_post_types' ],
'post_categories' => $_SESSION[ 'axf_post_categories' ],
'post_tags' => $_SESSION[ 'axf_post_tags' ],
'page_templates' => $_SESSION[ 'axf_page_templates' ],
'post_templates' => $_SESSION[ 'axf_post_templates' ],
'admin_pages' => $_SESSION[ 'axf_admin_pages' ],
'admin_subpages' => $_SESSION[ 'axf_admin_subpages' ],
);
}
wp_enqueue_style(
'actus-admin-styles',
ACTUS_XF_URL . 'css/actus-admin.css',
false, '1.0.1', 'all' );
wp_enqueue_style(
'actus-xf-admin-styles',
ACTUS_XF_URL . 'css/actus-xf-admin.css',
false, time(), 'all' );
wp_enqueue_script(
'actus_xf_admin_script',
ACTUS_XF_URL . 'js/actus-xf-admin.js',
array('jquery'), time(), true);
wp_enqueue_script(
'actus_xf_admin_events',
ACTUS_XF_URL . 'js/actus-xf-admin-events.js',
array('jquery', 'actus_xf_admin_script' ), time(), true);
$actus_nonce = wp_create_nonce( 'actus_nonce' );
$actus_xf_params_admin = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => $actus_nonce,
'plugin_dir' => ACTUS_XF_DIR,
'plugin_url' => ACTUS_XF_URL,
'options' => $axf_options,
);
wp_localize_script(
'actus_xf_admin_script',
'actusXFparams', $actus_xf_params_admin );
wp_localize_script(
'actus_xf_admin_events',
'actusXFparams', $actus_xf_params_admin );
}
/*
* Adds ACTUS menu on admin panel
*/
if ( !function_exists( 'actus_menu' ) ) {
function actus_menu(){
add_menu_page(
'ACTUS Plugins',
'ACTUS',
'manage_options',
'actus-plugins',
'actus_plugins_page',
ACTUS_XF_URL . 'img/actus_white_20.png',
66
);
}
if ( is_admin() ) {
add_action( 'admin_menu', 'actus_menu' );
}
}
/*
* Adds submenu on ACTUS menu
*/
if ( !function_exists( 'actus_xf_submenu' ) ) {
function actus_xf_submenu() {
add_submenu_page(
'actus-plugins',
'ACTUS Xfields Options',
'ACTUS Xfields',
'manage_options',
'actus-xfields',
'actus_xfields_admin_page'
);
}
if ( is_admin() ) {
add_action( 'admin_menu', 'actus_xf_submenu' );
}
}
/*
* Adds OPTIONS page
*/
if ( !function_exists( 'global_options_menu' ) ) {
function global_options_menu(){
add_menu_page(
'actus-global',
get_bloginfo('name'),
'manage_options',
'actus-global-options',
'actus_global_options_page',
get_site_icon_url(32),
//ACTUS_XF_URL . 'img/actus_white_20.png',
1
);
}
if ( is_admin() ) {
add_action( 'admin_menu', 'global_options_menu' );
}
}
/*
* Global Options Page content
*
*/
function actus_global_options_page(){
?>
FIELDSETS
0 )
foreach( $axf_options[ 'fieldsets' ] as $fieldset ) {
$where_str = 'where';
$targetsH = "
";
if ( isset( $fieldset['targets'] ) )
if ( sizeof( $fieldset['targets'] ) > 0 )
foreach( $fieldset['targets'] as $target ) {
$criteriaValue = '';
$targetValue = '';
if ( isset($target['criteria']) )
$criteriaValue = $target['criteria'];
if ( isset($target['criteria_title']) )
$criteriaValue = $target['criteria_title'];
$conditionValue = $target['condition'];
if ( isset($target['condition_title']) )
$conditionValue = $target['condition_title'];
if ( isset($target['value']) )
$targetValue = $target['value'];
if ( isset($target['value_title']) )
$targetValue = $target['value_title'];
$condition = "equals to";
if ( $target['condition'] == '>' )
$condition = "is larger than";
if ( ! isset($target['type']) || $target['type'] == '' ){
$target['type'] = 'post';
}
if ( $target['type'] == 'admin screen' ) {
$where_str = '';
$condition = "of";
$type_str = $target['type'];
} else {
$type_str = $target['type']."s";
}
$targetsH .= "- on ".$type_str." ".$where_str." ".$criteriaValue." ".$condition." ".$targetValue.".
";
}
$targetsH .= "
";
?>
ADD FIELDSET
Hide title
Hide permalink
Hide slug
Hide content editor
Hide excerpt
Hide comments
Hide author
Hide revisions
Hide page attributes
Hide post formats
Hide categories
Hide tags
Hide featured image
Hide custom fields
0 )
$actusXfieldsValuesStr = get_post_meta( $_POST['post_id'], 'actus_xfields', true );
else
$actusXfieldsValuesStr = get_option( 'AXF_globals' );
$actusXfieldsValues = json_decode( stripslashes($actusXfieldsValuesStr) );
} else $actusXfieldsValues = array();
$fieldsets = array();
$multi = array();
foreach( $fieldset_ids as $fieldset_id ) {
$fieldsets[ $fieldset_id ] = json_decode( get_option( $fieldset_id ) );
foreach( $fieldsets[ $fieldset_id ] as $key => $field ) {
$field->value = $actusXfieldsValues->{$field->name};
if ( $field->type == 'multiX' ) {
$field->value = $actusXfieldsValues->{$key};
}
if ( substr($field->parent_group,0,5) == 'multi' ) {
$key = $fieldsets[ $fieldset_id ]->{$field->parent_group}->name;
$field->value = $actusXfieldsValues->{$key}->{$field->name};
}
};
};
echo json_encode( $fieldsets );
wp_die();
}
// AJAX delete fieldset
add_action( 'wp_ajax_axf_delete_fieldset', 'axf_delete_fieldset_ajax_handler' );
function axf_delete_fieldset_ajax_handler() {
check_ajax_referer( 'actus_nonce' );
$fieldnames = explode(',', get_option( 'AXF_fieldnames' ) );
$fieldset = json_decode( get_option( sanitize_text_field($_POST['fieldset_id']) ) );
foreach( $fieldset as $key => $field ) {
$fieldnames = array_diff($fieldnames, array($field->name));
};
$fieldsets = sanitize_text_field(json_encode( $_POST['fieldsets'], JSON_UNESCAPED_UNICODE ));
unset( $_SESSION['AXF_fieldsets'] );
update_option( 'AXF_updated', date('Y-m-d h:i:s', time()) );
update_option( 'AXF_fieldsets', $fieldsets );
update_option( 'AXF_fieldnames', implode(',',$fieldnames) );
delete_option( sanitize_text_field($_POST['fieldset_id']) );
print_r( sanitize_text_field($_POST['fieldset_id']) . 'deleted!' );
wp_die();
}
// AJAX dynamic search
add_action( 'wp_ajax_axf_dynamic_search', 'axf_dynamic_search_ajax_handler' );
function axf_dynamic_search_ajax_handler() {
global $post, $wp_query;
check_ajax_referer( 'actus_nonce' );
$value = sanitize_text_field($_POST['value']);
$type = sanitize_text_field($_POST['type']);
$criteria = sanitize_text_field($_POST['criteria']);
$post_types = array();
$axf_post_types = get_post_types();
foreach ( $axf_post_types as $key => $post_type ) {
$post_types[] = $key;
}
$args = array();
$args['post_type'] = $post_types;
if ( $type != 'any item' ) $args['post_type'] = $type;
//$query = new WP_Query( array( 'post_title' => $value );
if ( $criteria == 'id' ) {
$args['p'] = $value;
$search_query = new WP_Query( $args );
} else {
$args['s'] = $value;
$search_query = new WP_Query( $args );
}
echo json_encode( $search_query, JSON_UNESCAPED_UNICODE );
wp_die();
}
// AJAX read page types
add_action( 'wp_ajax_axf_page_types', 'axf_page_types_ajax_handler' );
function axf_page_types_ajax_handler() {
global $submenu, $menu, $pagenow;
check_ajax_referer( 'actus_nonce' );
$axf_page_types = array();
if ( current_user_can('manage_options') ) { // ONLY DO THIS FOR ADMIN
$axf_page_types['menu'] = $menu;
$axf_page_types['submenu'] = $submenu;
}
echo json_encode( $axf_page_types, JSON_UNESCAPED_UNICODE );
wp_die();
}
?>