$data = $wp_scripts->get_data( 'aioseo/js/' . $this->scriptSlug, 'data' ); if ( ! is_array( $data ) ) { $data = json_decode( str_replace( 'var aioseo = ', '', substr( $data, 0, -1 ) ), true ); } // We have to temporarily modify the query here since the query incorrectly identifies // the current page as a category page when posts are filtered by a specific category. global $wp_query; $originalQuery = clone $wp_query; $wp_query->is_category = false; $wp_query->is_tag = false; $wp_query->is_tax = false; $posts = ! empty( $data['posts'] ) ? $data['posts'] : []; $postData = $this->getPostData( $postId, $columnName ); $addonsColumnData = array_filter( aioseo()->addons->doAddonFunction( 'admin', 'renderColumnData', [ $columnName, $postId, $postData ] ) ); $wp_query = $originalQuery; foreach ( $addonsColumnData as $addonColumnData ) { $postData = array_merge( $postData, $addonColumnData ); } $posts[] = $postData; $data['posts'] = $posts; $wp_scripts->add_data( 'aioseo/js/' . $this->scriptSlug, 'data', '' ); wp_localize_script( 'aioseo/js/' . $this->scriptSlug, 'aioseo', $data ); require AIOSEO_DIR . '/app/Common/Views/admin/posts/columns.php'; } /** * Gets the post data for the column. * * @since 4.5.0 * * @param int $postId The Post ID. * @param string $columnName The column name. * @return array The post data. */ protected function getPostData( $postId, $columnName ) { $nonce = wp_create_nonce( "aioseo_meta_{$columnName}_{$postId}" ); $thePost = Models\Post::getPost( $postId ); $postType = get_post_type( $postId ); $postData = [ 'id' => $postId, 'columnName' => $columnName, 'nonce' => $nonce, 'title' => $thePost->title, 'defaultTitle' => aioseo()->meta->title->getPostTypeTitle( $postType ), 'description' => $thePost->description, 'defaultDescription' => aioseo()->meta->description->getPostTypeDescription( $postType ), 'value' => ! empty( $thePost->seo_score ) ? (int) $thePost->seo_score : 0, 'showMedia' => false, 'isSpecialPage' => aioseo()->helpers->isSpecialPage( $postId ), 'postType' => $postType, 'isPostVisible' => aioseo()->helpers->isPostPubliclyViewable( $postId ) ]; return $postData; } /** * Checks whether the AIOSEO Details column should be registered. * * @since 4.0.0 * * @return bool Whether the column should be registered. */ public function shouldRegisterColumn( $screen, $postType ) { if ( 'type' === $postType ) { $postType = '_aioseo_type'; } if ( 'edit' === $screen || 'upload' === $screen ) { if ( aioseo()->options->advanced->postTypes->all && in_array( $postType, aioseo()->helpers->getPublicPostTypes( true ), true ) ) { return true; } $postTypes = aioseo()->options->advanced->postTypes->included; if ( in_array( $postType, $postTypes, true ) ) { return true; } } return false; } }