class.jetpack-sync-defaults.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. require_once( JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' );
  3. /**
  4. * Just some defaults that we share with the server
  5. */
  6. class Jetpack_Sync_Defaults {
  7. static $default_options_whitelist = array(
  8. 'stylesheet',
  9. 'blogname',
  10. 'blogdescription',
  11. 'blog_charset',
  12. 'permalink_structure',
  13. 'category_base',
  14. 'tag_base',
  15. 'sidebars_widgets',
  16. 'comment_moderation',
  17. 'default_comment_status',
  18. 'page_on_front',
  19. 'rss_use_excerpt',
  20. 'subscription_options',
  21. 'stb_enabled',
  22. 'stc_enabled',
  23. 'comment_registration',
  24. 'show_avatars',
  25. 'avatar_default',
  26. 'avatar_rating',
  27. 'highlander_comment_form_prompt',
  28. 'jetpack_comment_form_color_scheme',
  29. 'stats_options',
  30. 'gmt_offset',
  31. 'timezone_string',
  32. 'jetpack_sync_non_public_post_stati',
  33. 'jetpack_options',
  34. 'site_icon', // (int) - ID of core's Site Icon attachment ID
  35. 'default_post_format',
  36. 'default_category',
  37. 'large_size_w',
  38. 'large_size_h',
  39. 'thumbnail_size_w',
  40. 'thumbnail_size_h',
  41. 'medium_size_w',
  42. 'medium_size_h',
  43. 'thumbnail_crop',
  44. 'image_default_link_type',
  45. 'site_logo',
  46. 'sharing-options',
  47. 'sharing-services',
  48. 'post_count',
  49. 'default_ping_status',
  50. 'sticky_posts',
  51. 'blog_public',
  52. 'default_pingback_flag',
  53. 'require_name_email',
  54. 'close_comments_for_old_posts',
  55. 'close_comments_days_old',
  56. 'thread_comments',
  57. 'thread_comments_depth',
  58. 'page_comments',
  59. 'comments_per_page',
  60. 'default_comments_page',
  61. 'comment_order',
  62. 'comments_notify',
  63. 'moderation_notify',
  64. 'social_notifications_like',
  65. 'social_notifications_reblog',
  66. 'social_notifications_subscribe',
  67. 'comment_whitelist',
  68. 'comment_max_links',
  69. 'moderation_keys',
  70. 'jetpack_wga',
  71. 'disabled_likes',
  72. 'disabled_reblogs',
  73. 'jetpack_comment_likes_enabled',
  74. 'twitter_via',
  75. 'jetpack-twitter-cards-site-tag',
  76. 'wpcom_publish_posts_with_markdown',
  77. 'wpcom_publish_comments_with_markdown',
  78. 'jetpack_activated',
  79. 'jetpack_available_modules',
  80. 'jetpack_autoupdate_plugins',
  81. 'jetpack_autoupdate_plugins_translations',
  82. 'jetpack_autoupdate_themes',
  83. 'jetpack_autoupdate_themes_translations',
  84. 'jetpack_autoupdate_core',
  85. 'jetpack_autoupdate_translations',
  86. 'carousel_background_color',
  87. 'carousel_display_exif',
  88. 'jetpack_portfolio',
  89. 'jetpack_portfolio_posts_per_page',
  90. 'jetpack_testimonial',
  91. 'jetpack_testimonial_posts_per_page',
  92. 'tiled_galleries',
  93. 'gravatar_disable_hovercards',
  94. 'infinite_scroll',
  95. 'infinite_scroll_google_analytics',
  96. 'wp_mobile_excerpt',
  97. 'wp_mobile_featured_images',
  98. 'wp_mobile_app_promos',
  99. 'monitor_receive_notifications',
  100. 'post_by_email_address',
  101. 'jetpack_protect_key',
  102. 'jetpack_protect_global_whitelist',
  103. 'jetpack_sso_require_two_step',
  104. 'jetpack_sso_match_by_email',
  105. 'jetpack_relatedposts',
  106. 'verification_services_codes',
  107. 'users_can_register',
  108. 'active_plugins',
  109. 'uninstall_plugins',
  110. 'advanced_seo_front_page_description', // Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION
  111. 'advanced_seo_title_formats', // Jetpack_SEO_Titles::TITLE_FORMATS_OPTION
  112. 'jetpack_api_cache_enabled',
  113. 'start_of_week',
  114. 'blacklist_keys',
  115. 'posts_per_page',
  116. 'posts_per_rss',
  117. 'show_on_front',
  118. 'ping_sites',
  119. 'uploads_use_yearmonth_folders',
  120. 'date_format',
  121. 'time_format',
  122. 'admin_email',
  123. 'new_admin_email',
  124. 'default_email_category',
  125. 'default_role',
  126. 'page_for_posts',
  127. 'mailserver_url',
  128. 'mailserver_login', // Not syncing contents, only the option name
  129. 'mailserver_pass', // Not syncing contents, only the option name
  130. 'mailserver_port',
  131. 'wp_page_for_privacy_policy',
  132. 'enable_header_ad',
  133. 'wordads_second_belowpost',
  134. 'wordads_display_front_page',
  135. 'wordads_display_post',
  136. 'wordads_display_page',
  137. 'wordads_display_archive',
  138. 'wordads_custom_adstxt',
  139. );
  140. public static function get_options_whitelist() {
  141. /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */
  142. $options_whitelist = apply_filters( 'jetpack_options_whitelist', self::$default_options_whitelist );
  143. /**
  144. * Filter the list of WordPress options that are manageable via the JSON API.
  145. *
  146. * @module sync
  147. *
  148. * @since 4.8
  149. *
  150. * @param array The default list of options.
  151. */
  152. return apply_filters( 'jetpack_sync_options_whitelist', $options_whitelist );
  153. }
  154. // Do not sync contents for these events, only the option name
  155. static $default_options_contentless = array(
  156. 'mailserver_login',
  157. 'mailserver_pass',
  158. );
  159. public static function get_options_contentless() {
  160. /**
  161. * Filter the list of WordPress options that should be synced without content
  162. *
  163. * @module sync
  164. *
  165. * @since 6.1
  166. *
  167. * @param array The list of options synced without content.
  168. */
  169. return apply_filters( 'jetpack_sync_options_contentless', self::$default_options_contentless );
  170. }
  171. static $default_constants_whitelist = array(
  172. 'EMPTY_TRASH_DAYS',
  173. 'WP_POST_REVISIONS',
  174. 'AUTOMATIC_UPDATER_DISABLED',
  175. 'ABSPATH',
  176. 'WP_CONTENT_DIR',
  177. 'FS_METHOD',
  178. 'DISALLOW_FILE_EDIT',
  179. 'DISALLOW_FILE_MODS',
  180. 'WP_AUTO_UPDATE_CORE',
  181. 'WP_HTTP_BLOCK_EXTERNAL',
  182. 'WP_ACCESSIBLE_HOSTS',
  183. 'JETPACK__VERSION',
  184. 'IS_PRESSABLE',
  185. 'DISABLE_WP_CRON',
  186. 'ALTERNATE_WP_CRON',
  187. 'WP_CRON_LOCK_TIMEOUT',
  188. 'PHP_VERSION',
  189. 'WP_MEMORY_LIMIT',
  190. 'WP_MAX_MEMORY_LIMIT'
  191. );
  192. public static function get_constants_whitelist() {
  193. /**
  194. * Filter the list of PHP constants that are manageable via the JSON API.
  195. *
  196. * @module sync
  197. *
  198. * @since 4.8
  199. *
  200. * @param array The default list of constants options.
  201. */
  202. return apply_filters( 'jetpack_sync_constants_whitelist', self::$default_constants_whitelist );
  203. }
  204. static $default_callable_whitelist = array(
  205. 'wp_max_upload_size' => 'wp_max_upload_size',
  206. 'is_main_network' => array( 'Jetpack', 'is_multi_network' ),
  207. 'is_multi_site' => 'is_multisite',
  208. 'main_network_site' => array( 'Jetpack_Sync_Functions', 'main_network_site_url' ),
  209. 'site_url' => array( 'Jetpack_Sync_Functions', 'site_url' ),
  210. 'home_url' => array( 'Jetpack_Sync_Functions', 'home_url' ),
  211. 'single_user_site' => array( 'Jetpack', 'is_single_user_site' ),
  212. 'updates' => array( 'Jetpack', 'get_updates' ),
  213. 'has_file_system_write_access' => array( 'Jetpack_Sync_Functions', 'file_system_write_access' ),
  214. 'is_version_controlled' => array( 'Jetpack_Sync_Functions', 'is_version_controlled' ),
  215. 'taxonomies' => array( 'Jetpack_Sync_Functions', 'get_taxonomies' ),
  216. 'post_types' => array( 'Jetpack_Sync_Functions', 'get_post_types' ),
  217. 'post_type_features' => array( 'Jetpack_Sync_Functions', 'get_post_type_features' ),
  218. 'shortcodes' => array( 'Jetpack_Sync_Functions', 'get_shortcodes' ),
  219. 'rest_api_allowed_post_types' => array( 'Jetpack_Sync_Functions', 'rest_api_allowed_post_types' ),
  220. 'rest_api_allowed_public_metadata' => array( 'Jetpack_Sync_Functions', 'rest_api_allowed_public_metadata' ),
  221. 'sso_is_two_step_required' => array( 'Jetpack_SSO_Helpers', 'is_two_step_required' ),
  222. 'sso_should_hide_login_form' => array( 'Jetpack_SSO_Helpers', 'should_hide_login_form' ),
  223. 'sso_match_by_email' => array( 'Jetpack_SSO_Helpers', 'match_by_email' ),
  224. 'sso_new_user_override' => array( 'Jetpack_SSO_Helpers', 'new_user_override' ),
  225. 'sso_bypass_default_login_form' => array( 'Jetpack_SSO_Helpers', 'bypass_login_forward_wpcom' ),
  226. 'wp_version' => array( 'Jetpack_Sync_Functions', 'wp_version' ),
  227. 'get_plugins' => array( 'Jetpack_Sync_Functions', 'get_plugins' ),
  228. 'get_plugins_action_links' => array( 'Jetpack_Sync_functions', 'get_plugins_action_links' ),
  229. 'active_modules' => array( 'Jetpack', 'get_active_modules' ),
  230. 'hosting_provider' => array( 'Jetpack_Sync_Functions', 'get_hosting_provider' ),
  231. 'locale' => 'get_locale',
  232. 'site_icon_url' => array( 'Jetpack_Sync_Functions', 'site_icon_url' ),
  233. 'roles' => array( 'Jetpack_Sync_Functions', 'roles' ),
  234. 'timezone' => array( 'Jetpack_Sync_Functions', 'get_timezone' ),
  235. );
  236. static $default_post_type_attributes = array(
  237. 'name' => '',
  238. 'label' => '',
  239. 'labels' => array(),
  240. 'description' => '',
  241. 'public' => false,
  242. 'hierarchical' => false,
  243. 'exclude_from_search' => true,
  244. 'publicly_queryable' => null,
  245. 'show_ui' => false,
  246. 'show_in_menu' => null,
  247. 'show_in_nav_menus' => null,
  248. 'show_in_admin_bar' => false,
  249. 'menu_position' => null,
  250. 'menu_icon' => null,
  251. 'supports' => array(),
  252. 'capability_type' => 'post',
  253. 'capabilities' => array(),
  254. 'cap' => array(),
  255. 'map_meta_cap' => true,
  256. 'taxonomies' => array(),
  257. 'has_archive' => false,
  258. 'rewrite' => true,
  259. 'query_var' => true,
  260. 'can_export' => true,
  261. 'delete_with_user' => null,
  262. 'show_in_rest' => false,
  263. 'rest_base' => false,
  264. '_builtin' => false,
  265. '_edit_link' => 'post.php?post=%d',
  266. );
  267. public static function get_callable_whitelist() {
  268. /**
  269. * Filter the list of callables that are manageable via the JSON API.
  270. *
  271. * @module sync
  272. *
  273. * @since 4.8
  274. *
  275. * @param array The default list of callables.
  276. */
  277. return apply_filters( 'jetpack_sync_callable_whitelist', self::$default_callable_whitelist );
  278. }
  279. static $blacklisted_post_types = array(
  280. 'ai1ec_event',
  281. 'bwg_album',
  282. 'bwg_gallery',
  283. 'customize_changeset', // WP built-in post type for Customizer changesets
  284. 'dn_wp_yt_log',
  285. 'http',
  286. 'idx_page',
  287. 'jetpack_migration',
  288. 'postman_sent_mail',
  289. 'rssap-feed',
  290. 'rssmi_feed_item',
  291. 'secupress_log_action',
  292. 'sg_optimizer_jobs',
  293. 'snitch',
  294. 'wpephpcompat_jobs',
  295. 'wprss_feed_item',
  296. 'wp_automatic',
  297. 'jp_sitemap_master',
  298. 'jp_sitemap',
  299. 'jp_sitemap_index',
  300. 'jp_img_sitemap',
  301. 'jp_img_sitemap_index',
  302. 'jp_vid_sitemap',
  303. 'jp_vid_sitemap_index',
  304. );
  305. static $default_post_checksum_columns = array(
  306. 'ID',
  307. 'post_modified',
  308. );
  309. static $default_post_meta_checksum_columns = array(
  310. 'meta_id',
  311. 'meta_value'
  312. );
  313. static $default_comment_checksum_columns = array(
  314. 'comment_ID',
  315. 'comment_content',
  316. );
  317. static $default_comment_meta_checksum_columns = array(
  318. 'meta_id',
  319. 'meta_value'
  320. );
  321. static $default_option_checksum_columns = array(
  322. 'option_name',
  323. 'option_value',
  324. );
  325. static $default_multisite_callable_whitelist = array(
  326. 'network_name' => array( 'Jetpack', 'network_name' ),
  327. 'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ),
  328. 'network_add_new_users' => array( 'Jetpack', 'network_add_new_users' ),
  329. 'network_site_upload_space' => array( 'Jetpack', 'network_site_upload_space' ),
  330. 'network_upload_file_types' => array( 'Jetpack', 'network_upload_file_types' ),
  331. 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ),
  332. );
  333. public static function get_multisite_callable_whitelist() {
  334. /**
  335. * Filter the list of multisite callables that are manageable via the JSON API.
  336. *
  337. * @module sync
  338. *
  339. * @since 4.8
  340. *
  341. * @param array The default list of multisite callables.
  342. */
  343. return apply_filters( 'jetpack_sync_multisite_callable_whitelist', self::$default_multisite_callable_whitelist );
  344. }
  345. static $post_meta_whitelist = array(
  346. '_feedback_akismet_values',
  347. '_feedback_email',
  348. '_feedback_extra_fields',
  349. '_g_feedback_shortcode',
  350. '_jetpack_post_thumbnail',
  351. '_menu_item_classes',
  352. '_menu_item_menu_item_parent',
  353. '_menu_item_object',
  354. '_menu_item_object_id',
  355. '_menu_item_orphaned',
  356. '_menu_item_type',
  357. '_menu_item_xfn',
  358. '_publicize_facebook_user',
  359. '_publicize_twitter_user',
  360. '_thumbnail_id',
  361. '_wp_attached_file',
  362. '_wp_attachment_backup_sizes',
  363. '_wp_attachment_context',
  364. '_wp_attachment_image_alt',
  365. '_wp_attachment_is_custom_background',
  366. '_wp_attachment_is_custom_header',
  367. '_wp_attachment_metadata',
  368. '_wp_page_template',
  369. '_wp_trash_meta_comments_status',
  370. '_wpas_mess',
  371. 'content_width',
  372. 'custom_css_add',
  373. 'custom_css_preprocessor',
  374. 'enclosure',
  375. 'imagedata',
  376. 'nova_price',
  377. 'publicize_results',
  378. 'sharing_disabled',
  379. 'switch_like_status',
  380. 'videopress_guid',
  381. 'vimeo_poster_image',
  382. 'advanced_seo_description', // Jetpack_SEO_Posts::DESCRIPTION_META_KEY
  383. );
  384. public static function get_post_meta_whitelist() {
  385. /**
  386. * Filter the list of post meta data that are manageable via the JSON API.
  387. *
  388. * @module sync
  389. *
  390. * @since 4.8
  391. *
  392. * @param array The default list of meta data keys.
  393. */
  394. return apply_filters( 'jetpack_sync_post_meta_whitelist', self::$post_meta_whitelist );
  395. }
  396. static $comment_meta_whitelist = array(
  397. 'hc_avatar',
  398. 'hc_post_as',
  399. 'hc_wpcom_id_sig',
  400. 'hc_foreign_user_id'
  401. );
  402. public static function get_comment_meta_whitelist() {
  403. /**
  404. * Filter the list of comment meta data that are manageable via the JSON API.
  405. *
  406. * @module sync
  407. *
  408. * @since 5.7.0
  409. *
  410. * @param array The default list of comment meta data keys.
  411. */
  412. return apply_filters( 'jetpack_sync_comment_meta_whitelist', self::$comment_meta_whitelist );
  413. }
  414. // TODO: move this to server? - these are theme support values
  415. // that should be synced as jetpack_current_theme_supports_foo option values
  416. static $default_theme_support_whitelist = array(
  417. 'post-thumbnails',
  418. 'post-formats',
  419. 'custom-header',
  420. 'custom-background',
  421. 'custom-logo',
  422. 'menus',
  423. 'automatic-feed-links',
  424. 'editor-style',
  425. 'widgets',
  426. 'html5',
  427. 'title-tag',
  428. 'jetpack-social-menu',
  429. 'jetpack-responsive-videos',
  430. 'infinite-scroll',
  431. 'site-logo',
  432. );
  433. static function is_whitelisted_option( $option ) {
  434. foreach ( self::$default_options_whitelist as $whitelisted_option ) {
  435. if ( $whitelisted_option[0] === '/' && preg_match( $whitelisted_option, $option ) ) {
  436. return true;
  437. } elseif ( $whitelisted_option === $option ) {
  438. return true;
  439. }
  440. }
  441. return false;
  442. }
  443. static $default_capabilities_whitelist = array(
  444. 'switch_themes',
  445. 'edit_themes',
  446. 'edit_theme_options',
  447. 'install_themes',
  448. 'activate_plugins',
  449. 'edit_plugins',
  450. 'install_plugins',
  451. 'edit_users',
  452. 'edit_files',
  453. 'manage_options',
  454. 'moderate_comments',
  455. 'manage_categories',
  456. 'manage_links',
  457. 'upload_files',
  458. 'import',
  459. 'unfiltered_html',
  460. 'edit_posts',
  461. 'edit_others_posts',
  462. 'edit_published_posts',
  463. 'publish_posts',
  464. 'edit_pages',
  465. 'read',
  466. 'publish_pages',
  467. 'edit_others_pages',
  468. 'edit_published_pages',
  469. 'delete_pages',
  470. 'delete_others_pages',
  471. 'delete_published_pages',
  472. 'delete_posts',
  473. 'delete_others_posts',
  474. 'delete_published_posts',
  475. 'delete_private_posts',
  476. 'edit_private_posts',
  477. 'read_private_posts',
  478. 'delete_private_pages',
  479. 'edit_private_pages',
  480. 'read_private_pages',
  481. 'delete_users',
  482. 'create_users',
  483. 'unfiltered_upload',
  484. 'edit_dashboard',
  485. 'customize',
  486. 'delete_site',
  487. 'update_plugins',
  488. 'delete_plugins',
  489. 'update_themes',
  490. 'update_core',
  491. 'list_users',
  492. 'remove_users',
  493. 'add_users',
  494. 'promote_users',
  495. 'delete_themes',
  496. 'export',
  497. 'edit_comment',
  498. 'upload_plugins',
  499. 'upload_themes',
  500. );
  501. public static function get_capabilities_whitelist() {
  502. /**
  503. * Filter the list of capabilities that we care about
  504. *
  505. * @module sync
  506. *
  507. * @since 5.5.0
  508. *
  509. * @param array The default list of capabilities.
  510. */
  511. return apply_filters( 'jetpack_sync_capabilities_whitelist', self::$default_capabilities_whitelist );
  512. }
  513. static function get_max_sync_execution_time() {
  514. $max_exec_time = intval( ini_get( 'max_execution_time' ) );
  515. if ( 0 === $max_exec_time ) {
  516. // 0 actually means "unlimited", but let's not treat it that way
  517. $max_exec_time = 60;
  518. }
  519. return floor( $max_exec_time / 3 );
  520. }
  521. static $default_network_options_whitelist = array(
  522. 'site_name',
  523. 'jetpack_protect_key',
  524. 'jetpack_protect_global_whitelist',
  525. 'active_sitewide_plugins',
  526. );
  527. static $default_taxonomy_whitelist = array();
  528. static $default_dequeue_max_bytes = 500000; // very conservative value, 1/2 MB
  529. static $default_upload_max_bytes = 600000; // a little bigger than the upload limit to account for serialization
  530. static $default_upload_max_rows = 500;
  531. static $default_sync_wait_time = 10; // seconds, between syncs
  532. static $default_sync_wait_threshold = 5; // only wait before next send if the current send took more than X seconds
  533. static $default_enqueue_wait_time = 10; // wait between attempting to continue a full sync, via requests
  534. static $default_max_queue_size = 1000;
  535. static $default_max_queue_lag = 900; // 15 minutes
  536. static $default_queue_max_writes_sec = 100; // 100 rows a second
  537. static $default_post_types_blacklist = array();
  538. static $default_post_meta_whitelist = array();
  539. static $default_comment_meta_whitelist = array();
  540. static $default_disable = 0; // completely disable sending data to wpcom
  541. static $default_sync_via_cron = 1; // use cron to sync
  542. static $default_render_filtered_content = 0; // render post_filtered_content
  543. static $default_max_enqueue_full_sync = 100; // max number of items to enqueue at a time when running full sync
  544. static $default_max_queue_size_full_sync = 1000; // max number of total items in the full sync queue
  545. static $default_sync_callables_wait_time = MINUTE_IN_SECONDS; // seconds before sending callables again
  546. static $default_sync_constants_wait_time = HOUR_IN_SECONDS; // seconds before sending constants again
  547. static $default_sync_queue_lock_timeout = 120; // 2 minutes
  548. static $default_cron_sync_time_limit = 30; // 30 seconds
  549. }