Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
Hitting keys

Andrei Lupu andreilupu

⌨️
Hitting keys
View GitHub Profile
@andreilupu
andreilupu / How to send a POST request from WordPress admin Dashboard – JS
Last active Apr 6, 2018
How to send a POST request from WordPress admin Dashboard
View How to send a POST request from WordPress admin Dashboard – JS
(function(){
var request = wp.ajax.post('custom_action', {param1: 'uppercase this string pls'});
// on success
request.done( function ( res ) {
console.log( res );
});
// on fail
@andreilupu
andreilupu / tinymce.plugin.example.js
Last active Dec 25, 2020
TinyMCE Plugin Example
View tinymce.plugin.example.js
(function () {
/**
* A TinyMCE plugin example and some events handlings.
*/
tinymce.PluginManager.add('gridable', function ( editor, url ) {
// if your plugin needs a toolbar, save it for a larger scope
var toolbar;
/**
@andreilupu
andreilupu / WordPress Paginated API results
Last active Oct 26, 2016
How to loop the API results which are paginated
View WordPress Paginated API results
<?php
/**
* Let's imagine that we need the issues number from an github organization
* The issues API results are limited to 100 per page so we need to call this recursively
* $offset (int) = the number of pages to skip for the current request
*/
function request_issues_number( $offset = 0 ) {
$page = 1;
if ( ! empty( $offset ) ) {
@andreilupu
andreilupu / pixcare-auto-installer.php
Last active Feb 22, 2017
PixCare auto-installer from theme
View pixcare-auto-installer.php
<?php
/**
* A WordPress theme script which redirects the admin user, after the first theme activation, on a page where
* it forces a plugin installation, in this case, the Pixelgrade Care plugin.
*
* Inspired from
* WooCommerce - https://github.com/woocommerce/woocommerce
* Envato WordPress Theme Setup Wizard - https://github.com/dtbaker/envato-wp-theme-setup-wizard
* Shiny Updates V3 - https://make.wordpress.org/core/2016/07/06/shiny-updates-in-4-6/
*
@andreilupu
andreilupu / fix_featured_listings_meta.php
Created Jan 12, 2017
This code should be runned only once
View fix_featured_listings_meta.php
View gridable_editable_attributes.php
<?php
add_filter( 'gridable_row_options', function ( $options ) {
$options['bg_color'] = array(
'type' => 'color',
'label' => 'Row Background Color',
'default' => 'transparent'
);
View customify_conditional_fields.php
<?php
/**
* This shows how the field visibility can be changed conditionally between fields values
**/
function example_add_customify_fold_example_options( $options ) {
$folding_examples_section = array(
'folding_section' => array(
'title' => esc_html__( 'Folding', 'example' ),
'options' => array(
@andreilupu
andreilupu / wp_disable_jquery_warnings.php
Created May 7, 2017
Add this file in the `/wp-content/mu-plugins/` directory in it will automatically be loaded by WordPress
View wp_disable_jquery_warnings.php
<?php
function disable_jquerymigrate_warning( $scripts ) {
if ( ! empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) );
}
}
add_action( 'wp_default_scripts', 'disable_jquerymigrate_warning' );
@andreilupu
andreilupu / replace-textdomain.sh
Created Jan 25, 2018
A fast bash script to replace all the 'textdomain' strings, from vendor, with the ones provided in `package.json`
View replace-textdomain.sh
#!/bin/bash
#get the textdomain from the package.json file.
#export TEXTDOMAIN
TEXTDOMAIN=$(node -pe "require('./package.json').textdomain")
# if there is a textdomain, apply to the vendor folder.
if [ "$TEXTDOMAIN" != "undefined" ]; then
find "vendor" -type f -name "**.php" -exec sed -i "s/, 'textdomain' )/, '$TEXTDOMAIN' )/g" {} +
fi;