Last active
December 8, 2016 14:39
-
-
Save musamamasood/4fa764dcef7bec4db4745efed5928f26 to your computer and use it in GitHub Desktop.
Helper Functions
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
| /** | |
| * The main logging function | |
| * | |
| * @uses error_log | |
| * @param string $type type of the error. e.g: debug, error, info | |
| * @param string $msg | |
| */ | |
| public static function log( $type = '', $msg = '' ) { | |
| if ( WP_DEBUG == true ) { | |
| $msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg ); | |
| error_log( $msg, 3, dirname( __FILE__ ) . '/log.txt' ); | |
| } | |
| } | |
| /** | |
| * Helper function for converting a normal date string to unix date/time string | |
| * | |
| * @since 0.1 | |
| * @param string $date | |
| * @param int $gmt | |
| * @return string | |
| */ | |
| function lddos_date2mysql( $date, $gmt = 0 ) { | |
| if (empty( $date ) ) { | |
| return; | |
| } | |
| $time = strtotime( $date ); | |
| return ( $gmt ) ? gmdate( 'Y-m-d H:i:s', $time ) : gmdate( 'Y-m-d H:i:s', ( $time + ( get_option( 'timezone_string' ) * 3600 ) ) ); | |
| } | |
| /** | |
| * Helper function for removing https or http from Google fonts. | |
| * | |
| * @since 0.1 | |
| * @param string $date | |
| * @param int $gmt | |
| * @return string | |
| */ | |
| add_filter( 'style_loader_tag', 'remove_https_http', 10, 4 ); | |
| function remove_https_http( $html, $handle, $href, $media ){ | |
| $handles = array('et-gf-open-sans', 'divi-fonts', 'twentysixteen-fonts', 'open-sans'); | |
| if( in_array( $handle, $handles) ){ | |
| $html = str_replace('https:', '', $html); | |
| } | |
| return $html; | |
| } | |
| /** | |
| * Helper function for path in 4.7 version including get_parent_theme_file_uri() and get_parent_theme_file_path(). | |
| * | |
| * @since 0.1 | |
| * @param string $date | |
| * @param int $gmt | |
| * @return string | |
| */ | |
| wp_enqueue_script( | |
| 'my-script', | |
| get_theme_file_uri( 'js/my-script.js' ), | |
| array(), | |
| filemtime( get_theme_file_path( 'js/my-script.js' ) ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment