ajax - PHP Warning: Missing argument 2

From ajax Im updating a custom user field and visualising proper content using a shortcode.localising jqueryfunction loc

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
  • What happens if you change your function to select_age( $atts, $content = '' ) ? – Howdy_McGee Commented Oct 27, 2015 at 21:58
  • What happens if you change your function to select_age( $atts, $content = '' ) ? – Howdy_McGee Oct 27 at 21:58 – Oniromancer Commented Nov 7, 2015 at 2:19
Add a comment  | 

1 Answer 1

Reset to default 1

You 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

相关推荐

  • ajax - PHP Warning: Missing argument 2

    From ajax Im updating a custom user field and visualising proper content using a shortcode.localising jqueryfunction loc

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信