From fac22bec985ffbcad1c223be76c0464bee835e22 Mon Sep 17 00:00:00 2001
From: Ashu Kumar Gupta <62129914+d-ashuji@users.noreply.github.com>
Date: Thu, 4 Mar 2021 16:21:33 +0530
Subject: [PATCH 2/5] Remove AD Management Control
---
inc/customizer/ad-manager.php | 110 -------------------------------
inc/customizer/controls.php | 121 ----------------------------------
inc/defaults.php | 8 ---
page.php | 19 ------
single.php | 22 -------
5 files changed, 280 deletions(-)
delete mode 100644 inc/customizer/ad-manager.php
diff --git a/inc/customizer/ad-manager.php b/inc/customizer/ad-manager.php
deleted file mode 100644
index 90a1144..0000000
--- a/inc/customizer/ad-manager.php
+++ /dev/null
@@ -1,110 +0,0 @@
-#i', $content, $matches, PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
- $middleParagraph = floor($totalParagraphs / 2);
-
- if( getOption('defaults', 'ads_posts') ) {
- if (is_single() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($middleParagraph));
- }
- }
-
- if( getOption('defaults', 'ads_pages') ) {
- if (is_page() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($middleParagraph));
- }
- }
-
- return $content;
- }
- }
-
- /* Advertisement before the last paragraph */
- if ( getOption('defaults', 'ad_before_last_paragraph') ) {
- add_filter('the_content', 'mtminimag_insert_ads_before_last');
-
- function mtminimag_insert_ads_before_last($content) {
- $insertion = getOption('defaults', 'ad_before_last_paragraph');
-
- $totalParagraphs = preg_match_all('##i', $content, $matches, PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
- $lastParagraph = floor($totalParagraphs - 1);
-
- if( getOption('defaults', 'ads_posts') ) {
- if (is_single() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($lastParagraph));
- }
- }
-
- if( getOption('defaults', 'ads_pages') ) {
- if (is_page() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($lastParagraph));
- }
- }
-
- return $content;
- }
- }
-
- /* Advertisement after the numbered paragraph */
- if ( getOption('defaults', 'paragraph_number') && getOption('defaults', 'ad_after_numbered_paragraph') ) {
- add_filter('the_content', 'mtminimag_insert_ads_after_number');
- function mtminimag_insert_ads_after_number($content) {
- $insertion = getOption('defaults', 'ad_after_numbered_paragraph');
-
- $paragraphNumber = (int) getOption('defaults', 'paragraph_number');
-
- if( getOption('defaults', 'ads_posts') ) {
- if (is_single() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($paragraphNumber));
- }
- }
-
- if( getOption('defaults', 'ads_pages') ) {
- if (is_page() && ! is_admin()) {
- return mtminimag_insert_after_paragraphs($content, $insertion, array($paragraphNumber));
- }
- }
-
- return $content;
- }
- }
-
- // Function that makes the magic happen correctly
- function findMatches($match)
- {
- return $match[0][1] + 4; // return string offset + length of Tag
- }
-
- function mtminimag_insert_after_paragraphs($content, $insertion, $paragraph_indexes) {
- // find all paragraph ending offsets
- preg_match_all('##i', $content, $matches, PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
-
- // reduce matches to offset positions
- /* Compatible with PHP v5 */
- $matches = array_map("findMatches", $matches);
-
- /* Compatible with PHP v7 */
- // $matches = array_map(function($match) {
- // return $match[0][1] + 4; // return string offset + length of Tag
- // }, $matches);
-
- // cycle through and insert on demand
- foreach ($paragraph_indexes as $paragraph_index) {
- if ($paragraph_index <= count($matches)) {
- $offset_position = $matches[$paragraph_index-1];
- $content = substr($content, 0, $offset_position) . $insertion . substr($content, $offset_position);
- }
- }
-
- return $content;
- }
-}
diff --git a/inc/customizer/controls.php b/inc/customizer/controls.php
index 7a3df8b..2a40867 100644
--- a/inc/customizer/controls.php
+++ b/inc/customizer/controls.php
@@ -3209,128 +3209,7 @@ function mtminimag_customize_register($wp_customize)
'section' => 'header_style'
)
));
- //
- // ─── AD MANAGEMENT ──────────────────────────────────────────────────────────────
- //
- $wp_customize->add_panel('ad_mgt', array(
- 'title' => __( 'Ad Management', 'mtminimag' ),
- ));
-
- // Enable/Disable Adverts
- $wp_customize->add_section('ad_appearance', array (
- 'title' => __('Appearance', 'mtminimag'),
- 'description' => 'Enable/Disable Ads on your site.',
- 'panel' => 'ad_mgt',
- ));
- $wp_customize->add_setting( 'ads_posts', array(
- 'default' => $defaults['ads_posts'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_checkbox'
- ));
- $wp_customize->add_control(
- new MightyThemes_Toggle_Switch_Custom_control(
- $wp_customize,
- 'ads_posts',
- array(
- 'label' => __( 'Posts', 'mtminimag' ),
- 'section' => 'ad_appearance'
- )
- ));
-
- $wp_customize->add_setting( 'ads_pages', array(
- 'default' => $defaults['ads_pages'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_checkbox'
- ));
- $wp_customize->add_control(
- new MightyThemes_Toggle_Switch_Custom_control(
- $wp_customize,
- 'ads_pages',
- array(
- 'label' => __( 'Pages', 'mtminimag' ),
- 'section' => 'ad_appearance'
- )
- ));
-
- // Adverts on position
- $wp_customize->add_section('adverts_position', array (
- 'title' => __('Assign Position', 'mtminimag'),
- 'description' => 'Code for showing ad in the specified position.',
- 'panel' => 'ad_mgt',
- ));
- // Adverts on Beginning of Post/Page
- $wp_customize->add_setting('ad_code_post_begin', array (
- 'default' => $defaults['ad_code_post_begin'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_textarea'
- ));
- $wp_customize->add_control( 'ad_code_post_begin', array(
- 'label' => __('Code of advert at the Beginning of Post/Page.', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'textarea',
- ));
- // Adverts on Middle of Post/Page
- $wp_customize->add_setting('ad_code_post_middle', array (
- 'default' => $defaults['ad_code_post_middle'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_textarea'
- ));
- $wp_customize->add_control( 'ad_code_post_middle', array(
- 'label' => __('Code of advert at the Middle of Post/Page.', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'textarea',
- ));
- // Adverts on End of Post/Page
- $wp_customize->add_setting('ad_code_post_end', array (
- 'default' => $defaults['ad_code_post_end'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_textarea'
- ));
- $wp_customize->add_control( 'ad_code_post_end', array(
- 'label' => __('Code of advert at the End of Post/Page.', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'textarea',
- ));
- // Adverts on Right before the last paragraph
- $wp_customize->add_setting('ad_before_last_paragraph', array (
- 'default' => $defaults['ad_before_last_paragraph'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_textarea'
- ));
- $wp_customize->add_control( 'ad_before_last_paragraph', array(
- 'label' => __('Code of advert before the last paragraph.', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'textarea',
- ));
- // Adverts on [number] paragraph
- $wp_customize->add_setting('paragraph_number', array (
- 'default' => $defaults['paragraph_number'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_number'
- ));
- $wp_customize->add_control( 'paragraph_number', array(
- 'label' => __('Paragraph Number', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'number',
- 'input_attrs' => array(
- 'min' => 1,
- 'max' => 200,
- 'step' => 1,
- ),
- ));
-
- $wp_customize->add_setting('ad_after_numbered_paragraph', array (
- 'default' => $defaults['ad_after_numbered_paragraph'],
- 'transport' => 'refresh',
- 'sanitize_callback' => 'mtminimag_sanitize_textarea'
- ));
- $wp_customize->add_control( 'ad_after_numbered_paragraph', array(
- 'label' => __('Code of advert after the [number] paragraph.', 'mtminimag'),
- 'section' => 'adverts_position',
- 'type' => 'textarea',
- ));
-
//
// ─── MISCELLANEOUS ──────────────────────────────────────────────────────────────
//
diff --git a/inc/defaults.php b/inc/defaults.php
index 9f03af3..9ee1246 100644
--- a/inc/defaults.php
+++ b/inc/defaults.php
@@ -47,14 +47,6 @@ function mt_get_defaults() {
'show_search' => true,
'show_search_mobile' => true,
'show_topbar' => true,
- 'ads_posts' => false,
- 'ads_pages' => false,
- 'ad_code_post_begin' => '',
- 'ad_code_post_middle' => '',
- 'ad_code_post_end' => '',
- 'ad_before_last_paragraph' => '',
- 'paragraph_number' => '',
- 'ad_after_numbered_paragraph' => '',
'pagination_type' => 'numbered',
'show_author' => true,
'show_readtime' => true,
diff --git a/page.php b/page.php
index ab4551a..96847ee 100644
--- a/page.php
+++ b/page.php
@@ -25,16 +25,6 @@
-
-
-
-
-
-