Skip to content

Instantly share code, notes, and snippets.

@bogdan-mainwp
Created April 11, 2023 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan-mainwp/54adc8d69b845125ae045fe227443a1b to your computer and use it in GitHub Desktop.
Save bogdan-mainwp/54adc8d69b845125ae045fe227443a1b to your computer and use it in GitHub Desktop.
Snippet exapmle for creating a custom field in the edit site form
add_action( 'mainwp_manage_sites_edit', 'myhook_mainwp_manage_sites_edit', 10, 1 );
function myhook_mainwp_manage_sites_edit( $website ) {
$myvalue = apply_filters( 'mainwp_getwebsiteoptions', false, $website, 'my_site_value' );
?>
<div class="ui grid field">
<label class="six wide column middle aligned"><?php esc_html_e( 'My Value', 'mainwp' ); ?></label>
<div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'My Value', 'mainwp' ); ?>" data-inverted="" data-position="top left">
<div class="ui left labeled input">
<input type="text" id="mainwp_managesites_edit_my_value" name="mainwp_managesites_edit_my_value" value="<?php echo esc_html($myvalue); ?>"/>
</div>
</div>
</div>
<?php
}
add_action( 'mainwp_update_site', 'myhook_mainwp_update_site', 10, 1 );
function myhook_mainwp_update_site( $site_id ) {
$myvalue = isset( $_POST['mainwp_managesites_edit_my_value'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_managesites_edit_my_value'] ) ) : '';
apply_filters( 'mainwp_updatewebsiteoptions', false, $site_id, 'my_site_value', $myvalue );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment