column
11 years ago
storage_model
11 years ago
addons.php
11 years ago
column.php
11 years ago
settings.php
11 years ago
storage_model.php
11 years ago
third_party.php
11 years ago
upgrade.php
11 years ago
utility.php
11 years ago
third_party.php
198 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Fix for getting the columns loaded by WordPress SEO Yoast |
| 5 | * |
| 6 | * The added columns from WordPress SEO by Yoast weren't available on |
| 7 | * the admin columns settings page. The reason was that class-metabox.php was prevented |
| 8 | * from loading. This fix will also load this class when admin columns is loaded. |
| 9 | * |
| 10 | * @since 1.4.6 |
| 11 | */ |
| 12 | function cpac_pre_load_wordpress_seo_class_metabox() { |
| 13 | |
| 14 | if ( ! defined('WPSEO_PATH') || ! file_exists( WPSEO_PATH . 'admin/class-metabox.php' ) ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | global $pagenow; |
| 19 | |
| 20 | // page is a CPAC page or CPAC ajax event |
| 21 | if ( |
| 22 | ( isset( $_GET['page'] ) && 'codepress-admin-columns' == $_GET['page'] && 'options-general.php' == $pagenow ) |
| 23 | || |
| 24 | // for when column list is populated through ajax |
| 25 | ( defined('DOING_AJAX') && DOING_AJAX && |
| 26 | ( ! empty( $_POST['type'] ) |
| 27 | || |
| 28 | ( ! empty( $_POST['plugin_id'] ) && 'cpac' === $_POST['plugin_id'] ) ) |
| 29 | ) |
| 30 | ) { |
| 31 | |
| 32 | require_once WPSEO_PATH . 'admin/class-metabox.php'; |
| 33 | if ( class_exists( 'WPSEO_Metabox', false ) ) { |
| 34 | new WPSEO_Metabox; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | add_action( 'plugins_loaded', 'cpac_pre_load_wordpress_seo_class_metabox', 0 ); |
| 40 | |
| 41 | /** |
| 42 | * WPML compatibility |
| 43 | * |
| 44 | * @since 2.0 |
| 45 | */ |
| 46 | function cac_add_wpml_columns( $storage_model ) { |
| 47 | |
| 48 | if ( ! class_exists( 'SitePress', false ) ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if ( 'post' !== $storage_model->type ) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | global $pagenow, $cpac; |
| 57 | |
| 58 | // check if we are on the correct page or when a columns is being refreshed by ajax. |
| 59 | if ( ( 'options-general.php' !== $pagenow ) && ( empty( $_POST['action'] ) || 'cpac_column_refresh' !== $_POST['action'] ) ) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | // prevent PHP errors from SitePress |
| 64 | global $sitepress, $posts, $__management_columns_posts_translations; |
| 65 | $__management_columns_posts_translations = 'not_null'; |
| 66 | $posts = get_posts( array( |
| 67 | 'post_type' => $storage_model->post_type, |
| 68 | 'numberposts' => -1 |
| 69 | )); |
| 70 | |
| 71 | // Trigger SitePress::add_posts_management_column() |
| 72 | add_filter( 'manage_' . $storage_model->post_type . 's_columns', array( $sitepress, 'add_posts_management_column' ) ); |
| 73 | } |
| 74 | add_action( 'cac/set_columns', 'cac_add_wpml_columns' ); |
| 75 | |
| 76 | /** |
| 77 | * Fix which remove the Advanced Custom Fields Type (acf) from the admin columns settings page |
| 78 | * |
| 79 | * @since 2.0 |
| 80 | * |
| 81 | * @return array Posttypes |
| 82 | */ |
| 83 | function cpac_remove_acf_from_cpac_post_types( $post_types ) { |
| 84 | if ( class_exists( 'Acf', false ) ) { |
| 85 | if ( isset( $post_types['acf'] ) ) { |
| 86 | unset( $post_types['acf'] ); |
| 87 | } |
| 88 | if ( isset( $post_types['acf-field-group'] ) ) { |
| 89 | unset( $post_types['acf-field-group'] ); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return $post_types; |
| 94 | } |
| 95 | add_filter( 'cac/post_types', 'cpac_remove_acf_from_cpac_post_types' ); |
| 96 | |
| 97 | /** |
| 98 | * bbPress - remove posttypes: forum, reply and topic |
| 99 | * |
| 100 | * The default columns of bbPress are not recognised by Admin Columns as of yet. |
| 101 | * |
| 102 | * @since 2.0 |
| 103 | * |
| 104 | * @return array Posttypes |
| 105 | */ |
| 106 | function cpac_posttypes_remove_bbpress( $post_types ) { |
| 107 | if ( class_exists( 'bbPress', false ) ) { |
| 108 | unset( $post_types['topic'] ); |
| 109 | unset( $post_types['reply'] ); |
| 110 | unset( $post_types['forum'] ); |
| 111 | } |
| 112 | |
| 113 | return $post_types; |
| 114 | } |
| 115 | add_filter( 'cac/post_types', 'cpac_posttypes_remove_bbpress' ); |
| 116 | |
| 117 | /** |
| 118 | * Fix for Ninja Forms |
| 119 | * |
| 120 | * @since 2.0 |
| 121 | * |
| 122 | * @return array Posttypes |
| 123 | */ |
| 124 | function cpac_remove_ninja_forms_from_cpac_post_types( $post_types ) { |
| 125 | if ( class_exists( 'Ninja_Forms', false ) ) { |
| 126 | if ( isset( $post_types['nf_sub'] ) ) { |
| 127 | unset( $post_types['nf_sub'] ); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return $post_types; |
| 132 | } |
| 133 | add_filter( 'cac/post_types', 'cpac_remove_ninja_forms_from_cpac_post_types' ); |
| 134 | |
| 135 | /** |
| 136 | * Add support for All in SEO columns |
| 137 | * |
| 138 | * @since 2.0 |
| 139 | */ |
| 140 | function cpac_load_aioseop_addmycolumns() { |
| 141 | if ( function_exists('aioseop_addmycolumns') ) { |
| 142 | aioseop_addmycolumns(); |
| 143 | } |
| 144 | } |
| 145 | add_action( 'cac/columns/default/posts', 'cpac_load_aioseop_addmycolumns' ); |
| 146 | |
| 147 | /** |
| 148 | * WPML Register labels |
| 149 | * |
| 150 | * To enable the translation of the column labels |
| 151 | * |
| 152 | * @since 2.0 |
| 153 | */ |
| 154 | function cpac_wpml_register_column_labels() { |
| 155 | global $cpac; |
| 156 | |
| 157 | // dont load this unless required by WPML |
| 158 | if ( !isset( $_GET['page'] ) || 'wpml-string-translation/menu/string-translation.php' !== $_GET['page'] ) return; |
| 159 | |
| 160 | foreach ( $cpac->storage_models as $storage_model ) { |
| 161 | foreach ( $storage_model->get_stored_columns() as $column_name => $options ) { |
| 162 | icl_register_string( 'Admin Columns', $storage_model->key . '_' . $column_name, stripslashes( $options['label'] ) ); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | add_action( 'wp_loaded', 'cpac_wpml_register_column_labels', 99 ); |
| 167 | |
| 168 | /** |
| 169 | * WPML Display translated label |
| 170 | * |
| 171 | * @since 2.0 |
| 172 | */ |
| 173 | function cpac_wpml_set_translated_label( $label, $column_name, $column_options, $storage_model ) { |
| 174 | |
| 175 | // register with WPML |
| 176 | if( function_exists('icl_t') ) { |
| 177 | $name = $storage_model->key . '_' . $column_name; |
| 178 | $label = icl_t( 'Admin Columns', $name, $label ); |
| 179 | } |
| 180 | |
| 181 | return $label; |
| 182 | } |
| 183 | add_filter( 'cac/headings/label', 'cpac_wpml_set_translated_label', 10, 4 ); |
| 184 | |
| 185 | /** |
| 186 | * Set WPML to be a columns screen for translation so that storage models are loaded |
| 187 | * |
| 188 | * @since 2.2 |
| 189 | */ |
| 190 | function cpac_wpml_is_cac_screen( $is_columns_screen ) { |
| 191 | |
| 192 | if ( isset( $_GET['page'] ) && $_GET['page'] == 'wpml-string-translation/menu/string-translation.php' ) { |
| 193 | return true; |
| 194 | } |
| 195 | |
| 196 | return $is_columns_screen; |
| 197 | } |
| 198 | add_filter( 'cac/is_cac_screen', 'cpac_wpml_is_cac_screen' ); |