From ajax Im updating a custom user field and visualising proper content using a shortcode.
localising jquery
function localise_jquery1410() {
wp_enqueue_script('jquery');
wp_enqueue_script( 'control-panel', LI_BASE_URL . 'js/control-panel.js' , array('jquery'),'1.0' , true);
wp_localize_script( 'control-panel', 'ajax_var', array(
'ajaxurl' => admin_url( 'admin-ajax.php'),
)
);
}
add_action( 'wp_enqueue_scripts', 'localise_jquery1410' );
updating custom user's field
function user_setting_age(){
if ( isset( $_POST["age_var"] ) ) {
$update_uf = $_POST['age_var'];
update_user_meta(get_current_user_id(), 'cp-age', $update_uf);
die();
}
}
add_action( 'wp_ajax_age', 'user_setting_age' );
returning proper content
function select_age ($atts,$content) {
// as correctly answered by @Howdy_McGee this should be $content=''
$age = $atts["age"];
$user_id = get_current_user_id();
$cuf = get_user_meta($user_id, 'cp-age', true);
if($cuf==$age) {
return $content;
}
else {
return null;
}
}
//[set age="young"]Younger Content[/set] || [set age="old"]Elder Content[/set], etc...
add_shortcode( 'set', 'select_age' );
add_action('wpcf_after_init', 'select_age');
control-panel.js
jQuery(document).ready( function ($j) {
$j('#age').on( "click", function() {
var data = {
action: 'age',
age_var: 'young'
};
$j.post(ajax_var.ajaxurl, data, function(response) {
location.reload();
});
return false;
});
});
and Im getting this
PHP Warning: Missing argument 2 for select_age()
thank you for reading.
From ajax Im updating a custom user field and visualising proper content using a shortcode.
localising jquery
function localise_jquery1410() {
wp_enqueue_script('jquery');
wp_enqueue_script( 'control-panel', LI_BASE_URL . 'js/control-panel.js' , array('jquery'),'1.0' , true);
wp_localize_script( 'control-panel', 'ajax_var', array(
'ajaxurl' => admin_url( 'admin-ajax.php'),
)
);
}
add_action( 'wp_enqueue_scripts', 'localise_jquery1410' );
updating custom user's field
function user_setting_age(){
if ( isset( $_POST["age_var"] ) ) {
$update_uf = $_POST['age_var'];
update_user_meta(get_current_user_id(), 'cp-age', $update_uf);
die();
}
}
add_action( 'wp_ajax_age', 'user_setting_age' );
returning proper content
function select_age ($atts,$content) {
// as correctly answered by @Howdy_McGee this should be $content=''
$age = $atts["age"];
$user_id = get_current_user_id();
$cuf = get_user_meta($user_id, 'cp-age', true);
if($cuf==$age) {
return $content;
}
else {
return null;
}
}
//[set age="young"]Younger Content[/set] || [set age="old"]Elder Content[/set], etc...
add_shortcode( 'set', 'select_age' );
add_action('wpcf_after_init', 'select_age');
control-panel.js
jQuery(document).ready( function ($j) {
$j('#age').on( "click", function() {
var data = {
action: 'age',
age_var: 'young'
};
$j.post(ajax_var.ajaxurl, data, function(response) {
location.reload();
});
return false;
});
});
and Im getting this
PHP Warning: Missing argument 2 for select_age()
thank you for reading.
Share Improve this question edited Oct 27, 2015 at 22:25 Oniromancer asked Oct 27, 2015 at 21:47 OniromancerOniromancer 13 bronze badges 2 |1 Answer
Reset to default 1You are hooking select_age()
to wpcf_after_init
which more than likely does not accept two arguments. I am not sure why you are hooking into that hook but it is not necessary for a shortcode, nor is there any obvious reason in the code.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745411775a4626567.html
select_age( $atts, $content = '' )
? – Howdy_McGee ♦ Commented Oct 27, 2015 at 21:58