@@ -20,12 +20,12 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function __construct() { |
| 22 | 22 | |
| 23 | - add_action( 'media_buttons', array( $this, 'add_shortcode_button'), 30); |
|
| 23 | + add_action( 'media_buttons', array( $this, 'add_shortcode_button' ), 30 ); |
|
| 24 | 24 | |
| 25 | - add_action( 'admin_footer', array( $this, 'add_shortcode_popup') ); |
|
| 25 | + add_action( 'admin_footer', array( $this, 'add_shortcode_popup' ) ); |
|
| 26 | 26 | |
| 27 | 27 | // adding styles and scripts |
| 28 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles') ); |
|
| 28 | + add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ) ); |
|
| 29 | 29 | |
| 30 | 30 | // ajax - populate sort fields based on the selected view |
| 31 | 31 | add_action( 'wp_ajax_gv_sortable_fields', array( $this, 'get_sortable_fields' ) ); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function is_post_editor_screen() { |
| 42 | 42 | global $current_screen, $pagenow; |
| 43 | - return !empty( $current_screen->post_type ) && 'gravityview' != $current_screen->post_type && in_array( $pagenow , array( 'post.php' , 'post-new.php' ) ); |
|
| 43 | + return ! empty( $current_screen->post_type ) && 'gravityview' != $current_screen->post_type && in_array( $pagenow, array( 'post.php', 'post-new.php' ) ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @since 1.15.3 |
| 57 | 57 | */ |
| 58 | - if( ! GVCommon::has_cap( array( 'publish_gravityviews' ) ) ) { |
|
| 58 | + if ( ! GVCommon::has_cap( array( 'publish_gravityviews' ) ) ) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if( !$this->is_post_editor_screen() ) { |
|
| 62 | + if ( ! $this->is_post_editor_screen() ) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | ?> |
| 66 | - <a href="#TB_inline?width=600&height=800&inlineId=select_gravityview_view" class="thickbox hide-if-no-js button gform_media_link" id="add_gravityview" title="<?php esc_attr_e("Insert View", 'gravityview'); ?>"><span class="icon gv-icon-astronaut-head"></span><?php esc_html_e( 'Add View', 'gravityview' ); ?></a> |
|
| 66 | + <a href="#TB_inline?width=600&height=800&inlineId=select_gravityview_view" class="thickbox hide-if-no-js button gform_media_link" id="add_gravityview" title="<?php esc_attr_e( "Insert View", 'gravityview' ); ?>"><span class="icon gv-icon-astronaut-head"></span><?php esc_html_e( 'Add View', 'gravityview' ); ?></a> |
|
| 67 | 67 | <?php |
| 68 | 68 | |
| 69 | 69 | } |
@@ -79,17 +79,17 @@ discard block |
||
| 79 | 79 | function add_shortcode_popup() { |
| 80 | 80 | global $post; |
| 81 | 81 | |
| 82 | - if( !$this->is_post_editor_screen() ) { |
|
| 82 | + if ( ! $this->is_post_editor_screen() ) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $post_type = get_post_type_object($post->post_type); |
|
| 86 | + $post_type = get_post_type_object( $post->post_type ); |
|
| 87 | 87 | |
| 88 | - $views = get_posts( array('post_type' => 'gravityview', 'posts_per_page' => -1 ) ); |
|
| 88 | + $views = get_posts( array( 'post_type' => 'gravityview', 'posts_per_page' => -1 ) ); |
|
| 89 | 89 | |
| 90 | 90 | // If there are no views set up yet, we get outta here. |
| 91 | - if( empty( $views ) ) { |
|
| 92 | - echo '<div id="select_gravityview_view"><div class="wrap">'. GravityView_Post_Types::no_views_text() .'</div></div>'; |
|
| 91 | + if ( empty( $views ) ) { |
|
| 92 | + echo '<div id="select_gravityview_view"><div class="wrap">' . GravityView_Post_Types::no_views_text() . '</div></div>'; |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | <div class="wrap"> |
| 100 | 100 | |
| 101 | 101 | <h2 class=""><?php esc_html_e( 'Embed a View', 'gravityview' ); ?></h2> |
| 102 | - <p class="subtitle"><?php printf( esc_attr ( __( 'Use this form to embed a View into this %s. %sLearn more about using shortcodes.%s', 'gravityview') ), $post_type->labels->singular_name, '<a href="http://gravityview.co/support/documentation/202934188/" target="_blank">', '</a>' ); ?></p> |
|
| 102 | + <p class="subtitle"><?php printf( esc_attr( __( 'Use this form to embed a View into this %s. %sLearn more about using shortcodes.%s', 'gravityview' ) ), $post_type->labels->singular_name, '<a href="http://gravityview.co/support/documentation/202934188/" target="_blank">', '</a>' ); ?></p> |
|
| 103 | 103 | |
| 104 | 104 | <div> |
| 105 | 105 | <h3><label for="gravityview_id"><?php esc_html_e( 'Select a View', 'gravityview' ); ?></label></h3> |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | <select name="gravityview_id" id="gravityview_id"> |
| 108 | 108 | <option value=""><?php esc_html_e( '— Select a View to Insert —', 'gravityview' ); ?></option> |
| 109 | 109 | <?php |
| 110 | - foreach( $views as $view ) { |
|
| 111 | - $title = empty( $view->post_title ) ? __('(no title)', 'gravityview') : $view->post_title; |
|
| 112 | - echo '<option value="'. $view->ID .'">'. esc_html( sprintf('%s #%d', $title, $view->ID ) ) .'</option>'; |
|
| 110 | + foreach ( $views as $view ) { |
|
| 111 | + $title = empty( $view->post_title ) ? __( '(no title)', 'gravityview' ) : $view->post_title; |
|
| 112 | + echo '<option value="' . $view->ID . '">' . esc_html( sprintf( '%s #%d', $title, $view->ID ) ) . '</option>'; |
|
| 113 | 113 | } |
| 114 | 114 | ?> |
| 115 | 115 | </select> |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | foreach ( $settings as $key => $setting ) { |
| 127 | 127 | |
| 128 | - if( empty( $setting['show_in_shortcode'] ) ) { continue; } |
|
| 128 | + if ( empty( $setting[ 'show_in_shortcode' ] ) ) { continue; } |
|
| 129 | 129 | |
| 130 | 130 | GravityView_Render_Settings::render_setting_row( $key, array(), NULL, 'gravityview_%s', 'gravityview_%s' ); |
| 131 | 131 | } |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | </table> |
| 135 | 135 | |
| 136 | 136 | <div class="submit"> |
| 137 | - <input type="submit" class="button button-primary button-large alignleft hide-if-js" value="<?php esc_attr_e('Insert View', 'gravityview' ); ?>" id="insert_gravityview_view" /> |
|
| 138 | - <input class="button button-secondary alignright" type="submit" onclick="tb_remove(); return false;" value="<?php esc_attr_e("Cancel", 'gravityview'); ?>" /> |
|
| 137 | + <input type="submit" class="button button-primary button-large alignleft hide-if-js" value="<?php esc_attr_e( 'Insert View', 'gravityview' ); ?>" id="insert_gravityview_view" /> |
|
| 138 | + <input class="button button-secondary alignright" type="submit" onclick="tb_remove(); return false;" value="<?php esc_attr_e( "Cancel", 'gravityview' ); ?>" /> |
|
| 139 | 139 | </div> |
| 140 | 140 | |
| 141 | 141 | </div> |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | function add_scripts_and_styles() { |
| 158 | 158 | |
| 159 | - if( ! $this->is_post_editor_screen() ) { |
|
| 159 | + if ( ! $this->is_post_editor_screen() ) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -167,22 +167,22 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | $protocol = is_ssl() ? 'https://' : 'http://'; |
| 169 | 169 | |
| 170 | - wp_enqueue_style( 'jquery-ui-datepicker', $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', array(), GravityView_Plugin::version ); |
|
| 170 | + wp_enqueue_style( 'jquery-ui-datepicker', $protocol . 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', array(), GravityView_Plugin::version ); |
|
| 171 | 171 | |
| 172 | 172 | //enqueue styles |
| 173 | - wp_register_style( 'gravityview_postedit_styles', plugins_url('assets/css/admin-post-edit.css', GRAVITYVIEW_FILE), array(), GravityView_Plugin::version ); |
|
| 173 | + wp_register_style( 'gravityview_postedit_styles', plugins_url( 'assets/css/admin-post-edit.css', GRAVITYVIEW_FILE ), array(), GravityView_Plugin::version ); |
|
| 174 | 174 | wp_enqueue_style( 'gravityview_postedit_styles' ); |
| 175 | 175 | |
| 176 | - $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
| 176 | + $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
| 177 | 177 | |
| 178 | 178 | // custom js |
| 179 | - wp_register_script( 'gravityview_postedit_scripts', plugins_url('assets/js/admin-post-edit'.$script_debug.'.js', GRAVITYVIEW_FILE), array( 'jquery', 'jquery-ui-datepicker' ), GravityView_Plugin::version ); |
|
| 179 | + wp_register_script( 'gravityview_postedit_scripts', plugins_url( 'assets/js/admin-post-edit' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery', 'jquery-ui-datepicker' ), GravityView_Plugin::version ); |
|
| 180 | 180 | wp_enqueue_script( 'gravityview_postedit_scripts' ); |
| 181 | - wp_localize_script('gravityview_postedit_scripts', 'gvGlobals', array( |
|
| 182 | - 'nonce' => wp_create_nonce( 'gravityview_ajaxaddshortcode'), |
|
| 181 | + wp_localize_script( 'gravityview_postedit_scripts', 'gvGlobals', array( |
|
| 182 | + 'nonce' => wp_create_nonce( 'gravityview_ajaxaddshortcode' ), |
|
| 183 | 183 | 'loading_text' => esc_html__( 'Loading…', 'gravityview' ), |
| 184 | - 'alert_1' => esc_html__( 'Please select a View', 'gravityview'), |
|
| 185 | - )); |
|
| 184 | + 'alert_1' => esc_html__( 'Please select a View', 'gravityview' ), |
|
| 185 | + ) ); |
|
| 186 | 186 | |
| 187 | 187 | } |
| 188 | 188 | |
@@ -198,16 +198,16 @@ discard block |
||
| 198 | 198 | function get_sortable_fields() { |
| 199 | 199 | |
| 200 | 200 | // Not properly formatted request |
| 201 | - if ( empty( $_POST['viewid'] ) || !is_numeric( $_POST['viewid'] ) ) { |
|
| 201 | + if ( empty( $_POST[ 'viewid' ] ) || ! is_numeric( $_POST[ 'viewid' ] ) ) { |
|
| 202 | 202 | exit( false ); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Not valid request |
| 206 | - if( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajaxaddshortcode' ) ) { |
|
| 206 | + if ( empty( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxaddshortcode' ) ) { |
|
| 207 | 207 | exit( false ); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - $viewid = (int)$_POST['viewid']; |
|
| 210 | + $viewid = (int)$_POST[ 'viewid' ]; |
|
| 211 | 211 | |
| 212 | 212 | // fetch form id assigned to the view |
| 213 | 213 | $formid = gravityview_get_form_id( $viewid ); |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | /** @var WP_Admin_Bar $wp_admin_bar */ |
| 39 | 39 | global $wp_admin_bar; |
| 40 | 40 | |
| 41 | - if( is_admin() ) { |
|
| 41 | + if ( is_admin() ) { |
|
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | $view_data = GravityView_View_Data::getInstance()->get_views(); |
| 46 | 46 | |
| 47 | - if( empty( $view_data ) ) { |
|
| 47 | + if ( empty( $view_data ) ) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | 'parent' => 'gravityview', |
| 105 | 105 | 'title' => __( 'Edit Entry', 'gravityview' ), |
| 106 | 106 | 'meta' => array( |
| 107 | - 'title' => sprintf( __( 'Edit Entry %s', 'gravityview' ), GravityView_API::get_entry_slug( $entry['id'], $entry ) ), |
|
| 107 | + 'title' => sprintf( __( 'Edit Entry %s', 'gravityview' ), GravityView_API::get_entry_slug( $entry[ 'id' ], $entry ) ), |
|
| 108 | 108 | ), |
| 109 | - 'href' => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_entries&screen_mode=edit&view=entry&id=%d&lid=%d', $entry['form_id'], $entry['id'] ) ) ), |
|
| 109 | + 'href' => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_entries&screen_mode=edit&view=entry&id=%d&lid=%d', $entry[ 'form_id' ], $entry[ 'id' ] ) ) ), |
|
| 110 | 110 | ) ); |
| 111 | 111 | |
| 112 | 112 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | /** @var WP_Admin_Bar $wp_admin_bar */ |
| 123 | 123 | global $wp_admin_bar; |
| 124 | 124 | |
| 125 | - if( GVCommon::has_cap( array( 'edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms' ) ) ) { |
|
| 125 | + if ( GVCommon::has_cap( array( 'edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms' ) ) ) { |
|
| 126 | 126 | |
| 127 | 127 | $view_data = GravityView_View_Data::getInstance(); |
| 128 | 128 | |
@@ -139,32 +139,32 @@ discard block |
||
| 139 | 139 | $edit_view_title = __( 'Edit View', 'gravityview' ); |
| 140 | 140 | $edit_form_title = __( 'Edit Form', 'gravityview' ); |
| 141 | 141 | |
| 142 | - if( sizeof( $views ) > 1 ) { |
|
| 143 | - $edit_view_title = sprintf( _x( 'Edit View #%d', 'Edit View with the ID of %d', 'gravityview' ), $view['id'] ); |
|
| 144 | - $edit_form_title = sprintf( __( 'Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview' ), $view['form_id'] ); |
|
| 142 | + if ( sizeof( $views ) > 1 ) { |
|
| 143 | + $edit_view_title = sprintf( _x( 'Edit View #%d', 'Edit View with the ID of %d', 'gravityview' ), $view[ 'id' ] ); |
|
| 144 | + $edit_form_title = sprintf( __( 'Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview' ), $view[ 'form_id' ] ); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if( GVCommon::has_cap( 'edit_gravityview', $view['id'] ) && ! in_array( $view['id'], $added_views ) ) { |
|
| 147 | + if ( GVCommon::has_cap( 'edit_gravityview', $view[ 'id' ] ) && ! in_array( $view[ 'id' ], $added_views ) ) { |
|
| 148 | 148 | |
| 149 | - $added_views[] = $view['id']; |
|
| 149 | + $added_views[ ] = $view[ 'id' ]; |
|
| 150 | 150 | |
| 151 | 151 | $wp_admin_bar->add_menu( array( |
| 152 | - 'id' => 'edit-view-' . $view['id'], |
|
| 152 | + 'id' => 'edit-view-' . $view[ 'id' ], |
|
| 153 | 153 | 'parent' => 'gravityview', |
| 154 | 154 | 'title' => $edit_view_title, |
| 155 | - 'href' => esc_url_raw( admin_url( sprintf( 'post.php?post=%d&action=edit', $view['id'] ) ) ), |
|
| 155 | + 'href' => esc_url_raw( admin_url( sprintf( 'post.php?post=%d&action=edit', $view[ 'id' ] ) ) ), |
|
| 156 | 156 | ) ); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( ! empty( $view['form_id'] ) && GVCommon::has_cap( array( 'gravityforms_edit_forms' ), $view['form_id'] ) && ! in_array( $view['form_id'], $added_forms ) ) { |
|
| 159 | + if ( ! empty( $view[ 'form_id' ] ) && GVCommon::has_cap( array( 'gravityforms_edit_forms' ), $view[ 'form_id' ] ) && ! in_array( $view[ 'form_id' ], $added_forms ) ) { |
|
| 160 | 160 | |
| 161 | - $added_forms[] = $view['form_id']; |
|
| 161 | + $added_forms[ ] = $view[ 'form_id' ]; |
|
| 162 | 162 | |
| 163 | 163 | $wp_admin_bar->add_menu( array( |
| 164 | - 'id' => 'edit-form-' . $view['form_id'], |
|
| 164 | + 'id' => 'edit-form-' . $view[ 'form_id' ], |
|
| 165 | 165 | 'parent' => 'gravityview', |
| 166 | 166 | 'title' => $edit_form_title, |
| 167 | - 'href' => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $view['form_id'] ) ) ), |
|
| 167 | + 'href' => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $view[ 'form_id' ] ) ) ), |
|
| 168 | 168 | ) ); |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -36,7 +36,6 @@ |
||
| 36 | 36 | * @since 1.16.4 |
| 37 | 37 | * @since 1.17 Moved to GravityView_Plugin_Hooks_Gravity_Forms_Survey class |
| 38 | 38 | * |
| 39 | - * @param array $form |
|
| 40 | 39 | * |
| 41 | 40 | * @return array Form, with all fields set to `allowsPrepopulate => true` |
| 42 | 41 | */ |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | public function fix_survey_fields( $fields ) { |
| 44 | 44 | |
| 45 | 45 | /** @var GF_Field $field */ |
| 46 | - foreach( $fields as &$field ) { |
|
| 47 | - if( 'survey' === $field->type ) { |
|
| 46 | + foreach ( $fields as &$field ) { |
|
| 47 | + if ( 'survey' === $field->type ) { |
|
| 48 | 48 | $field->allowsPrepopulate = true; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | 62 | function add_render_hooks() { |
| 63 | - add_filter( 'gform_field_value', array( $this, 'fix_survey_field_value'), 10, 3 ); |
|
| 63 | + add_filter( 'gform_field_value', array( $this, 'fix_survey_field_value' ), 10, 3 ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | 75 | function remove_render_hooks() { |
| 76 | - remove_filter( 'gform_field_value', array( $this, 'fix_survey_field_value'), 10 ); |
|
| 76 | + remove_filter( 'gform_field_value', array( $this, 'fix_survey_field_value' ), 10 ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function fix_survey_field_value( $value, $field, $name ) { |
| 93 | 93 | |
| 94 | - if( 'survey' === $field->type ) { |
|
| 94 | + if ( 'survey' === $field->type ) { |
|
| 95 | 95 | |
| 96 | - $entry = GravityView_Edit_Entry::getInstance()->instances['render']->get_entry(); |
|
| 96 | + $entry = GravityView_Edit_Entry::getInstance()->instances[ 'render' ]->get_entry(); |
|
| 97 | 97 | |
| 98 | 98 | // We need to run through each survey row until we find a match for expected values |
| 99 | 99 | foreach ( $entry as $field_id => $field_value ) { |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 105 | + if ( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 106 | 106 | list( $row_val, $col_val ) = explode( ':', $field_value, 2 ); |
| 107 | 107 | |
| 108 | 108 | // If the $name matches the $row_val, we are processing the correct row |
| 109 | - if( $row_val === $name ) { |
|
| 109 | + if ( $row_val === $name ) { |
|
| 110 | 110 | $value = $field_value; |
| 111 | 111 | break; |
| 112 | 112 | } |
@@ -7,133 +7,133 @@ |
||
| 7 | 7 | |
| 8 | 8 | class GravityView_GFFormsModel extends GFFormsModel { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Given information provided in an entry, get array of media IDs |
|
| 12 | - * |
|
| 13 | - * This is necessary because GF doesn't expect to need to update post images, only to create them. |
|
| 14 | - * |
|
| 15 | - * @see GFFormsModel::create_post() |
|
| 16 | - * |
|
| 17 | - * @since 1.17 |
|
| 18 | - * |
|
| 19 | - * @param array $form Gravity Forms form array |
|
| 20 | - * @param array $entry Gravity Forms entry array |
|
| 21 | - * |
|
| 22 | - * @return array Array of "Field ID" => "Media IDs" |
|
| 23 | - */ |
|
| 24 | - public static function get_post_field_images( $form, $entry ) { |
|
| 25 | - |
|
| 26 | - $post_data = self::get_post_fields( $form, $entry ); |
|
| 27 | - |
|
| 28 | - $media = get_attached_media( 'image', $entry['post_id'] ); |
|
| 29 | - |
|
| 30 | - $post_images = array(); |
|
| 31 | - |
|
| 32 | - foreach ( $media as $media_item ) { |
|
| 33 | - foreach( (array) $post_data['images'] as $post_data_item ) { |
|
| 34 | - if( |
|
| 35 | - rgar( $post_data_item, 'title' ) === $media_item->post_title && |
|
| 36 | - rgar( $post_data_item, 'description' ) === $media_item->post_content && |
|
| 37 | - rgar( $post_data_item, 'caption' ) === $media_item->post_excerpt |
|
| 38 | - ) { |
|
| 39 | - $post_images["{$post_data_item['field_id']}"] = $media_item->ID; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return $post_images; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Alias of GFFormsModel::get_post_fields(); just making it public |
|
| 49 | - * |
|
| 50 | - * @see GFFormsModel::get_post_fields() |
|
| 51 | - * |
|
| 52 | - * @since 1.17 |
|
| 53 | - * |
|
| 54 | - * @param array $form Gravity Forms form array |
|
| 55 | - * @param array $entry Gravity Forms entry array |
|
| 56 | - * |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public static function get_post_fields( $form, $entry ) { |
|
| 60 | - |
|
| 61 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'get_post_fields' ); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * If the method changes to public, use Gravity Forms' method |
|
| 65 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 66 | - */ |
|
| 67 | - if( $reflection->isPublic() ) { |
|
| 68 | - return parent::get_post_fields( $form, $entry ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // It was private; let's make it public |
|
| 72 | - $reflection->setAccessible( true ); |
|
| 73 | - |
|
| 74 | - return $reflection->invoke( new GFFormsModel, $form, $entry ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
| 79 | - * |
|
| 80 | - * @since 1.16.2 |
|
| 81 | - * |
|
| 82 | - * @param string $url URL of the post image to update |
|
| 83 | - * @param int $post_id ID of the post image to update |
|
| 84 | - * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
| 85 | - */ |
|
| 86 | - public static function copy_post_image( $url, $post_id ) { |
|
| 87 | - |
|
| 88 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * If the method changes to public, use Gravity Forms' method |
|
| 92 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 93 | - */ |
|
| 94 | - if( $reflection->isPublic() ) { |
|
| 95 | - return parent::copy_post_image( $url, $post_id ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // It was private; let's make it public |
|
| 99 | - $reflection->setAccessible( true ); |
|
| 100 | - |
|
| 101 | - return $reflection->invoke( new GFFormsModel, $url, $post_id ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
| 106 | - * |
|
| 107 | - * Note: The method became public in GF 1.9.17.7 |
|
| 108 | - * |
|
| 109 | - * @see GFFormsModel::media_handle_upload |
|
| 110 | - * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
| 111 | - * |
|
| 112 | - * @uses copy_post_image |
|
| 113 | - * @uses wp_insert_attachment |
|
| 114 | - * @uses wp_update_attachment_metadata |
|
| 115 | - * |
|
| 116 | - * @param string $url URL of the post image to update |
|
| 117 | - * @param int $post_id ID of the post image to update |
|
| 118 | - * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
| 119 | - * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
| 120 | - */ |
|
| 121 | - public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
| 122 | - |
|
| 123 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * If the method changes to public, use Gravity Forms' method |
|
| 127 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 128 | - */ |
|
| 129 | - if( $reflection->isPublic() ) { |
|
| 130 | - return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // It was private; let's make it public |
|
| 134 | - $reflection->setAccessible( true ); |
|
| 135 | - |
|
| 136 | - return $reflection->invoke( new GFFormsModel, $url, $post_id, $post_data ); |
|
| 137 | - } |
|
| 10 | + /** |
|
| 11 | + * Given information provided in an entry, get array of media IDs |
|
| 12 | + * |
|
| 13 | + * This is necessary because GF doesn't expect to need to update post images, only to create them. |
|
| 14 | + * |
|
| 15 | + * @see GFFormsModel::create_post() |
|
| 16 | + * |
|
| 17 | + * @since 1.17 |
|
| 18 | + * |
|
| 19 | + * @param array $form Gravity Forms form array |
|
| 20 | + * @param array $entry Gravity Forms entry array |
|
| 21 | + * |
|
| 22 | + * @return array Array of "Field ID" => "Media IDs" |
|
| 23 | + */ |
|
| 24 | + public static function get_post_field_images( $form, $entry ) { |
|
| 25 | + |
|
| 26 | + $post_data = self::get_post_fields( $form, $entry ); |
|
| 27 | + |
|
| 28 | + $media = get_attached_media( 'image', $entry['post_id'] ); |
|
| 29 | + |
|
| 30 | + $post_images = array(); |
|
| 31 | + |
|
| 32 | + foreach ( $media as $media_item ) { |
|
| 33 | + foreach( (array) $post_data['images'] as $post_data_item ) { |
|
| 34 | + if( |
|
| 35 | + rgar( $post_data_item, 'title' ) === $media_item->post_title && |
|
| 36 | + rgar( $post_data_item, 'description' ) === $media_item->post_content && |
|
| 37 | + rgar( $post_data_item, 'caption' ) === $media_item->post_excerpt |
|
| 38 | + ) { |
|
| 39 | + $post_images["{$post_data_item['field_id']}"] = $media_item->ID; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return $post_images; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Alias of GFFormsModel::get_post_fields(); just making it public |
|
| 49 | + * |
|
| 50 | + * @see GFFormsModel::get_post_fields() |
|
| 51 | + * |
|
| 52 | + * @since 1.17 |
|
| 53 | + * |
|
| 54 | + * @param array $form Gravity Forms form array |
|
| 55 | + * @param array $entry Gravity Forms entry array |
|
| 56 | + * |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public static function get_post_fields( $form, $entry ) { |
|
| 60 | + |
|
| 61 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'get_post_fields' ); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * If the method changes to public, use Gravity Forms' method |
|
| 65 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 66 | + */ |
|
| 67 | + if( $reflection->isPublic() ) { |
|
| 68 | + return parent::get_post_fields( $form, $entry ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // It was private; let's make it public |
|
| 72 | + $reflection->setAccessible( true ); |
|
| 73 | + |
|
| 74 | + return $reflection->invoke( new GFFormsModel, $form, $entry ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
| 79 | + * |
|
| 80 | + * @since 1.16.2 |
|
| 81 | + * |
|
| 82 | + * @param string $url URL of the post image to update |
|
| 83 | + * @param int $post_id ID of the post image to update |
|
| 84 | + * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
| 85 | + */ |
|
| 86 | + public static function copy_post_image( $url, $post_id ) { |
|
| 87 | + |
|
| 88 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * If the method changes to public, use Gravity Forms' method |
|
| 92 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 93 | + */ |
|
| 94 | + if( $reflection->isPublic() ) { |
|
| 95 | + return parent::copy_post_image( $url, $post_id ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // It was private; let's make it public |
|
| 99 | + $reflection->setAccessible( true ); |
|
| 100 | + |
|
| 101 | + return $reflection->invoke( new GFFormsModel, $url, $post_id ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
| 106 | + * |
|
| 107 | + * Note: The method became public in GF 1.9.17.7 |
|
| 108 | + * |
|
| 109 | + * @see GFFormsModel::media_handle_upload |
|
| 110 | + * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
| 111 | + * |
|
| 112 | + * @uses copy_post_image |
|
| 113 | + * @uses wp_insert_attachment |
|
| 114 | + * @uses wp_update_attachment_metadata |
|
| 115 | + * |
|
| 116 | + * @param string $url URL of the post image to update |
|
| 117 | + * @param int $post_id ID of the post image to update |
|
| 118 | + * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
| 119 | + * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
| 120 | + */ |
|
| 121 | + public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
| 122 | + |
|
| 123 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * If the method changes to public, use Gravity Forms' method |
|
| 127 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 128 | + */ |
|
| 129 | + if( $reflection->isPublic() ) { |
|
| 130 | + return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // It was private; let's make it public |
|
| 134 | + $reflection->setAccessible( true ); |
|
| 135 | + |
|
| 136 | + return $reflection->invoke( new GFFormsModel, $url, $post_id, $post_data ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file |
@@ -25,18 +25,18 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | $post_data = self::get_post_fields( $form, $entry ); |
| 27 | 27 | |
| 28 | - $media = get_attached_media( 'image', $entry['post_id'] ); |
|
| 28 | + $media = get_attached_media( 'image', $entry[ 'post_id' ] ); |
|
| 29 | 29 | |
| 30 | 30 | $post_images = array(); |
| 31 | 31 | |
| 32 | 32 | foreach ( $media as $media_item ) { |
| 33 | - foreach( (array) $post_data['images'] as $post_data_item ) { |
|
| 34 | - if( |
|
| 33 | + foreach ( (array)$post_data[ 'images' ] as $post_data_item ) { |
|
| 34 | + if ( |
|
| 35 | 35 | rgar( $post_data_item, 'title' ) === $media_item->post_title && |
| 36 | 36 | rgar( $post_data_item, 'description' ) === $media_item->post_content && |
| 37 | 37 | rgar( $post_data_item, 'caption' ) === $media_item->post_excerpt |
| 38 | 38 | ) { |
| 39 | - $post_images["{$post_data_item['field_id']}"] = $media_item->ID; |
|
| 39 | + $post_images[ "{$post_data_item[ 'field_id' ]}" ] = $media_item->ID; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * If the method changes to public, use Gravity Forms' method |
| 65 | 65 | * @todo: If/when the method is public, remove the unneeded copied code. |
| 66 | 66 | */ |
| 67 | - if( $reflection->isPublic() ) { |
|
| 67 | + if ( $reflection->isPublic() ) { |
|
| 68 | 68 | return parent::get_post_fields( $form, $entry ); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * If the method changes to public, use Gravity Forms' method |
| 92 | 92 | * @todo: If/when the method is public, remove the unneeded copied code. |
| 93 | 93 | */ |
| 94 | - if( $reflection->isPublic() ) { |
|
| 94 | + if ( $reflection->isPublic() ) { |
|
| 95 | 95 | return parent::copy_post_image( $url, $post_id ); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * If the method changes to public, use Gravity Forms' method |
| 127 | 127 | * @todo: If/when the method is public, remove the unneeded copied code. |
| 128 | 128 | */ |
| 129 | - if( $reflection->isPublic() ) { |
|
| 129 | + if ( $reflection->isPublic() ) { |
|
| 130 | 130 | return parent::media_handle_upload( $url, $post_id, $post_data ); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | function edit_entry_fix_hidden_fields( $fields ) { |
| 48 | 48 | |
| 49 | 49 | /** @var GF_Field $field */ |
| 50 | - foreach( $fields as &$field ) { |
|
| 50 | + foreach ( $fields as &$field ) { |
|
| 51 | 51 | if ( 'hidden' === $field->type ) { |
| 52 | 52 | |
| 53 | 53 | // Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | 32 | private function add_hooks() { |
| 33 | - add_filter( 'gravityview/edit_entry/field_value_post_custom_field', array( $this, 'edit_entry_field_value'), 10, 2 ); |
|
| 33 | + add_filter( 'gravityview/edit_entry/field_value_post_custom_field', array( $this, 'edit_entry_field_value' ), 10, 2 ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function edit_entry_field_value( $field_value, $field ) { |
| 47 | 47 | |
| 48 | - if( 'list' === $field->inputType ) { |
|
| 48 | + if ( 'list' === $field->inputType ) { |
|
| 49 | 49 | $field_value = is_string( $field_value ) ? json_decode( $field_value, true ) : $field_value; |
| 50 | 50 | |
| 51 | 51 | if ( ! is_array( $field_value ) ) { |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | var $name = 'post_category'; |
| 11 | 11 | |
| 12 | - var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
| 12 | + var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' ); |
|
| 13 | 13 | |
| 14 | 14 | var $_gf_field_class_name = 'GF_Field_Post_Category'; |
| 15 | 15 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $entry = GFAPI::get_entry( $entry_id ); |
| 43 | 43 | $post_id = rgar( $entry, 'post_id' ); |
| 44 | 44 | |
| 45 | - if( empty( $post_id ) ) { |
|
| 45 | + if ( empty( $post_id ) ) { |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | $post_category_fields = GFAPI::get_fields_by_type( $form, 'post_category' ); |
| 52 | 52 | |
| 53 | - if( $post_category_fields ) { |
|
| 53 | + if ( $post_category_fields ) { |
|
| 54 | 54 | |
| 55 | 55 | $updated_categories = array(); |
| 56 | 56 | |
@@ -117,18 +117,18 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return mixed |
| 119 | 119 | */ |
| 120 | - function edit_entry_post_category_choices( $choices, $field, $form_id ) { |
|
| 120 | + function edit_entry_post_category_choices( $choices, $field, $form_id ) { |
|
| 121 | 121 | |
| 122 | - $entry = GravityView_Edit_Entry::getInstance()->instances['render']->get_entry(); |
|
| 122 | + $entry = GravityView_Edit_Entry::getInstance()->instances[ 'render' ]->get_entry(); |
|
| 123 | 123 | |
| 124 | 124 | // $entry['post_id'] should always be set, but we check to make sure. |
| 125 | - if( $entry && isset( $entry['post_id'] ) && $post_id = $entry['post_id'] ) { |
|
| 125 | + if ( $entry && isset( $entry[ 'post_id' ] ) && $post_id = $entry[ 'post_id' ] ) { |
|
| 126 | 126 | |
| 127 | 127 | $post_categories = wp_get_post_categories( $post_id, array( 'fields' => 'ids' ) ); |
| 128 | 128 | |
| 129 | 129 | // Always use the live value |
| 130 | 130 | foreach ( $choices as &$choice ) { |
| 131 | - $choice['isSelected'] = in_array( $choice['value'], array_values( $post_categories ) ); |
|
| 131 | + $choice[ 'isSelected' ] = in_array( $choice[ 'value' ], array_values( $post_categories ) ); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -137,12 +137,12 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 139 | 139 | |
| 140 | - if( 'edit' === $context ) { |
|
| 140 | + if ( 'edit' === $context ) { |
|
| 141 | 141 | return $field_options; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $this->add_field_support('dynamic_data', $field_options ); |
|
| 145 | - $this->add_field_support('link_to_term', $field_options ); |
|
| 144 | + $this->add_field_support( 'dynamic_data', $field_options ); |
|
| 145 | + $this->add_field_support( 'link_to_term', $field_options ); |
|
| 146 | 146 | |
| 147 | 147 | return $field_options; |
| 148 | 148 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | var $name = 'checkbox'; |
| 11 | 11 | |
| 12 | - var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
| 12 | + var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' ); |
|
| 13 | 13 | |
| 14 | 14 | var $_gf_field_class_name = 'GF_Field_Checkbox'; |
| 15 | 15 | |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | $field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type ); |
| 40 | 40 | |
| 41 | 41 | // It's not the parent field; it's an input |
| 42 | - if( floor( $field_id ) !== floatval( $field_id ) ) { |
|
| 42 | + if ( floor( $field_id ) !== floatval( $field_id ) ) { |
|
| 43 | 43 | |
| 44 | - if( $this->is_choice_value_enabled() ) { |
|
| 44 | + if ( $this->is_choice_value_enabled() ) { |
|
| 45 | 45 | |
| 46 | 46 | $desc = esc_html__( 'This input has a label and a value. What should be displayed?', 'gravityview' ); |
| 47 | 47 | $default = 'value'; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $field_options['choice_display'] = array( |
|
| 62 | + $field_options[ 'choice_display' ] = array( |
|
| 63 | 63 | 'type' => 'radio', |
| 64 | 64 | 'class' => 'vertical', |
| 65 | 65 | 'label' => __( 'What should be displayed:', 'gravityview' ), |