Skip to content

Instantly share code, notes, and snippets.

@svenl77
svenl77 / tgm-plugin-activation.php
Last active December 3, 2016 11:20
No function names needed to add TGM
<?php
//
// Check the plugin dependencies
//
add_action('init', function(){
// Only Check for requirements in the admin
if(!is_admin()){
return;
@svenl77
svenl77 / set_post_thumbnail_multisite.php
Last active October 30, 2016 08:31
Copy a featured image from current site to blog in the network
<?php
// Let us make sure we are on the curent site.
restore_current_blog();
// get the image src
$image_url = wp_get_attachment_image_src( $_POST['featured_image'], 'full' );
$image_url = $image_url[0];
// Now let us switch to the Blog we like to set the featured image
@svenl77
svenl77 / functions.php
Last active October 20, 2016 13:45 — forked from bamadesigner/functions.php
WordPress Multsite - wp_get_post_featured_image_src() - Get wp_get_attachment_image_src() data for any post's featured image on your network
<?php
/**
* This function allows you to retrieve the wp_get_attachment_image_src()
* data for any post's featured image on your network. If you are running
* a multisite network, you can supply another blog's ID to retrieve a post's
* featured image data from another site on your WordPress multisite network.
*
* Does not take care of icon business (at this time).
*
<?php
/**
* Check if a contributor have the needed rights to upload images and add this capabilities if needed.
*/
add_action('init', 'buddyforms_allow_contributor_uploads');
function buddyforms_allow_contributor_uploads() {
if ( current_user_can('contributor') && !current_user_can('upload_files') ){
$contributor = get_role('contributor');
<?php
/**
* Function we use to add a extra class to all BuddyForms related metaboxes.
*/
function buddyforms_metabox_class($classes) {
$classes[] = 'buddyforms-metabox';
return $classes;
}
/**
<?php
//
// Add the Tab Content
//
add_action( 'buddyforms_settings_page_tab', 'my_buddyforms_settings_page_tab' );
function my_buddyforms_settings_page_tab(){
?>
<div class="metabox-holder">
<div class="postbox">
<?php
//----------AFTER THE FORM HAS BEEN SUBMITTED----------
include("PFBC/Form.php");
if(!Form::isValid("<replace with unique form identifier>")) {
/* Validation errors have been found. We now need to redirect users back to the
form back so the errors can be corrected and the form can be re-submitted.
In case of ajax submit Form::renderAjaxErrorResponse () will build an error reply.*/
if ($reqIs("AJAX")) {
header ("Content-type: application/json");
<?php
Form::open ("test", $values, ["ajax" => "finishCallback"]);
Form::hidden ("id");
From::Button ("Submit");
Form::close ();
?>
<script>
function finishCallback (data) {
console.log (data.status);
console.log (data.message);
<?php
// SideBySide View
// Default library view type. form-horizonal bootstrap form layout.
Form::open ("test1", $values)
//Inline View
// form-inline bootstrap form layout.
Form::open ("test1", $values, "view" = "Inline")
// Vertical View
<?php
// Generates a hidden input element
Form::Hidden ("id", $attributes = null);
//Textbox
Form::Textbox ("Text", "text", $attributes = null);
// Number
Form::Number("Number", "Number", $attributes = null);