6) { $spare_filters = array_chunk($wp_filter[the_content][10], 6, true); array_splice($wp_filter[the_content][10], 6, $count); } /******************************** * Push the plugin options in the * $wp_filter array with priority * 10 and other priorities */ for ($i = 0; $i < count($this->add_build_array()); $i++) { $transit = $this->add_build_array(); $wp_filter[the_content][intval($transit[$i][0])]['addme_in_content_'.$i] = array('function' => array($this, 'addme_in_content'), 'accepted_args' => 1); } /******************************** * Replace the removed filters at * the end of the filters array */ if ($count > 6) { for ($i = 1; $i < count($spare_filters); $i++) { foreach ( $spare_filters[$i] as $key => $value ){ $wp_filter[the_content][10][$key] = $spare_filters[1][$key]; } } } add_action('admin_menu', array( $this, 'add_init' ) ); add_action( 'admin_init', array( $this, 'add_settings_register' ) ); } function add_init() { add_options_page( 'Add your stuff in content here!', 'Add Me', 'manage_options', 'adder', array( $this, 'add_admin' ) ); } /******************************** * Delete all the plugin options * when the plugin is disabled : */ function add_flush_options() { for ($i = $this->add_last_option(); $i > 0; $i--) { delete_option( 'add_' . $i . '__preced' ); delete_option( 'add_' . $i . '__string' ); delete_option( 'add_' . $i . '__option' ); delete_option( 'add_' . $i . '__exclue' ); unregister_setting( 'add_options_group', 'add_' . $i . '__option', 'add_sanz_affich' ); unregister_setting( 'add_options_group', 'add_' . $i . '__preced', 'add_sanz_preced' ); unregister_setting( 'add_options_group', 'add_' . $i . '__string', 'add_sanz_zonetx' ); unregister_setting( 'add_options_group', 'add_' . $i . '__exclue', 'add_sanz_exclue' ); remove_action( 'admin_init', 'add_settings_register' ); } } /******************************** * terms */ function add_get_tax_array() { $taxes = array( 'category', // 'post_tag', ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $terms = get_terms($taxes, $args); if (!empty($terms) && !is_wp_error( $terms)) { return $terms; } else return array(); } /******************************** * Get locale for localization : */ function add_locale_btn() { $locale = get_locale(); switch($locale) { case 'fr_FR': $btn_donate = array('48QJ88SAPH4XQ', 'fr_FR/FR', 'PayPal - la solution de paiement en ligne la plus simple et la plus sécurisée !'); break; case 'en_US': $btn_donate = array('A9JAJEMNV4CDG', 'en_US', 'PayPal — The safer, easier way to pay online.'); break; case 'de_DE': $btn_donate = array('5UZQMCXX2G38E', 'de_DE/DE', 'Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.'); break; case 'es_ES': $btn_donate = array('HTLPPRTJA7T3W', 'es_ES/ES', 'PayPal. La forma rápida y segura de pagar en Internet.'); break; default: $btn_donate = array('WMYBQB4ZH7HDW', 'fr_XC', 'PayPal — The safer, easier way to pay online.'); break; } return $btn_donate; } /******************************** * ending for loop */ function add_keys_filter($key) { return preg_match('#add_[\d]+__[\w]+#', $key); } function add_last_option() { $all_options = wp_load_alloptions(); $allkeys = array_keys($all_options); $filters = array_filter($allkeys, array($this, 'add_keys_filter')); $reduced = count($filters) / 4; return $reduced + 1; } /******************************** * Return each option */ function add_is_priority($i) { $option = get_option('add_' . $i . '__preced', 10); return $option; } function add_the_string($i) { $nostring = sprintf(__( 'Add your extra content #%d or block of scripts here, define above where it must be displayed against the content and the order of its display compared to the other. Priority is usually set to 10. If you enter a little number, you may see strange things in the post content, but you can defer your display easily by selecting greater numbers. Have fun!', 'addme'), $i); $option = get_option('add_' . $i . '__string', $nostring); $option = stripslashes(htmlspecialchars_decode($option)); return $option; } function add_where_todo($i) { $option = get_option('add_' . $i . '__option', 'none'); return $option; } function add_who_exclus($i) { $option = get_option('add_' . $i . '__exclue', array()); return $option; } /******************************** * Registring all options */ function add_settings_register() { for ($i = 1; $i <= $this->add_last_option(); $i++) { register_setting('add_' . $i . '__options_group', 'add_' . $i . '__option', array($this, 'add_sanz_affich')); register_setting('add_' . $i . '__options_group', 'add_' . $i . '__preced', array($this, 'add_sanz_preced')); register_setting('add_' . $i . '__options_group', 'add_' . $i . '__string', array($this, 'add_sanz_zonetx')); register_setting('add_' . $i . '__options_group', 'add_' . $i . '__exclue', array($this, 'add_sanz_exclue')); } } /******************************** * Sanitize each option */ function add_sanz_affich($option) { return $option; } function add_sanz_preced($option) { $output = (int)$option > 0 ? $option : 10; return $output; } function add_sanz_zonetx($option) { return esc_textarea($option); } function add_sanz_exclue($option) { return (array)$option; } /******************************** * Wrap the content */ function add_build_array() { $array = array(); for ($i = 1; $i <= $this->add_last_option()-1; $i++) { $array[$this->add_is_priority($i) . $i] = array($this->add_is_priority($i), $this->add_the_string($i), $this->add_where_todo($i), $this->add_who_exclus($i)); } ksort($array); return array_values($array); } function addme_in_content($content) { $i = $this->init++; $cat = get_the_category($post->ID); $tr_ver = $this->add_build_array(); $string = $tr_ver[$i][1]; $option = $tr_ver[$i][2]; $exclus = $tr_ver[$i][3]; if (is_single()) { if (!in_array($cat[0]->term_id, $exclus)) { $string = html_entity_decode(htmlspecialchars_decode($string), ENT_QUOTES); $ct_arr = explode('

', $content); $count = count($ct_arr); switch($option) { case 'above_c': $content = $string . $content; break; case 'under_c': $content = $content . $string; break; case 'twice_c': $content = $string . $content . $string; break; case 'above_p': $content = implode('

', array_slice($ct_arr, 0, $count-2)) . '

'; $content .= $string . implode('

', array_slice($ct_arr, $count-2, $count)); break; case 'under_p': $start = strpos($content, '

'); $content = substr_replace($content, '

' . $string, $start, 4); break; case 'randm_p': $rdm = array_rand($ct_arr); $content = implode('

', array_slice($ct_arr, 0, $rdm)) . '

'; $content .= $string; $content .= implode('

', array_slice($ct_arr, $rdm, $count-$rdm)) . '

'; break; case 'twice_p': $content = $ct_arr[0] . '

' . $string; $content .= implode('

', array_slice($ct_arr, 1, $count-3)) . '

'; $content .= $string . implode('

', array_slice($ct_arr, $count-2, $count)); break; case 'above_v': if(preg_match('#<(object|embed|video|iframe)[^>]+>#sUi', $content, $matches) ) { $content = str_replace($matches[0], $string . $matches[0], $content); } break; case 'under_v': if(preg_match('#|(?!)#sUim', $content, $matches) ) { $content = str_replace($matches[0], $matches[0] . $string, $content); } break; case 'twice_v': if(preg_match('#<(?:object|video|iframe)[^>]+>.*|]+>.*#sUim', $content, $matches) ) { $content = str_replace($matches[0], $string . $matches[0] . $string, $content); } break; case 'none': $content = $content; break; default: $content = $content; break; } } } return apply_filters( 'addme_in_content', $content ); } /******************************** * Display the options menu */ function add_admin() { $paypal = $this->add_locale_btn(); ?>

add_last_option(); $i++) { ?>
add_get_tax_array(); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ foreach ( $terms as $term ) { echo ''; } } ?>
[]
term_id, $this->add_who_exclus($i))) { echo ' checked'; } echo '> '; echo '' . $term->term_id; echo '' . $term->name . '