Advertisement
Guest User

Untitled

a guest
Jan 7th, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: JKWS Webhost Information for MainWP
  4.  * Description: Adds the Webhost field to child sites.
  5.  * Version: 0.9.2
  6.  * Author: Jos Klever
  7.  * Author URI: https://joskleverwebsupport.nl
  8.  * Plugin URI: https://github.com/josklever/mainwp-jkws-webhost-information
  9.  *
  10.  * RequiresPlugins: mainwp
  11.  *
  12.  * License: GPL3
  13.  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
  14.  *
  15.  * GitHub Plugin URI: https://github.com/josklever/mainwp-jkws-webhost-information
  16.  * Primary Branch: main
  17.  */
  18.  
  19. // Exit if accessed directly.
  20. defined( 'ABSPATH' ) || exit;
  21.  
  22. // Add the Webhost field to the Edit page of a single site
  23. add_action( 'mainwp_manage_sites_edit', 'jkws_mainwp_manage_sites_edit', 10, 1 );
  24. function jkws_mainwp_manage_sites_edit( $website ) {
  25.     $webhost  = apply_filters( 'mainwp_getwebsiteoptions', false, $website, 'webhost' );
  26.     ?>
  27.     <h3 class="ui dividing header">Additional information (Optional)</h3>
  28.     <div class="ui grid field">
  29.         <label class="six wide column middle aligned"><?php esc_html_e( 'Webhost', 'mainwp' ); ?></label>
  30.         <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Webhost', 'mainwp' ); ?>" data-inverted="" data-position="top left">
  31.             <div class="ui left labeled input">
  32.                 <input type="text" id="mainwp_managesites_edit_webhost" name="mainwp_managesites_edit_webhost" value="<?php echo esc_html($webhost); ?>"/>
  33.             </div>
  34.         </div>
  35.     </div>
  36.     <?php
  37. }
  38.  
  39. //  Update the Webhost field in the database of the added new site
  40. add_action( 'mainwp_added_new_site', 'jkws_mainwp_update_site', 10, 1 );
  41. //  Update the Webhost field in the database of the edited site
  42. add_action( 'mainwp_update_site', 'jkws_mainwp_update_site', 10, 1 );
  43. function jkws_mainwp_update_site( $site_id ) {
  44.     $webhost = isset( $_POST['mainwp_managesites_edit_webhost'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_managesites_edit_webhost'] ) ) : '';
  45.     apply_filters( 'mainwp_updatewebsiteoptions', false, $site_id, 'webhost', $webhost );  
  46. }
  47.  
  48. //Add the Webhost column to the Sites Overview page
  49. add_filter( 'mainwp_sitestable_getcolumns', 'jkws_mainwp_sitestable_getcolumns', 10, 1 );
  50. function jkws_mainwp_sitestable_getcolumns( $columns ) {
  51.     $columns['webhost'] = "Webhost";
  52.     return $columns;
  53. }
  54. add_filter( 'mainwp-sitestable-item', 'jkws_sitestable_item', 10 );
  55. function jkws_sitestable_item( $item ) {
  56.      $webhost = apply_filters( 'mainwp_getwebsiteoptions', array(), $item['id'], 'webhost' );
  57.      if ( isset( $webhost ) ) {
  58.           $item[ 'webhost' ] = $webhost;
  59.      } else {
  60.           $item[ 'webhost' ] = '';
  61.      }
  62.      return $item;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement