Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / functions.php
Created May 6, 2020 15:28 — forked from LukaHarambasic/functions.php
Wordpress: ACF-Field as CPT Title
// inspired by: https://gist.github.com/rveitch/9018669face1686e74aaa68026856f36
// add iitle to CPTs which doesn't provide a title (useful for the relationship field (https://www.advancedcustomfields.com/resources/relationship/))
function sync_acf_post_title($post_id, $post, $update) {
$post_type = get_post_type($post_id);
// check for the current CPT
if($post_type === "cpt_name_1") {
@dgoze
dgoze / acf-php-to-json.php
Created May 6, 2020 15:28 — forked from ollietreend/acf-php-to-json.php
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@dgoze
dgoze / load.php
Created May 6, 2020 15:28 — forked from yratof/load.php
ACF Load layouts into flex field
<?php
add_filter( 'acf/load_field/name=flex_layout', __CLASS__ . '::craft_content_layouts' );
static function craft_content_layouts( $field ) {
// Remove the layouts
// that are named in this list
$remove_list = [
'paragraph',
'banner',
@dgoze
dgoze / acf-options.php
Created May 6, 2020 15:28 — forked from danielpost/acf-options.php
ACF Wrapper - easier way to register ACF fields using PHP
<?php
$reusable_checkbox_field = array(
'type' => 'checkbox',
'choices' => array(
'red' => __('Red', THEME_SLUG),
'white' => __('White', THEME_SLUG),
'blue' => __('Blue', THEME_SLUG),
),
);
@dgoze
dgoze / shortcode.php
Created May 6, 2020 15:28 — forked from Bobz-zg/shortcode.php
Filter WordPress posts by custom taxonomy term with AJAX
<?php
/**
* Shortocde for displaying terms filter and results on page
*/
function vb_filter_posts_sc($atts) {
$a = shortcode_atts( array(
'tax' => 'post_tag', // Taxonomy
'terms' => false, // Get specific taxonomy terms only
'active' => false, // Set active term by ID
@dgoze
dgoze / add-query-vars.php
Created May 6, 2020 15:28 — forked from carlodaniele/add-query-vars.php
Register custom query vars
<?php
/**
* Register custom query vars
*
* @param array $vars The array of available query variables
*
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
*/
function myplugin_register_query_vars( $vars ) {
$vars[] = 'key1';
@dgoze
dgoze / login-logout-menu-items.php
Created May 6, 2020 15:29 — forked from carlodaniele/login-logout-menu-items.php
Add login and logout links to main menu
<?php
/**
* Add login and logout links to main menu
*
* @param string $items The HTML list content for the menu items.
* @param obj $args An object containing wp_nav_menu() arguments.
*
* @link https://codex.wordpress.org/Function_Reference/wp_login_url
* @link https://codex.wordpress.org/Function_Reference/wp_logout_url
* @link https://developer.wordpress.org/reference/functions/wp_nav_menu/
@dgoze
dgoze / custom-login-page.php
Created May 6, 2020 15:29 — forked from carlodaniele/custom-login-page.php
Switch the URL of default login page with the URL of a custom login page
<?php
/**
* Set a custom login page
*
* @param string $url Default login URL
* @param string $redirect Redirect URL on login
* @param bool $force_reauth Whether to force reauthorization
* @link https://developer.wordpress.org/reference/hooks/login_url/
*/
function frontend_login_url( $url, $redirect, $force_reauth ){
//Setting Ajax handlers
add_action( 'wp_ajax_nopriv_get_author_info', array( $this, 'bps_get_author_info_cb' ) );
add_action( 'wp_ajax_get_author_info', array( $this, 'bps_get_author_info_cb' ) );
/**
* Function used to get author info for popup on article
*/
public function bps_get_author_info_cb() {
global $coauthors_plus;
//Checking nonce
@dgoze
dgoze / remove-columns-in-admin.php
Created May 6, 2020 15:29 — forked from jdhobbsuk/remove-columns-in-admin.php
Remove columns from admin list
// Remove columns from Page section
// -------------------------------------------------------------
function my_pages_columns( $defaults ) {
unset( $defaults['comments'] );
unset( $defaults['author'] );
unset( $defaults['tags'] );
unset( $defaults['date'] );
// WordPress SEO
unset( $defaults['wpseo-title'] );