Skip to content

Commit

Permalink
image update, non static function fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jupitercow committed Feb 19, 2015
1 parent f752b71 commit 9dc3c7c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 40 deletions.
86 changes: 47 additions & 39 deletions gravityforms-update-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Gravity Forms: Post Updates
Plugin URI: https://wordpress.org/plugins/gravity-forms-post-updates/
Description: Allow Gravity Forms to update post Content and the meta data associated with it. Based off the original version by Kevin Miller, this version removed delete functionality, fixed a few bugs, and adds support for file uploads.
Version: 1.2.14
Version: 1.2.16
Author: Jake Snyder
Author URI: http://Jupitercow.com/
Contributer: p51labs
Expand Down Expand Up @@ -47,7 +47,7 @@ class gform_update_post
* @since 1.2
* @var string
*/
const VERSION = '1.2.14';
const VERSION = '1.2.16';

/**
* Settings
Expand Down Expand Up @@ -302,7 +302,7 @@ public static function admin_warnings()
public static function scripts_and_styles()
{
// register acf scripts
wp_register_script( self::PREFIX, self::$settings['dir'] . 'js/scripts.js', array('jquery'), self::VERSION );
wp_register_script( self::PREFIX, plugins_url( 'js/scripts.js', __FILE__ ), array('jquery'), self::VERSION );
$args = array(
'url' => admin_url( 'admin-ajax.php' ),
'action' => self::PREFIX . '_delete_upload',
Expand Down Expand Up @@ -517,8 +517,10 @@ public static function shortcode( $atts )
*/
public static function setup_form( $args=array() )
{
if ( is_numeric($args) ) {
if ( is_numeric($args) )
{
$post_id = $args;
$form_id = false;
}
elseif ( is_array($args) )
{
Expand All @@ -529,7 +531,8 @@ public static function setup_form( $args=array() )
$args = wp_parse_args( $args, $defaults );
extract($args);
}
else {
else
{
return false;
}

Expand Down Expand Up @@ -739,6 +742,7 @@ public static function create_uploaded_file( $file, $field, $form_id )
// If this is an image, set up and create a thumbnail
if ( 'image/' == substr($mime, 0, 6) )
{
$image_url = '';
if ( apply_filters(self::PREFIX . '/image/resize', true) )
{
// Get settings for image thumb
Expand All @@ -751,43 +755,47 @@ public static function create_uploaded_file( $file, $field, $form_id )
$baseurl = GFFormsModel::get_upload_url($form_id);
$filename = str_replace($baseurl, $basedir, $file);

// Make sure the server supports resize and save
$img_editor_test = wp_image_editor_supports( array(
'methods' => array(
'resize',
'save'
)
) );
if ( true === $img_editor_test && is_writable($basedir) )
if ( is_file($filename) )
{
// Get the image editor
$image_editor = wp_get_image_editor( $filename );
if (! is_wp_error($image_editor) )
// Make sure the server supports resize and save
$img_editor_test = wp_image_editor_supports( array(
'methods' => array(
'resize',
'save'
)
) );
if ( true === $img_editor_test && is_writable($basedir) )
{
// Create thumbnail filename
$thumbname = $image_editor->generate_filename( 'thumb' );
// Test if thumbnail exists
$thumb_exists = file_exists($thumbname);
if ( $thumb_exists ) $thumbsize = getimagesize( $thumbname );

// If no thumbnail, or the size has changed, generate a new one
if (! $thumb_exists || $thumbsize[0] != $width || $thumbsize[1] != $height )
// Get the image editor
$image_editor = wp_get_image_editor( $filename );
if (! is_wp_error($image_editor) )
{
$image_editor->resize( $width, $height, $crop );
$resized = $image_editor->save($thumbname);
if (! is_wp_error($resized) )
// Create thumbnail filename
$thumbname = $image_editor->generate_filename( 'thumb' );
// Test if thumbnail exists
$thumb_exists = file_exists($thumbname);
if ( $thumb_exists ) $thumbsize = getimagesize( $thumbname );

// If no thumbnail, or the size has changed, generate a new one
if (! $thumb_exists || $thumbsize[0] != $width || $thumbsize[1] != $height )
{
$pathinfo = pathinfo($file);
$image_url = $pathinfo['dirname'] . '/' . $resized['file'];
$image_editor->resize( $width, $height, $crop );
$resized = $image_editor->save($thumbname);
if (! is_wp_error($resized) )
{
$pathinfo = pathinfo($file);
$image_url = $pathinfo['dirname'] . '/' . $resized['file'];
}
}
// Otherwise use the existing file
else
{
$image_url = str_replace($basedir, $baseurl, $thumbname);
}
}
// Otherwise use the existing file
else
{
$image_url = str_replace($basedir, $baseurl, $thumbname);
}
}
}

}

// If there is no thumbnail at this point, use the file itself
Expand Down Expand Up @@ -977,9 +985,9 @@ public static function populate_element( $field, $field_type, $value )

$value = (! is_array($value) ) ? array($value) : $value;

if ( isset($field['choices']) )
if ( isset($field->choices) )
{
foreach ( $field['choices'] as &$choice )
foreach ( $field->choices as &$choice )
{
$choice['isSelected'] = ( in_array($choice['value'], $value) ) ? true : '';
}
Expand Down Expand Up @@ -1183,7 +1191,7 @@ public static function current_user_can( $post_id=false )
* @type action
* @return void
*/
public function gform_field_standard_settings( $position, $form_id )
public static function gform_field_standard_settings( $position, $form_id )
{
if ( 700 == $position ) :
?>
Expand All @@ -1210,7 +1218,7 @@ public function gform_field_standard_settings( $position, $form_id )
* @type action
* @return void
*/
public function gform_editor_js()
public static function gform_editor_js()
{
?>
<script type="text/javascript">
Expand Down Expand Up @@ -1252,7 +1260,7 @@ public function gform_editor_js()
* @type filter
* @return void
*/
public function gform_tooltips($tooltips)
public static function gform_tooltips($tooltips)
{
$tooltips['form_' . self::$settings['unique_field']] = __("<h6>Unique Meta Field</h6>Check this box to ensure this meta field is saved as unique.", self::PREFIX);
return $tooltips;
Expand Down
11 changes: 10 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=jacob
Tags: gravity forms, update posts, frontend, front end
Requires at least: 3.6.1
Tested up to: 4.0
Stable tag: 1.2.14
Stable tag: 1.2.16
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -132,6 +132,15 @@ Image fields are only supported if they are the "Featured Image". Otherwise you

== Changelog ==

## 1.2.16 - 2015-02-18

- Fixed a few non-static function declarations.
- Updated image upload to hopefully shutdown when the image is moved.

## 1.2.15 - 2015-02-18

- Fixed field treatment to object from array for GF 1.9.x.

## 1.2.14 - 2015-02-18

- Fixing capabilites to plural.
Expand Down

0 comments on commit 9dc3c7c

Please sign in to comment.