Get specific color from admin color scheme

Color schemes are registered globally within $_wp_admin_css_colors (see wp-includes/general-template.php for reference). You can return the colors for the current user depending on get_user_meta() for a specific settings page like this: global $pagenow; if ( $pagenow == ‘options-permalink.php’ ) : add_action( ‘admin_notices’, ‘get_current_user_admin_color’ ); function get_current_user_admin_color() { global $_wp_admin_css_colors; $user_admin_color = get_user_meta(get_current_user_id(), ‘admin_color’, true); echo ‘<pre>’; … Read more

Show message on wordpress admin dashboard

When you redirect the user to the admin dashboard pass on a GET variable named “success_notice”, for example. So you get a URL like this: /wp-admin/index.php?success_notice=1. With that setup, just add the code that shows the success message on the dashboard only if that GET variable is set. add_action(‘admin_notices’, ‘wpse75629_admin_notice’); function wpse75629_admin_notice() { global $pagenow; … Read more

Writing a plugin that notify my friends of new post that mentions(@) them

Twice edited according to kaiser’s suggestions, unsecure version removed. <?php function my_email_friend($post_id = ”) { // get post object $post = get_post($post_id); // get post content $content = $post->post_content; // if @David exists if( 0 !== preg_match(‘/(@\w)/’, $content, $matches) ) $friend_display_name_like=”%” . like_escape($matches[0]) . ‘%’; else return; // do nothing if no matches global $wpdb; … Read more

Shortcode adding p and br tags

Not sure if this will be helpful to anyone else but the cause of the issue was a custom formatter the theme had: function my_formatter($content) { $new_content=””; $pattern_full=”{(\[raw\].*?\[/raw\])}is”; $pattern_contents=”{\[raw\](.*?)\[/raw\]}is”; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if (preg_match($pattern_contents, $piece, $matches)) { $new_content .= $matches[1]; } else { $new_content .= wptexturize(wpautop($piece)); } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)