Last active
February 15, 2019 15:35
-
-
Save kasparsd/a33023c58b85796ee9808a0ac9689225 to your computer and use it in GitHub Desktop.
Must-use plugin for WordPress plugin and theme demo sites
This file contains 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
#!/usr/bin/env bash | |
# Dump specific DB tables to a file. | |
mysqldump -u sqluser dbname wp_posts wp_postmeta > dump.sql |
This file contains 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
#!/usr/bin/env bash | |
# Replace certain DB tables with pre-defined content. Call every hour via cron. | |
mysql -u root dbname < dump.sql |
This file contains 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 | |
/** | |
* A very basic set of helpers for creating locked-down WP sites. | |
*/ | |
// Auto login demo user. | |
add_action( 'plugins_loaded', function() { | |
if ( is_admin() && ! is_user_logged_in() ) { | |
$user = get_user_by( 'login', 'demo' ); | |
$redirect_url = $_SERVER['REQUEST_URI']; | |
if ( isset( $user->ID ) ) { | |
wp_set_current_user( $user->ID, $user->user_login ); | |
wp_set_auth_cookie( $user->ID ); | |
do_action( 'wp_login', $user->user_login, $user ); | |
wp_safe_redirect( $redirect_url ); | |
exit; | |
} | |
} | |
} ); | |
add_filter( 'user_has_cap', function( $allcaps ) { | |
$allow_caps = array_fill_keys( [ | |
'wpcf7_read_contact_forms', | |
'wpcf7_edit_contact_forms', | |
'wpcf7_edit_contact_form', | |
], true ); | |
return array_merge( $allcaps, $allow_caps ); | |
} ); | |
// Limit user capabilities to only certain things. | |
add_filter( 'map_meta_cap', function( $caps, $cap, $user_id, $args ) { | |
$user = get_user_by( 'id', $user_id ); | |
$allow_caps = array( | |
'wpcf7_read_contact_forms', | |
'wpcf7_edit_contact_forms', | |
'wpcf7_edit_contact_form', | |
); | |
if ( ! in_array( 'administrator', $user->roles ) ) { | |
if ( in_array( $cap, $allow_caps, true ) ) { | |
return array( $cap ); | |
} | |
return array( 'do_not_allow' ); | |
} | |
return $caps; | |
}, 9876, 4 ); | |
add_action( 'admin_notices', function() { | |
$url = 'https://preseto.com/go/cf7-storage?utm_source=demo_notice'; | |
?> | |
<div class="notice notice-warning"> | |
<p> | |
This is a demo of the <a href="<?php echo esc_url( $url ) ?>">Storage for Contact Form 7 plugin</a>. | |
<a href="<?php echo esc_url( $url ) ?>" class="button button-primary">Buy Now</a> | |
</p> | |
</div> | |
<?php | |
} ); | |
add_action( 'wp_head', 'preseto_track' ); | |
add_action( 'admin_head', 'preseto_track' ); | |
function preseto_track() { | |
// Output tracking scripts. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment