PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/blogtemplates/blogtemplatesfiles/filters.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 176 lines | 101 code | 37 blank | 38 comment | 36 complexity | dbf35ffc61e9eba2e41a16d398e35110 MD5 | raw file
  1. <?php
  2. /**
  3. * Contains specific behavior altering filters.
  4. */
  5. /**
  6. * Ensure we're the last thing to run on blog creation.
  7. */
  8. function blog_template_ensure_last_place () {
  9. global $wp_filter, $blog_templates;
  10. if (!$wp_filter || !$blog_templates) return false;
  11. $tag = 'wpmu_new_blog';
  12. $method = 'set_blog_defaults';
  13. $action_order = false;
  14. $bt_callback = array($blog_templates, $method);
  15. if (!is_callable($bt_callback)) return false;
  16. if (has_action($tag, $bt_callback)) {
  17. // This is all provided it's even bound
  18. $actions = !empty($wp_filter[$tag]) ? $wp_filter[$tag] : false;
  19. if (!$actions) return false;
  20. $highest = max(array_keys($actions));
  21. if (!$idx = _wp_filter_build_unique_id($tag, $bt_callback, false)) return false; // Taken from core (`has_filter()`)
  22. foreach ($actions as $priority => $callbacks) {
  23. if (!isset($actions[$priority][$idx])) continue;
  24. $action_order = $priority;
  25. break;
  26. }
  27. if ($action_order >= $highest) return true; // We're the on the bottom, all good.
  28. // If we reached here, this is not good - we need to re-bind to highest position
  29. remove_action($tag, $bt_callback, $action_order, 6);
  30. $action_order = $highest + 10;
  31. } else {
  32. // No action bound, let's do our thing
  33. $action_order = defined('NBT_APPLY_TEMPLATE_ACTION_ORDER') && NBT_APPLY_TEMPLATE_ACTION_ORDER ? NBT_APPLY_TEMPLATE_ACTION_ORDER : 9999;
  34. $action_order = apply_filters('blog_templates-actions-action_order', $action_order);
  35. }
  36. add_action($tag, $bt_callback, $action_order, 6);
  37. return true;
  38. }
  39. if (defined('NBT_ENSURE_LAST_PLACE') && NBT_ENSURE_LAST_PLACE) add_action('init', 'blog_template_ensure_last_place', 99);
  40. /* ----- Default filters ----- */
  41. /**
  42. * Exclude Gravity Forms option AND Formidable Pro (thank you, wecreateyou/Stephanie).
  43. **/
  44. function blog_template_exclude_gravity_forms( $and ) {
  45. //$and .= " AND `option_name` != 'rg_forms_version'";
  46. $and .= " AND `option_name` NOT IN ('rg_forms_version','frm_db_version','frmpro_db_version')";
  47. return $and;
  48. }
  49. add_filter('blog_template_exclude_settings', 'blog_template_exclude_gravity_forms');
  50. /**
  51. * Exclude Contact Form 7 postmeta fields
  52. */
  53. function blog_template_contact_form7_postmeta ($row, $table) {
  54. if ("postmeta" != $table) return $row;
  55. $key = @$row['meta_key'];
  56. $wpcf7 = array('mail', 'mail_2');
  57. if (defined('NBT_PASSTHROUGH_WPCF7_MAIL_FIELDS') && NBT_PASSTHROUGH_WPCF7_MAIL_FIELDS) return $row;
  58. if (defined('NBT_CONVERT_WPCF7_MAIL_FIELDS') && NBT_CONVERT_WPCF7_MAIL_FIELDS) return blog_template_convert_wpcf7_mail_fields($row);
  59. if (in_array($key, $wpcf7)) return false;
  60. return $row;
  61. }
  62. function blog_template_convert_wpcf7_mail_fields ($row) {
  63. global $_blog_template_current_templated_blog_id;
  64. if (!$_blog_template_current_templated_blog_id) return $row; // Can't do the replacement
  65. $value = @$row['meta_value'];
  66. $wpcf7 = $value ? unserialize($value) : false;
  67. if (!$wpcf7) return $row; // Something went wrong
  68. // Get convertable values
  69. switch_to_blog($_blog_template_current_templated_blog_id);
  70. $admin_email = get_option("admin_email");
  71. $site_url = get_bloginfo('url');
  72. // ... more stuff at some point
  73. restore_current_blog();
  74. // Get target values
  75. $new_site_url = get_bloginfo('url');
  76. $new_admin_email = get_option('admin_email');
  77. // ... more stuff at some point
  78. // Do the replace
  79. foreach ($wpcf7 as $key => $val) {
  80. $val = preg_replace('/' . preg_quote($site_url, '/') . '/i', $new_site_url, $val);
  81. $val = preg_replace('/' . preg_quote($admin_email, '/') . '/i', $new_admin_email, $val);
  82. $wpcf7[$key] = $val;
  83. }
  84. // Right, so now we have the replaced array - populate it.
  85. $row['meta_value'] = serialize($wpcf7);
  86. return $row;
  87. }
  88. function blog_template_check_postmeta ($tbl, $templated_blog_id) {
  89. global $_blog_template_current_templated_blog_id;
  90. $_blog_template_current_templated_blog_id = $templated_blog_id;
  91. if ("postmeta" == $tbl) add_filter('blog_templates-process_row', 'blog_template_contact_form7_postmeta', 10, 2);
  92. }
  93. add_action('blog_templates-copying_table', 'blog_template_check_postmeta', 10, 2);
  94. /**
  95. * Exclude EPanel temporary folder paths.
  96. */
  97. function blog_template_exclude_epanel_temp_path ($and) {
  98. $and .= " AND `option_name` != 'et_images_temp_folder'";
  99. return $and;
  100. }
  101. add_filter('blog_template_exclude_settings', 'blog_template_exclude_epanel_temp_path');
  102. /**
  103. * Ensure the newly registered user is added to new blog.
  104. */
  105. function blog_template_add_user_as_admin ($template, $blog_id, $user_id) {
  106. if (is_super_admin($user_id)) return false;
  107. if (!in_array('users', $template['to_copy'])) return false; // Only apply this if we're trumping over users
  108. return add_user_to_blog($blog_id, $user_id, 'administrator');
  109. }
  110. add_action('blog_templates-copy-after_copying', 'blog_template_add_user_as_admin', 10, 3);
  111. /* ----- Optional (switchable) filters ----- */
  112. if (defined('NBT_REASSIGN_POST_AUTHORS_TO_USER') && NBT_REASSIGN_POST_AUTHORS_TO_USER) {
  113. /**
  114. * Optionally transfer post ownership to the new or predefined user ID.
  115. */
  116. function blog_template_reassign_post_authors ($template, $blog_id, $user_id) {
  117. $new_author = false;
  118. if ('current_user' == NBT_REASSIGN_POST_AUTHORS_TO_USER) $new_author = $user_id;
  119. else if (is_numeric(NBT_REASSIGN_POST_AUTHORS_TO_USER)) $new_author = NBT_REASSIGN_POST_AUTHORS_TO_USER;
  120. if (!$new_author) return false;
  121. global $wpdb;
  122. $wpdb->query("UPDATE {$wpdb->posts} SET post_author={$new_author}");
  123. }
  124. add_action('blog_templates-copy-posts', 'blog_template_reassign_post_authors', 10, 3);
  125. }
  126. // Play nice with Multisite Privacy, if requested so
  127. if (defined('NBT_TO_MULTISITE_PRIVACY_ALLOW_SIGNUP_OVERRIDE') && NBT_TO_MULTISITE_PRIVACY_ALLOW_SIGNUP_OVERRIDE) {
  128. /**
  129. * Keeps user-selected Multisite Privacy settings entered on registration time.
  130. * Propagate template settings on admin blog creation time.
  131. */
  132. function blog_template_exclude_multisite_privacy_settings ($and) {
  133. $user = wp_get_current_user();
  134. if (is_super_admin($user->ID)) return $and;
  135. $and .= " AND `option_name` NOT IN ('spo_settings', 'blog_public')";
  136. return $and;
  137. }
  138. add_filter('blog_template_exclude_settings', 'blog_template_exclude_multisite_privacy_settings');
  139. }