Created
May 31, 2016 15:26
-
-
Save anthonysbrown/c1d865f09af053cc92fb30412f91656e to your computer and use it in GitHub Desktop.
Create a new tab in funeralpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$wpfh_obits_extra_tab = new wpfh_obits_extra_tab; | |
add_filter('wpfh_obit_permissions', array( | |
$wpfh_obits_extra_tab, | |
'permissions' | |
)); | |
add_filter('wpfp_frontend_top_obit_content', array( | |
$wpfh_obits_extra_tab, | |
'view' | |
)); | |
add_filter('wpfp_frontend_obit_menu', array( | |
$wpfh_obits_extra_tab, | |
'menu' | |
)); | |
add_action('funeralpress/admin/obit/content_tab', array( | |
$wpfh_obits_extra_tab, | |
'settings_tab' | |
), 12, 2); | |
add_action('funeralpress/admin/obit/content_content', array( | |
$wpfh_obits_extra_tab, | |
'settings' | |
), 12, 2); | |
add_action('wpfh_update_obit', array( | |
$wpfh_obits_extra_tab, | |
'save_settings' | |
)); | |
add_action('wpfh_insert_obit', array( | |
$wpfh_obits_extra_tab, | |
'save_settings' | |
)); | |
add_action('wpfp_settings_terminology', array( | |
$wpfh_obits_extra_tab, | |
'settings_terminology' | |
)); | |
class wpfh_obits_extra_tab | |
{ | |
function __construct() | |
{ | |
$tab = get_option('wpfh_terminology_extra_tab', __("extra_tab", "sp-wpfh")); | |
$this->namespace = sanitize_title($tab); | |
$this->name = $tab; | |
} | |
function settings_terminology() | |
{ | |
if ($_POST['save-settings'] != "") { | |
update_option('wpfh_terminology_extra_tab', $_POST['wpfh_terminology_extra_tab']); | |
} | |
echo ' <tr> | |
<td width="300"><strong>' . __("Extra Tab", "sp-wpfh") . '</strong><br><em>' . __("extratab title", "sp-wpfh") . '</em></td> | |
<td><input type="text" name="wpfh_terminology_extra_tab" value="' . get_option('wpfh_terminology_extra_tab', __("extra_tab", "sp-wpfh")) . '" style="width:100%" ></td> | |
</tr>'; | |
} | |
function menu($additional_menu_items) | |
{ | |
$id = $_GET['id']; | |
if ($id != '') { | |
$obit_permissions = wpfh_get_meta(array( | |
'meta_name' => 'obit_permissions', | |
'oid' => $id | |
)); | |
$content = wpfh_get_meta(array( | |
'meta_name' => 'obit_extra_tab_tab', | |
'oid' => $id | |
)); | |
} | |
if ($obit_permissions[$this->namespace] == 1 && $content != '') { | |
if ($_GET['f'] == $this->namespace) { | |
$current = 'id="current"'; | |
} | |
$extra_tab_name = wpfh_get_meta(array( | |
'meta_name' => 'obit_extra_tab_name', | |
'oid' => get_query_var('id') | |
)); | |
if ($extra_tab_name != '') { | |
$content_name = stripslashes($extra_tab_name); | |
} else { | |
$content_name = stripslashes($this->name); | |
} | |
$additional_menu_items .= '<li ' . $current . '><a href="' . wpfh_obit_page($_GET['id'], $this->namespace) . '" >' . $content_name . '</a></li>'; | |
} | |
return $additional_menu_items; | |
} | |
function view($html) | |
{ | |
global $wpdb; | |
if ($_GET['f'] == $this->namespace) { | |
$content = wpfh_get_meta(array( | |
'meta_name' => 'obit_extra_tab_tab', | |
'oid' => $_GET['id'] | |
)); | |
$html .= apply_filters('the_content', $content); | |
} | |
return $html; | |
} | |
function permissions($permissions) | |
{ | |
$permissions[] = $this->namespace; | |
return $permissions; | |
} | |
function save_settings($insert_id) | |
{ | |
if ($_POST['save-obit'] != "") { | |
if ($_POST['extra_tab'] != '') { | |
wpfh_set_meta(array( | |
'meta_name' => 'obit_extra_tab_tab', | |
'meta_value' => $_POST['extra_tab'], | |
'oid' => $insert_id | |
)); | |
wpfh_set_meta(array( | |
'meta_name' => 'obit_extra_tab_name', | |
'meta_value' => $_POST['extra_tab_name'], | |
'oid' => $insert_id | |
)); | |
} | |
} | |
} | |
function settings_tab($r, $obit_id) | |
{ | |
if (wpfh_feature_disabled('Obituary: Extra Tab') == false) { | |
echo ' <li><a href="#obit-extra-tab">' . $this->name . '</a></li>'; | |
} | |
} | |
function settings($r, $obit_id) | |
{ | |
if (wpfh_feature_disabled('Obituary: Extra Tab') == false) { | |
if ($r[0]['id'] != '') { | |
$extra_tab_content = wpfh_get_meta(array( | |
'meta_name' => 'obit_extra_tab_tab', | |
'oid' => $r[0]['id'] | |
)); | |
$extra_tab_name = wpfh_get_meta(array( | |
'meta_name' => 'obit_extra_tab_name', | |
'oid' => $r[0]['id'] | |
)); | |
} | |
$add_buttons = (wpfh_feature_disabled('Obituary: Editor Add Media Buttons') == 'false' ? false : true); | |
echo '<div id="obit-extra-tab">'; | |
echo '<p>Tab Name: <input type="text" name="extra_tab_name" value="' . $extra_tab_name . '"></p>'; | |
echo the_editor($extra_tab_content, "extra_tab", "", $add_buttons); | |
echo '</div>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment