Created
September 13, 2022 10:06
-
-
Save adczk/66088f0503e4e57e6cc980d04e131f28 to your computer and use it in GitHub Desktop.
Forminator - custom logo/image upload and shortcode display on multisite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* tested with Forminator 1.18 | |
| use as MU plugin */ | |
| add_shortcode('custom-site-logo', 'my_custom_site_logo' ); | |
| function my_custom_site_logo() { | |
| $logo_url = get_option( 'frmt_site_custom_logo' ); | |
| $html = '<img class="fl-photo-img size-full frmt-custom-logo" src="' . $logo_url . '"itemprop="image" height="68" width="300">'; | |
| return $html; | |
| } | |
| # get uploaded logo URL and site ID | |
| # and save them in subsites _options table | |
| add_action( 'forminator_custom_form_submit_before_set_fields', 'my_custom_logo_setfile', 10, 3 ); | |
| function my_custom_logo_setfile( $entry, $form_id, $fields_data ) { | |
| $site_id = 'hidden-1'; // set ID of hidden field for site ID here | |
| $upload_form_id = 1245; // set ID of the form here | |
| $upload_field = 'upload-1'; // set ID of upload field | |
| ######################### | |
| if ( $form_id<>$upload_form_id ) { | |
| return; | |
| } | |
| // get site ID and URL from form | |
| $blog_id = 0; | |
| $logo_url = ''; | |
| foreach ( $fields_data as $field_data ) { | |
| if ( $field_data['name'] == $site_id ) { | |
| $blog_id = $field_data['value']; | |
| } | |
| if ( $field_data['name'] == $upload_field ) { | |
| $logo_url = $field_data['value']['file']['file_url']; | |
| } | |
| } | |
| // if site ID set: get file URL, switch to blog, save option, switch back | |
| if ($blog_id > 0) { | |
| if ( is_multisite() ) { | |
| switch_to_blog( $blog_id ); | |
| } | |
| // set option | |
| update_option( 'frmt_site_custom_logo', $logo_url, false); | |
| if ( is_multisite() ) { | |
| restore_current_blog(); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment