Skip to main content
added 3 characters in body
Source Link
gmazzap
  • 46.3k
  • 6
  • 95
  • 147

An alternative way is using the load-{$page} hook.

Example:

add_action('load-edit.php', 'my_edit_notice''maybe_edit_notice'); // only on edit.php paged

function maybe_edit_notice() {
  // some example notices based on the get variables
  // the url should be something htt://example.com/wp-admin/edit.php?done=1&error=1
  if ( isset($_GET['done']) ) {
    $message = isset($_GET['error']) ? 'There was an error.' : 'Everithing ok.';
    $class = isset($_GET['error']) ? 'error' : 'updated';
    global $my_notice_args;
    $my_notice_args = compact('message', 'class');
    add_action('admin_notices', 'print_my_notice');
  }
}

function print_my_notice() {
  global $my_notice_args;
  if ( ! empty($my_notice_args) ) {
    printf('<div class="%s"><p>%s</p></div>', $my_args_notice['class'], $my_args_notice['class']$my_args_notice['message']);
  }
}

See 'admin_notices' hook docs on Codex

An alternative way is using the load-{$page} hook.

Example:

add_action('load-edit.php', 'my_edit_notice'); // only on edit.php paged

function maybe_edit_notice() {
  // some example notices based on the get variables
  // the url should be something htt://example.com/wp-admin/edit.php?done=1&error=1
  if ( isset($_GET['done']) ) {
    $message = isset($_GET['error']) ? 'There was an error.' : 'Everithing ok.';
    $class = isset($_GET['error']) ? 'error' : 'updated';
    global $my_notice_args;
    $my_notice_args = compact('message', 'class');
    add_action('admin_notices', 'print_my_notice');
  }
}

function print_my_notice() {
  global $my_notice_args;
  if ( ! empty($my_notice_args) ) {
    printf('<div class="%s"><p>%s</p></div>', $my_args_notice['class'], $my_args_notice['class']);
  }
}

See 'admin_notices' hook docs on Codex

An alternative way is using the load-{$page} hook.

Example:

add_action('load-edit.php', 'maybe_edit_notice'); // only on edit.php paged

function maybe_edit_notice() {
  // some example notices based on the get variables
  // the url should be something htt://example.com/wp-admin/edit.php?done=1&error=1
  if ( isset($_GET['done']) ) {
    $message = isset($_GET['error']) ? 'There was an error.' : 'Everithing ok.';
    $class = isset($_GET['error']) ? 'error' : 'updated';
    global $my_notice_args;
    $my_notice_args = compact('message', 'class');
    add_action('admin_notices', 'print_my_notice');
  }
}

function print_my_notice() {
  global $my_notice_args;
  if ( ! empty($my_notice_args) ) {
    printf('<div class="%s"><p>%s</p></div>', $my_args_notice['class'], $my_args_notice['message']);
  }
}

See 'admin_notices' hook docs on Codex

Source Link
gmazzap
  • 46.3k
  • 6
  • 95
  • 147

An alternative way is using the load-{$page} hook.

Example:

add_action('load-edit.php', 'my_edit_notice'); // only on edit.php paged

function maybe_edit_notice() {
  // some example notices based on the get variables
  // the url should be something htt://example.com/wp-admin/edit.php?done=1&error=1
  if ( isset($_GET['done']) ) {
    $message = isset($_GET['error']) ? 'There was an error.' : 'Everithing ok.';
    $class = isset($_GET['error']) ? 'error' : 'updated';
    global $my_notice_args;
    $my_notice_args = compact('message', 'class');
    add_action('admin_notices', 'print_my_notice');
  }
}

function print_my_notice() {
  global $my_notice_args;
  if ( ! empty($my_notice_args) ) {
    printf('<div class="%s"><p>%s</p></div>', $my_args_notice['class'], $my_args_notice['class']);
  }
}

See 'admin_notices' hook docs on Codex