Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
billerickson committed Jul 4, 2012
0 parents commit 309b35e
Show file tree
Hide file tree
Showing 27 changed files with 1,513 additions and 0 deletions.
212 changes: 212 additions & 0 deletions genesis-title-toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php
/*
Plugin Name: Genesis Title Toggle
Plugin URI: http://www.billerickson.net/
Description: Turn on/off page titles on a per page basis, and set sitewide defaults from Theme Settings. Must be using the Genesis theme.
Version: 1.2.3
Author: Bill Erickson
Author URI: http://www.billerickson.net
License: GPLv2
*/

class BE_Title_Toggle {
var $instance;

function __construct() {
$this->instance =& $this;
register_activation_hook( __FILE__, array( $this, 'activation_hook' ) );
add_action( 'init', array( $this, 'init' ) );
}

function init() {
// Translations
load_plugin_textdomain( 'genesis-title-toggle', false, basename( dirname( __FILE__ ) ) . '/languages' );

// Metabox on Theme Settings, for Sitewide Default
add_filter( 'genesis_theme_settings_defaults', array( $this, 'setting_defaults' ) );
add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization' ) );
add_action( 'genesis_theme_settings_metaboxes', array( $this, 'register_metabox' ) );

// Metabox on Edit screen, for Page Override
add_filter( 'cmb_meta_boxes', array( $this, 'create_metaboxes' ) );
add_action( 'init', array( $this, 'initialize_cmb_meta_boxes' ), 50 );

// Removes Page Title
add_action( 'genesis_before', array( $this, 'title_toggle' ) );
}

/**
* Activation Hook - Confirm site is using Genesis
*
*/
function activation_hook() {
if ( 'genesis' != basename( TEMPLATEPATH ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( sprintf( __( 'Sorry, you can&rsquo;t activate unless you have installed <a href="%s">Genesis</a>', 'genesis-title-toggle'), 'http://www.billerickson.net/get-genesis' ) );
}
}

/**
* Sitewide Setting - Register Defaults
* @link http://www.billerickson.net/genesis-theme-options/
*
* @param array $defaults
* @return array modified defaults
*
*/
function setting_defaults( $defaults ) {
$post_types = apply_filters( 'be_title_toggle_post_types', array( 'page' ) );
foreach ( $post_types as $post_type )
$defaults[] = array( 'be_title_toggle_' . $post_type => '' );
return $defaults;
}

/**
* Sitewide Setting - Sanitization
* @link http://www.billerickson.net/genesis-theme-options/
*
*/
function sanitization() {
$fields = array();
$post_types = apply_filters( 'be_title_toggle_post_types', array( 'page' ) );
foreach ( $post_types as $post_type )
$fields[] = 'be_title_toggle_' . $post_type;

genesis_add_option_filter( 'one_zero', GENESIS_SETTINGS_FIELD, $fields );
}

/**
* Sitewide Setting - Register Metabox
* @link http://www.billerickson.net/genesis-theme-options/
*
* @param string, Genesis theme settings page hook
*/

function register_metabox( $_genesis_theme_settings_pagehook ) {
add_meta_box('be-title-toggle', __( 'Title Toggle', 'genesis-title-toggle' ), array( $this, 'create_sitewide_metabox' ), $_genesis_theme_settings_pagehook, 'main', 'high');
}

/**
* Sitewide Setting - Create Metabox
* @link http://www.billerickson.net/genesis-theme-options/
*
*/
function create_sitewide_metabox() {
$post_types = apply_filters( 'be_title_toggle_post_types', array( 'page' ) );
foreach ( $post_types as $post_type )
echo '<p><input type="checkbox" name="' . GENESIS_SETTINGS_FIELD . '[be_title_toggle_' . $post_type . ']" id="' . GENESIS_SETTINGS_FIELD . '[be_title_toggle_' . $post_type . ']" value="1" ' . checked( 1, genesis_get_option( 'be_title_toggle_' . $post_type ), false ) .' /> <label for="' . GENESIS_SETTINGS_FIELD . '[be_title_toggle_' . $post_type . ']"> ' . sprintf( __( 'By default, remove titles in the <strong>%s</strong> post type.', 'genesis-title-toggle' ), $post_type ) .'</label></p>';


}

/**
* Create Page Specific Metaboxes
* @link http://www.billerickson.net/wordpress-metaboxes/
*
* @param array $meta_boxes, current metaboxes
* @return array $meta_boxes, current + new metaboxes
*
*/
function create_metaboxes( $meta_boxes ) {

// Make sure we're still in Genesis, plugins like WP Touch need this check
if ( !function_exists( 'genesis_get_option' ) )
return $meta_boxes;


// Get all post types used by plugin and split them up into show and hide.
// Sitewide default checked = hide by default, so metabox should let you override that and show the title
// Sitewide default empty = display by default, so metabox should let you override that and hide the title

$show = array();
$hide = array();
$post_types = apply_filters( 'be_title_toggle_post_types', array( 'page' ) );
foreach ( $post_types as $post_type ) {
$default = genesis_get_option( 'be_title_toggle_' . $post_type );
if ( !empty( $default ) ) $show[] = $post_type;
else $hide[] = $post_type;
}


// Create the show and hide metaboxes that override the default

if ( !empty( $show ) ) {
$meta_boxes[] = array(
'id' => 'be_title_toggle_show',
'title' => __( 'Title Toggle', 'genesis-title-toggle' ),
'pages' => $show,
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Show Title', 'genesis-title-toggle' ),
'desc' => __( 'By default, this post type is set to remove titles. This checkbox lets you show this specific page&rsquo;s title', 'genesis-title-toggle' ),
'id' => 'be_title_toggle_show',
'type' => 'checkbox'
)
)
);
}

if ( !empty( $hide ) ) {
$meta_boxes[] = array(
'id' => 'be_title_toggle_hide',
'title' => __( 'Title Toggle', 'genesis-title-toggle' ),
'pages' => $hide,
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Hide Title', 'genesis-title-toggle' ),
'desc' => __( 'By default, this post type is set to display titles. This checkbox lets you hide this specific page&rsquo;s title', 'genesis-title-toggle' ),
'id' => 'be_title_toggle_hide',
'type' => 'checkbox'
)
)
);
}

return $meta_boxes;
}

function initialize_cmb_meta_boxes() {
$post_types = apply_filters( 'be_title_toggle_post_types', array( 'page' ) );
if ( !class_exists('cmb_Meta_Box') && !empty( $post_types ) ) {
require_once( dirname( __FILE__) . '/lib/metabox/init.php' );
}
}

function title_toggle() {
// Make sure we're on the single page
if ( !is_singular() )
return;

global $post;
$post_type = get_post_type( $post );

// See if post type has pages turned off by default
$default = genesis_get_option( 'be_title_toggle_' . $post_type );

// If titles are turned off by default, let's check for an override before removing
if ( !empty( $default ) ) {
$override = get_post_meta( $post->ID, 'be_title_toggle_show', true );

// If override is empty, get rid of that title
if (empty( $override ) )
remove_action( 'genesis_post_title', 'genesis_do_post_title' );

// If titles are turned on by default, let's see if this specific one is turned off
} else {
$override = get_post_meta( $post->ID, 'be_title_toggle_hide', true );

// If override has a value, the title's gotta go
if ( !empty( $override ) )
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
}
}
}

new BE_Title_Toggle;
?>
Binary file added languages/genesis-title-toggle-de_DE.mo
Binary file not shown.
59 changes: 59 additions & 0 deletions languages/genesis-title-toggle-de_DE.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
msgid ""
msgstr ""
"Project-Id-Version: Genesis Title Toggle\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tags/genesis-title-toggle\n"
"POT-Creation-Date: 2011-09-01 13:09+0100\n"
"PO-Revision-Date: 2011-09-01 23:11+0100\n"
"Last-Translator: David Decker <deckerweb.mobil@googlemail.com>\n"
"Language-Team: DECKERWEB <deckerweb.mobil@googlemail.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
"X-Poedit-Basepath: ../\n"
"X-Textdomain-Support: yes\n"
"X-Poedit-SearchPath-0: .\n"

#@ genesis-title-toggle
#: genesis-title-toggle.php:86
#: genesis-title-toggle.php:131
#: genesis-title-toggle.php:150
msgid "Title Toggle"
msgstr "Seitentitelanzeige"

#@ genesis-title-toggle
#: genesis-title-toggle.php:138
msgid "Show Title"
msgstr "Seitentitel anzeigen"

#@ genesis-title-toggle
#: genesis-title-toggle.php:157
msgid "Hide Title"
msgstr "Seitentitel verbergen"

#@ genesis-title-toggle
#: genesis-title-toggle.php:45
#, php-format
msgid "Sorry, you can&rsquo;t activate unless you have installed <a href=\"%s\">Genesis</a>"
msgstr "Hinweis: Sie k&ouml;nnen dieses Plugin <em>nicht</em> aktivieren, solange das <a href=\"%s\">Genesis Framework</a> nicht installiert ist."

#@ genesis-title-toggle
#: genesis-title-toggle.php:97
#, php-format
msgid "By default, remove titles in the <strong>%s</strong> post type."
msgstr "Standardm&auml;&szlig;ig werden die Titel f&uuml;r den Inhaltstyp (Post Type) <strong>%s</strong> entfernt."

#@ genesis-title-toggle
#: genesis-title-toggle.php:139
msgid "By default, this post type is set to remove titles. This checkbox lets you show this specific page&rsquo;s title"
msgstr "Standardm&auml;&szlig;ig ist dieser Inhaltstyp (Post Type) so eingestellt, dass die Seitentitel entfernt werden. Mit dem Setzen dieser Einstellung, wird der Titel f&uuml;r diese Seite dennoch angezeigt."

#@ genesis-title-toggle
#: genesis-title-toggle.php:158
msgid "By default, this post type is set to display titles. This checkbox lets you hide this specific page&rsquo;s title"
msgstr "Standardm&auml;&szlig;ig ist dieser Inhaltstyp (Post Type) so eingestellt, dass die Seitentitel angezeigt werden. Mit dem Setzen dieser Einstellung, wird der Titel f&uuml;r diese Seite dennoch entfernt."

58 changes: 58 additions & 0 deletions languages/genesis-title-toggle.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
msgid ""
msgstr ""
"Project-Id-Version: Genesis Title Toggle\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tags/genesis-title-toggle\n"
"POT-Creation-Date: 2011-09-01 13:09+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Poedit-Language: \n"
"X-Poedit-Country: \n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
"X-Poedit-Basepath: ../\n"
"X-Textdomain-Support: yes\n"
"X-Poedit-SearchPath-0: .\n"

#@ genesis-title-toggle
#: genesis-title-toggle.php:86
#: genesis-title-toggle.php:131
#: genesis-title-toggle.php:150
msgid "Title Toggle"
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:138
msgid "Show Title"
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:157
msgid "Hide Title"
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:45
#, php-format
msgid "Sorry, you can&rsquo;t activate unless you have installed <a href=\"%s\">Genesis</a>"
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:97
#, php-format
msgid "By default, remove titles in the <strong>%s</strong> post type."
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:139
msgid "By default, this post type is set to remove titles. This checkbox lets you show this specific page&rsquo;s title"
msgstr ""

#@ genesis-title-toggle
#: genesis-title-toggle.php:158
msgid "By default, this post type is set to display titles. This checkbox lets you hide this specific page&rsquo;s title"
msgstr ""
45 changes: 45 additions & 0 deletions lib/metabox/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
=== Custom Metaboxes and Fields ===
Contributors: Andrew Norcross (@norcross / andrewnorcross.com)
Jared Atchison (@jaredatch / jaredatchison.com)
Bill Erickson (@billerickson / billerickson.net)
Version: 0.6
Requires at least: 3.0
Tested up to: 3.2

== Description ==

This will create metaboxes with custom fields that will blow your mind.

== Installation ==

This script is easy to install. If you can't figure it out you probably shouldn't be using it.

1. Place metabox directory inside of your (activated) theme. E.g. inside /themes/twentyten/lib/metabox/.
2. Include init.php.
3. See example-functions.php for further guidance.
4. Profit.

== Frequently Asked Questions ==

Coming soon.

== TODO ==
* Add media upload to WYSIWYG option
* Security & best practices audit
* File handling improvement and fixes

== Changelog ==

= 0.6 =
* Added the ability to limit metaboxes to certain posts by id. props @billerickson

= 0.5 =
* Fixed define to prevent notices. props @destos
* Added text_date_timestap option. props @andrewyno
* Fixed WYSIWYG paragraph breaking/spacing bug. props @wpsmith
* Added taxonomy_radio and taxonomies_select options. props @c3mdigital
* Fixed script causing the dashboard widgets to not be collapsible.
* Fixed various spacing and whitespace inconsistencies

= 0.4 =
* Think we have a release that is mostly working. We'll say the initial release :)
Loading

0 comments on commit 309b35e

Please sign in to comment.