Skip to content

Instantly share code, notes, and snippets.

View mangesh's full-sized avatar

Mangesh mangesh

  • NBA
  • India
  • 07:47 (UTC +05:30)
View GitHub Profile
@mangesh
mangesh / functions.php
Created August 7, 2019 08:00
Create attachment in WordPress from remote URL
<?php
/**
* Upload Article Feature image.
*
* @param int $post_id Article ID.
*
* @param string $image_name image name.
*
* @param string $full_image_path Full image path from where image will upload.
*/
@mangesh
mangesh / functions.php
Created March 9, 2017 08:58
S3 migration
<?php
/**
* set /?do=now at the end of site your URL to fire this script.
*/
/**
* Function return attachment data needed for s3 table upload.
*
* @return array $attachment_data_array Attachment data array.
*/
@mangesh
mangesh / pre-commit.phpversioncompatibility
Created March 1, 2017 12:29
php version compatibility checker pre commit hook
#!/bin/bash
# PHP CodeSniffer pre-commit hook for git
#
# @author Soenke Ruempler <soenke@ruempler.eu>
# @author Sebastian Kaspari <s.kaspari@googlemail.com>
#
# see the README
PHPCS_BIN=/Users/mangesh/pear/bin/phpcs
PHPCS_CODING_STANDARD=PHPCompatibility
@mangesh
mangesh / pre-commit
Last active March 1, 2017 13:19
This file will act as a parent file for all it's child hooks
#!/bin/bash
hookname=`basename $0`
FILE=`mktemp`
trap 'rm -f $FILE' EXIT
cat - > $FILE
for hook in $GIT_DIR/hooks/$hookname.*
@mangesh
mangesh / pre-commit.phplint
Created March 1, 2017 12:14
phplint pre commit hook
#!/usr/bin/php
<?php
// copied from http://phpadvent.org/2008/dont-commit-that-error-by-travis-swicegood
// authored by Travis Swicegood
// Store this file in your projects .git/hooks/ directory
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
exec("git diff-index --cached --name-only {$against}", $output);
@mangesh
mangesh / functions.php
Created February 28, 2017 11:19
Replace media ID with the media title in URL
<?php
function custom_get_rtmedia_permalink( $permalink, $media, $id ) {
$post = get_post( $media[0]->media_id );
$title = isset( $post->post_name ) ? $post->post_name : '';
if ( ! empty( $title ) ) {
$permalink = str_replace( '/' . $id , '/' . $title, $permalink );
}
@mangesh
mangesh / functions.php
Created February 24, 2017 06:58
Open edit media in same window.
<?php
// Check if function doest not exists.
if ( ! function_exists( 'rtmedia_wp_footer_add_js_callback' ) ) {
function rtmedia_wp_footer_add_js_callback() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Event will fire when someone click on edit button of media.
jQuery( 'body' ).on( 'click', '.rtmedia-gallery-item-actions a:first',function(){
var target = jQuery( this ).attr( 'target' );
@mangesh
mangesh / functions.php
Created February 20, 2017 19:51
Album description on album single page
<?php
function rtmedia_get_single_album_desc_custom(){
$desc = '';
global $rtmedia_query;
if ( isset( $rtmedia_query->media_query ) && is_array( $rtmedia_query->media_query ) && isset( $rtmedia_query->media_query['album_id'] ) ) {
$id = $rtmedia_query->media_query['album_id'];
$album_desc = get_post( rtmedia_media_id( $id ) );
if( isset($album_desc) ){
$desc = $album_desc->post_content;
}else{
@mangesh
mangesh / functions.php
Created February 15, 2017 10:49
rtMedia photo edit and the rtAmazon S3 ( with delete local file option on ) compatiility
<?php
/**
* When 'Delete local file' option is on in rtAmazon S3 plugin,
* Fetch the original image from S3 bucket and Upload back the filtered photos
* modified by 'rtMedia Photo Filter' addon to the S3 bucket
* to the S3 bucket
*
*/
function custom_rtmedia_photo_filter_compatibility() {
if ( ! class_exists( 'RTAWSS3_Client' ) ) {
@mangesh
mangesh / functions.php
Created January 30, 2017 12:08
Make rtMedia custom attribute mandatory and make attributes dependant on category
<?php
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
* to a class, you either have to have access to that class object, or it has to be a call
* to a static method. This method allows you to remove filters with a callback to a class
* you don't have access to.
*