Skip to content

Instantly share code, notes, and snippets.

View danielpataki's full-sized avatar

Daniel Pataki danielpataki

View GitHub Profile
@danielpataki
danielpataki / docblock.php
Last active September 13, 2015 17:34
docblock
/**
* Retrive Channel IDs
*
* This function retreives all categories which are set as channels.
* Channels on the website are special categories that have a mailing
* list attached which users can subscribe to.
*
* It returns an array of term objects if $format is set to 'objects',
* otherwise returns an array of term_ids.
*
@danielpataki
danielpataki / auto-add.php
Last active February 7, 2018 13:05
OOP plugin
/*
Plugin Name: Auto Add Read Posts
Description: A plugin that adds read posts to the user's read list - requires the Unread Posts plugin
Version: 1.0.0
Author: Daniel Pataki
Author URI: http://danielpataki.com/
License: GPLv2 or later
*/
add_action( 'wp', 'auto_add_post_to_read_list' );
@danielpataki
danielpataki / display-skeleton.php
Last active September 13, 2015 17:35
Creating An Authors Widget
public function widget( $args, $instance ) {
echo $args['before_widget'];
if( !empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
}
// Main Widget Code Here
@danielpataki
danielpataki / nonce-url.php
Last active September 13, 2015 17:35
Nonces
$delete_link = wp_get_shortlink( get_the_ID() ) . '&delete=true';
$nonced_link = wp_nonce_url( $delete_link, 'delete-post-' . get_the_ID(), '_mynonce' );
@danielpataki
danielpataki / bold.html
Last active August 29, 2015 14:20
Showing code
<strong>bold text</bold>
@danielpataki
danielpataki / __.php
Last active December 15, 2015 14:46
Translating Plugins
<?php $greeting = __( 'Hello There!', 'text-domain' ); ?>
@danielpataki
danielpataki / changelog.txt
Last active August 29, 2015 14:19
Submitting and maintaining plugins
== Changelog ==
= 1.1.4 =
* WordPress 4.2 compatibility check
= 1.1.3 =
* Added hook for modifying the post types
* Added Hungarian translation
@danielpataki
danielpataki / enqueue.php
Last active March 11, 2016 15:26
Tabbed Interface
function welcome_screen_assets( $hook ) {
if( 'dashboard_page_welcome-screen-about' == $hook ) {
wp_enqueue_style( 'welcome_screen_css', plugin_dir_url( __FILE__ ) . '/style.css' );
}
}
add_action( 'admin_enqueue_scripts', 'welcome_screen_assets' );
@danielpataki
danielpataki / new-role.php
Last active December 7, 2016 14:22
Hide Pages
register_activation_hook( __FILE__, 'my_initial_setup' );
function my_initial_setup() {
$admin = get_role( 'administrator' );
$overlord_caps = $admin->capabilities;
$overlord_caps[] = 'be_overlord';
$role = add_role( 'overlord', 'Overlord', $overlord_caps );
}
@danielpataki
danielpataki / migrate.php
Last active September 13, 2015 17:35
Migrate From Media Custom Fields to ACF
$args = array(
'post_type' => 'attachment',
'post_status' => 'any',
'posts_per_page' => -1
);
$attachments = new WP_Query( $args );
while ( $attachments->have_posts() ) {
$attachments->the_post();