| @@ -1,58 +1,79 @@ | ||
| 1 | -<?php | |
| 2 | -//per agganciarsi ogni volta che viene scritto un contenuto | |
| 3 | -add_filter('wp_head', 'tcmp_head'); | |
| 4 | -function tcmp_head(){ | |
| 5 | - global $post, $tcmp; | |
| 6 | - | |
| 7 | - $tcmp->Options->setPostShown(NULL); | |
| 8 | - if($post && isset($post->ID) && (is_page($post->ID) || is_single($post->ID))) { | |
| 9 | - $tcmp->Options->setPostShown($post); | |
| 10 | - $tcmp->Log->info('POST ID=%s IS SHOWN', $post->ID); | |
| 11 | - } | |
| 12 | - | |
| 13 | - //future development | |
| 14 | - //is_archive(); | |
| 15 | - //is_post_type_archive(); | |
| 16 | - //is_post_type_hierarchical(); | |
| 17 | - //is_attachment(); | |
| 18 | - $tcmp->Manager->writeCodes(TCMP_POSITION_HEAD); | |
| 19 | -} | |
| 20 | -add_action('wp_footer', 'tcmp_footer'); | |
| 21 | -function tcmp_footer() { | |
| 22 | - global $tcmp; | |
| 23 | - //there isn't a hook when <BODY> starts | |
| 24 | - $tcmp->Manager->writeCodes(TCMP_POSITION_BODY); | |
| 25 | - $tcmp->Manager->writeCodes(TCMP_POSITION_CONVERSION); | |
| 26 | - $tcmp->Manager->writeCodes(TCMP_POSITION_FOOTER); | |
| 27 | -} | |
| 28 | - | |
| 29 | -//volendo funziona anche con gli shortcode | |
| 30 | -add_shortcode('tcmp', 'tcmp_shortcode'); | |
| 31 | -add_shortcode('tcm', 'tcmp_shortcode'); | |
| 32 | -function tcmp_shortcode($atts, $content='') { | |
| 33 | - global $tcmp; | |
| 34 | - extract(shortcode_atts(array('id' => false), $atts)); | |
| 35 | - | |
| 36 | - if (!isset($id) || !$id) { | |
| 37 | - return ''; | |
| 38 | - } | |
| 39 | - | |
| 40 | - $snippet=$tcmp->Manager->get($id, true); | |
| 41 | - return $snippet['code']; | |
| 42 | -} | |
| 43 | - | |
| 44 | -function tcmp_ui_first_time() { | |
| 45 | - global $tcmp; | |
| 46 | - if($tcmp->Options->isShowActivationNotice()) { | |
| 47 | - //$tcmp->Options->pushSuccessMessage('FirstTimeActivation'); | |
| 48 | - //$tcmp->Options->writeMessages(); | |
| 49 | - $tcmp->Options->setShowActivationNotice(FALSE); | |
| 50 | - } | |
| 51 | -} | |
| 52 | -function tcmp_admin_footer() { | |
| 53 | - global $tcmp; | |
| 54 | - if($tcmp->Lang->bundle->autoPush && TCMP_AUTOSAVE_LANG) { | |
| 55 | - $tcmp->Lang->bundle->store(TCMP_PLUGIN_DIR.'languages/Lang.txt'); | |
| 56 | - } | |
| 57 | -} | |
| 58 | -add_filter('admin_footer', 'tcmp_admin_footer'); | |
| 1 | +<?php | |
| 2 | +//per agganciarsi ogni volta che viene scritto un contenuto | |
| 3 | +add_filter( 'wp_head', 'tcmp_head', get_option( 'TCM_HookPriority', TCMP_HOOK_PRIORITY_DEFAULT ) ); | |
| 4 | +function tcmp_head() { | |
| 5 | + global $post, $tcmp; | |
| 6 | + | |
| 7 | + $tcmp->options->setPostShown( null ); | |
| 8 | + if ( $post && isset( $post->ID ) && ( is_page( $post->ID ) || is_single( $post->ID ) ) ) { | |
| 9 | + $tcmp->options->setPostShown( $post ); | |
| 10 | + $tcmp->log->info( 'POST ID=%s IS SHOWN', $post->ID ); | |
| 11 | + } | |
| 12 | + | |
| 13 | + $tcmp->body_written = false; | |
| 14 | + | |
| 15 | + //future development | |
| 16 | + //is_archive(); | |
| 17 | + //is_post_type_archive(); | |
| 18 | + //is_post_type_hierarchical(); | |
| 19 | + //is_attachment(); | |
| 20 | + $tcmp->manager->write_codes( TCMP_POSITION_HEAD ); | |
| 21 | +} | |
| 22 | + | |
| 23 | +add_action( 'wp_body_open', 'tcmp_body', get_option( 'TCM_HookPriority', TCMP_HOOK_PRIORITY_DEFAULT ) ); | |
| 24 | +function tcmp_body() { | |
| 25 | + global $tcmp; | |
| 26 | + | |
| 27 | + $tcmp->manager->write_codes( TCMP_POSITION_BODY ); | |
| 28 | + $tcmp->body_written = true; | |
| 29 | +} | |
| 30 | + | |
| 31 | +add_action( 'wp_footer', 'tcmp_footer', get_option( 'TCM_HookPriority', TCMP_HOOK_PRIORITY_DEFAULT ) ); | |
| 32 | +function tcmp_footer() { | |
| 33 | + global $tcmp; | |
| 34 | + | |
| 35 | + if ( ! $tcmp->body_written ) { | |
| 36 | + // this is a fallback if wp_body_open() is not called by the theme | |
| 37 | + $tcmp->manager->write_codes( TCMP_POSITION_BODY ); | |
| 38 | + } | |
| 39 | + | |
| 40 | + $tcmp->manager->write_codes( TCMP_POSITION_CONVERSION ); | |
| 41 | + $tcmp->manager->write_codes( TCMP_POSITION_FOOTER ); | |
| 42 | + | |
| 43 | + if ( $tcmp->options->getModifySuperglobalVariable() ) { | |
| 44 | + if ( function_exists( 'wp_cache_set_home' ) ) { | |
| 45 | + unset( $_POST ); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | + | |
| 50 | +//volendo funziona anche con gli shortcode | |
| 51 | +add_shortcode( 'tcmp', 'tcmp_shortcode' ); | |
| 52 | +add_shortcode( 'tcm', 'tcmp_shortcode' ); | |
| 53 | +function tcmp_shortcode( $atts, $content = '' ) { | |
| 54 | + global $tcmp; | |
| 55 | + extract( shortcode_atts( array( 'id' => false ), $atts ) ); | |
| 56 | + | |
| 57 | + if ( ! isset( $id ) || ! $id ) { | |
| 58 | + return ''; | |
| 59 | + } | |
| 60 | + | |
| 61 | + $snippet = $tcmp->manager->get( $id, true ); | |
| 62 | + return $snippet['code']; | |
| 63 | +} | |
| 64 | + | |
| 65 | +function tcmp_ui_first_time() { | |
| 66 | + global $tcmp; | |
| 67 | + if ( $tcmp->options->isShowActivationNotice() ) { | |
| 68 | + //$tcmp->options->pushSuccessMessage('FirstTimeActivation'); | |
| 69 | + //$tcmp->options->writeMessages(); | |
| 70 | + $tcmp->options->setShowActivationNotice( false ); | |
| 71 | + } | |
| 72 | +} | |
| 73 | +function tcmp_admin_footer() { | |
| 74 | + global $tcmp; | |
| 75 | + if ( $tcmp->lang->bundle->autoPush && TCMP_AUTOSAVE_LANG ) { | |
| 76 | + $tcmp->lang->bundle->store( TCMP_PLUGIN_DIR . 'languages/Lang.txt' ); | |
| 77 | + } | |
| 78 | +} | |
| 79 | +add_filter( 'admin_footer', 'tcmp_admin_footer' ); | |