Last active
March 14, 2019 19:48
-
-
Save jtsternberg/0802e7e9f80bfacf9d0e2ca20bc830b9 to your computer and use it in GitHub Desktop.
Filter OptinMonster campaigns loaded into WordPress by name
This file contains 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 | |
function filter_om_campaigns_by_name( $campaigns, $save ) { | |
// Make sure this is the refresh request and that we have data. | |
if ( ! isset( $campaigns->success ) && ! empty( $campaigns ) ) { | |
// Loop through the campaigns | |
foreach ( (array) $campaigns as $slug => $campaign ) { | |
// If we don't have a title | |
// OR title does not start with 'SOME PREFIX: ' | |
if ( ! isset( $campaign->title ) || 0 !== strpos( $campaign->title, 'SOME PREFIX: ') ) { | |
// then we do NOT bring this into WordPress. | |
unset( $campaigns->$slug ); | |
} | |
} | |
} | |
return $campaigns; | |
} | |
add_filter( 'optin_monster_pre_store_options', 'filter_om_campaigns_by_name', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment