function block_instance($blockname, $instance = NULL) { if (!block_load_class($blockname)) { return false; } $classname = 'block_' . $blockname; $retval = new $classname(); if ($instance !== NULL) { $retval->_load_instance($instance); } return $retval; }
/** * Creates a new instance of the specified block class. * * @param string $blockname the name of the block. * @param $instance block_instances DB table row (optional). * @param moodle_page $page the page this block is appearing on. * @return block_base the requested block instance. */ function block_instance($blockname, $instance = NULL, $page = NULL) { if (!block_load_class($blockname)) { return false; } $classname = 'block_' . $blockname; $retval = new $classname(); if ($instance !== NULL) { if (is_null($page)) { global $PAGE; $page = $PAGE; } $retval->_load_instance($instance, $page); } return $retval; }