Skip to content

Instantly share code, notes, and snippets.

View mustafauysal's full-sized avatar
💭
addressing some issues... 🧑🏻‍💻

Mustafa Uysal mustafauysal

💭
addressing some issues... 🧑🏻‍💻
View GitHub Profile
jQuery(document).ready(function($){
var custom_uploader;
$('#upload_image_button').click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
@mustafauysal
mustafauysal / rename_file_if_exists.php
Last active December 17, 2015 02:49
If file exist in the path, rename it
<?php
/**
* Create a better name for file
* @param mixed $context
* @return type $new_text
*/
function rename_file($context) {
$context = trim($context);
$search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü',' ');
$replace = array('c','c','g','g','i','i','o','o','s','s','u','u','-');
<?php
/**
* Created by JetBrains PhpStorm.
* User: Yusuf Koç
* Date: 07.09.2011
* Time: 14:23
*/
class Validation
@mustafauysal
mustafauysal / wp_smtp.php
Last active December 17, 2015 04:58
Send WordPress system mails via SMTP.
<?php
function wp_smtp($phpmailer){
$phpmailer->Mailer = "smtp";
$phpmailer->From = "System";
$phpmailer->FromName = "System Name";
$phpmailer->Sender = "no_reply@example.com";
$phpmailer->AddReplyTo($phpmailer->From,$phpmailer->FromName);
$phpmailer->Host = 'smtp.gmail.com';
@mustafauysal
mustafauysal / theme-fixer.php
Created May 28, 2013 22:03
a part of validate_current_theme() function in the wordpress core. You can use this code under the mu-plugins folder for prevent to get death of the white screen.
<?php
if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) {
switch_theme( WP_DEFAULT_THEME );
return false;
}
@mustafauysal
mustafauysal / upload_mime.php
Last active December 20, 2015 04:19
Modify wordpress allowed mime types
<?php
add_filter('upload_mimes','external_mimes');
function external_mimes($mimes){
return array_merge($mimes,array (
'rar'=> 'application/x-rar-compressed', // you can add more?
));
}
@mustafauysal
mustafauysal / youtube-regex.php
Created August 20, 2013 12:17
regex youtube id
<?php
$url = "http://www.youtube.com/watch?v=hLQl3WQQoQ0";
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
echo $matches[1];
@mustafauysal
mustafauysal / php-oci8 encoding.md
Last active August 20, 2018 20:06
Solution for the oracle character issue [PHP]

If you are going crazy with charecter issue due to oracle connection;

add this:

putenv ("NLS_LANG=AMERICAN_AMERICA.AL32UTF8");

before connection string.

Full list here

@mustafauysal
mustafauysal / wp-conditional.php
Last active December 21, 2015 20:59
If WordPress' Conditional Tags ( @see http://codex.wordpress.org/Conditional_Tags ) not enough. You can use this way.
<?php
if ( isset( $_GET['page'] ) && $_GET['page'] == 'my_super_page_slug' ) {
add_action( 'blah', 'call_back_blah' );
}
@mustafauysal
mustafauysal / sticky-posts.php
Last active December 21, 2015 22:48
Get latest sticky posts in loop.
<?php
$sticky = get_option( 'sticky_posts' );
$args = array(
'posts_per_page' => 1,
'post__in' => $sticky,
'ignore_sticky_posts' => 1
);
query_posts( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();