id_base . '[' . $widget->number . '][acf]'; // get id if ( $widget->number !== '__i__' ) { $post_id = "widget_{$widget->id}"; } // get field groups $field_groups = acf_get_field_groups( array( 'widget' => $widget->id_base, ) ); // render if ( ! empty( $field_groups ) ) { // render post data acf_form_data( array( 'screen' => 'widget', 'post_id' => $post_id, 'widget_id' => 'widget-' . $widget->id_base, 'widget_number' => $widget->number, 'widget_prefix' => $prefix, ) ); // wrap echo '
'; // loop foreach ( $field_groups as $field_group ) { // load fields $fields = acf_get_fields( $field_group ); // bail if not fields if ( empty( $fields ) ) { continue; } // change prefix acf_prefix_fields( $fields, $prefix ); // render acf_render_fields( $fields, $post_id, 'div', $field_group['instruction_placement'], $this->get_render_args( $widget ) ); } // wrap echo '
'; // jQuery selector looks odd, but is necessary due to WP adding an incremental number into the ID // - not possible to find number via PHP parameters if ( $widget->updated ) : ?> id}", $this->filter_values( $new_instance['acf'], $new_instance['_acf_fields'] ?? array(), $widget->id_base, "widget_{$widget->id}" ) ); // return return $instance; } /** * Returns the render ID widget fields are rendered for. * * Widgets are rendered for their widget type rather than their number: the widgets screen renames * the `__i__` template, and the block widget editor renders forms with temporary numbers. Location * rules only depend on the widget type, so a list from one widget accepted on another of the same * type grants nothing. * * @since 6.8.11 * * @param string $id_base The widget type. * @return string */ public static function get_render_id( $id_base ) { return 'widget/' . $id_base; } /** * Returns the args widget fields are rendered with. The list is submitted with the widget's * instance, alongside its values. * * @since 6.8.11 * * @param WP_Widget $widget The widget. * @return array */ private function get_render_args( $widget ) { return array( 'render_id' => self::get_render_id( $widget->id_base ), 'prefix' => 'widget-' . $widget->id_base . '[' . $widget->number . '][acf]', 'list_name' => 'widget-' . $widget->id_base . '[' . $widget->number . '][_acf_fields]', ); } /** * Returns a widget's submitted values restricted to the fields rendered for its widget type, * or belonging to field groups located on it. * * @since 6.8.11 * * @param mixed $values The submitted values. * @param mixed $lists The submitted field lists, keyed by render ID. * @param string $id_base The widget type. * @param string $post_id The widget's ACF post ID (`widget_{id_base}-{number}`). * @return array */ public function filter_values( $values, $lists, $id_base, $post_id ) { return acf_filter_save_values( $values, array( 'context' => 'widget', 'post_id' => $post_id, 'render_ids' => array( self::get_render_id( $id_base ) ), 'lists' => is_array( $lists ) ? $lists : array(), 'screen' => array( 'widget' => $id_base ), ) ); } /** * This function will add some custom HTML to the footer of the edit page * * @type function * @date 11/06/2014 * @since 5.0.0 * * @param n/a * @return n/a */ function admin_footer() { ?>