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
@mustafauysal
mustafauysal / get_featured_image.php
Created August 30, 2013 08:10
Sometimes 'the_post_thumbnail' function not ideal for your work. Use this
@mustafauysal
mustafauysal / author-url.php
Created September 10, 2013 22:37
change wordpress author url
<?php
// use in plugin or theme' functions page.
function author_permalinks() {
global $wp_rewrite;
$wp_rewrite->author_base = 'user';
$wp_rewrite->flush_rules();
}
add_action('init','author_permalinks');
@mustafauysal
mustafauysal / br.php
Created September 13, 2013 14:08
please don't break me!
<?php
add_filter('the_content', 'remove_br_tags');
function remove_br_tags($content) {
return preg_replace('/<br(\s+)?\/?>/i', "\n", $content);
}
@mustafauysal
mustafauysal / distraction_free_mode.php
Last active December 23, 2015 20:39
Force WordPress distraction free mode
<?php
function force_distraction_free_mode() {
global $pagenow;
if ( $pagenow == 'post-new.php' ) {
?>
<script type="text/javascript">
jQuery(window).bind("load", function() {
fullscreen.on();
});
</script>
@mustafauysal
mustafauysal / es.sh
Last active December 27, 2015 17:39 — forked from rajraj/es.sh
cd ~
sudo yum update
sudo yum install java-1.7.0-openjdk.i686 -y
wget https://github.com/elasticsearch/elasticsearch/archive/v0.90.6.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@mustafauysal
mustafauysal / fix-duplicated-posts.php
Created November 13, 2013 00:12
Bulk Fixing WordPress Duplicated Posts! Read for more information: http://uysalmustafa.com/2013/11/13/bulk-fixing-wordpress-duplicated-posts/
<?php
require( 'wp-load.php' );
//set_time_limit(30000); // you can set time limit, but I prefer to use command line > php fix-duplicated-posts.php
$query = "SELECT id,post_name, Count(*) FROM wp_posts WHERE post_type = 'post' GROUP BY post_name HAVING Count(*) > 1";
$duplicated_posts = $wpdb->get_results( $query );
foreach ( $duplicated_posts as $result ) {
$prepost = get_post($result->id);
$prepost->post_name = '';
@mustafauysal
mustafauysal / wp-title-hack.php
Created December 5, 2013 19:33
super-duper title hack for Adem's blog :)
<?php echo urldecode(str_replace('%26%23215%3B','x', urlencode(get_the_title()))); ?>
@mustafauysal
mustafauysal / post-type-upload.php
Created December 7, 2013 17:37
Change WordPress upload_dir per post type.
<?php
/**
* Change upload dir for video post type
* Media files that comes from video post type will be stored under
* wp-content/uploads/video/year/month/file-name.blah
* use "upload_dir" filter
* @param $args
* @return mixed
*/
public function video_upload_directory( $args ) {
@mustafauysal
mustafauysal / main-query-with-post-type.php
Last active December 30, 2015 15:09
Custom post type in main query! Drop-in mu-plugins or add theme's function file
<?php
/**
* @param $q
* display custom post type in main loop!
* You can use conditional tags (http://codex.wordpress.org/Conditional_Tags) for show only front-end
*/
function add_post_type_to_query( $q ) {
if ( $q->is_main_query() && is_home() ) {
$q->query_vars['post_type'] = array( 'post', 'video' ); // add whatever you want to show
@mustafauysal
mustafauysal / upload-limitation.php
Created December 7, 2013 18:40
WordPress upload size limitation.
<?php
function restricted_upload_size() {
if ( ! current_user_can( 'manage_options' ) ) {
return 2 * 1024 * 1024; // 2mb
}
return 500 * 1024 * 1024;
}
add_filter( 'upload_size_limit', 'restricted_upload_size' );