Skip to content

Commit 7cb9b55

Browse files
authored
Merge pull request #16 from ahmedkaludi/Development-2.0
Development 2.0 Resolve 3 Conflicts, from 2 files
2 parents 4720b3e + 439305b commit 7cb9b55

File tree

343 files changed

+92667
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+92667
-85
lines changed

admin/control-center.php

Lines changed: 240 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function adsforwp_setup_post_type() {
66
'labels' => array(
77
'name' => esc_html__( 'Ads', 'ads-for-wp' ),
88
'singular_name' => esc_html__( 'Ad', 'ads-for-wp' ),
9-
'add_new' => esc_html__( 'Add New Ad', 'ads-for-wp' )
9+
'add_new' => esc_html__( 'Add New Ad', 'ads-for-wp' ),
10+
'add_new_item' => esc_html__( 'Add New Ad', 'ads-for-wp' )
1011
),
1112
'public' => true,
1213
'has_archive' => false,
@@ -20,14 +21,28 @@ function adsforwp_setup_post_type() {
2021
/*
2122
* Hiding Visaul Editor part, as there is no need for Visual Editor to add Advert Code
2223
*/
23-
add_filter( 'user_can_richedit', 'adsforwp_hide_visual_editor');
2424

25-
function adsforwp_hide_visual_editor($content) {
26-
global $post_type;
25+
/*
26+
Not Needed Anymore
27+
*/
28+
29+
// add_filter( 'user_can_richedit', 'adsforwp_hide_visual_editor');
30+
31+
// function adsforwp_hide_visual_editor($content) {
32+
// global $post_type;
33+
34+
// if ('ads-for-wp-ads' == $post_type)
35+
// return false;
36+
// return $content;
37+
// }
38+
39+
/*
40+
* Hiding WYSIWYG For AMPforWP Ads 2.0, as there is no need for it
41+
*/
42+
add_action( 'init', 'removing_wysiwig_adsforwp' );
2743

28-
if ('ads-for-wp-ads' == $post_type)
29-
return false;
30-
return $content;
44+
function removing_wysiwig_adsforwp() {
45+
remove_post_type_support( 'ads-for-wp-ads', 'editor' );
3146
}
3247

3348
/*
@@ -36,7 +51,56 @@ function adsforwp_hide_visual_editor($content) {
3651

3752
add_shortcode('ads-for-wp', 'adsforwp_shortcode_generator');
3853
function adsforwp_shortcode_generator( $atts ){
39-
$content = '';
54+
$adsPostId = get_ad_id(get_the_ID());
55+
$selected_ads_for = get_post_meta($adsPostId,'select_ads_for',true);
56+
if('1' === $selected_ads_for){
57+
$ad_vendor = get_post_meta($adsPostId,'ad_vendor',true);
58+
$ad_type = get_post_meta($adsPostId,'ad_type_format',true);
59+
}
60+
elseif('2' === $selected_ads_for){
61+
$ad_vendor = get_post_meta($adsPostId,'_amp_ad_vendor',true);
62+
$ad_type = get_post_meta($adsPostId,'_amp_ad_type_format',true);
63+
}
64+
65+
$content = '';
66+
$show_ads = '';
67+
68+
$show_ads = 'yes';
69+
$show_ads = apply_filters('adsforwp_advert_on_off', $show_ads);
70+
if('1' === $selected_ads_for){
71+
$global_visibility = get_post_meta($adsPostId,'ad_visibility_status',true);
72+
if($global_visibility != 'show'){
73+
$show_ads = 'no';
74+
}
75+
}
76+
elseif('2' === $selected_ads_for){
77+
$global_visibility = get_post_meta($adsPostId,'_amp_ad_visibility_status',true);
78+
if($global_visibility != 'show'){
79+
$show_ads = 'no';
80+
}
81+
}
82+
if ( $show_ads == 'yes' ) {
83+
if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()){
84+
if('1' === $ad_vendor && '3' === $ad_type){
85+
$content = ampforwp_incontent_adsense_ads($adsPostId);
86+
}
87+
elseif('2' === $ad_vendor && '3' === $ad_type){
88+
$content = ampforwp_incontent_dfp_ads($adsPostId);
89+
}
90+
elseif('3' === $ad_vendor && '3' === $ad_type){
91+
$content = ampforwp_incontent_custom_ads($adsPostId);
92+
}
93+
elseif('4' === $ad_vendor && '3' === $ad_type){
94+
$content = adsforwp_incontent_media_net_ads($adsPostId);
95+
}
96+
else{
97+
if('3' === $ad_type){
98+
$content = get_post_field('post_content', $atts['ads-id']);
99+
}
100+
}
101+
}
102+
}
103+
/* $content = '';
40104
$show_ads = '';
41105
42106
$ad_id = $atts['ads-id'];
@@ -45,7 +109,7 @@ function adsforwp_shortcode_generator( $atts ){
45109
46110
if ( $show_ads == 'yes' ) {
47111
$content = get_post_field('post_content', $atts['ads-id']);
48-
}
112+
}*/
49113

50114
return $content ;
51115
}
@@ -78,10 +142,11 @@ function adsforwp_save_ads_data() {
78142
* Insert the ad in the Content
79143
*/
80144
add_filter('the_content', 'adsforwp_insert_ads');
81-
function adsforwp_insert_ads( $content ){
82-
global $post;
83-
84145

146+
function adsforwp_insert_ads( $content ){
147+
global $post,$post_id;
148+
// $post_id = $post->ID;
149+
// $cmb2_incontent_options = '';
85150
$currentPostId = $post->ID;
86151

87152
$show_ads = '';
@@ -92,8 +157,34 @@ function adsforwp_insert_ads( $content ){
92157
if ( $show_ads != 'yes' ) {
93158
return $content ; // Do not show ads and return the content as it is
94159
}
160+
if(function_exists(ampforwp_is_front_page())){
161+
if(!is_singular() && !ampforwp_is_front_page()){
162+
return $content;
163+
}
164+
}
95165

96166
$post_meta = get_post_meta($currentPostId, 'adsforwp-advert-data', true);
167+
if(empty($post_meta)){
168+
$post_meta = array('post_id' => '',
169+
'ads_id' => '',
170+
'visibility' => '',
171+
'paragraph' => '',
172+
'content'=>'',);
173+
174+
}
175+
$selected_ads_for = get_post_meta(get_ad_id(get_the_ID()),'select_ads_for',true);
176+
if('1' === $selected_ads_for){
177+
$cmb2_incontent_options = get_metadata('post',get_ad_id(get_the_ID()), 'incontent_ad_type');
178+
$incontent_visibility = 'ad_visibility_status';
179+
$amp_ad_type = 'ad_type_format';
180+
181+
}
182+
elseif('2' === $selected_ads_for){
183+
$cmb2_incontent_options = get_metadata('post',get_ad_id(get_the_ID()), '_amp_incontent_ad_type');
184+
$incontent_visibility = '_amp_ad_visibility_status';
185+
$amp_ad_type = '_amp_ad_type_format';
186+
}
187+
97188
//Get all other adds which are set to inline
98189
$args = array(
99190
'post_type' =>'ads-for-wp-ads',
@@ -102,7 +193,7 @@ function adsforwp_insert_ads( $content ){
102193
'meta_query' =>array(
103194
'adsforwp_ads_position'=>'hide',
104195
array(
105-
'key' => 'adsforwp_ads_controller_default',
196+
'key' => $incontent_visibility,
106197
'value' => 'show',
107198
)
108199

@@ -112,36 +203,161 @@ function adsforwp_insert_ads( $content ){
112203
while ($query->have_posts()) {
113204
$query->the_post();
114205
$adsPostId = get_the_ID();
115-
$adsType = get_post_field('adsforwp_ads_position', $adsPostId);
116-
if($adsType!='hide'){
206+
$adsType = get_post_meta($adsPostId, $incontent_visibility,true);
207+
$ads_format = get_post_meta($adsPostId, $amp_ad_type,true);
208+
209+
if($adsType =='hide' ){
117210
continue;
118211
}
119-
if(!isset($post_meta[$adsPostId])){
212+
if($ads_format != '2'){
213+
continue;
214+
}
215+
216+
217+
if(isset($cmb2_incontent_options)){
218+
if('1' === $selected_ads_for){
219+
if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()){
220+
$adsVisiblityType = get_post_meta($currentPostId,'adsforwp-advert-data',true);
221+
222+
$adsVisiblityType = (isset($adsVisiblityType[$adsPostId]['visibility'])
223+
? $adsVisiblityType[$adsPostId]['visibility']
224+
: get_post_meta($adsPostId,'ad_visibility_status',true)
225+
);
226+
$adsparagraphs = ( isset($post_meta[$adsPostId]['paragraph'])
227+
? $post_meta[$adsPostId]['paragraph']
228+
: get_post_meta($adsPostId,'incontent_ad_type',true) );
229+
230+
231+
$ad_vendor = get_post_meta($adsPostId,'ad_vendor',true);
232+
$ad_type = get_post_meta($adsPostId,'ad_type_format',true);
233+
if('1' === $ad_vendor && '2' === $ad_type){
234+
$adsContent = ampforwp_incontent_adsense_ads($adsPostId);
235+
$post_meta[$adsPostId] = array(
236+
'post_id' => $currentPostId,
237+
'ads_id' => $adsPostId,
238+
'visibility' => $adsVisiblityType,
239+
'paragraph' => $adsparagraphs,
240+
'content'=>$adsContent,
241+
);
242+
}
243+
elseif('2' === $ad_vendor && '2' === $ad_type){
244+
$adsContent = ampforwp_incontent_dfp_ads($adsPostId);
245+
$post_meta[$adsPostId] = array(
246+
'post_id' => $currentPostId,
247+
'ads_id' => $adsPostId,
248+
'visibility' => $adsVisiblityType,
249+
'paragraph' => $adsparagraphs,
250+
'content'=>$adsContent,
251+
);
252+
}
253+
elseif('3' === $ad_vendor && '2' === $ad_type){
254+
$adsContent = ampforwp_incontent_custom_ads($adsPostId);
255+
$post_meta[$adsPostId] = array(
256+
'post_id' => $currentPostId,
257+
'ads_id' => $adsPostId,
258+
'visibility' => $adsVisiblityType,
259+
'paragraph' => $adsparagraphs,
260+
'content'=>$adsContent,
261+
);
262+
}
263+
}
264+
}
265+
if('2' === $selected_ads_for){
266+
$adsVisiblityType = get_post_field('adsforwp_incontent_ads_default', $post_id);
267+
$adsVisiblityType = (isset($adsVisiblityType[$adsPostId]['visibility'])
268+
? $adsVisiblityType[$adsPostId]['visibility']
269+
: get_post_meta($adsPostId,'_amp_ad_visibility_status',true)
270+
);
271+
$adsparagraphs = ( isset($post_meta[$adsPostId]['paragraph'])
272+
? $post_meta[$adsPostId]['paragraph']
273+
: get_post_meta($adsPostId,'_amp_incontent_ad_type',true) );
274+
$ad_vendor = get_post_meta($adsPostId,'_amp_ad_vendor',true);
275+
$ad_type = get_post_meta($adsPostId,'_amp_ad_type_format',true);
276+
if('1' === $ad_vendor && '2' === $ad_type){
277+
$adsContent = ampforwp_incontent_adsense_ads($adsPostId);
278+
$post_meta[$adsPostId] = array(
279+
'post_id' => $currentPostId,
280+
'ads_id' => $adsPostId,
281+
'visibility' => $adsVisiblityType,
282+
'paragraph' => $adsparagraphs,
283+
'content'=>$adsContent,
284+
);
285+
286+
}
287+
elseif('2' === $ad_vendor && '2' === $ad_type){
288+
$adsContent = ampforwp_incontent_dfp_ads($adsPostId);
289+
$post_meta[$adsPostId] = array(
290+
'post_id' => $currentPostId,
291+
'ads_id' => $adsPostId,
292+
'visibility' => $adsVisiblityType,
293+
'paragraph' => $adsparagraphs,
294+
'content'=>$adsContent,
295+
);
296+
}
297+
elseif('3' === $ad_vendor && '2' === $ad_type){
298+
$adsContent = ampforwp_incontent_custom_ads($adsPostId);
299+
$post_meta[$adsPostId] = array(
300+
'post_id' => $currentPostId,
301+
'ads_id' => $adsPostId,
302+
'visibility' => $adsVisiblityType,
303+
'paragraph' => $adsparagraphs,
304+
'content'=>$adsContent,
305+
);
306+
}
307+
308+
}
309+
}
310+
elseif(!isset($post_meta[$adsPostId])){
311+
120312
$adsVisiblityType = get_post_field('adsforwp_incontent_ads_default', $post_id);
121313
$adsparagraphs = get_post_field('adsforwp_incontent_ads_paragraphs', $post_id);
122-
$adsContent = get_post_field('post_content', $adsPostId);
314+
$adsContent = ampforwp_incontent_adsense_ads($adsPostId);
123315
$post_meta[$adsPostId] = array(
124316
'post_id' => $currentPostId,
125317
'ads_id' => $adsPostId,
126318
'visibility' => $adsVisiblityType,
127319
'paragraph' => $adsparagraphs,
128320
'content'=>$adsContent,
129321
);
130-
}else{
322+
}
323+
else{
131324
$adsContent = get_post_field('post_content', $adsPostId);
132-
$post_meta[$adsPostId]['content'] = $adsContent;
325+
$ad_vendor = get_post_meta($adsPostId,'ad_vendor',true);
326+
if('1' === $ad_vendor){
327+
$post_meta[$adsPostId]['content'] = ampforwp_incontent_adsense_ads($adsPostId);
328+
329+
}
330+
elseif('2' === $ad_vendor){
331+
$post_meta[$adsPostId]['content'] = ampforwp_incontent_dfp_ads($adsPostId);
332+
333+
}
334+
elseif('3' === $ad_vendor){
335+
$post_meta[$adsPostId]['content'] = ampforwp_incontent_custom_ads($adsPostId);
336+
337+
}else{
338+
$post_meta[$adsPostId]['content'] = $adsContent;
339+
}
133340
}
134341

135342
}
136343
wp_reset_query();
137-
344+
ksort($post_meta);
138345
$content = preg_split("/\\r\\n|\\r|\\n/", $content);
139346
if(count($post_meta)>0){
140347
foreach ($post_meta as $key => $adsValue) {
141348
if($adsValue['visibility']!="show"){
142349
continue;
143350
}
144-
array_splice( $content, $adsValue['paragraph'], 0, $adsValue['content'] );
351+
if(isset($adsValue['paragraph']) && isset($adsValue['content'])){
352+
353+
if(count($content) > $adsValue['paragraph']){
354+
355+
$content[$adsValue['paragraph']] .= $adsValue['content'];
356+
}
357+
358+
//array_splice( $content, $adsValue['paragraph'], 0, $adsValue['content'] );
359+
}
360+
145361
}
146362
$content = implode(' ', $content);
147363
}
@@ -163,10 +379,11 @@ function adsforwp_admin_enqueue() {
163379

164380
// Localize the script with new data
165381
$data = array(
166-
'ajax_url' => admin_url( 'admin-ajax.php' ),
382+
'ajax_url' => admin_url( 'admin-ajax.php' ),
383+
'id' => get_the_ID()
167384
);
168385
wp_localize_script( 'adsforwp-admin-js', 'adsforwp_localize_data', $data );
169-
386+
170387
// Enqueued script with localized data.
171388
wp_enqueue_script( 'adsforwp-admin-js' );
172389

0 commit comments

Comments
 (0)