Created
December 20, 2012 14:47
-
-
Save lgedeon/4345678 to your computer and use it in GitHub Desktop.
Dashboard Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function wp_dashboard_setup() { | |
| wp_add_dashboard_widget( 'plugin_analytics_link', 'Analytics Link', array($this, 'wp_add_dashboard_widget_callback' ), array($this, 'wp_add_dashboard_widget_control_callback' ) ); | |
| } | |
| function wp_add_dashboard_widget_callback() { | |
| if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) | |
| $widget_options = array(); | |
| if ( !isset($widget_options['plugin_analytics_link']) ) | |
| $widget_options['plugin_analytics_link'] = array( 'label' => '', 'link' => '' ); | |
| $link_label = isset( $widget_options['plugin_analytics_link']['label'] ) ? $widget_options['plugin_analytics_link']['label'] : ''; | |
| $link_url = isset( $widget_options['plugin_analytics_link']['url'] ) ? $widget_options['plugin_analytics_link']['url'] : ''; | |
| ?> | |
| <p>Enter a link and then hide this widget. The link will show up in the header of the Google Analyticator Widget.</p> | |
| <p>Link Label: <?php echo $link_label ?></p> | |
| <p>Link Url: <a href="<?php echo esc_url( $link_url ) ?>"><?php echo esc_url( $link_url ) ?></a></p> | |
| <a href="/wp-admin/index.php?edit=plugin_analytics_link#plugin_analytics_link">Edit</a> | |
| <?php | |
| } | |
| function wp_add_dashboard_widget_control_callback() { | |
| if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) | |
| $widget_options = array(); | |
| if ( !isset($widget_options['plugin_analytics_link']) ) | |
| $widget_options['plugin_analytics_link'] = array( 'label' => '', 'link' => '' ); | |
| if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['plugin-analytics-link']) ) { | |
| $widget_options['plugin_analytics_link']['label'] = sanitize_text_field( $_POST['plugin-analytics-link']['label'] ); | |
| $widget_options['plugin_analytics_link']['url'] = esc_url_raw( $_POST['plugin-analytics-link']['url'] ); | |
| update_option( 'dashboard_widget_options', $widget_options ); | |
| return; | |
| } | |
| $link_label = isset( $widget_options['plugin_analytics_link']['label'] ) ? $widget_options['plugin_analytics_link']['label'] : ''; | |
| $link_url = isset( $widget_options['plugin_analytics_link']['url'] ) ? $widget_options['plugin_analytics_link']['url'] : ''; | |
| ?> | |
| <p>Enter link and then hide this widget. The link will show up in the header of the Google Analyticator Widget.</p> | |
| <p><label for="link-label">Link Label:</label> | |
| <input id="link-label" name="plugin-analytics-link[label]" type="text" value="<?php echo sanitize_text_field( $link_label ) ?>" /></p> | |
| <p><label for="link-url">Link Url:</label> | |
| <input id="link-url" name="plugin-analytics-link[url]" type="text" value="<?php echo esc_url( $link_url ) ?>" /></p> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment