Skip to content

Instantly share code, notes, and snippets.

View itzikbenh's full-sized avatar

Isaac Ben Hutta itzikbenh

View GitHub Profile
@itzikbenh
itzikbenh / button.php
Last active January 9, 2020 20:35
guide
<button class="delete-post" id="<?php echo $post->ID ?>" type="button" name="button">
Delete Post
</button>
@itzikbenh
itzikbenh / functions.php
Created August 22, 2018 02:34
WP - update user and keeps him login with ability to make more requests without page refresh.
<?php
function my_update_cookie( $logged_in_cookie ) {
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
}
add_action( 'set_logged_in_cookie', 'my_update_cookie' );
wp_localize_script(
'theme_js',
'theme_data',
@itzikbenh
itzikbenh / a-theme-auth.php
Last active January 9, 2020 20:17
WordPress class for registering users via Linkedin
<?php
function a_theme_auth_options_page()
{
add_options_page( "A-Theme Auth options", "A-Theme Auth", "manage_options", "a-theme-auth", "a_theme_auth_options" );
}
add_action( 'admin_menu', 'a_theme_auth_options_page' );
function register_a_theme_auth_settings()
{
@itzikbenh
itzikbenh / admin.js
Created August 26, 2017 23:14
Category Image
$('#update-cat-featured-img, #add-cat-featured-img').click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Featured Image',
button: {
text: 'Insert image'
},
multiple: false // Set this to "add" to allow multiple files to be selected
})
@itzikbenh
itzikbenh / exampleOne.php
Last active January 9, 2020 20:12
Datatables Sample
<?php
function athdata_get_companies( WP_REST_Request $request ) {
$draw = $request['draw'];
$start = $request['start']; //Start is the offset
$length = $request['length']; //How many records to show
$column = $request['order'][0]['column']; //Column to orderBy
$dir = $request['order'][0]['dir']; //Direction of orderBy
$searchValue = $request['search']['value']; //Text search value
$args = [
@itzikbenh
itzikbenh / main.php
Last active January 9, 2020 20:11
WordPress API login
<?php
//Register login route
//Test in postman with - www.yourdomain.com/wp-json/login-user/v1/user
function uab_register_endpoints()
{
register_rest_route('login-user/v1', '/user/', array(
'methods' => 'POST',
'callback' => 'uab_login_user'
));
@itzikbenh
itzikbenh / event.php
Last active January 9, 2020 20:11
Custom taxonomy
<?php
function ath_register_event_taxonomies()
{
$ath_taxonomy = new Ath_Taxonomy();
$ath_taxonomy->create_hierarchical_taxonomy( "event", "event_category", "Event Categories", "Event Category", "event-category" );
$ath_taxonomy->create_taxonomy( "event", "event_tag", "Event Tags", "Event Tag", "event-tag" );
}
add_action( 'init', 'ath_register_event_taxonomies' );
@itzikbenh
itzikbenh / contact.js
Last active January 9, 2020 20:11
WordPress contact form using the API
(function($) {
$(".submit-contact-form").on("click", function(e) {
e.preventDefault();
$.ajax({
url: theme_data.site_url + 'wp-json/send-contact-form/v1/contact',
method: 'POST',
data: data
}).done(function(data){
@itzikbenh
itzikbenh / rm_mysql.md
Created December 20, 2019 21:43 — forked from vitorbritto/rm_mysql.md
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

brew remove mysql

@itzikbenh
itzikbenh / ReadMore.vue
Last active September 22, 2019 12:04
Vue Read More Component
<template>
<div v-if="text">
<div v-html="formattedText"></div>
<span v-if="text.length > maxChars">
<a href="#" v-if="!isReadMore" @click.prevent="triggerReadMore()">{{ readMoreText }}</a>
<a href="#" v-if="isReadMore && readLessText" @click.prevent="triggerReadLess()">{{ readLessText }}</a>
</span>
</div>
</template>