Programming

  • 6 {{ upvoteCount | shortNum }}

    Remove some menus in WordPress

    Jeremy Lebre in Programming

    You can remove some menus of the WordPress interface by adding the following code to the functions.php file of your theme: PHP Code: function remove_menu() {global $menu;unset($menu[2]); /* remove the menu "Dashboard" */unset($menu[5]); /* remove the menu "Posts" */unset($menu[10]); /* remove the menu "Medias" */unset($menu[15]); /* remove the menu "Links" */unset($menu[20]); /* remove the menu "Pages" */unset($menu[25]); /* remove the menu "Comments" */unset($menu[60]); /* remove the menu "Appearance" */unset($menu[65]); /* remove the menu "Plugins" */unset($menu[70]); /* remove the menu "Users" */unset($menu[75]); /* remove the menu "Tools" */unset($menu[80]); /* remove the menu "Settings" */}add_action('admin_head', 'remove_menu');  If you prefer to keep one ... [read more]

  • 2 {{ upvoteCount | shortNum }}

    Allow HTML in WordPress comments

    Jeremy Lebre in Programming

    In WordPress, some HTML tags are forbidden by default in comments. To allow them, add the following code to the functions.php file of your theme: PHP Code: function comments_allowed_tags($data) {global $allowedtags;$allowedtags['a'] = array('class' => array(), 'href' => array(), 'name' => array(), 'rel' => array(), 'rev' => array(), 'style' => array(), 'title' => array());$allowedtags['blockquote'] = array('cite' => array(), 'class' => array(), 'style' => array());$allowedtags['code'] = array('class' => array(), 'style' => array());$allowedtags['del'] = array('cite' => array(), 'class' => array(), 'datetime' => array(), 'style' => array());$allowedtags['em'] = array('class' => array(), 'style' => array());$allowedtags['ins'] = array('cite' => array(), 'class' => array(), 'datetime' => array(), 'style' => array());$allowedtags['li'] = array('class' => array(), 'style' => array());$allowedtags['ol'] = array('class' => array(), 'style' => array());$allowedtags['p'] = array('class' => array(), 'style' => array());$allowedtags['pre'] = array('class' => array(), 'style' => array());$allowedtags['span'] = array('class' => array(), 'style' => array());$allowedtags['strong'] = array('class' => array(), 'style' => array());$allowedtags['ul'] = array('class' => array(), 'style' => array()); return $data; }add_filter('preprocess_comment', 'comments_allowed_tags');  [read more]

  • 1 {{ upvoteCount | shortNum }}

    A PHP function to convert currencies in real time

    Jeremy Lebre in Programming

    This PHP function returns the conversion rate of 2 currencies in real time: PHP Code: function get_conversion_rate($currency1, $currency2) {$fp = @fsockopen("download.finance.yahoo.com", 80, $errno, $errstr, 30);if (!$fp) { return 1; }else {$file = "/d/quotes.csv";$str = "?s=".$currency1.$currency2."=X&f=sl1d1t1ba&e=.csv";$out = "GET ".$file.$str." HTTP/1.0\r\n";$out .= "Host: yahoo.com\r\n";$out .= "Connection: Close\r\n\r\n";@fputs($fp, $out);while (!@feof($fp)) { $data .= @fgets($fp, 128); }@fclose($fp);@preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);$data = $match[2];$search = array("'<script[^>]*?>.*?</script>'si", "'<[\/\!]*?[^<>]*?>'si", "'([\r\n])[\s]+'", "'&(quot|#34);'i", "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&#(\d+);'e");$replace = array("", "", "\\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)");$data = @preg_replace($search, $replace, $data);$result = split(",", $data);return $result[1]; } }  Example: EUR/USD = get_conversion_rate('EUR', 'USD'); And this function converts an amount in US dollars ... [read more]