Errors adding screen options to plugin

I have created a plugin, and it all works as it should, but I am having problems adding screen options (using this tutorial).

class MyClassName {

  public function __construct() {

        add_action('admin_menu', array($this, 'AddMenu'));
        add_action('admin_head', array($this, 'AdminCSS'));
        add_filter('set-screen-option', array($this, 'SetScreenOption'), 10, 3);

  public function AddMenu() {

    global $hook;
    $hook = add_media_page('MyPlugin', 'MyPlugin', 'edit_others_posts', 'my-plugin-page.php', array($this,'DisplayThePage'));
    add_action("load-$hook", "TheScreenOptions");  


   public function TheScreenOptions() {

    global $hook;
    $screen = get_current_screen();
    if(!is_object($screen) || $screen->id != $hook)
    $args = array(
        'label' => __('Posts per page', 'textdomain'),
        'default' => 20,
        'option' => 'MySettingName'
    add_screen_option( 'per_page', $args );

   function SetScreenOption($status, $option, $value) {

       if ( 'MySettingName' == $option ) return $value;
       return $status; // or return false;

    public function AdminCSS() {

    // stuff here


    public function DisplayThePage() {

    // stuff here


The error I get is Array() expects parameter 1 to be a valid callback, function 'SetScreenOption' not found or invalid function name, no matter what I try. The function is definitely there, and spelled identically and has the same case etc.

Any help gratefully received. Thanks.

Read more here: Errors adding screen options to plugin

Leave a Reply

Your email address will not be published. Required fields are marked *