options_key ); // If we request a widget and it exists, return it. if ( isset( $opts[ $this->id ] ) ) { return $opts[ $this->id ]; } // Something went wrong. return FALSE; } /** * Gets one specific option for the specified widget * * @since 1.4.0 * * @param string $option * @param string $default * * @return string */ protected function get_widget_option( $option, $default = '' ) { $opts = $this->get_dashboard_widget_options(); // If widget opts dont exist, return false. if ( ! $opts ) { return FALSE; } // Otherwise fetch the option or use default. if ( ! empty( $opts[ $option ] ) ) { return $opts[ $option ]; } return ( isset( $default ) ) ? $default : FALSE; } /** * Saves an array of options for a single dashboard widget to the database * Can also be used to define default values for a widget * * @since 1.4.0 * * @param array $args An associative array of options being saved. * @param bool $add_only If true, options will not be added if widget options already exist. */ protected function update_dashboard_widget_options( $args = array(), $add_only = FALSE ) { // Fetch ALL dashboard widget options from the db... $opts = get_option( $this->options_key ); // Get just our widget's options, or set empty array. $w_opts = isset( $opts[ $this->id ] ) ? $opts[ $this->id ] : array(); $opts[ $this->id ] = $add_only ? array_merge( $args, $w_opts ) : array_merge( $w_opts, $args ); // Save the entire widgets array back to the db. update_option( $this->options_key, $opts ); } /** * Getter for the id prop * * @since 1.4.0 * * @return string */ public function get_id() { return $this->id; } /** * Getter for the title prop * * @since 1.4.0 * * @return string */ public function get_title() { return $this->title; } /** * Getter for the description prop * * @since 1.4.0 * * @return string */ public function get_description() { return $this->description; } /** * Getter for the thumbnail prop * * @since 1.4.0 * * @return string */ public function get_thumbnail() { return $this->thumbnail; } /** * Getter for the default_layout * * @since 1.4.0 * * @return array */ public function get_default_layout() { return $this->default_layout; } /** * Getter for the has_config prop * * @since 1.4.0 * * @return bool */ public function has_config() { return $this->has_config; } }