Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bogdan-mainwp's full-sized avatar

Bogdan Rapaić bogdan-mainwp

View GitHub Profile
@bogdan-mainwp
bogdan-mainwp / mainwp-hello-world-extension.php
Created September 11, 2023 16:37
Basic MainWP one-page extension demo
<?php
/**
* Plugin Name: MainWP Hello World Extension
* Plugin URI: https://yourwebsiteurl.com
* Description: MainWP Hello World Extension is used for the demo.
* Version: 1.0
* Author: Your Name
* Author URI: https://yourwebsiteurl.com
*/
@bogdan-mainwp
bogdan-mainwp / mainwp-custom-edit-site-field.php
Created April 11, 2023 16:48
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>
@bogdan-mainwp
bogdan-mainwp / show-full-comment-content.php
Created April 20, 2020 11:12
Filter to display custom comment lenght in the MainWP Comments extension
<?php
// Add the following code snippet to the PHP section of the MainWP Custom Dashboard Extension,
// or the functions.php file of the active theme on your Dashboard site.
add_filter( 'mainwp_comments_widget_limit_string', 'mycustom_mainwp_comments_widget_limit_string', 10, 1 );
function mycustom_mainwp_comments_widget_limit_string( $length = false ) {
return 99999;
}
@bogdan-mainwp
bogdan-mainwp / hide-custom-branding.php
Created October 3, 2019 17:00
Hide custom branding for certain user
<?php
// Hide custom branidng for the user with specific ID
// Replace ID with actual ID number
add_filter( 'mainwp_child_branding_init_options', 'mycustom_mainwp_child_branding_init_options' );
function mycustom_mainwp_child_branding_init_options( $option ) {       
$current_user_id = get_current_user_id();       
if ( $current_user_id == 'ID' && is_array( $option ) && isset( $option[ 'cancelled_branding' ] ) ) {        
$option[ 'cancelled_branding' ] = true;    
@bogdan-mainwp
bogdan-mainwp / premium-plugin-updates.php
Last active May 14, 2020 01:36
Support for the Premium Plugin updates
<?php
// Add the following code snippet to the PHP section of the MainWP Custom Dashboard Extension or the functions.php file of the active theme on your Dashboard site.
add_filter( 'mainwp_detect_premium_plugins_update', 'myhook_mainwp_detect_premium_plugins_update', 10 );
function myhook_mainwp_detect_premium_plugins_update( $premiums ) {
// add plugin info (slug) here. In this example, we used Elementor Extras, but you should replace it with the correct plugin info
$premiums[] = 'elementor-extras/elementor-extras.php';
return $premiums;
}
@bogdan-mainwp
bogdan-mainwp / code-snippets-customizations.php
Created March 8, 2019 09:52
Custom code snippet to change code editor height and background color for the Code Snippets extension.
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
add_filter( 'mainwp_codesnippets_editor_attr', 'myhook_mainwp_codesnippets_editor_attr', 10);
function myhook_mainwp_codesnippets_editor_attr( $data ) {
$data['height'] = 500;
// supported themes: 'erlang-dark', 'night', 'xq-dark', 'xq-light', 'the-matrix', 'eclipse'
@bogdan-mainwp
bogdan-mainwp / disable-referral-in-google-analytics.php
Created December 6, 2018 13:55
Custom snippet for disabling referral in Google Analytics
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
add_filter( 'mainwp_open_hide_referrer', 'myhook_mainwp_open_hide_referrer');
function myhook_mainwp_open_hide_referrer() {
return true;
}
@bogdan-mainwp
bogdan-mainwp / purge-sg-optimizer-cache.php
Created December 6, 2018 13:09
Custom code snippet for clearing SG Optimizer cache on child sites
<?php
// Use this snippet in the MainWP Code Snippets Extension (https://mainwp.com/extension/code-snippets/)
// Snippet Type: This Code Snippet only returns information from Child Site
if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
sg_cachepress_purge_cache();
echo "Cache cleared successfully!";
} else {
echo "Clearing cache failed!";
@bogdan-mainwp
bogdan-mainwp / custom-mainwp-menu-header.php
Last active December 6, 2018 14:00
Custom snippet for renaming the MainWP Dashboard WP Admin menu header
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
add_action( 'admin_head', 'mycustom_menu_admin_head' );
function mycustom_menu_admin_head() {
global $menu;
foreach( $menu as &$item ) {
@bogdan-mainwp
bogdan-mainwp / specific-time-for-emails.php
Last active April 16, 2020 11:56
Set specific time for email notifications about Trusted Updates
<?php
// Add the following code snippet to the PHP section in the MainWP Custom Dashbaord plugin
add_filter( 'mainwp_updatescheck_sendmail_at_time', 'mycustom_mainwp_updatescheck_sendmail_at_time', 10, 1 );
function myhook_mainwp_updatescheck_sendmail_at_time( $hour ) {
$hour = '12:00'; // send email notifactions after 12:00
return $hour;
}