ACF
3 weeks ago
WooCommerce
3 weeks ago
ACF.php
3 weeks ago
BulkyBulkEditProductsWooCommerce.php
3 weeks ago
EDD.php
3 weeks ago
Elementor.php
3 weeks ago
Formello.php
3 weeks ago
Integration.php
3 weeks ago
JetEngine.php
3 weeks ago
LimitLoginAttempts.php
3 weeks ago
MonsterInsights.php
3 weeks ago
RankMath.php
3 weeks ago
SchemaPro.php
3 weeks ago
UltimateMember.php
3 weeks ago
WooCommerce.php
3 weeks ago
JetEngine.php
191 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Makes JetEngine compatible with WP-Parsidate plugin |
| 4 | * |
| 5 | * @package WP-Parsidate |
| 6 | * @subpackage Plugins/JetEngine |
| 7 | */ |
| 8 | |
| 9 | namespace WPParsidate\App\Integration; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | use Jet_Engine_Render_Dynamic_Field; |
| 14 | use WPParsidate\Addons\Addon; |
| 15 | use WPParsidate\Helper\Date; |
| 16 | |
| 17 | class JetEngine extends Addon { |
| 18 | public string $addonID = 'jet_engine'; |
| 19 | public string $currentTab = 'integration'; |
| 20 | |
| 21 | public function initAction(): void { |
| 22 | // Dynamic Field rendering |
| 23 | add_filter( 'jet-engine/listings/dynamic-field/custom-value', [ $this, 'convertDateMeta' ], 10, 3 ); |
| 24 | |
| 25 | // Table Builder - Hook into meta retrieval for all sources |
| 26 | add_filter( 'jet-engine/listing/data/get-post-meta', [ $this, 'convertTableBuilderDateMeta' ], 10, 3 ); |
| 27 | add_filter( 'jet-engine/listing/data/get-term-meta', [ $this, 'convertTableBuilderDateMeta' ], 10, 3 ); |
| 28 | add_filter( 'jet-engine/listing/data/get-user-meta', [ $this, 'convertTableBuilderDateMeta' ], 10, 3 ); |
| 29 | add_filter( 'jet-engine/listing/data/get-comment-meta', [ $this, 'convertTableBuilderDateMeta' ], 10, 3 ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Convert dates in Table Builder cells and metabox display |
| 34 | * Handles dates retrieved from post/term/user/comment meta |
| 35 | * |
| 36 | * @param mixed $value Meta value |
| 37 | * @param string $metaKey Meta key name |
| 38 | * @param int $objectId Object ID (post, term, user, etc) |
| 39 | * |
| 40 | * @return mixed |
| 41 | */ |
| 42 | public function convertTableBuilderDateMeta( $value, $metaKey, $objectId ) { |
| 43 | if ( is_admin() || ( $this->getSetting( 'date_to_shamsi', false ) === false && $this->getSetting( 'datetime_to_shamsi', false ) === false ) ) { |
| 44 | return $value; |
| 45 | } |
| 46 | |
| 47 | return $this->convertDate( $value ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Convert date/datetime meta value to Shamsi date in Dynamic Fields |
| 52 | * |
| 53 | * @param string|null $value Value |
| 54 | * @param array $settings Settings |
| 55 | * @param Jet_Engine_Render_Dynamic_Field $dynamicField Field |
| 56 | * |
| 57 | * @return null|string |
| 58 | */ |
| 59 | public function convertDateMeta( ?string $value, array $settings, Jet_Engine_Render_Dynamic_Field $dynamicField ): ?string { |
| 60 | $source = $dynamicField->get( 'dynamic_field_source' ); |
| 61 | if ( $source !== 'meta' || is_admin() || ( $this->getSetting( 'date_to_shamsi', false ) === false && $this->getSetting( 'datetime_to_shamsi', false ) === false ) ) { |
| 62 | return $value; |
| 63 | } |
| 64 | |
| 65 | $objectContext = $dynamicField->get( 'object_context' ); |
| 66 | $field = ! empty( $settings['dynamic_field_post_meta_custom'] ) ? $settings['dynamic_field_post_meta_custom'] : false; |
| 67 | |
| 68 | if ( ! $field && isset( $settings['dynamic_field_post_meta'] ) ) { |
| 69 | $field = ! empty( $settings['dynamic_field_post_meta'] ) ? $settings['dynamic_field_post_meta'] : false; |
| 70 | } |
| 71 | |
| 72 | if ( $field ) { |
| 73 | $result = jet_engine()->listings->data->get_meta_by_context( $field, $objectContext ); |
| 74 | if ( $result ) { |
| 75 | return $this->convertDate( $value ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return $value; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Convert date base on input format |
| 84 | * |
| 85 | * @param mixed $date date string |
| 86 | * |
| 87 | * @return string Shamsi date |
| 88 | */ |
| 89 | private function convertDate( $date ): string { |
| 90 | if ( ! is_string( $date ) ) { |
| 91 | return $date; |
| 92 | } |
| 93 | |
| 94 | $value = $date; |
| 95 | $isDate = Date::isDateString( $date, 'Y-m-d' ); |
| 96 | $isDateTime = Date::isDateString( $date, 'Y-m-d\TH:i' ); |
| 97 | |
| 98 | if ( $isDate['type'] === 'gregorian' && $this->getSetting( 'date_to_shamsi', false ) ) { |
| 99 | $value = parsidate( $this->getSetting( 'date_format', 'j F Y' ), $date, true ); |
| 100 | |
| 101 | } else if ( $isDateTime['type'] === 'gregorian' && $this->getSetting( 'datetime_to_shamsi', false ) ) { |
| 102 | $value = parsidate( $this->getSetting( 'datetime_format', 'j F Y, g:i a' ), $date, true ); |
| 103 | } |
| 104 | |
| 105 | return $value; |
| 106 | } |
| 107 | |
| 108 | public function addSectionSettings( $sections ) { |
| 109 | $sections[ $this->addonID ] = array( |
| 110 | 'title' => esc_html__( 'Jet Engine', 'wp-parsidate' ), |
| 111 | 'desc' => esc_html__( 'ParsiDate integration for Jet Engine', 'wp-parsidate' ), |
| 112 | 'settings_key' => $this->addonID, |
| 113 | 'settings' => [ |
| 114 | 'jetengine_start_grid' => array( |
| 115 | 'id' => 'edd_start_grid', |
| 116 | 'title' => esc_html__( 'Meta date field conversion', 'wp-parsidate' ), |
| 117 | 'type' => 'startGrid', |
| 118 | ), |
| 119 | 'convert_notice' => array( |
| 120 | 'id' => 'convert_notice', |
| 121 | 'notices' => array( |
| 122 | array( |
| 123 | 'message' => esc_html__( 'Currently only "Dynamic Field" is supported.', 'wp-parsidate' ), |
| 124 | 'type' => 'warning' |
| 125 | ) |
| 126 | ), |
| 127 | 'type' => 'notice', |
| 128 | ), |
| 129 | 'date_to_shamsi' => array( |
| 130 | 'id' => 'date_to_shamsi', |
| 131 | 'title' => esc_html__( 'Date field to Shamsi', 'wp-parsidate' ), |
| 132 | 'type' => 'toggle', |
| 133 | 'default' => false, |
| 134 | 'sanitize' => 'bool' |
| 135 | ), |
| 136 | 'date_format' => array( |
| 137 | 'id' => 'date_format', |
| 138 | 'title' => esc_html__( 'Date format', 'wp-parsidate' ), |
| 139 | 'type' => 'text', |
| 140 | 'default' => 'j F Y', |
| 141 | 'class' => 'ltr-field', |
| 142 | ), |
| 143 | 'datetime_to_shamsi' => array( |
| 144 | 'id' => 'datetime_to_shamsi', |
| 145 | 'title' => esc_html__( 'Datetime field to Shamsi', 'wp-parsidate' ), |
| 146 | 'type' => 'toggle', |
| 147 | 'default' => false, |
| 148 | 'sanitize' => 'bool' |
| 149 | ), |
| 150 | 'datetime_format' => array( |
| 151 | 'id' => 'datetime_format', |
| 152 | 'title' => esc_html__( 'Datetime format', 'wp-parsidate' ), |
| 153 | 'type' => 'text', |
| 154 | 'default' => 'j F Y, g:i a', |
| 155 | 'class' => 'ltr-field', |
| 156 | ), |
| 157 | 'jetengine_end_grid' => array( |
| 158 | 'type' => 'endGrid', |
| 159 | ) |
| 160 | ] |
| 161 | ); |
| 162 | |
| 163 | return $sections; |
| 164 | } |
| 165 | |
| 166 | public function info(): array { |
| 167 | $svg = '<svg width="255" height="69" viewBox="0 0 255 69" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M127.732 0.00520562C130.434 -0.14649 131.976 3.05172 130.18 5.08471L114.199 23.1808C112.327 25.2999 108.84 23.9452 108.876 21.1133L108.971 13.7711C108.984 12.8091 108.544 11.8973 107.785 11.3102L101.991 6.82848C99.7564 5.09993 100.863 1.5136 103.679 1.35547L127.732 0.00520562Z" fill="#9D64ED"></path> <path d="M6.02065 59.8968C19.315 59.8968 30.1032 49.0912 30.1032 35.7565V17.6551C30.1032 14.3138 27.4138 11.6162 24.0826 11.6162C20.7514 11.6162 18.0619 14.3138 18.0619 17.6551V35.7565C18.0619 42.4238 12.6678 47.8343 6.02065 47.8343C2.68943 47.8343 0 50.5319 0 53.8579C0 57.1839 2.68943 59.8968 6.02065 59.8968Z" fill="#0f1629"></path> <path d="M107.057 47.8343C100.41 47.8343 95.0162 42.4238 95.0162 35.7565V35.1741H99.7991C103.13 35.1741 105.835 32.4612 105.835 29.1199C105.835 25.7785 103.13 23.0656 99.7991 23.0656H95.0162V17.6551C95.0162 14.3291 92.3268 11.6162 88.9956 11.6162C85.6643 11.6162 82.9749 14.3138 82.9749 17.6551V35.7565C82.9749 49.0912 93.7632 59.8968 107.057 59.8968C110.389 59.8968 113.078 57.1992 113.078 53.8579C113.078 50.5166 110.389 47.8343 107.057 47.8343Z" fill="#0f1629"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M79.5521 27.2807C79.5521 27.2807 79.5369 27.2807 79.5216 27.296C80.1481 28.936 80.0564 30.8213 79.109 32.4613C78.3297 33.8407 77.0767 34.791 75.6708 35.2202L51.4201 46.5163C55.4696 48.7541 60.2677 48.3709 63.874 45.9339C64.9437 44.8916 66.4106 44.2632 68.0151 44.2632C71.3311 44.2632 74.0205 46.9608 74.0205 50.2868C74.0205 52.4479 72.8897 54.3485 71.1783 55.4061L71.2241 55.4674C63.7976 60.8625 53.6206 61.7209 45.1703 56.8162C33.6944 50.1488 29.7519 35.3888 36.3838 23.8474C43.0004 12.2907 57.67 8.33629 69.1612 15.0189C74.1122 17.9005 77.6573 22.284 79.5521 27.2807ZM65.1118 26.8669C64.5158 26.3457 63.874 25.8706 63.1558 25.4568C57.4102 22.1308 50.0754 24.108 46.7595 29.871C45.6287 31.8482 45.1092 34.0093 45.155 36.1398L65.1118 26.8669Z" fill="#0f1629"></path> <path d="M198.625 59.2103C198.927 59.4846 199.325 59.6218 199.818 59.6218C200.285 59.6218 200.655 59.4846 200.929 59.2103C201.231 58.9085 201.382 58.5108 201.382 58.017V38.7186C201.382 38.2248 201.231 37.8408 200.929 37.5664C200.655 37.2647 200.285 37.1138 199.818 37.1138C199.325 37.1138 198.927 37.2647 198.625 37.5664C198.351 37.8408 198.214 38.2248 198.214 38.7186V58.017C198.214 58.5108 198.351 58.9085 198.625 59.2103Z" fill="#0f1629"></path> <path d="M198.214 32.176C198.653 32.615 199.174 32.8344 199.777 32.8344C200.408 32.8344 200.943 32.615 201.382 32.176C201.821 31.7371 202.04 31.2022 202.04 30.5713C202.04 29.8855 201.807 29.3505 201.341 28.9665C200.902 28.555 200.395 28.3493 199.818 28.3493C199.215 28.3493 198.68 28.555 198.214 28.9665C197.775 29.3505 197.555 29.8855 197.555 30.5713C197.555 31.2022 197.775 31.7371 198.214 32.176Z" fill="#0f1629"></path> <path d="M144.741 59.2103C145.043 59.4846 145.441 59.6218 145.934 59.6218C146.401 59.6218 146.771 59.4846 147.045 59.2103C147.347 58.9085 147.498 58.5245 147.498 58.0582V45.8783C147.498 44.7262 147.814 43.6975 148.445 42.7922C149.075 41.887 149.926 41.1737 150.996 40.6525C152.093 40.1313 153.314 39.8707 154.658 39.8707C156.743 39.8707 158.485 40.4879 159.884 41.7224C161.31 42.9294 162.023 44.8085 162.023 47.3597V58.0582C162.023 58.4971 162.174 58.8674 162.476 59.1691C162.778 59.4709 163.162 59.6218 163.628 59.6218C164.067 59.6218 164.437 59.4709 164.739 59.1691C165.041 58.8674 165.192 58.4971 165.192 58.0582V47.3597C165.192 45.1102 164.739 43.2037 163.834 41.6401C162.956 40.0765 161.749 38.8969 160.213 38.1014C158.677 37.2784 156.935 36.8669 154.987 36.8669C153.478 36.8669 152.066 37.155 150.749 37.731C149.46 38.3071 148.376 39.1026 147.498 40.1176V38.7186C147.498 38.2248 147.347 37.8408 147.045 37.5664C146.771 37.2647 146.401 37.1138 145.934 37.1138C145.441 37.1138 145.043 37.2647 144.741 37.5664C144.467 37.8408 144.33 38.2248 144.33 38.7186V58.0582C144.33 58.5245 144.467 58.9085 144.741 59.2103Z" fill="#0f1629"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M124.568 58.3873C126.296 59.3475 128.271 59.8275 130.493 59.8275C131.783 59.8275 133.127 59.5806 134.526 59.0869C135.925 58.5656 137.077 57.921 137.982 57.1529C138.311 56.8786 138.462 56.5494 138.435 56.1653C138.435 55.7813 138.257 55.4247 137.9 55.0955C137.626 54.876 137.297 54.78 136.912 54.8075C136.528 54.8075 136.186 54.9309 135.884 55.1778C135.28 55.699 134.471 56.1379 133.456 56.4945C132.468 56.8237 131.481 56.9883 130.493 56.9883C128.957 56.9883 127.586 56.6728 126.379 56.0419C125.172 55.3835 124.198 54.492 123.457 53.3673C122.716 52.2151 122.264 50.8984 122.099 49.4171H138.723C139.162 49.4171 139.519 49.2936 139.793 49.0467C140.067 48.7724 140.204 48.4158 140.204 47.9769C140.204 45.8372 139.779 43.9307 138.929 42.2573C138.078 40.584 136.871 39.2809 135.308 38.3482C133.772 37.3881 131.961 36.9081 129.876 36.9081C127.764 36.9081 125.899 37.4018 124.28 38.3894C122.662 39.3769 121.386 40.7348 120.453 42.4631C119.548 44.1638 119.095 46.1389 119.095 48.3884C119.095 50.6104 119.575 52.5855 120.536 54.3137C121.523 56.0419 122.867 57.3998 124.568 58.3873ZM124.65 41.7224C126.022 40.4056 127.764 39.7473 129.876 39.7473C131.961 39.7473 133.648 40.4056 134.937 41.7224C136.254 43.0117 137.022 44.6988 137.242 46.7836H122.181C122.456 44.6988 123.279 43.0117 124.65 41.7224Z" fill="#0f1629"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M180.859 59.8275C178.692 59.8275 176.772 59.3475 175.098 58.3873C173.425 57.3998 172.108 56.0419 171.148 54.3137C170.216 52.5855 169.749 50.6104 169.749 48.3884C169.749 46.1389 170.243 44.1501 171.231 42.4219C172.218 40.6937 173.576 39.3495 175.304 38.3894C177.032 37.4018 178.994 36.9081 181.188 36.9081C183.41 36.9081 185.372 37.4018 187.073 38.3894C188.801 39.3495 190.145 40.6937 191.105 42.4219C192.093 44.1501 192.6 46.1389 192.628 48.3884V56.7826C192.628 59.0046 192.134 60.9934 191.146 62.749C190.159 64.5321 188.814 65.9311 187.114 66.9461C185.413 67.9885 183.465 68.5098 181.271 68.5098C179.104 68.5098 177.197 68.0983 175.551 67.2753C173.905 66.4798 172.547 65.3825 171.477 63.9835C171.176 63.6543 171.039 63.2977 171.066 62.9136C171.121 62.5296 171.327 62.2141 171.683 61.9672C172.04 61.7203 172.438 61.638 172.876 61.7203C173.315 61.8026 173.658 62.0084 173.905 62.3375C174.701 63.3251 175.716 64.1206 176.95 64.7241C178.212 65.3276 179.666 65.6294 181.312 65.6294C182.848 65.6294 184.233 65.2591 185.468 64.5184C186.702 63.7777 187.676 62.7353 188.389 61.3911C189.13 60.047 189.5 58.4696 189.5 56.6591V54.7663C188.677 56.3299 187.511 57.5644 186.003 58.4696C184.521 59.3749 182.807 59.8275 180.859 59.8275ZM181.188 56.9472C182.807 56.9472 184.233 56.5905 185.468 55.8773C186.73 55.1366 187.717 54.1217 188.43 52.8324C189.144 51.5431 189.5 50.0617 189.5 48.3884C189.5 46.715 189.144 45.2337 188.43 43.9444C187.717 42.6276 186.73 41.6127 185.468 40.8994C184.233 40.1588 182.807 39.7884 181.188 39.7884C179.57 39.7884 178.13 40.1588 176.868 40.8994C175.606 41.6127 174.618 42.6276 173.905 43.9444C173.192 45.2337 172.835 46.715 172.835 48.3884C172.835 50.0617 173.192 51.5431 173.905 52.8324C174.618 54.1217 175.606 55.1366 176.868 55.8773C178.13 56.5905 179.57 56.9472 181.188 56.9472Z" fill="#0f1629"></path> <path d="M209.82 59.6218C209.326 59.6218 208.928 59.4846 208.627 59.2103C208.352 58.9085 208.215 58.5245 208.215 58.0582V38.7186C208.215 38.2248 208.352 37.8408 208.627 37.5664C208.928 37.2647 209.326 37.1138 209.82 37.1138C210.286 37.1138 210.657 37.2647 210.931 37.5664C211.233 37.8408 211.384 38.2248 211.384 38.7186V40.1176C212.261 39.1026 213.345 38.3071 214.634 37.731C215.951 37.155 217.364 36.8669 218.873 36.8669C220.82 36.8669 222.562 37.2784 224.098 38.1014C225.635 38.8969 226.842 40.0765 227.719 41.6401C228.625 43.2037 229.077 45.1102 229.077 47.3597V58.0582C229.077 58.4971 228.926 58.8674 228.625 59.1691C228.323 59.4709 227.953 59.6218 227.514 59.6218C227.047 59.6218 226.663 59.4709 226.362 59.1691C226.06 58.8674 225.909 58.4971 225.909 58.0582V47.3597C225.909 44.8085 225.196 42.9294 223.769 41.7224C222.37 40.4879 220.628 39.8707 218.543 39.8707C217.199 39.8707 215.979 40.1313 214.881 40.6525C213.811 41.1737 212.961 41.887 212.33 42.7922C211.699 43.6975 211.384 44.7262 211.384 45.8783V58.0582C211.384 58.5245 211.233 58.9085 210.931 59.2103C210.657 59.4846 210.286 59.6218 209.82 59.6218Z" fill="#0f1629"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M239.107 58.3873C240.836 59.3475 242.811 59.8275 245.033 59.8275C246.322 59.8275 247.666 59.5806 249.065 59.0869C250.464 58.5656 251.616 57.921 252.522 57.1529C252.851 56.8786 253.002 56.5494 252.974 56.1653C252.974 55.7813 252.796 55.4247 252.439 55.0955C252.165 54.876 251.836 54.78 251.452 54.8075C251.068 54.8075 250.725 54.9309 250.423 55.1778C249.82 55.699 249.01 56.1379 247.995 56.4945C247.008 56.8237 246.02 56.9883 245.033 56.9883C243.497 56.9883 242.125 56.6728 240.918 56.0419C239.711 55.3835 238.737 54.492 237.996 53.3673C237.256 52.2151 236.803 50.8984 236.639 49.4171H253.262C253.701 49.4171 254.058 49.2936 254.332 49.0467C254.607 48.7724 254.744 48.4158 254.744 47.9769C254.744 45.8372 254.319 43.9307 253.468 42.2573C252.618 40.584 251.411 39.2809 249.847 38.3482C248.311 37.3881 246.5 36.9081 244.416 36.9081C242.303 36.9081 240.438 37.4018 238.819 38.3894C237.201 39.3769 235.925 40.7348 234.993 42.4631C234.087 44.1638 233.635 46.1389 233.635 48.3884C233.635 50.6104 234.115 52.5855 235.075 54.3137C236.062 56.0419 237.407 57.3998 239.107 58.3873ZM239.19 41.7224C240.561 40.4056 242.303 39.7473 244.416 39.7473C246.5 39.7473 248.187 40.4056 249.477 41.7224C250.793 43.0117 251.562 44.6988 251.781 46.7836H236.721C236.995 44.6988 237.818 43.0117 239.19 41.7224Z" fill="#0f1629"></path> </svg>'; |
| 168 | |
| 169 | return array( |
| 170 | 'id' => $this->addonID, |
| 171 | 'title' => esc_html__( 'Jet Engine', 'wp-parsidate' ), |
| 172 | 'desc' => esc_html__( 'ParsiDate integration for Jet Engine', 'wp-parsidate' ), |
| 173 | 'force_enable' => false, |
| 174 | 'icon' => $svg, |
| 175 | 'image_link' => 'https://crocoblock.com/plugins/jetengine/', |
| 176 | 'tags' => [ esc_html__( 'Meta', 'wp-parsidate' ) ], |
| 177 | 'cat' => 'integration', |
| 178 | 'settings_key' => $this->addonID, |
| 179 | 'requires_plugins' => [ |
| 180 | 'jet-engine/jet-engine.php' => array( |
| 181 | 'is_wp_plugin' => false, |
| 182 | 'is_free' => false, |
| 183 | 'plugin_link' => 'https://crocoblock.com/plugins/jetengine/', |
| 184 | 'class_check' => 'Jet_Engine', |
| 185 | 'function_check' => 'jet_engine', |
| 186 | ) |
| 187 | ] |
| 188 | ); |
| 189 | } |
| 190 | } |
| 191 |